<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="企业名称" prop="companyName">
          <el-input
            v-model="queryParams.companyName"
            placeholder="请输入企业名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="证照类型" prop="licenseType">
        <el-select
                clearable
                v-model="queryParams.licenseType"
                style="width: 200px"
              >
                <el-option
                  v-for="level in licenseTypeList"
                  :key="level.value"
                  :label="level.label"
                  :value="level.value"
                >
                </el-option>
              </el-select>
      </el-form-item>
        <el-form-item label="证照名称" prop="licenseName">
          <el-input
            v-model="queryParams.licenseName"
            placeholder="请输入证照名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" 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-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="企业属性" align="center" prop="companyAttributes">
            <template slot-scope="scope">
                {{ scope.row.companyAttributes == '1' ?  '客户' : scope.row.companyAttributes == '0' ? '供应商' : '未知' }}
            </template>
        </el-table-column>
        <el-table-column label="企业名称" align="center" prop="companyName" />
        <el-table-column label="证照类型" align="center" prop="licenseType" />
        <el-table-column label="证照编号" align="center" prop="licenseNumber" />
        <el-table-column label="证照名称" align="center" prop="licenseName" />
        <el-table-column label="颁发日期 " align="center" prop="licenseDate" />
        <el-table-column label="预警天数" align="center" prop="warningDays" />
        <el-table-column label="有效期至" align="center" prop="validUntil" />
        <el-table-column label="工单状态" align="center" prop="workState">
            <template slot-scope="scope">
                {{ scope.row.workState == '1' ?  '草稿' : scope.row.workState == '2' ? '审批中' : scope.row.workState == '3' ? '已审批' : '待处理' }}
            </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
            >编辑</el-button>
            <el-button
              size="mini"
              type="text"
              @click="handleInfo(scope.row)"
            >查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
    </div>
  </template>
  
  <script>
  import { listInfo, getLicenseType } from "@/api/qualityControl/qualityControl.js";
  
  export default {
    name: "Info",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 合作企业证照表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          status: 0,
          companyAttributes: null,
          companyName: null,
          licenseType: null,
          licenseNumber: null,
          licenseName: null,
          licenseDate: null,
          warningDays: null,
          validUntil: null,
          workState: null,
        },
        licenseTypeList : [{
          value: 'A',
          label: 'A'
        }, {
          value: 'B',
          label: 'B'
        }, {
          value: 'C',
          label: 'C'
        }],
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
      getLicenseType().then(res=>{
            if(res.code == '200'){
                this.licenseTypeList = res.data
            }
        });
    },
    methods: {
      /** 查询合作企业证照列表 */
      getList() {
        this.loading = true;
        listInfo(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          status: 0,
          companyAttributes: null,
          companyName: null,  
          licenseType: null,
          licenseNumber: null,
          licenseName: null,
          licenseDate: null,
          warningDays: null,
          validUntil: null,
          workState: 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
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        if(row.companyAttributes == '1'){
            // 客户
            this.$router.push({ path: '/qualityControl/khDetail',  query:{'companyCode': row.companyId, 'licenseNumber': row.id, 'isFlag': false} });
        }
        if(row.companyAttributes == '0'){
            // 供应商
            this.$router.push({ path: '/qualityControl/gysDetail',  query:{'companyCode': row.companyId, 'licenseNumber': row.id, 'isFlag': false} });
        }
        if(row.companyAttributes == '3'){
            // 客户和供应商
            
        }
      },
      /** 查看按钮操作 */
      handleInfo(row) {
        this.reset();
        if(row.companyAttributes == '1'){
            // 客户
            this.$router.push({ path: '/qualityControl/khDetail',  query:{'companyCode': row.companyId, 'licenseNumber': row.id, 'isFlag': true} });
        }
        if(row.companyAttributes == '0'){
            // 供应商
            this.$router.push({ path: '/qualityControl/gysDetail',  query:{'companyCode': row.companyId, 'licenseNumber': row.id, 'isFlag': true} });
        }
        if(row.companyAttributes == '3'){
            // 客户和供应商
            
        }
      },
    }
  };
  </script>
  