FlatQuickShipmentDetailModel.vue 4.54 KB
<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-table
        ref="table"
        rowKey="id"
        size="middle"
        :columns="columns"
        :scroll="{y: 600}"
        :dataSource="dataSource"
        :pagination="false">
        <span slot="shipQty" slot-scope="text, record">
          <a-input-number :max="record.availableQty" :min="0" placeholder="请输入出库数量" v-model="record.shipQty" :value="text"/>
        </span>
        <span slot="zoneCode" slot-scope="zoneCode">
          <a-tag :key="zoneCode" color=blue>
            {{ solutionZoneCode(zoneCode) }}
          </a-tag>
        </span>
        <span slot="inventoryStatus_dictText" slot-scope="inventoryStatus_dictText">
          <a-tag :key="inventoryStatus_dictText" :color="getStatusColor(inventoryStatus_dictText)">
            {{ inventoryStatus_dictText }}
          </a-tag>
        </span>
      </a-table>
    </a-spin>
  </j-modal>
</template>

<script>

import {flatShipmentInventoryDetail} from '@/api/api'
import inputNumber from "ant-design-vue/lib/input-number";

export default {
  name: 'flatQuickShipmentDetailModel',
  computed: {
    inputNumber() {
      return inputNumber
    }
  },
  components: {},
  data() {
    return {
      title: '操作',
      width: 1200,
      columns: [
        {
          title: '#', dataIndex: '', key: 'rowIndex', width: 60, align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {title: '库区', dataIndex: 'zoneCode', align: 'center', scopedSlots: {customRender: 'zoneCode'}},
        {title: '库位', dataIndex: 'locationCode', align: 'center'},
        {title: '容器', dataIndex: 'containerCode', align: 'center'},
        {title: '物料编码', dataIndex: 'materialCode', align: 'center'},
        {title: '物料名称', dataIndex: 'materialName', align: 'center'},
        {title: '物料规格', dataIndex: 'materialSpec', align: 'center'},
        {title: '物料单位', dataIndex: 'materialUnit', align: 'center'},
        {title: '批次', dataIndex: 'batch', align: 'center'},
        {title: '库存状态', dataIndex: 'inventoryStatus_dictText', align: 'center', scopedSlots: {customRender: 'inventoryStatus_dictText'}},
        {title: '可出数量', dataIndex: 'availableQty', key: 'availableQty', align: 'center'},
        {title: '出库数量', dataIndex: 'shipQty', align: 'center', key: 'shipQty', scopedSlots: {customRender: 'shipQty'}}
      ],
      dataSource: [],
      zoneList: [],
      querySource: {},
      visible: false,
      labelCol: {
        xs: {span: 24},
        sm: {span: 5}
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16}
      },
      confirmLoading: false,
      validatorRules: {}
    }
  },
  created() {

  },
  methods: {
    open(recordList) {
      this.visible = true;
      this.dataSource = recordList;
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      let dataSource = this.dataSource.filter(data => data.shipQty);
      if (dataSource) {
        try {
          dataSource.forEach(data => {
            if (data.shipQty < 0) {
              throw new Error(`第 ${data.index} 行出库数量异常`);
            }
          })
        } catch (e) {
          this.$message.warning(e);
          return;
        }
      }
      let params = dataSource.map(data => {
        return {inventoryDetailId: data.id, shipQty: data.shipQty}
      })
      flatShipmentInventoryDetail(params).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
          this.$emit("ok");
        } else {
          this.$message.error(res.message);
        }
      }).finally(() => {
        this.close()
      });
    },
    handleCancel() {
      this.close()
    },
    solutionZoneCode(value) {
      let actions = []
      Object.keys(this.zoneList).some((key) => {
        if (this.zoneList[key].code === ('' + value)) {
          actions.push(this.zoneList[key].name)
          return true
        }
      })
      return actions.join('')
    },
    getStatusColor(status) {
      const colors = {
        '良品': 'green',
        '报废品': 'purple',
        '待确认	': 'grey',
        '次品': 'red',
        '锁定': 'red',
        default: 'blue'
      };
      return colors[status] || colors.default;
    },
  }
}
</script>