<template>
  <div>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearchShow="false" :refreshShow="false" :columns="columns"></right-toolbar>
    </el-row>
    <el-table :data="dataList" v-loading="loading" ref="table" highlight-current-row>
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <!-- <el-table-column type="index" label="序号" width="50" align="center" /> -->
      <el-table-column prop="outStoreId" label="ID" align="center" v-if="columns.showColumn('outStoreId')" />
      <el-table-column prop="outSotreNo" label="出库记录单号" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('outSotreNo')" />
      <el-table-column prop="bomNo" label="生产令号" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('bomNo')" />
      <el-table-column prop="materialCode" label="物料编码" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('materialCode')" />
      <el-table-column prop="materialName" label="物料名称" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('materialName')" />
      <el-table-column prop="materialSpec" label="规格型号 / 图号" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('materialSpec')" />
      <el-table-column prop="category" label="物料类型" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('category')">
        <template #default="scope">
          <dict-tag :options="options.materialTypeOptions" :value="scope.row.category" />
        </template></el-table-column>
      <el-table-column prop="keyFlag" label="关键件" align="center" v-if="columns.showColumn('keyFlag')">
        <template #default="scope">
          <el-icon v-if="scope.row.keyFlag" size="large" color="red">
            <StarFilled />
          </el-icon>
          <el-icon v-else />
        </template>
      </el-table-column>
      <el-table-column prop="bnSnCode" label="BN/SN码" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('bnSnCode')" />
      <el-table-column prop="result" label="出库结果" align="center" v-if="columns.showColumn('result')">
        <template #default="scope">
          <dict-tag :options="options.operationResultOptions" :value="scope.row.result" />
        </template></el-table-column>
      <el-table-column prop="outStoreQty" label="出库数量" align="center" v-if="columns.showColumn('outStoreQty')" />
      <el-table-column prop="createBy" label="创建人" align="center" v-if="columns.showColumn('createBy')" />
      <el-table-column prop="createTime" label="创建时间" align="center" width="160"
        v-if="columns.showColumn('createTime')" />
      <el-table-column prop="updateBy" label="更新人" align="center" v-if="columns.showColumn('updateBy')" />
      <el-table-column prop="updateTime" label="更新时间" align="center" width="160"
        v-if="columns.showColumn('updateTime')" />
      <el-table-column prop="remark" label="备注" align="center" :show-overflow-tooltip="true"
        v-if="columns.showColumn('remark')" />
    </el-table>
    <pagination class="mt10" background :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />
  </div>
</template>
<script setup>
import { listOutOutstoreRecord } from '@/api/business/outoutstorerecord.js';
const { proxy } = getCurrentInstance()
const props = defineProps({
  tranceParams: {
    type: Object
  }
})
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  sort: '',
  sortType: 'asc',
})
const loading = ref(false)
const total = ref(0)
const dataList = ref([])

const columns = ref([
  { visible: false, prop: 'outStoreId', label: 'ID' },
  { visible: false, prop: 'outSotreNo', label: '出库记录单号' },
  { visible: true, prop: 'bomNo', label: '生产令号' },
  { visible: true, prop: 'materialCode', label: '物料编码' },
  { visible: false, prop: 'materialName', label: '物料名称' },
  { visible: true, prop: 'materialSpec', label: '规格型号 / 图号' },
  { visible: true, prop: 'category', label: '物料类型' },
  { visible: true, prop: 'keyFlag', label: '关键件标识' },
  { visible: true, prop: 'bnSnCode', label: 'BN / SN码' },
  { visible: true, prop: 'result', label: '出库结果' },
  { visible: true, prop: 'outStoreQty', label: '出库数量' },
  { visible: true, prop: 'createBy', label: '创建人' },
  { visible: true, prop: 'createTime', label: '创建时间' },
  { visible: false, prop: 'updateBy', label: '更新人' },
  { visible: false, prop: 'updateTime', label: '更新时间' },
  { visible: false, prop: 'remark', label: '备注' },
])
const state = reactive({
  form: {},
  options: {
    keyFlagOptions: [], // 关键件标识字典
    operationResultOptions: [],// 操作结果字典
    materialTypeOptions: [],// 物料类型字典
    qaResultOptions: [],//质检结果字典
  }
})

const { form, rules, options } = toRefs(state)

var dictParams = [
  { dictType: 'my_key_flag', columnName: 'keyFlagOptions' },
  { dictType: 'my_operation_result', columnName: 'operationResultOptions' },
  { dictType: 'my_material_type', columnName: 'materialTypeOptions' },
  { dictType: 'my_qa_result', columnName: 'qaResultOptions' },
]
proxy.getDicts(dictParams).then((response) => {
  response.data.forEach((element) => {
    state.options[element.columnName] = element.list
  })
})
function getList() {
  loading.value = true
  listOutOutstoreRecord(queryParams).then(res => {
    const { code, data } = res
    if (code == 200) {
      dataList.value = data.result
      total.value = data.totalNum
      loading.value = false
    }
  })
}
function handleQuery() {
  queryParams.pageNum = 1
  queryParams.materialCode = props.tranceParams.materialCode
  queryParams.bnSnCode = props.tranceParams.bnSnCode
  getList()
}
handleQuery()
</script>
<style></style>
