<template>
  <div class="mod-config">
    <el-form label-position="top" style="margin-top: 1px; margin-left: 0px;">
      <el-form :inline="true" label-position="top" style="margin-top: 0px">
<!--        <el-button type="primary" @click="addModal()">新增</el-button>-->
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ '导出' }}
        </download-excel>
      </el-form>
    </el-form>
    <el-table
      :data="dataList"
      height="240"
      border
      v-loading="dataListLoading"
      style="width: 100%; ">
      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <div v-if="item.columnProp === 'codeNo'">
            <el-link style="cursor:pointer;" v-if="!item.columnHidden" @click="handleClick(scope.row)"> {{ scope.row[item.columnProp] }}</el-link>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </div>
          <div v-else>
            <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </div>
        </template>
      </el-table-column>
<!--      <el-table-column-->
<!--        header-align="center"-->
<!--        align="center"-->
<!--        width="150"-->
<!--        fixed="right"-->
<!--        label="操作">-->
<!--        <template slot-scope="scope">-->
<!--          <a type="text" size="small" @click="updateModel(scope.row)">修改</a>-->
<!--          <a type="text" size="small" @click="deleteData(scope.row)">删除</a>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
  import {
    technicalSpecificationListSearch, // 测试信息列表查询

  } from "@/api/sampleManagement/technicalSpecificationList.js"
  import Chooselist from '@/views/modules/common/Chooselist'
  export default {
    components: {
      Chooselist
    },
    data() {
      return {
        dataList: [],
        searchData: {
          site: '',
          username: this.$store.state.user.name,
          projectId: '',
          page: 1,
          limit: 1000
        },
        visible:false,
        dataListLoading: false,
        currentRow:'',
        columnList:[
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9CodeNo',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "codeNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "参数卡编码",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9Status',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "statusDesc",
            headerAlign: "center",
            align: "left",
            columnLabel: "状态",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 50
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9TestPartNo',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "testPartNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "项目料号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9PartName',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "partDesc",
            headerAlign: "center",
            align: "left",
            columnLabel: "物料名称",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 102001,
            serialNumber: '102001Table1FinalPartNo',
            tableId: '102001Table1',
            tableName: '询价信息表',
            columnProp: 'finalPartNo',
            headerAlign: 'center',
            align: 'left',
            columnLabel: 'IFS料号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 102001,
            serialNumber: '102001Table1CustomerPartNo',
            tableId: '102001Table1',
            tableName: '询价信息表',
            columnProp: 'customerPartNo',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '客户料号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9RevNo',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "revNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "版本号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 50
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9ECNFlag',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "ecnFlag",
            headerAlign: "center",
            align: "left",
            columnLabel: "ECN变更",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 50
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9EcnNo',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "ecnNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "ECN单据号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9ProofingNo',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "proofingNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "打样申请单号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9CreateDate',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "createDate",
            headerAlign: "center",
            align: "left",
            columnLabel: "创建时间",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9CreateBy',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "createBy",
            headerAlign: "center",
            align: "left",
            columnLabel: "创建人",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9UpdateDate',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "updateDate",
            headerAlign: "center",
            align: "left",
            columnLabel: "上次修改日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9UpdateBy',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "updateBy",
            headerAlign: "center",
            align: "left",
            columnLabel: "修改人",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },{
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table9ecnAddress',
            tableId: "101002001Table9",
            tableName: "技术参数卡列表",
            columnProp: "ecnAddress",
            headerAlign: "center",
            align: "left",
            columnLabel: "ECN文档链接",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200
          },
        ],
        // 导出 start
        exportData: [],
        exportName: '技术参数卡'+this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["技术参数卡"],
        exportFooter: [],
        // 导出 end
      }
    },
    methods: {
      // 获取基础数据列表S
      getBaseList (val, type) {
        this.tagNo = val
        this.tagNo1 = type
        this.$nextTick(() => {
          let strVal = ''
          // if (val === 1013) {
          //   if(type==1) {
          //     strVal = this.dataForm.partType
          //   }
          // }
          this.$refs.baseList.init(val, strVal)
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        // if (this.tagNo === 1013) {
        //   if(this.tagNo1==1) {
        //     this.dataForm.partType = val.Base_id
        //     this.dataForm.partTypeDesc = val.Base_desc
        //   }
        // }
      },
      //初始化组件的参数
      init(inData) {
        //初始化参数
        this.searchData = JSON.parse(JSON.stringify(inData));
        //刷新表格
       this.searchTable();

      },
      searchTable(){
        technicalSpecificationListSearch(this.searchData).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code == 0) {
            this.dataList = data.page.list
          } else {
            this.dataList = [];
          }
        });
      },
      createExportData() {

        return this.dataList;

      },
      startDownload() {
        //  this.exportData = this.dataList

      },
      finishDownload() {
      },
      fields() {
        let json = "{"
        this.columnList.forEach((item, index) => {
          if (index == this.columnList.length - 1) {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
          } else {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
          }
        })
        json += "}"
        let s = eval("(" + json + ")")

        return s
      },
      handleClick(row){
        if (this.$router.resolve(`/sampleManagement-technicalSpecificationList`).resolved.name === '404'){
          this.$alert('权限不足,访问失败', '警告', {confirmButtonText: '确定',});
        }else {
          this.$router.push({name:`sampleManagement-technicalSpecificationList`,params:{codeNo:row.codeNo?row.codeNo:' '},})
        }
      }
    },
  }
</script>

<style scoped>

</style>
