<template>

  <div>
    <el-col :span="24" class="text-right">
      <el-button
        type="primary"
        plain
        icon="el-icon-printer"
        size="mini"
        class="mb10"
        :loading="printLoading"
        @click="handlePrint"
      >检验单打印</el-button>
    </el-col>
    <!-- 列表 -->
    <AutoResizer :given-height="250">
      <template #default="{height}">
        <el-table
          v-if="columnsList.length > 0"
          v-loading="loading"
          :data="list"
          :height="height"
          border
        >
          <el-table-column
            v-if="columnsList[5].visible"
            :key="Math.random()"
            label="检验单号"
            align="center"
            prop="id"
          />
          <el-table-column
            v-if="columnsList[6].visible"
            :key="Math.random()"
            label="入库单号"
            align="center"
            prop="warehousingOrderNo"
          />
          <el-table-column
            v-if="columnsList[7].visible"
            :key="Math.random()"
            label="检验时间"
            align="center"
            prop="createTime"
            width="160"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnsList[8].visible"
            :key="Math.random()"
            label="检验人"
            align="center"
            prop="creator"
            width="120"
            :formatter="handleName"
          />
          <el-table-column
            v-if="columnsList[4].visible"
            :key="Math.random()"
            label="检验状态"
            align="center"
            prop="status"
          >
            <template slot-scope="scope">
              <dict-tag :type="DICT_TYPE.WMS_TEST_STATUS" :value="scope.row.status" />
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnsList[9].visible"
            :key="Math.random()"
            label="检验结果"
            align="center"
            prop="inspection"
          >
            <template slot-scope="scope">
              <dict-tag :type="DICT_TYPE.WMS_TEST_RESULT" :value="scope.row.inspection" />
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="160"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                v-hasPermi="['wms:incoming-stock:update']"
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleView(scope.row)"
              >检验详情</el-button>
              <el-button
                type="text"
                icon="el-icon-magic-stick"
                size="mini"
                @click="handleResetInspection(scope.row)"
              >重新检验</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </AutoResizer>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 检验详情 -->
    <ViewTempInspect ref="viewTempInspect" />
    <!-- 检验单打印 -->
    <FilePreview v-model="filePreviewvisible" :src="'data:application/pdf;base64,'+baseData" />
  </div>

</template>

<script>
import { getFqcInspectedPage, updatefqcReinspection } from '@/api/wms/quality/tempInspectionExecute'
import { getExportPdf } from '@/api/common'
import FilePreview from '@/components/FilePreview'
import { getFormColumnsList } from '@/api/system/saveColumns/index'
import { mapGetters } from 'vuex'
import { isArray } from 'min-dash'
import ViewTempInspect from './ViewTempInspect.vue'

// import { log } from 'bpmn-js-token-simulation'
export default {
  name: 'AwaitWare',
  components: {
    ViewTempInspect,
    FilePreview
  },
  props: {
    'activeName': {
      type: String,
      default: ''
    },
    'queryParamspro': {
      type: Object,
      default: () => {}
    }
  },
  inject: ['paramsQuery'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 领料单列表
      list: [],
      // 是否显示弹出层
      open: false,
      baseData: '',
      printLoading: false,
      filePreviewvisible: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        type: 1
      },
      currentRows: [],
      users: [],
      //   表单参数
      form: {},
      // 表单校验
      rules: {},
      // 显示隐藏列参数
      columns: [
        { key: 0, label: '生产入库单号', visible: true },
        { key: 1, label: '申请入库时间', visible: true },
        { key: 2, label: '申请人', visible: true },
        { key: 3, label: '入库箱数', visible: true },
        { key: 4, label: '检验状态', visible: true },
        { key: 5, label: '检验单号', visible: true },
        { key: 6, label: '入库单号', visible: true },
        { key: 7, label: '检验时间', visible: true },
        { key: 8, label: '检验人', visible: true },
        { key: 9, label: '检验结果', visible: true }
      ],
      // 显示隐藏持久化参数
      columnsList: []
    }
  },
  computed: {
    ...mapGetters([
      'userId'
    ])
  },
  created() {
    // 获取显隐列列表
    this.getColumnsList()
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 执行查询
      const params = {
        ...this.paramsQuery,
        ...this.queryParams
      }
      getFqcInspectedPage(params).then(response => {
        this.list = response.data.list
        this.total = response.data.total
        this.users = response.data.users
        this.loading = false
      }).finally(() => {
        this.loading = false
      })
    },
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        wmsIncomingReceiptId: undefined,
        orderType: undefined,
        erpStockId: undefined,
        wmsStoreAreaId: undefined,
        wmsStoreId: undefined,
        inQty: undefined,
        funitId: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    // 重新检验
    handleResetInspection(row) {
      const { materialNo, materialLots, id, warehousingOrderNo } = row
      const params = {
        id,
        materialNo,
        materialLots,
        type: this.queryParams.type,
        warehousingOrderNo
      }
      updatefqcReinspection(params).then(res => {
        this.$modal.msgSuccess('操作成功')
        this.$emit('fqcspectedComplete')
        this.getList()
      })
    },
    handleName(row, column, cellValue) {
      const user = this.users.find(item => item.id.toString() === cellValue)
      return user && user.nickname
    },
    // 单据打印
    handlePrint() {
      const params = {
        excelConfigId: '760673760947855360',
        queryParam: {
          jigNo: '夹具码AA12',
          locationNo: '位置码AA',
          hotPressId: '002',
          qualified: 1
        }
      }
      getExportPdf(params).then(res => {
        const { file } = res.result
        this.baseData = file
        this.filePreviewvisible = true
        this.printLoading = true
      }).finally(() => {
        this.printLoading = false
      })
    },
    // 查看检验详情
    handleView(row) {
      const { warehousingOrderNo, id } = row
      this.$refs.viewTempInspect.visible = true
      this.$refs.viewTempInspect.queryParams.warehousingOrderNo = warehousingOrderNo
      this.$refs.viewTempInspect.queryParams.type = 1
      this.$refs.viewTempInspect.queryParams.materialLots = id
    },
    // 获取显示隐藏列
    getColumnsList() {
      const { componentName } = this.$route.meta || null
      const params = {
        userId: this.userId,
        vueForm: componentName
      }
      getFormColumnsList(params).then(res => {
        if (isArray(res.data)) {
          this.columnsList = res.data.length === 0 ? this.columns : res.data
        } else {
          this.columnsList = this.columns
        }
      }).catch((err) => {
        if (err) {
          this.columnsList = this.columns
        }
      }).finally(() => {
        this.$emit('columns', this.columnsList)
      })
    }
  }
}
</script>

        <style>

        </style>

