<template>
  <el-dialog title="选择工单" :visible.sync="visible" width="60%">
    <div>
      <el-input
        style="width: 320px; margin-bottom: 16px"
        v-model="searchVal"
        @input="_getCheckAbnormalList"
        placeholder="搜索工单号或名称"
      ></el-input>
      <el-radio-group v-model="selected" class="w100">
        <el-table
          :data="tableData"
          class="w100"
          :header-cell-style="{ background: '#F0F3F3' }"
          border
        >
          <el-table-column
            label="盘点单号"
            prop="workOrderCode"
          ></el-table-column>
          <el-table-column label="盘点名称" prop="planName"></el-table-column>
          <el-table-column label="资产类型" prop="assetDict">
            <template slot-scope="{ row }">
              {{ useDictLabel(row.assetDict) }}
            </template>
          </el-table-column>
          <el-table-column
            label="盘点仓库"
            prop="bizTypeName"
          ></el-table-column>
          <el-table-column
            label="盘点部门"
            prop="executorDeptName"
          ></el-table-column>
          <el-table-column
            label="盘点人员"
            prop="executeUserName"
          ></el-table-column>
          <el-table-column
            label="盘盈数量"
            prop="inventoryProfitNum"
          ></el-table-column>
          <el-table-column
            label="盘亏数量"
            prop="inventoryLossesNum"
          ></el-table-column>
          <el-table-column label="破损数量" prop="damagedNum"></el-table-column>
          <el-table-column
            label="盘点审核时间"
            prop=""
            width="120"
          ></el-table-column>
          <el-table-column label="操作" prop="" align="center" fixed="right">
            <template slot-scope="{ row }">
              <el-radio :label="row.id"><span></span></el-radio>
            </template>
          </el-table-column>
        </el-table>
      </el-radio-group>
    </div>
    <div class="footer" slot="footer">
      <el-button type="primary" @click="confirm">确定选中</el-button>
      <el-button @click="cancel">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
// import { getCheckAbnormalList } from '@/api/workspace/workOrder'
import { warehousingType } from '@/utils/dict/warehouse'
import { useDictLabel } from '@/utils/dict'
export default {
  data () {
    return {
      useDictLabel: useDictLabel(warehousingType),
      tableData: [],
      searchVal: '',
      visible: false,
      selected: ''
    }
  },
  created () {
    // this._getCheckAbnormalList()
  },
  methods: {
    open () {
      this.searchVal = ''
      this.visible = true
    },
    cancel () {
      this.visible = false
    },
    confirm () {
      if (!this.selected) {
        return this.$message.error('请选择工单！')
      }
      console.log(this.selected)
      this.$emit(
        'success',
        this.tableData.find(i => i.id === this.selected)
      )
      this.cancel()
    },
    async _getCheckAbnormalList () {
      const res = await getCheckAbnormalList({
        size: 99999,
        searchKey: this.searchVal
      })
      if (res?.success) {
        this.tableData = res.data.records
      }
    }
  }
}
</script>
