<!-- 证书模板 -->
<template>
  <div class="app-container certificateTemplate">
    <div class="page-container certificateTemplatePage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="shareStatus">
            <el-select v-model="queryParams.shareStatus" placeholder="是否共享" style="width: 120px">
              <el-option label="共享" value="1"/>
              <el-option label="不共享" value="0"/>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="templateType">
            <el-select v-model="queryParams.templateType" placeholder="证书类型" style="width: 200px">
              <el-option
                v-for="dict in optionClassList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="deptId">
            <el-cascader
              style="width: 180px"
              v-model="queryParams.deptId"
              :options="optionList"
              :props="{
                    emitPath:false,
                    checkStrictly: true,
                    value: 'deptId',
                    label: 'deptName',
                    children: 'child',
                  }"
              :show-all-levels="false"
              filterable
              placeholder="颁发单位"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="证书名称"
              style="width: 200px"
            />
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-submit-common-style-button"
             style="float: right;"
             @click="tableButton(1)"
             v-hasPermiRouter="['exam:certificateTemplate:add']"
          >新增</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box"  border :data="dataList">
          <el-table-column label="序号" type="index" align="center" width="50"/>
          <el-table-column label="证书模板名称" prop="templateName"  show-overflow-tooltip/>
          <el-table-column label="证书类型" prop="templateType" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.templateType==1?'考试证书':'培训证书'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="是否共享" prop="shareStatus" width="120" show-overflow-tooltip>
            <template slot-scope="scope">
              <span style="padding:2px 10px;border:1px solid rgb(1, 131, 251);border-radius:4px;color: rgb(1, 131, 251);background-color:rgba(1, 131, 251,0.2)" v-if="scope.row.shareStatus === 1">共享</span>
              <span style="padding:2px 10px;border:1px solid rgb(245, 154, 35);border-radius:4px;color: rgb(245, 154, 35);background-color:rgba(245, 154, 35,0.2)" v-if="scope.row.shareStatus === 0">不共享</span>
            </template>
          </el-table-column>
          <el-table-column label="颁发单位" prop="deptName" width="200" show-overflow-tooltip/>
          <el-table-column label="更新人" prop="updateName" width="200" show-overflow-tooltip/>
          <el-table-column label="操作" width="200" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(2,scope.row)"
                   v-hasPermiRouter="['exam:certificateTemplate:detail']"
                >预览</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-hasPermiRouter="['exam:certificateTemplate:edit']"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(4,scope.row)"
                   v-hasPermiRouter="['exam:certificateTemplate:del']"
                >删除</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <add-page :propsData="propsData" v-if="pageType === 2"></add-page>
    <fullScreenFileLook ref="fullScreenFileLook"></fullScreenFileLook>
  </div>
</template>
<script>
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  import {
    examElCertificateTemplatePage,examElExamTypeList,
    systemDeptCurrentDept,examElCertificateTemplateDel,
  } from "@/api/safetyEducationExaminationNew/index";
  import addPage from "./addPage.vue";
  import fullScreenFileLook from "@/components/fullScreenFileLook/fullScreenFileLook.vue";
  export default {
    name: 'index',
    components: {
      addPage,
      fullScreenFileLook,
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['exam:certificateTemplate:detail','exam:certificateTemplate:edit','exam:certificateTemplate:del',]),
        //页面状态
        pageType:1,
        //下拉列表数据
        optionClassList:[{value:'1',label:'考试证书'},{value:'2',label:'培训证书'},],
        optionList:[],
        queryParams:{
          page:1,
          pageSize:20,
          templateType:null,
          deptId:null,
          searchValue:'',
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      // this.examElExamTypeList();
      this.systemDeptCurrentDept();
      this.getList();
    },
    methods: {
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          templateType:null,
          deptId:null,
          shareStatus:'',
          searchValue:'',
        });
        this.getList();
      },
      //获取数据列表
      getList(){

        let obj = JSON.parse(JSON.stringify(this.queryParams))
        examElCertificateTemplatePage(obj).then(response => {

          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //证书模板列表
      examElExamTypeList(){
        examElExamTypeList({}).then(response => {
          this.$set(this,'optionClassList',response.data);
        });
      },
      //证书模板列表
      systemDeptCurrentDept(){
        systemDeptCurrentDept({}).then(response => {
          const list = response.data || [];
          this.formatTreeData(list);
          this.$set(this,'optionList',list);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //新增
          this.$set(this,'pageType',2);
          this.$set(this,'propsData',{});
        }else if(type == 2){
          //详情
          let obj = {
            name:row.templateName,
            url:localStorage.getItem('fileBrowseEnvironment') +'/'+row.templateWordPath,
            type:'docx'
          }
          this.fullScreenFileLookClick(obj);
        }else if(type == 3){
          //编辑
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          this.$set(this,'propsData',obj);
        }else if(type == 4){
          //删除
          this.$confirm('是否确认删除?', "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            examElCertificateTemplateDel({id:row.id}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 5){
          //启用&停用
          let text = row.state  ? "停用" : "启用";
          this.$confirm('是否确认' + text + '?', "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {

          }).catch(() => {});
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      fullScreenFileLookClick(item){
        this.$refs['fullScreenFileLook'].initialize(item.name,item.url,item.type);
      },
    },
  }
</script>
<style scoped lang="scss">
  .certificateTemplate{
    .certificateTemplatePage{
      .table-top-button-box{
        display: inline-block;
        vertical-align: top;
        margin-right:10px;
        div{
          display: flex;
          p{
            border:1px solid #DCDFE6;
            width:80px;
            text-align: center;
            height:40px;
            line-height:40px;
            cursor: pointer;
            font-size:14px;
          }
          p:nth-child(1){
            border-top-left-radius:4px;
            border-bottom-left-radius:4px;
          }
          p:nth-child(2){
            border-left:none;
            border-right:none;
          }
          p:nth-child(3){
            border-top-right-radius:4px;
            border-bottom-right-radius:4px;
          }
          .check-table-button{
            border:1px solid #0183fa;
            background-color: #0183fa;
            color:#fff;
          }
        }
      }
    }
  }
</style>
