<template>

  <div>
    <!-- 列表 -->
    <AutoResizer :given-height="250">
      <template #default="{height}">
        <el-table
          v-if="columnsList.length > 0"
          v-loading="loading"
          :height="height"
          :data="list"
          border
        >
          <!-- <el-table-column
        label="销售出库单"
        align="center"
        prop="saleOutNo"
        show-overflow-tooltip
      />
      <el-table-column label="客户名称" align="center" prop="customerName" />
      <el-table-column label="产品编码" align="center" prop="materialNo" />
      <el-table-column label="产品名称" align="center" prop="materialName" /> -->
          <el-table-column
            v-if="columnsList[0].visible"
            :key="Math.random()"
            label="批号"
            align="center"
            prop="materialLots"
          />
          <el-table-column
            v-if="columnsList[1].visible"
            :key="Math.random()"
            label="生产订单"
            align="center"
            prop="erpOrderNo"
          />
          <el-table-column
            v-if="columnsList[2].visible"
            :key="Math.random()"
            label="审核状态"
            align="center"
            prop="auditStatus"
          >
            <template slot-scope="scope">
              <dict-tag :type="DICT_TYPE.WMS_OQC_AUDIT_STATUS" :value="scope.row.auditStatus" />
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnsList[7].visible"
            :key="Math.random()"
            label="审核时间"
            align="center"
            prop="auditTime"
            width="160"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.auditTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnsList[3].visible"
            :key="Math.random()"
            label="时间"
            align="center"
            prop="ipqcDate"
          />
          <el-table-column
            v-if="columnsList[4].visible"
            :key="Math.random()"
            label="班别"
            align="center"
            prop="classFlag"
          >
            <template slot-scope="scope">
              <dict-tag :type="DICT_TYPE.CLASS_FLAG" :value="scope.row.classFlag" />
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnsList[5].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[6].visible"
            :key="Math.random()"
            label="创建人"
            align="center"
            prop="creator"
          />
          <!-- <el-table-column label="检验结果" align="center" prop="testResult" /> -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="160"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleView(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"
    />
    <!-- 明细 -->
    <SalesDetails ref="salesDetails" />
    <!-- 检验单打印 -->
    <FilePreview v-model="filePreviewvisible" :src="'data:application/pdf;base64,'+baseData" />
    <!-- 检验执行 -->
    <InspectDetail ref="inspectDetail" />

  </div>
</template>

<script>
import { getFQCpage, updateOqcReinspection } from '@/api/wms/quality/fqcInspectionExecute'
import SalesDetails from '@/views/wms/output/salesIssue/components/SalesDetails.vue'
import FilePreview from '@/components/FilePreview'
import InspectDetail from './InspectDetail.vue'
import { getFormColumnsList } from '@/api/system/saveColumns/index'
import { mapGetters } from 'vuex'
import { isArray } from 'min-dash'

export default {
  name: 'AlreadyOqcInspect',
  components: {
    SalesDetails,
    FilePreview,
    InspectDetail
  },
  props: {
    'activeName': {
      type: String,
      default: ''
    },
    'queryParamspro': {
      type: Object,
      default: () => {}
    }
  },
  inject: ['paramsQuery'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 领料单列表
      list: [],
      users: [],
      // 是否显示弹出层
      open: false,
      baseData: '',
      filePreviewvisible: false,
      printLoading: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        type: 2,
        audited: 1
      },
      //   表单参数
      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 }
      ],
      // 显示隐藏持久化参数
      columnsList: []
    }
  },
  computed: {
    ...mapGetters([
      'userId'
    ])
  },
  created() {
    // 获取显隐列列表
    this.getColumnsList()
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 执行查询
      const params = {
        ...this.paramsQuery,
        ...this.queryParams
      }
      getFQCpage(params).then(response => {
        this.list = response.data.list
        this.total = response.data.total
        this.users = response.data.users
      }).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 { id, saleOutNo } = row
      const params = {
        id,
        warehousingOrderNo: saleOutNo,
        type: this.queryParams.type
      }
      updateOqcReinspection(params).then(res => {
        this.$modal.msgSuccess('操作成功')
        this.getList()
        this.$emit('resetComplete')
      })
    },
    // 查看检验详情
    handleView(row) {
      const { materialLots, materialNo, wmsIncomingReceiptInspectionId, auditStatus } = row
      this.$refs.inspectDetail.queryParams.materialLots = materialLots
      this.$refs.inspectDetail.queryParams.materialNo = materialNo
      this.$refs.inspectDetail.queryParams.key = wmsIncomingReceiptInspectionId
      this.$refs.inspectDetail.queryParams.type = 2
      this.$refs.inspectDetail.apiStatus = auditStatus
      this.$refs.inspectDetail.visible = true
    },
    handleName(row, column, cellValue) {
      const user = this.users.find(item => item.id.toString() === cellValue)
      return user && user.nickname
    },
    // 获取显示隐藏列
    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>

