loulijun2021
2023-06-01 3a521043130335b438c59ba925b835afc286d377
src/views/produceManager/productWarehouse.vue
@@ -19,6 +19,9 @@
          <div style="font-size: 14px;margin-left: 5px;color: #a7a7a7">
            查询项
          </div>
          <div v-if="!isPermission" style="font-size: 14px;margin-left: 10px;color: red">
            当前用户在ERP系统中不存在或未授权,无法入库提交
          </div>
        </div>
        <el-form
          ref="form"
@@ -399,21 +402,9 @@
                    min-width="130"
                    fixed="right"
                  >
                    <template slot-scope="{row}">
                      <el-input-number v-model="row.stinhouseqty" :max="row.good_qty" size="small" />
                      <!--                      <div-->
                      <!--                        v-if="!(row.index === tabClickIndex && tabClickLabel === '可入库数量')"-->
                      <!--                      >-->
                      <!--                        {{ row.stinhouseqty }}-->
                      <!--                      </div>-->
                      <!--                      <el-input-->
                      <!--                        v-if="row.index === tabClickIndex && tabClickLabel === '可入库数量'"-->
                      <!--                        v-model="row.stinhouseqty"-->
                      <!--                        oninput="value=value.replace(/[^0-9]/g,'')"-->
                      <!--                      />-->
                    </template>
                    <!--                    <template slot-scope="{row}">-->
                    <!--                      <el-input-number v-model="row.stinhouseqty" :min="0" :max="row.good_qty" size="small" />-->
                    <!--                    </template>-->
                  </el-table-column>
                </el-table>
                <el-table
@@ -563,11 +554,15 @@
                    fixed
                    label="序号"
                  />
                  <!--                  <el-table-column-->
                  <!--                    prop="stockname"-->
                  <!--                    label="仓库"-->
                  <!--                    width="110"-->
                  <!--                  >-->
                  <el-table-column
                    prop="stockcode"
                    label="仓库"
                    width="110"
                  >
                    <template slot-scope="{row}">
                      <div>{{ stockcodeArr.find(i=>i.code===row.stockcode).name }}</div>
                    </template>
                  </el-table-column>
                  <!--                    <template slot-scope="{row}">-->
                  <!--                      <div v-if="row.stockname">{{ row.stockname }}</div>-->
                  <!--                      <div v-else>/</div>-->
@@ -677,11 +672,14 @@
<script>
import elDragDialog from '@/directive/el-drag-dialog'
import waves from '@/directive/waves'
import { WareHouseSelect } from '@/api/materialManager'
import { ProductInHouseOrderSearch, ProductInHouseWkshopOrder } from '@/api/produceManager'
import { handleDatetime } from '@/utils/global'
import { WorkShopSelect } from '@/api/deviceManager'
import $ from 'jquery'
import {
  ProductInHouseOrderCodeSearch,
  ProductInHouseOrderSearch, ProductInHouseOrderSeave,
  ProductInHouseWkshopOrder
} from '@/api/produceManager'
import { handleDatetime, handleDatetime2 } from '@/utils/global'
import { ErpUserSelect, ErpWarehouseSelect, ErpWkshopDepartmentSelect } from '@/api/basicInfo'
import { getCookie } from '@/utils/auth'
export default {
  name: 'Zzjg',
@@ -692,10 +690,12 @@
      mainHeight: 0,
      tableHeight: 0,
      form: {
        hbillno: '', // 入库单号
        incbit: '', // 流水号
        documentType: 'Y', // 单据类型
        wkshopcode: '', // 生产车间
        erpordercode: '', // 订单编号
        wkshopcode: 'CJ001', // 生产车间
        erpordercode: 'MO-2023-05-0007', // 订单编号
        mesordercode: '', // 工单编号
        partcode: '', // 产品编码
        partname: '', // 产品名称
@@ -723,20 +723,52 @@
      tableDataSummary: [], // 汇总表
      xxx: ''
      isPermission: true, // 是否有权限可提交
      userArr: [] // ERP人员数组
    }
  },
  watch: {},
  created() {
    this.getWareHouseSelect()
    this.getWorkShopSelect()
    this.getErpUserSelect()
  },
  mounted() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
    this.getWareHouseSelect()
    this.getWorkShopSelect()
    this.getProductInHouseOrderCodeSearch()
    this.getProductInHouseOrderSearch()
  },
  methods: {
    async getProductInHouseOrderCodeSearch() {
      const { data: res } = await ProductInHouseOrderCodeSearch({ rightcode: '2064' })
      this.form.hbillno = res[0]
      this.form.incbit = res[1]
    },
    async getErpUserSelect() {
      const { data: res } = await ErpUserSelect()
      this.userArr = res
      if (!res.map(i => i.name).includes(getCookie('username'))) {
        this.isPermission = false
        await this.$alert('当前用户在ERP系统中不存在或未授权,无法入库提交', '提示', {
          confirmButtonText: '确定'
          // callback: action => {
          //   this.$message({
          //     type: 'info',
          //     message: `action: ${action}`
          //   })
          // }
        })
      }
    },
    // 单据类型改变
    documentTypeChange(val) {
      this.form.erpordercode = ''
@@ -787,12 +819,12 @@
    },
    // 获取仓库接口
    async getWareHouseSelect() {
      const { data: res } = await WareHouseSelect()
      const { data: res } = await ErpWarehouseSelect()
      this.stockcodeArr = res
    },
    // 获取所属车间
    async getWorkShopSelect() {
      const { data: res } = await WorkShopSelect()
      const { data: res } = await ErpWkshopDepartmentSelect()
      this.WorkShopArr = res
    },
@@ -846,161 +878,177 @@
    // tab点击
    tabClick(val) {
      console.log(val.label)
      // this.$nextTick(() => {
      //   this.$refs.tableDataRef.doLayout()
      // })
      const data = [
        {
          'inbarcode': 'IN23053150',
          'saleOrderid': 13,
          'saleOrderCode': 'SO-2023-05-0009',
          'saleOrderDetailId': 19,
          'mpoid': 19,
          'm_po': 'MO-2023-05-0007',
          'sbid': 30,
          'wo_code': 'MO-2023-05-0007_4',
          'materiel_id': 11,
          'partcode': '301',
          'partname': '电脑',
          'partspec': '',
          'step_code': 'Step08',
          'wkshp_id': 1,
          'wkshp_code': 'CJ001',
          'stck_id': 3,
          'stockcode': '03',
          'stockname': '成品仓库',
          'qty': 80.00,
          'plan_qty': 40.0,
          'good_qty': 20.00,
          'inhouseqty': 0.00,
          'stinhouseqty': 20.00,
          'lm_date': '2023-05-31 09:52:24',
          'style': 'S'
        },
        {
          'inbarcode': 'IN23053148',
          'saleOrderid': 13,
          'saleOrderCode': 'SO-2023-05-0009',
          'saleOrderDetailId': 19,
          'mpoid': 19,
          'm_po': 'MO-2023-05-0007',
          'sbid': 30,
          'wo_code': 'MO-2023-05-0007_3',
          'materiel_id': 11,
          'partcode': '301',
          'partname': '电脑',
          'partspec': '',
          'step_code': 'Step08',
          'wkshp_id': 1,
          'wkshp_code': 'CJ001',
          'stck_id': 3,
          'stockcode': '03',
          'stockname': '成品仓库',
          'qty': 80.00,
          'plan_qty': 40.0,
          'good_qty': 1.00,
          'inhouseqty': 0.00,
          'stinhouseqty': 1.00,
          'lm_date': '2023-05-31 09:52:31',
          'style': 'S'
        },
        {
          'inbarcode': 'IN23053149',
          'saleOrderid': 13,
          'saleOrderCode': 'SO-2023-05-0009',
          'saleOrderDetailId': 19,
          'mpoid': 19,
          'm_po': 'MO-2023-05-0007',
          'sbid': 30,
          'wo_code': 'MO-2023-05-0007_3',
          'materiel_id': 11,
          'partcode': '301',
          'partname': '电脑',
          'partspec': '',
          'step_code': 'Step08',
          'wkshp_id': 1,
          'wkshp_code': 'CJ001',
          'stck_id': 3,
          'stockcode': '03',
          'stockname': '成品仓库',
          'qty': 80.00,
          'plan_qty': 40.0,
          'good_qty': 9.00,
          'inhouseqty': 0.00,
          'stinhouseqty': 9.00,
          'lm_date': '2023-05-31 09:52:31',
          'style': 'S'
        },
        {
          'inbarcode': 'IN23053145',
          'saleOrderid': 13,
          'saleOrderCode': 'SO-2023-05-0009',
          'saleOrderDetailId': 20,
          'mpoid': 19,
          'm_po': 'MO-2023-05-0007',
          'sbid': 31,
          'wo_code': 'MO-2023-05-0007_5',
          'materiel_id': 24,
          'partcode': '308',
          'partname': '电池包',
          'partspec': '',
          'step_code': 'Step08',
          'wkshp_id': 1,
          'wkshp_code': 'CJ001',
          'stck_id': 2,
          'stockcode': '02',
          'stockname': '半成品库',
          'qty': 70.00,
          'plan_qty': 70.0,
          'good_qty': 5.00,
          'inhouseqty': 0.00,
          'stinhouseqty': 5.00,
          'lm_date': '2023-05-31 09:52:40',
          'style': 'S'
        },
        {
          'inbarcode': 'IN23053147',
          'saleOrderid': 13,
          'saleOrderCode': 'SO-2023-05-0009',
          'saleOrderDetailId': 20,
          'mpoid': 19,
          'm_po': 'MO-2023-05-0007',
          'sbid': 31,
          'wo_code': 'MO-2023-05-0007_5',
          'materiel_id': 24,
          'partcode': '308',
          'partname': '电池包',
          'partspec': '',
          'step_code': 'Step08',
          'wkshp_id': 1,
          'wkshp_code': 'CJ001',
          'stck_id': 2,
          'stockcode': '02',
          'stockname': '半成品库',
          'qty': 70.00,
          'plan_qty': 70.0,
          'good_qty': 10.00,
          'inhouseqty': 0.00,
          'stinhouseqty': 10.00,
          'lm_date': '2023-05-31 09:52:40',
          'style': 'S'
        }
      ]
      const stockcodeArr = [...new Set(this.multipleSelection.map(i => i.stockcode))]// 数组去重
      const partcodeArr = data.map(i => i.partcode)
      // const partcodeArr = [...new Set(this.multipleSelection.map(i => i.partcode))]// 数组去重
      const newData = []
      if (val.label === '汇总') {
        data.forEach(i => {
          // if ()
      const Array2D = []
      stockcodeArr.forEach(i => {
        Array2D.push(this.multipleSelection.filter(j => j.stockcode === i))
        })
      Array2D.forEach(k => {
        const partcodeArr = [...new Set(k.map(j => j.partcode))]
        partcodeArr.forEach(i => {
          const t = k.find(j => j.partcode === i)
          let sum = 0
          const good_qty = k.filter(j => j.partcode === i).map(j => parseFloat(j.good_qty)).reduce((pre, curr) => {
            sum = pre + curr
            return sum
          })
          sum = 0
          const inhouseqty = k.filter(j => j.partcode === i).map(j => parseFloat(j.inhouseqty)).reduce((pre, curr) => {
            sum = pre + curr
            return sum
          })
          sum = 0
          const stinhouseqty = k.filter(j => j.partcode === i).map(j => parseFloat(j.stinhouseqty)).reduce((pre, curr) => {
            sum = pre + curr
            return sum
          })
          newData.push(
            {
              stockcode: t.stockcode,
              partcode: t.partcode,
              partname: t.partname,
              partspec: t.partspec,
              qty: t.qty,
              good_qty,
              inhouseqty,
              stinhouseqty,
              unitid: t.unitid,
              unitname: t.unitname,
              sourceVoucherDetailId: t.sourceVoucherDetailId,
              saleOrderDetailId: t.saleOrderDetailId,
              ManufactureOrderDetailId: t.ManufactureOrderDetailId,
              stck_id: this.stockcodeArr.find(i => i.code === t.stockcode).id,
              SourceVoucherDetailIdByMergedFlow: t.sbid,
              materiel_code: t.partcode,
              warehouse: t.warehouse,
              materiel_id: t.materiel_id
      }
          )
        })
      })
      // console.log(Array2D, 'Array2D')
      // console.log(newData, 'newData')
      // partcodeArr.forEach(i => {
      //   const t = this.multipleSelection.find(j => j.partcode === i)
      //   let sum = 0
      //   const good_qty = this.multipleSelection.filter(j => j.partcode === i).map(j => parseFloat(j.good_qty)).reduce((pre, curr) => {
      //     sum = pre + curr
      //     return sum
      //   })
      //   sum = 0
      //   const inhouseqty = this.multipleSelection.filter(j => j.partcode === i).map(j => parseFloat(j.inhouseqty)).reduce((pre, curr) => {
      //     sum = pre + curr
      //     return sum
      //   })
      //   sum = 0
      //   const stinhouseqty = this.multipleSelection.filter(j => j.partcode === i).map(j => parseFloat(j.stinhouseqty)).reduce((pre, curr) => {
      //     sum = pre + curr
      //     return sum
      //   })
      //   newData.push(
      //     {
      //       partcode: i,
      //       partname: t.partname,
      //       partspec: t.partspec,
      //       qty: t.qty,
      //       good_qty,
      //       inhouseqty,
      //       stinhouseqty
      //     }
      //   )
      // })
      this.tableDataSummary = newData.flat()
    },
    // 提交
    submit() {
    // 入库提交
    async  submit() {
      await this.tabClick()
      this.multipleSelection.forEach(i => {
        i.stockname = this.stockcodeArr.find(j => j.code === i.stockcode).name
        i.id = this.stockcodeArr.find(j => j.code === i.stockcode).id
      })
      const head = {
        hbillno: this.form.hbillno,
        incbit: this.form.incbit,
        sourceVoucherId: this.form.documentType === 'Y' ? this.tableDataDetail[0].mpoid : '',
        sourceVoucherCode: this.form.documentType === 'Y' ? this.tableDataDetail[0].m_po : this.tableDataDetail[0].wo_code,
        saleOrderId: this.tableDataDetail[0].saleOrderid,
        saleOrderCode: this.tableDataDetail[0].saleOrderCode,
        rdDirectionFlag: 1,
        makerid: this.userArr.find(i => i.name === getCookie('username').id),
        maker: getCookie('username'),
        accountingyear: new Date().getFullYear(),
        VoucherYear: new Date().getFullYear(),
        VoucherPeriod: new Date().getMonth() + 1,
        ManufactureOrderCode: this.form.documentType === 'Y' ? this.tableDataDetail[0].m_po : this.tableDataDetail[0].wo_code,
        idbusitype: '03',
        iddepartment: this.WorkShopArr.find(i => i.code === this.form.wkshopcode).id,
        idrdstyle: 21,
        idwarehouse: '',
        voucherState: handleDatetime(new Date().getTime()),
        idvouchertype: 15,
        voucherdate: handleDatetime(new Date().getTime()),
        madedate: handleDatetime(new Date().getTime()),
        createdtime: handleDatetime2(new Date().getTime()),
        DataSource: '56133'
      }
      const subsum = []
      this.tableDataSummary.forEach((i, index) => {
        subsum.push({
          code: index.toString().padStart(4, '0'),
          rownumber: index + 1,
          arrivalQuantity: i.qty,
          quantity: i.stinhouseqty,
          compositionQuantity: i.stinhouseqty + i.unitname,
          baseQuantity: i.stinhouseqty,
          sourceVoucherId: this.form.documentType === 'Y' ? this.tableDataDetail[0].mpoid : '',
          sourceVoucherCode: this.form.documentType === 'Y' ? this.tableDataDetail[0].m_po : this.tableDataDetail[0].wo_code,
          sourceVoucherDetailId: i.sourceVoucherDetailId,
          idsourcevouchertype: 69,
          saleOrderId: this.tableDataDetail[0].saleOrderid,
          saleOrderCode: this.tableDataDetail[0].saleOrderCode,
          saleOrderDetailId: i.saleOrderDetailId,
          ManufactureOrderId: this.form.documentType === 'Y' ? this.tableDataDetail[0].mpoid : '',
          ManufactureOrderCode: this.form.documentType === 'Y' ? this.tableDataDetail[0].m_po : this.tableDataDetail[0].wo_code,
          ManufactureOrderDetailId: i.ManufactureOrderDetailId,
          idbusiTypeByMergedFlow: 3,
          idinventory: i.materiel_id,
          idbaseunit: i.unitid,
          idwarehouse: i.stck_id,
          SourceVoucherIdByMergedFlow: this.tableDataDetail[0].mpoid,
          SourceVoucherCodeByMergedFlow: this.tableDataDetail[0].m_po,
          SourceVoucherDetailIdByMergedFlow: i.SourceVoucherDetailIdByMergedFlow,
          idsourceVoucherTypeByMergedFlow: 69,
          createdtime: handleDatetime2(new Date().getTime()),
          DataSource: '56133',
          materiel_code: i.materiel_code,
          warehouse: i.warehouse
        })
      })
      const data = {
        head, sub: this.multipleSelection, subsum
      }
      console.log(JSON.stringify(data))
      const res = await ProductInHouseOrderSeave(data)
      if (res.code === '200') {
        this.$message.success('入库提交成功!')
      }
    },
    // 获取页面高度
    getHeight() {