BaofeiReceiveDetailModal.vue 7.13 KB
<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-table ref="table" rowKey="id" size="middle" :columns="columns" :dataSource="dataSource" :pagination="false">

      <span slot="taskQty" slot-scope="text, record">
        <a-input-number :min="0" placeholder="请输入组盘数量" v-model="record.taskQty" :value="text"/>
      </span>

      <span slot="sn" slot-scope="text, record">
        <a-input placeholder="请输入序列号" v-model="record.sn" @change="snChangeEvent(record)" :value="text"/>
      </span>

      <span slot="containerCode" slot-scope="text, record">
        <a-input placeholder="请输入容器编码" v-model="record.containerCode" :value="text"/>
      </span>

      <span slot="toLocationCode" slot-scope="text, record">
        <a-input placeholder="请输入报废库位码" v-model="record.toLocationCode" :value="text"/>
      </span>

      <span slot="inventoryStatus" slot-scope="inventoryStatus">
        <a-tag :key="inventoryStatus" :color="getStatusColor(inventoryStatus)">
            {{ solutionInvStatus(inventoryStatus) }}
        </a-tag>
      </span>

    </a-table>
  </j-modal>

</template>

<script>

import {postAction, getAction} from '@/api/manage'
import {ajaxGetDictItems} from '@/api/api'
import {simpleDebounce} from '@/utils/util'

export default {
  name: 'BaofeiReceiveDetailModal',
  data() {
    return {
      title: '操作',
      width: 1200,
      visible: false,
      querySource: {},
      dataSource: [],
      invStatus: [],
      inventoryDetailIdInner: null,
      labelCol: {
        xs: {span: 24},
        sm: {span: 3}
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 6}
      },
      columns: [
        {
          title: '物料编码',
          dataIndex: 'materialCode',
          align: 'center',
          width: 124
        },
        {
          title: '物料名称',
          dataIndex: 'materialName',
          align: 'center',
          width: 96
        },
        {
          title: '库存状态',
          dataIndex: 'inventoryStatus',
          align: 'center',
          width: 96,
          scopedSlots: {customRender: 'inventoryStatus'}
        },
        {
          title: '批次',
          dataIndex: 'batch',
          align: 'center'
        },
        {
          title: '可收数量',
          dataIndex: 'qty',
          align: 'center',
          width: 80
        },
        {
          title: '组盘数量',
          dataIndex: 'taskQty',
          align: 'center',
          width: 147,
          scopedSlots: {customRender: 'taskQty'}
        },
        {
          title: '序列号',
          dataIndex: 'sn',
          align: 'center',
          width: 147,
          scopedSlots: {customRender: 'sn'}
        },
        {
          title: '容器编码',
          dataIndex: 'containerCode',
          align: 'center',
          width: 147,
          scopedSlots: {customRender: 'containerCode'}
        },
        {
          title: '报废库位编码',
          dataIndex: 'toLocationCode',
          align: 'center',
          width: 147,
          scopedSlots: {customRender: 'toLocationCode'}
        },
      ],
      confirmLoading: false,
      superFieldList: [],
      url: {
        flatReceive: '/receipt/receiveHeader/baofeiReceive',
        flatReceiveGetMaterialInfoBySn: '/receipt/receiveHeader/flatReceiveGetMaterialInfoBySn',
        listReceiptDetailByIds: '/receipt/receiptHeader/listReceiptDetailByIds'
      }
    }
  },
  props: {
    receiptDetailId: {
      type: [String, Number],
      default: null,
      required: false
    }
  },
  watch: {
    receiptDetailId: {
      immediate: true,
      handler(val) {
        if (!this.receiptDetailId) {
          this.clearList()
        } else {
          this.searchReceive(val);
        }
      }
    }
  },
  created() {
    //备份model原始值
    this.loadFrom();
  },
  methods: {
    clearList() {
      this.dataSource = []
      this.selectedRowKeys = []
    },
    snChangeEvent: simpleDebounce(function (record) {
      if (record.sn == null || record.sn === '') {
        return
      }
      let that = this;
      getAction(that.url.flatReceiveGetMaterialInfoBySn, {sn: record.sn})
        .then(res => {
          if (res.success) {
            let result = res.result
            if (result.materialCode !== record.materialCode) {
              that.$message.warning("该序列号对应的入库物料 " + result.materialCode + " 与单据明细物料 " + record.materialCode + " 不一致")
              record.sn = null;
              return;
            }
            record.taskQty = result.qty;
            record.sn = result.sn;
            // this.$set(record, 'containerCode', result.containerCode)
            // this.$set(record, 'toLocationCode', result.toLocationCode)
            that.$message.success(res.message);
          } else {
            that.$message.warning(res.message);
            record.sn = null;
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    }, 500),
    loadFrom() {
      ajaxGetDictItems('inventory_status').then((res) => {
        if (res.success) {
          this.invStatus = res.result
        }
      })
    },
    getStatusColor(status) {
      const colors = {
        'good': 'green',
        'defective': 'red',
        'discussed': 'grey',
        'scrap': 'purple',
        'pendingInspection': 'orange',
        default: 'blue'
      };
      return colors[status] || colors.default;
    },
    solutionInvStatus(value) {
      let actions = []
      Object.keys(this.invStatus).some(key => {
        if (this.invStatus[key].value === '' + value) {
          actions.push(this.invStatus[key].text)
          return true
        }
      })
      return actions.join('')
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.dataSource.forEach(data => {
        this.$set(data, 'containerCode', null)
        this.$set(data, 'toLocationCode', null)
        this.$set(data, 'taskQty', null)
        this.$set(data, 'sn', null)
      })
    },
    searchReceive() {
      postAction(this.url.listReceiptDetailByIds, [this.receiptDetailId])
        .then(res => {
          if (res.success) {
            this.dataSource = res.result
            this.dataSource.forEach(data => {
              data.qty = data.qty - data.taskQty;
              data.taskQty = 0;
            })
          } else {
            this.$message.error(res.message);
          }
        })
    },
    handleOk() {
      const that = this
      // 触发表单验证
      that.confirmLoading = true
      postAction(this.url.flatReceive, this.dataSource)
        .then(res => {
          if (res.success) {
            that.$message.success(res.message)
            that.$emit('ok')
            //that.close()
            this.searchReceive();
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>