ReceivePrintModal.vue 11.1 KB
<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @cancel="handleCancel"
    cancelText="关闭"
  >

    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料编码">
              <a-input hidden="hidden" placeholder="请输入物料编码" v-model="queryParam.receiveId"/>
              <a-input placeholder="请输入物料编码" v-model="queryParam.materialCode"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

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

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

    <div class="table-operator">
      <a-button v-has="'receiveHeader:print'" @click="batchPrint()" type="primary">打印</a-button>
      <a-input-number v-model:value="count"  :min="0"
                      :max="100"
                      :formatter="value => `${value}`"
                      :parser="value => value.replace('', '')">打印张数?</a-input-number>
    </div>

    <a-table ref="table" rowKey="id" size="middle" :columns="columns" :dataSource="dataSource" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" :pagination="ipagination" @change="handleTableChange">
      <span slot="action" slot-scope="text, record">
        <a-input-number placeholder="" v-model="record.taskQty" :value="text"/>
      </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 moment from 'moment';
import axios from 'axios';
import { getAction, httpAction } from '@/api/manage'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { validateDuplicateValue } from '@/utils/util'
import { searchMaterialByCode } from '@/api/api'
import { listReceiveByReceiveId,ajaxGetDictItems,remotePrint } from '@/api/api'
import SelectInvContainerHeader from "./SelectInvContainerHeader";
import { colAuthFilter } from "@/utils/authFilter"

export default {
  name: 'ReceivePrintModal',
  components: {SelectInvContainerHeader},
  mixins:[JeecgListMixin],
  props: {
    mainId: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {
      title: '操作',
      width: 900,
      visible: false,
      materialList: {},
      querySource: {},
      dataSource: [],
      invStatus:[],
      model: {},
      count : 1,
      ipagination: {
        current: 1,
        pageSize: 5,
        pageSizeOptions: ['5', '10', '20','50'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      /* 排序参数 */
      isorter: {
        column: 'id',
        order: 'asc',
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '物料编码',
          dataIndex: 'materialCode',
          align: 'center',
          width: 124
        },
        {
          title: '物料名称',
          dataIndex: 'materialName',
          align: 'center',
          width: 96
        },
        {
          title: '物料规格',
          dataIndex: 'materialSpec',
          align: 'center',
          width: 96
        },
        {
          title: '口径',
          dataIndex: 'diameter',
          align: 'center',
          width: 96
        },
        {
          title: '口径码',
          dataIndex: 'diameterCode',
          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: {
        list: '/receipt/receiveHeader/listReceiveDetailByMainId',
        add: '/receipt/receiveHeader/receive',
        edit: '/receipt/receiptHeader/editReceiptDetail'
      }
    }
  },
  created() {
    // 增加方法调用,根据权限过滤展示的列
    this.columns = colAuthFilter(this.columns,'receivePrint:');
    //备份model原始值
    this.getSuperFieldList()
    // this.modelDefault = JSON.parse(JSON.stringify(this.model))
    this.loadFrom();
  },
  methods: {
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      this.onClearSelected()
      var params = this.getQueryParams();//查询条件
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false;
      })
    },
    searchReset() {
      this.queryParam = {};
      this.queryParam['receiveId'] = this.mainId;
      this.loadData(1);
    },
    onClearSelected() {
      this.selectedRowKeys = [];
      this.selectionRows = [];
      this.selectedMainId=''
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedMainId=selectedRowKeys[0]
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectionRows;
    },
    batchPrint() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录!');
        return;
      } else {
        //调用打印机
        const objData = {
          template: "receipt_detail",
          count: this.count,
          data: {
            receive:[]
          }
        };

        for (const row of this.selectionRows) {
          if(row.taskQty <= 0){
            this.$message.warning('请输入收货数量!');
            return;
          }
        }
        this.selectionRows.forEach(x => {
          let obj ={
            id: x.id,
            materialCodeText: '品号',
            materialCode: x.materialCode,
            materialSpecText: '规格',
            materialSpec: x.materialSpec,
            materialNameText: '品名',
            materialName: x.materialName,
            diameterText: '口径',
            diameter: x.diameter,
            diameterCode: x.diameterCode,
            dateText: '日期',
            date: moment(moment.now()).format("yyyy/MM/DD"),
            qtyText: '数量',
            qty: x.taskQty,
            batchText: '批次',
            batch: x.batch,
            qcContext: x.materialCode + ' ' + x.batch + ' ' + x.diameterCode
          };
          objData.data.receive.push(obj);
        });
        remotePrint(objData).then((res) => {
          this.loading = false;
          if (res.success) {
            this.$message.success(res.message);
            this.selectionRows = [];
            this.selectedRowKeys = [];

          } else {
            this.$message.error(res.message);
          }
        });
      }
    },
    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) {
      this.model = Object.assign({}, record)
      this.visible = true
      this.searchReceive();
    },
    selectContainer(record){
      this.$refs.selectContainerForm.edit(record);
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.$refs.form.clearValidate()
    },
    searchReceive() {
      const that = this
      this.queryParam = {};
      this.mainId = that.model.id;
      this.queryParam.receiveId = that.model.id;
      this.queryParam.materialCode = that.model.materialCode;
      this.loadData(1);
      // listReceiveByReceiveId(that.querySource).then(res => {
      //   that.dataSource = res.result
      // })
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({type:'string',value:'inventoryStatus',text:'库存状态',dictCode:'inventory_status'})
      this.superFieldList = fieldList
    },
    handleOk() {
      console.log('handleOk')
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        this.$emit('ok')
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>