<template>
  <div class="app-container">
    <!-- 搜索栏 -->
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学员" prop="staffId">
        <el-select 
          v-model="queryParams.successorId" 
          placeholder="请选择学员"
          @change="someMethod()"
        >
          <el-option
            v-for="successor in this.successorOptions"
            :key="successor.key"
            :label="successor.value"
            :value="successor.key"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="年" prop="feedbackYear">
        <el-date-picker
          v-model="queryParams.feedbackYear"
          placeholder="请选择年"
          clearable
          type="year"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="季度" prop="feedbackSeason">
        <el-select 
          v-model="queryParams.feedbackSeason" 
          placeholder="请选择季度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            label="第一季度"
            value="1">
          </el-option>
          <el-option
            label="第二季度"
            value="2">
          </el-option>
          <el-option
            label="第三季度"
            value="3">
          </el-option>
          <el-option
            label="第四季度"
            value="4">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 标签页：后期改成每个导师生成独立标签页 -->
    <el-tabs type="border-card" id="border-card">
      <el-tab-pane label="居海波">
        <el-table
          :span-method="spanMethod"
          v-loading="loading"
          :data="dataList"
          @selection-change="handleSelectionChange"
          ref="feedbackListSeasonalTable"
          border
          :cell-style="tableCellStyle"
        >
          <el-table-column label="时间" align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.feedbackYear}}年{{scope.row.feedbackMonth}}月</span>
            </template>
          </el-table-column>
          <el-table-column label="培养内容" align="center" :show-overflow-tooltip="true" prop="plantName" width="400"/>
          <el-table-column label="开始日期" align="center" :show-overflow-tooltip="true" prop="startDate"/>
          <el-table-column label="结束日期" align="center" :show-overflow-tooltip="true" prop="endDate"/>
          <el-table-column label="实际完成日期" align="center" :show-overflow-tooltip="true" prop="dateOfCompletion"/>
          <el-table-column label="学习状态" align="center" :show-overflow-tooltip="true" prop="studyState"/>
          <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-chat-dot-round"
                v-hasPermi="['spec:plan:edit']"
                @click="handleFeedback(scope.row)"
              >详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <h3>汇报展示PPT</h3>
        <div>
          <el-upload
              ref="doc"
              :headers="doc.headers"
              class="upload-demo"
              action="doc.url + '?pType=' + doc.pType + '&pId=' + doc.pId"
              :disabled="doc.isUploading"
              :on-progress="handleFileDocProgress"
              :on-success="handleFileDocSuccess"
              :auto-upload="true"
              multiple
              :limit="3">
              <el-button size="small" type="primary" style="margin-bottom:10px;">点击上传汇报展示PPT</el-button>
            </el-upload>
          <el-table :data="doc.commonfileList" border style="width:50%;">
            <el-table-column :label="$t('文件名')" align="center" prop="fileName" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <a  class="link-type"  @click="handleDownload(scope.row)">
                  <span>{{ scope.row.fileName }}</span>
                </a>
              </template>
            </el-table-column>
            <!-- <el-table-column :label="$t('大小(Kb)')" align="center" prop="fileSize" :show-overflow-tooltip="true" width="80" />
            <el-table-column :label="$t('上传人')" align="center" prop="creator" :show-overflow-tooltip="true" width="120"/> -->
            <el-table-column :label="$t('操作')" align="center" width="120" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  v-if="scope.row.fileName.endsWith('pdf')"
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="handleSee(scope.row)"
                >{{ $t('预览') }}</el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-download"
                  @click="handleDownload(scope.row)"
                >{{ $t('下载') }}</el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDeleteDoc(scope.row)"
                >{{ $t('删除') }}</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div style="display:inline-block;width:40%;">
          <h3 style="margin-bottom:0px;">学员表现</h3>
          <div class="question">
            1、学员的现场表现、语言表达、汇报逻辑如何？
          </div>
          <div class="answer">
            <el-radio-group v-model="radio1" size="small">
              <el-radio label="1">优秀</el-radio>
              <el-radio label="2">良好</el-radio>
              <el-radio label="3">一般</el-radio>
              <el-radio label="4">合格</el-radio>
            </el-radio-group>
          </div>
          <h3 style="margin-bottom:0px;">汇报材料及内容</h3>
          <div class="question">
            2、汇报材料准备是否充足，汇报材料是否紧贴课题内容？
          </div>
          <div class="answer">
            <el-radio-group v-model="radio2" size="small">
              <el-radio label="1">优秀</el-radio>
              <el-radio label="2">良好</el-radio>
              <el-radio label="3">一般</el-radio>
              <el-radio label="4">合格</el-radio>
            </el-radio-group>
          </div>
          <div class="question">
            3、学员汇报内容中是否存在明显的不足点？
          </div>
          <div class="answer">
            <el-radio-group v-model="radio3" size="small">
              <el-radio label="1">内容出色</el-radio>
              <el-radio label="2">内容完善</el-radio>
              <el-radio label="3">基本完善</el-radio>
              <el-radio label="4">合格</el-radio>
            </el-radio-group>
          </div>
          <div class="question">
            4、学员汇报内容是否符合学习材料（SOP或者程序）的要求？
          </div>
          <div class="answer">
            <el-radio-group v-model="radio4" size="small">
              <el-radio label="1">完全符合</el-radio>
              <el-radio label="2">基本符合</el-radio>
              <el-radio label="3">一般</el-radio>
              <el-radio label="4">合格</el-radio>
            </el-radio-group>
          </div>
          <div class="question">
            5、学员对本季度的学习过程、学习目标及学习结果的阐述是否具体、完整、正确？
          </div>
          <div class="answer">
            <el-radio-group v-model="radio5" size="small">
              <el-radio label="1">完整流畅</el-radio>
              <el-radio label="2">阐述清晰</el-radio>
              <el-radio label="3">一般</el-radio>
              <el-radio label="4">合格</el-radio>
            </el-radio-group>
          </div>
        </div>
        <div style="display:inline-block;width:40%;">
          <div class="question">
            6、学员的汇报内容是否具有一定的意义，与学员的现阶段表现是否一致？
          </div>
          <div class="answer">
            <el-radio-group v-model="radio6" size="small">
              <el-radio label="1">内容积极，表现高度一致</el-radio>
              <el-radio label="2">内容充分，表现良好</el-radio>
              <el-radio label="3">一般</el-radio>
              <el-radio label="4">合格</el-radio>
            </el-radio-group>
          </div>
          <div class="question">
            7、学员汇报内容是否对装置后期的管理或者生产起到一定的启发作用？
          </div>
          <div class="answer">
            <el-radio-group v-model="radio7" size="small">
              <el-radio label="1">优秀</el-radio>
              <el-radio label="2">良好</el-radio>
              <el-radio label="3">一般</el-radio>
              <el-radio label="4">合格</el-radio>
            </el-radio-group>
          </div>
          <div class="question">
            8、学员在实际工作中是否运用到培训所学内容？
          </div>
          <div class="answer">
            <el-radio-group v-model="radio8" size="small">
              <el-radio label="1">灵活运用</el-radio>
              <el-radio label="2">基本运用</el-radio>
              <el-radio label="3">初步尝试</el-radio>
              <el-radio label="4">合格</el-radio>
            </el-radio-group>
          </div>
          <div class="question">
            9、学员的汇报内容对于装置及公司的人才培养计划是否能起到帮助？
          </div>
          <div class="answer">
            <el-radio-group v-model="radio9" size="small">
              <el-radio label="1">大有裨益</el-radio>
              <el-radio label="2">推进作用</el-radio>
              <el-radio label="3">参考意义</el-radio>
              <el-radio label="4">合格</el-radio>
            </el-radio-group>
          </div>
          <div class="question">
            10、学员本次汇报相较于上次是否有提升？
          </div>
          <div class="answer">
            <el-radio-group v-model="radio10" size="small">
              <el-radio label="1">进步明显</el-radio>
              <el-radio label="2">略有进步</el-radio>
              <el-radio label="3">一般</el-radio>
              <el-radio label="4">合格</el-radio>
            </el-radio-group>
          </div>
        </div>
        <h3 style="margin-top:0px;">导师反馈</h3>
        <div>
          <el-form>
            <el-form-item>
              <editor :min-height="300"/>
            </el-form-item>
          </el-form>
        </div>
        <div style="text-align:center; margin:30px 0px;">
          <el-button size="medium" type="success">保存</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane label="朱晶">

      </el-tab-pane>
      <el-tab-pane label="张磊">

      </el-tab-pane>
    </el-tabs>
    <!-- 反馈对话框 -->
    <el-dialog v-dialogDrag :title="feedbackDialog.title" :visible.sync="feedbackDialog.open" width="800px" append-to-body>
      <div style="width:700px; margin:0px auto;">
        <h3 style="margin-bottom:20px;text-align:center;">学员心得</h3>
        <el-table :data="tableData" border style="width: 100%">
          <el-table-column prop="id" label="编号" width="50"></el-table-column>
          <el-table-column prop="question" label="问题" width="250"></el-table-column>
          <el-table-column prop="answer" label="答案"></el-table-column>
        </el-table>
        <h3 style="margin-bottom:20px;text-align:center;">学习成果</h3>
        <el-table :data="doc.commonfileList" border>
          <el-table-column :label="$t('文件名')" align="center" prop="fileName" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <a  class="link-type"  @click="handleDownload(scope.row)">
                <span>{{ scope.row.fileName }}</span>
              </a>
            </template>
          </el-table-column>
          <el-table-column :label="$t('大小(Kb)')" align="center" prop="fileSize" :show-overflow-tooltip="true" width="80" />
          <el-table-column :label="$t('上传人')" align="center" prop="creator" :show-overflow-tooltip="true" width="120"/>
          <el-table-column :label="$t('操作')" align="center" width="120" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.fileName.endsWith('pdf')"
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleSee(scope.row)"
              >{{ $t('预览') }}</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-download"
                @click="handleDownload(scope.row)"
              >{{ $t('下载') }}</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDeleteDoc(scope.row)"
              >{{ $t('删除') }}</el-button>
            </template>
          </el-table-column>
        </el-table>
        <h3 style="margin-top:30px;margin-bottom:20px;text-align:center;">导师反馈</h3>
        <el-form>
          <el-form-item>
            <editor :min-height="192" v-model="mentorFeedback"/>
            <!-- <p v-html="mentorFeedback" /> -->
          </el-form-item>
        </el-form>
        <div style="text-align:center;">
          <el-button @click="handleReject()">{{ $t('确 定') }}</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listSuccessorsByMentorId} from "@/api/training/spec/plan";
import { listFeedback } from "@/api/training/spec/feedback";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import Editor from '@/components/Editor';

export default {
  name: "SeasonalFeedback",
  components: { Treeselect, Editor },
  data() {
    return {
      
      successorOptions: [],
      queryObject: {
        mentorStaffId: ""
      },


      dataList: [],
      tableData: [],

      // 导师反馈内容
      mentorFeedback: "<p>此处稍有不足，请重新学习<br/><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIkAAAAjCAYAAACgoylBAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAUcSURBVHhe7VpBixxFFO5f5JznLioJcQ+2oEkuanYirCYq2rjJogEJUYlDENnJTfRg/sDOCIqgKwmKScDticRJrh4CCrkYkKDP+qq6el5VV3f1jN0zk7E++EhPvXqvq977+lXPbCJqGB/f+oMupr/nPPTiq7Q9/NEYswmfAkY9iqJIsEejbEhhRD0x3u1Pss8aajzqZbMnfepGXVLTYNPXwIT63YjUVOWn3YBRT8Tp9sUsARmHrcH4DF9+XXIP7EXHc0KtwdiT3D+PXbY3TGW+hfXxvak1Va+liAWI5BXa3vvBGLPpFEmGSb+rxKJ3WppwV5Gyz7ngTMrEuuLxsboimfUeHE67LeSSvQmUisS3t5poXCSf371vCODEpU/p2eQ9+uDmb8Y4J3yqwZ6I0k16RFKWGF8iZxFJafLttVlw+nIhrJlIrt57YAjgw5/v0ealz+jIy2/QxlZCz525YNhB+BjARqc9UoAnCde8hY6oLw1VibR9xEiPF7qiJcukT+OqzuYQSSEOv4f24+sTEAVTxVW+eaEBo5iwl+0NU0tEUliTtbeaaFwkfz78u3DkVBFz4WMjP2Yy8uSrRGgbT0h5Ik0fKx4KktuET9982vhauqLwzk4CVN0DMO4jaC5CFnRqZ3GlbR6RCBhr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BHgRRBLgAdG/w/eQqkOct4wAAAAASUVORK5CYII='></p>",
      // 反馈对话框参数
      feedbackDialog: {
        id: 0,
        // 是否显示弹出层（报告附件）
        open: false,
        // 弹出层标题（报告附件）
        title: ""
      },
      // 问卷单选框
      radio1: '',
      radio2: '',
      radio3: '',
      radio4: '',
      radio5: '',
      radio6: '',
      radio7: '',
      radio8: '',
      radio9: '',
      radio10: '',
      // 报告附件参数
      doc: {
        file: "",
        // 是否显示弹出层（报告附件）
        open: false,
        // 弹出层标题（报告附件）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 报告附件上传位置编号
        ids: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/common/commonfile/uploadFile",
        commonfileList: null,
        queryParams: {
          pId: null,
          pType: 'plan'
        },
        pType: 'plan',
        pId: null
      },
      // 标签页选中项
      activeName: 'first',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专项培训反馈表格数据
      feedbackList: [],
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      clientHeight:300,
      // 是否显示弹出层
      open: false,
        // 用户导入参数
        upload: {
            // 是否显示弹出层（用户导入）
            open: false,
            // 弹出层标题（用户导入）
            title: "",
            // 是否禁用上传
            isUploading: false,
            // 是否更新已经存在的用户数据
            updateSupport: 0,
            // 设置上传的请求头部
            headers: { Authorization: "Bearer " + getToken() },
            // 上传的地址
            url: process.env.VUE_APP_BASE_API + "/spec/feedback/importData"
        },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        feedbackType: null,
        mentorId: null,
        successorId: null,
        successorName: null,
        parentId: null,
        planId: null,
        feedbackYear: null,
        feedbackSeason: null,
        feedbackMonth: null,
        successorFeedback: null,
        mentorFeedback: null,
        feedbackScore: null,
        feedbackStatus: null,
        meetingDate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  watch: {
  },
  created() {
    //设置表格高度对应屏幕高度
    this.$nextTick(() => {
      this.clientHeight = document.body.clientHeight -250
    })
    // 获取学员下拉列表
    this.getSuccessorOptions();
    // 获取当前日期
    let date = new Date();
    // 搜索条件默认为当年、当季度
    this.queryParams.feedbackYear = date.getFullYear().toString();
    this.queryParams.feedbackSeason = ( ( date.getMonth() + 2 ) / 3 ).toString();
    // 获取计划列表
    this.getList();
  },
  methods: {
    /** 查询学员下拉列表 */
    getSuccessorOptions() {
      listSuccessorsByMentorId(this.queryObject).then(response => {
        let successorList = response.data;
        for (let i = 0; i < successorList.length; i++) {
          if (i == 0) {
            // 默认选中列表中第一个学员
            this.queryParams.successorId = successorList[i].staffId;
          }
          let successor = {};
          successor.key = successorList[i].staffId;
          successor.value = successorList[i].staffName;
          this.successorOptions.push(successor);
        }
      });
    },
    /** 反馈处理 */
    handleFeedback(row) {
      this.feedbackDialog.title = "李滕 " + row.plantName + " " + this.$t('学习情况');
      this.feedbackDialog.open = true;
    },
    /** 合并单元格 */
    spanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (row.isFirstLine == 1) {
          return {
            rowspan: 3,
            colspan: 1
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
      }
    },
    /** 单元格样式 */
    tableCellStyle (row, column, rowIndex, columnIndex) {
      if (row.column.label === "实际完成日期" && row.row.dateOfCompletion > row.row.endDate) {
        return "background: #FFEEEE"
      }
    },
    /** 报告附件按钮操作 */
    handleDoc(row) {
      this.doc.id = row.id;
      this.doc.title = row.plantName + this.$t('附件');
      this.doc.open = true;
      this.doc.queryParams.pId = row.id
      this.doc.pId = row.id
      this.getFileList()
      this.$nextTick(() => {
        this.$refs.doc.clearFiles()
      })
    },
    getFileList (){
      allFileList(this.doc.queryParams).then(response => {
        this.doc.commonfileList = response;
      });
    },
    /** 附件上传中处理 */
    handleFileDocProgress(event, file, fileList) {
      this.doc.file = file;
      this.doc.isUploading = true;
    },
    /** 附件上传成功处理 */
    handleFileDocSuccess(response, file, fileList) {
      this.doc.isUploading = false;
      this.$alert(response.msg, this.$t('导入结果'), { dangerouslyUseHTMLString: true });
      this.getFileList()
    },





    /** 查询专项培训反馈列表 */
    getList() {
      this.loading = true;
      listFeedback(this.queryParams).then(response => {
        this.feedbackList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        feedbackType: null,
        mentorId: null,
        successorId: null,
        successorName: null,
        parentId: null,
        planId: null,
        feedbackYear: null,
        feedbackSeason: null,
        feedbackMonth: null,
        successorFeedback: null,
        mentorFeedback: null,
        feedbackScore: null,
        feedbackStatus: 0,
        meetingDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  }
};
</script>

<style scoped>
  .question,.answer{
    margin: 30px 0px;
    padding-left: 20px;
  }
  h3{
    margin: 30px 0px;
  }
</style>