<template>
  <!-- 列表 -->
  <div>
    <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[0].visible"
            :key="Math.random()"
            label="生产入库单号"
            align="center"
            prop="warehousingOrderNo"
          />
          <el-table-column
            v-if="columnsList[1].visible"
            :key="Math.random()"
            label="申请入库时间"
            align="center"
            prop="applyTime"
            width="160"
          >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.applyTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnsList[2].visible"
            :key="Math.random()"
            label="申请人"
            align="center"
            prop="applicant"
            width="120"
            :formatter="handleName"
          />
          <el-table-column
            v-if="columnsList[3].visible"
            :key="Math.random()"
            label="入库箱数"
            align="center"
            prop="inQty"
          />
          <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
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="160"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                v-hasPermi="['wms:incoming-produce-detail:query']"
                type="text"
                icon="el-icon-view"
                size="mini"
                @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"
    />

    <!-- 入库明细 -->
    <AwaitProductDetail ref="awaitProductDetail" @qualifiedComplete="fqcInspectComplete" />
  </div>

</template>

<script>
import { getFqcToInspectPage } from '@/api/wms/quality/tempInspectionExecute'
import AwaitProductDetail from './AwaitProductDetail.vue'
import { getFormColumnsList } from '@/api/system/saveColumns/index'
import { mapGetters } from 'vuex'
import { isArray } from 'min-dash'

export default {
  name: 'AwaitWare',
  components: {
    AwaitProductDetail
  },
  props: {
    'activeName': {
      type: String,
      default: ''
    },
    'queryParamspro': {
      type: Object,
      default: () => {}
    }
  },
  inject: ['paramsQuery'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 领料单列表
      list: [],
      users: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        status: 0
      },
      currentRows: [],
      //   表单参数
      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
      }
      getFqcToInspectPage(params).then(response => {
        this.list = response.data.list.list
        this.users = response.data.users
        this.total = response.data.list.total
        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()
    },
    handleName(row, column, cellValue) {
      const user = this.users.find(item => item.id.toString() === cellValue)
      return user && user.nickname
    },
    // 入库明细
    handleView(row) {
      const { warehousingOrderNo } = row
      this.$refs.awaitProductDetail.queryParams.warehousingOrderNo = warehousingOrderNo
      this.$refs.awaitProductDetail.open = true
    },
    fqcInspectComplete() {
      this.getList()
      this.$emit('fqcToInspectComplete')
    },
    // 获取显示隐藏列
    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>

