loulijun2021
2023-06-07 a93255e0a0334b51ecbaf3d8f496ad0fae1ed747
src/views/produceManager/productWarehouse.vue
@@ -206,15 +206,21 @@
              <el-date-picker
                v-model="form.lm_date"
                style="width: 200px"
                readonly
                type="date"
                placeholder="选择日期"
              />
            </el-form-item>
            <el-form-item label="单据编号" style=" display: flex;">
              <el-input v-model="form.OrgName" placeholder="请输入" style="width: 200px" />
              <el-input
                v-model="form.hbillno"
                readonly
                placeholder="请输入"
                style="width: 200px"
              />
            </el-form-item>
            <el-form-item label="入库仓库" style=" display: flex;">
            <el-form-item label="入库仓库" required style=" display: flex;">
              <el-select
                v-model="form.stockcode"
                :popper-append-to-body="false"
@@ -237,7 +243,14 @@
            class="bodySearchReset"
            :style="{marginLeft:$store.state.app.sidebar.opened? $store.state.settings.menuIsHorizontal?'15%':'3%':'10%'}"
          >
            <el-button v-waves type="primary" icon="el-icon-s-promotion" @click="submit">入库提交</el-button>
            <el-button
              v-waves
              type="primary"
              icon="el-icon-s-promotion"
              :disabled="$store.state.app.buttonIsDisabled"
              @click="submit"
            >入库提交
            </el-button>
            <!--            <el-button v-waves type="info" icon="el-icon-refresh" @click="reset">重置</el-button>-->
          </div>
        </el-form>
@@ -290,32 +303,33 @@
                    label="序号"
                  />
                  <el-table-column
                    prop="stockcode"
                    label="仓库"
                    width="160"
                    show-tooltip-when-overflow
                  >
                    <template slot-scope="{row}">
                      <div
                        v-if="!(row.index === tabClickIndex && tabClickLabel === '仓库')"
                      >
                        {{ row.stockcode ? stockcodeArr.find(i => i.code === row.stockcode).name : '/' }}
                      </div>
                      <el-select
                        v-if="row.index === tabClickIndex && tabClickLabel === '仓库'"
                        v-model="row.stockcode"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in stockcodeArr"
                          :key="item.code"
                          :label="item.name"
                          :value="item.code"
                        />
                      </el-select>
                    </template>
                  </el-table-column>
                  <!--                  <el-table-column-->
                  <!--                    prop="stockcode"-->
                  <!--                    label="仓库"-->
                  <!--                    width="160"-->
                  <!--                    show-tooltip-when-overflow-->
                  <!--                  >-->
                  <!--                    <template slot-scope="{row}">-->
                  <!--                      <div>{{ row.stockcode ? stockcodeArr.find(i => i.code === row.stockcode).name : '/' }}</div>-->
                  <!--                      &lt;!&ndash;                      <div&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                        v-if="!(row.index === tabClickIndex && tabClickLabel === '仓库')"&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                      >&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                        {{ row.stockcode ? stockcodeArr.find(i => i.code === row.stockcode).name : '/' }}&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                      </div>&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                      <el-select&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                        v-if="row.index === tabClickIndex && tabClickLabel === '仓库'"&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                        v-model="row.stockcode"&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                        placeholder="请选择"&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                      >&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                        <el-option&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                          v-for="item in stockcodeArr"&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                          :key="item.code"&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                          :label="item.name"&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                          :value="item.code"&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                        />&ndash;&gt;-->
                  <!--                      &lt;!&ndash;                      </el-select>&ndash;&gt;-->
                  <!--                    </template>-->
                  <!--                  </el-table-column>-->
                  <el-table-column
                    prop="inbarcode"
                    label="入库条码"
@@ -560,7 +574,7 @@
                    width="110"
                  >
                    <template slot-scope="{row}">
                      <div>{{ stockcodeArr.find(i=>i.code===row.stockcode).name }}</div>
                      <div>{{ stockcodeArr.find(i => i.code === row.stockcode).name }}</div>
                    </template>
                  </el-table-column>
                  <!--                    <template slot-scope="{row}">-->
@@ -677,9 +691,15 @@
  ProductInHouseOrderSearch, ProductInHouseOrderSeave,
  ProductInHouseWkshopOrder
} from '@/api/produceManager'
import { handleDatetime, handleDatetime2 } from '@/utils/global'
import { ErpUserSelect, ErpWarehouseSelect, ErpWkshopDepartmentSelect } from '@/api/basicInfo'
import { getTPlusToken, handleDatetime, handleDatetime2 } from '@/utils/global'
import {
  ErpUserSelect,
  ErpWarehouseSelect,
  ErpWkshopDepartmentSelect
} from '@/api/basicInfo'
import { getCookie } from '@/utils/auth'
import Vue from 'vue'
import axios from 'axios'
export default {
  name: 'Zzjg',
@@ -694,8 +714,8 @@
        incbit: '', // 流水号
        documentType: 'Y', // 单据类型
        wkshopcode: 'CJ001', // 生产车间
        erpordercode: 'MO-2023-05-0007', // 订单编号
        wkshopcode: '', // 生产车间
        erpordercode: '', // 订单编号
        mesordercode: '', // 工单编号
        partcode: '', // 产品编码
        partname: '', // 产品名称
@@ -703,7 +723,7 @@
        orderdate: '', // 工单日期
        saleOrderCode: '', // 销售订单
        lm_date: '', // 单据日期
        lm_date: new Date(), // 单据日期
        stockcode: '' // 入库仓库
      },
@@ -742,7 +762,7 @@
    this.getProductInHouseOrderCodeSearch()
    this.getProductInHouseOrderSearch()
    // this.getProductInHouseOrderSearch()
  },
  methods: {
    async getProductInHouseOrderCodeSearch() {
@@ -839,6 +859,8 @@
      this.form.orderdate = ''
      this.tableDataDetail = []
      this.tableDataSummary = []
      this.multipleSelection = []
    },
    // 表格单元格双击
@@ -971,87 +993,324 @@
      this.tableDataSummary = newData.flat()
    },
    // 入库提交
    async  submit() {
    async submit() {
      if (!this.form.stockcode) {
        return this.$message.error('入库仓库不能为空!')
      }
      if (this.multipleSelection.length === 0) {
        return this.$message.error('未选择产品!')
      }
      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 = {
        rightcode: '2064',
        hbillno: this.form.hbillno,
        incbit: this.form.incbit,
        wkshpcode: this.form.wkshopcode,
        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: 181,
        idvouchertype: 15,
        voucherdate: handleDatetime(new Date().getTime()),
        madedate: handleDatetime(new Date().getTime()),
        createdtime: handleDatetime2(new Date().getTime()),
        DataSource: '56133'
      const openToken = await getTPlusToken() // 获取TPlus   token
      // const openToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpc3YiLCJpc3MiOiJjaGFuamV0IiwidXNlcklkIjoiMzkwNTU0MDg2NTMwMjYxIiwib3JnSWQiOiIxMjM0OTc5MDE3MjIxMDM3IiwiYWNjZXNzX3Rva2VuIjoiYmstOGIwNDUxNzEtMDk5Yy00ODFlLTgyZDEtY2Q5NWQ2MjUzZGUwIiwiYXVkIjoiaXN2IiwibmJmIjoxNjg2MDQ3NTgyLCJhcHBJZCI6IjU4Iiwic2NvcGUiOiJhdXRoX2FsbCIsImlkIjoiNjA5Y2ZhYzItNzZmOC00NzJiLWI2NGEtMDg1NmRjMWZmYTg4IiwiZXhwIjoxNjg2NTY1OTgyLCJpYXQiOjE2ODYwNDc1ODIsIm9yZ0FjY291bnQiOiJ1dXhicGtzbTBibmgifQ.slZ_ix3DoGBX2WUX1TOiwe7jCEqDHf9Kc-Gn6cVCFZk'
      this.$store.state.app.buttonIsDisabled = true
      // 有源单
      if (this.form.documentType === 'Y') {
        const RDRecordDetails = []
        this.tableDataSummary.forEach((i, index) => {
          RDRecordDetails.push({
            Code: index + 1, // 行号,从1开始自增长
            SourceVoucherId: this.tableDataDetail[0].mpoid, // 来源单据的单据ID
            BaseQuantity: i.stinhouseqty, // 主计量单位数量
            SourceVoucherDetailId: i.sourceVoucherDetailId, // 来源单据的对应明细ID
            Inventory: {
              Code: i.materiel_code // 存货编码
            },
            IdSourceVoucherType: 69
          })
        })
        const data = {
          'dto': {
            'Warehouse': {
              'Code': this.form.stockcode// 仓库编码
            },
            'Code': this.form.hbillno, // 单据编码
            'IsModifiedCode': true,
            'BusiType': {
              'Code': '03'// 业务类型编码
            },
            'Department': {
              'Code': this.form.wkshopcode// 部门编码
            },
            'VoucherDate': handleDatetime(new Date().getTime()), // 单据日期
            'RdStyle': {
              'Code': '21'// 出库类别编码
            },
            'RDRecordDetails': RDRecordDetails,
            // 'Clerk': {
            //   'Code': this.userArr.find(i => i.name === getCookie('username')).code // 业务员code
            //   // 'Code': '001' // 业务员code
            //   // 'Name': getCookie('username')
            // },
            'ExternalCode': this.form.hbillno,
            'VoucherType': {
              'Code': 'ST1002'
            }
          }
        }
        const res = await axios.post(Vue.prototype.$chanjetBaseUrl + '/tplus/api/v2/ProductReceiveOpenApi/Create',
          data, {
            headers: {
              'openToken': openToken,
              'appKey': Vue.prototype.$AppKey,
              'appSecret': Vue.prototype.$AppSecret,
              'Content-Type': 'application/json'
            }
          }
        )
        if (res.data.code === 0) {
          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 = {
            rightcode: '2064',
            hbillno: this.form.hbillno,
            incbit: this.form.incbit,
            wkshpcode: this.form.wkshopcode,
            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: 181,
            idvouchertype: 15,
            voucherdate: handleDatetime(new Date().getTime()),
            madedate: handleDatetime(new Date().getTime()),
            createdtime: handleDatetime2(new Date().getTime()),
            DataSource: '56133',
            idsourcevouchertype: 69
          }
          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,
              idunit: 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
          }
          const r1 = await ProductInHouseOrderSeave(data)
          if (r1.code === '200') {
            this.$message.success('入库成功!')
            this.$store.state.app.buttonIsDisabled = false
            await this.getProductInHouseOrderCodeSearch()
            await this.wkshopcodeChange(this.form.wkshopcode)
            this.tableDataDetail = []
            this.tableDataSummary = []
            this.multipleSelection = []
            this.form.stockcode = ''
          }
        } else {
          this.$message.error('入库失败!')
          this.$store.state.app.buttonIsDisabled = false
        }
      }
      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,
      // 无源单
      if (this.form.documentType === 'N') {
        const RDRecordDetails = []
        this.tableDataSummary.forEach((i, index) => {
          RDRecordDetails.push({
            Code: index + 1, // 行号,从1开始自增长
            Inventory: {
              Code: i.materiel_code // 存货编码
            },
            BaseQuantity: i.stinhouseqty, // 主计量单位数量
            SNObject: {
              SnAccountDetails: [
                {
                  SNCode: index.toString().padStart(4, '0')
                }
              ]
            }
          })
        })
        const data = {
          'dto': {
            'IsModifiedCode': true,
            'ExternalCode': this.form.hbillno,
            'Code': this.form.hbillno,
            'VoucherType': {
              'Code': 'ST1002'
            },
            'VoucherDate': handleDatetime(new Date().getTime()),
            'BusiType': {
              'Code': '03'
            },
            'Warehouse': {
              'Code': this.form.stockcode
            },
            'Department': {
              'Code': this.form.wkshopcode,
              'Name': this.WorkShopArr.find(i => i.code === this.form.wkshopcode).name
            },
            'RDRecordDetails': RDRecordDetails
          }
        }
        const res = await axios.post(Vue.prototype.$chanjetBaseUrl + '/tplus/api/v2/productReceive/Create',
          data, {
            headers: {
              'openToken': openToken,
              'appKey': Vue.prototype.$AppKey,
              'appSecret': Vue.prototype.$AppSecret,
              'Content-Type': 'application/json'
            }
          }
        )
        if (res.data === null) {
          this.$message.success('入库成功!')
          this.$store.state.app.buttonIsDisabled = false
        } else {
          this.$message.error('入库失败!')
          this.$store.state.app.buttonIsDisabled = false
        }
      }
    },
    // 入库提交
    submit2() {
      this.tabClick()
      this.$confirm('是否确认提交?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.multipleSelection.length === 0) {
          return this.$message.error('未选择产品!')
        }
        if (this.multipleSelection.find(i => !i.stockcode)) {
          return this.$message.error('明细里面有产品未填写仓库!')
        }
        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 = {
          rightcode: '2064',
          hbillno: this.form.hbillno,
          incbit: this.form.incbit,
          wkshpcode: this.form.wkshopcode,
          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 : '',
          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,
          ManufactureOrderDetailId: i.ManufactureOrderDetailId,
          idbusiTypeByMergedFlow: 3,
          idinventory: i.materiel_id,
          idbaseunit: i.unitid,
          idunit: i.unitid,
          idwarehouse: i.stck_id,
          SourceVoucherIdByMergedFlow: this.tableDataDetail[0].mpoid,
          SourceVoucherCodeByMergedFlow: this.tableDataDetail[0].m_po,
          SourceVoucherDetailIdByMergedFlow: i.SourceVoucherDetailIdByMergedFlow,
          idsourceVoucherTypeByMergedFlow: 69,
          idbusitype: '03',
          iddepartment: this.WorkShopArr.find(i => i.code === this.form.wkshopcode).id,
          idrdstyle: 21,
          idwarehouse: '',
          voucherState: 181,
          idvouchertype: 15,
          voucherdate: handleDatetime(new Date().getTime()),
          madedate: handleDatetime(new Date().getTime()),
          createdtime: handleDatetime2(new Date().getTime()),
          DataSource: '56133',
          materiel_code: i.materiel_code,
          warehouse: i.warehouse
          idsourcevouchertype: 69
        }
        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,
            idunit: 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
        }
        ProductInHouseOrderSeave(data).then(res => {
          if (res.code === '200') {
            this.$message.success('入库提交成功!')
            this.getProductInHouseOrderCodeSearch()
            this.wkshopcodeChange(this.form.wkshopcode)
            this.tableDataDetail = []
            this.tableDataSummary = []
            this.multipleSelection = []
          }
        })
      })
      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() {