FlatQuickShipmentModal.vue 5.54 KB
<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >

    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">

      </a-form-model>
    </a-spin>

    <a-table ref="table" rowKey="id" size="middle" :columns="columns" :dataSource="dataSource" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" :pagination="false">
      <span slot="action" slot-scope="text, record">
        <a-input-number placeholder="" v-model="record.flatTaskQty" :value="text"  :min="0" :max="record.qty"/>
      </span>


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

    </a-table>
    <select-inv-container-header ref="selectContainerForm" v-on:getContainer="getContainerCode"></select-inv-container-header>
  </j-modal>

</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import {ajaxGetDictItems, flatQuickShipment} from '@api/api'
import SelectInvContainerHeader from "../../receipt/modules/SelectInvContainerHeader.vue";

export default {
  name: 'ReceiveModal',
  components: {SelectInvContainerHeader},
  mixins:[JeecgListMixin],
  props: {
    mainId: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {
      title: '操作',
      width: 800,
      visible: false,
      materialList: {},
      querySource: {},
      dataSource: [],
      invStatus:[],
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      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: 'action',
          align: 'center',
          key: 'action',
          scopedSlots: { customRender: 'action' }
        },
      ],
      confirmLoading: false,
      validatorRules: {
        containerCode: [{ required: true, message: '请输入容器编码!' }]
      },
      dictOptions: {},
      superFieldList:[],
      url: {
        add: '/receipt/receiveHeader/receive',
        edit: '/receipt/receiptHeader/editReceiptDetail'
      }
    }
  },
  created() {
    //备份model原始值
    this.getSuperFieldList()
    // this.modelDefault = JSON.parse(JSON.stringify(this.model))
    this.loadFrom();
  },
  methods: {
    loadData(){

    },
    onClearSelected() {
      this.selectedRowKeys = [];
      this.selectionRows = [];
      this.selectedMainId=''
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedMainId=selectedRowKeys[0]
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectionRows;
    },
    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',
        default: 'blue'
      };
      return colors[status] || colors.default;
    },
    getContainerCode(e){
      this.$nextTick(function (){
        let  record={containerCode: e}
        this.model = Object.assign({}, record)
      })
    },
    solutionInvStatus(value) {
      var actions = []
      Object.keys(this.invStatus).some(key => {
        if (this.invStatus[key].value == '' + value) {
          actions.push(this.invStatus[key].text)
          return true
        }
      })
      return actions.join('')
    },
    edit(record) {
      record.forEach(x => {
          x.flatTaskQty = x.qty
        })
      this.model = Object.assign({}, record)
      this.visible = true
      this.dataSource = record;
    },
    selectContainer(record){
      this.$refs.selectContainerForm.edit(record);
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.$refs.form.clearValidate()
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({type:'string',value:'inventoryStatus',text:'库存状态',dictCode:'inventory_status'})
      this.superFieldList = fieldList
    },
    handleOk() {
      if (this.dataSource[0] == null) {
        this.confirmLoading = false
        this.$message.warning('没有库存详情!')
        return;
      }
      flatQuickShipment(this.dataSource).then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
      }).finally(() => {
        this.close();
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>