deliverAdd.vue 11.7 KB
<template>
  <GLDialog v-if="dialogShow" bigTitle="详细信息" mode="big" :visible.sync="dialogShow" :close-on-click-modal="false">
    <div class="detail-info">
      <div>
        发货单号:
        <span>{{ detailInfo.deliveryNumber }}</span>
      </div>
      <div>
        承运公司:
        <span>{{ detailInfo.deliveryCompany }}</span>
      </div>
      <div>
        发货时间:
        <span>{{ dayjs(detailInfo.deliveryDate).format('YYYY-MM-DD HH:mm:ss') }}</span>
      </div>
    </div>
    <template v-for="(item, index) in detailInfo.deliveryDetailList">
      <div class="table-wrap" :key="index">
        <div class="detail-info">
          <div>
            商品名称:
            <span>{{ item.upgradeGoodsName }}</span>
          </div>
          <div>
            发货数量:
            <span>{{ membraneTypeList.includes(item.goodsType) ? `${item.purchaseNumber}卷` : `${item.purchaseNumber}件` }}</span>
            <span class="lookNumber" @click="lookNumber(item.deliveryCardList)" v-if="item.deliveryCardList && item.deliveryCardList.length > 0">查看卡号</span>
          </div>
          <div>
            可用库存数量:
            <span>{{ item.stockNum }}{{ membraneTypeList.includes(item.goodsType) ? `米` : `件` }}</span>
          </div>
          <div class="add-btn" @click="addLineTable(index)" v-if="item.deliveryCardList === null || item.deliveryCardList.length == 0">
            添加入库记录
          </div>
        </div>
        <el-form ref="addForm" :model="item" size="small" :rules="rules" v-if="item.deliveryCardList === null || item.deliveryCardList.length == 0">
          <GLTable :tableData="item.goodsWarehousingList" :noDataImg="url" :tableParams="tableParams" :hasPage="false">
            <template slot="increaseStockNum" slot-scope="scope">
              <el-form-item style="margin-bottom: 0px" :prop="'goodsWarehousingList.' + scope.index + '.increaseStockNum'" :rules="rules.increaseStockNum">
                <el-input v-model="scope.scope.increaseStockNum" placeholder="请输入" @blur="handleCalculate(scope.scope, 'increaseStockNum', index)"></el-input>
              </el-form-item>
            </template>
            <!-- 入库仓库 -->
            <template slot="yqMerchantId" slot-scope="scope">
              <el-form-item style="margin-bottom: 0px" :prop="'goodsWarehousingList.' + scope.index + '.yqMerchantId'" :rules="rules.shopMerchantName">
                <el-select style="width: 100%" v-model="scope.scope.yqMerchantId" placeholder="请选择" @change="handleSelect(scope.scope, scope.scope.yqMerchantId)">
                  <el-option v-for="item in storeUsageList" :key="item.merchantNo" :label="item.merchantName" :value="item.merchantNo"></el-option>
                </el-select>
              </el-form-item>
            </template>
            <!-- 入库门店 -->
            <template slot="merchantId" slot-scope="scope">
              <el-form-item style="margin-bottom: 0px" :prop="'goodsWarehousingList.' + scope.index + '.merchantId'" :rules="rules.merchantId">
                <el-select style="width: 100%" v-model="scope.scope.merchantId" placeholder="请选择" @change="handleStoreSelect(scope.scope, scope.scope.merchantId)">
                  <el-option v-for="item in refByYqShopList" :key="item.merchantId" :label="item.merchantName" :value="item.merchantId"></el-option>
                </el-select>
              </el-form-item>
            </template>
            <div class="table-btns" slot="auth-button" slot-scope="scope">
              <el-button type="text" @click="handleDelete(index, scope.index)">删除</el-button>
            </div>
          </GLTable>
        </el-form>
         <div v-else class="message">
          已自动入库至商户的权益卡管理中,可前往“库存管理-权益卡管理”中查询
        </div>
      </div>
    </template>
    <el-dialog width="750px" title="查看发货卡号" :visible.sync="innerVisible" append-to-body>
      <GLTable class="look-card-wrap" :tableData="tableData" :noDataImg="url" :tableParams="innerParams" :hasPage="false"></GLTable>
    </el-dialog>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogShow = false">关闭</el-button>
      <el-button type="primary" size="small" @click="handleSave">保存入库</el-button>
    </span>
  </GLDialog>
</template>
<script>
import BigNumber from 'bignumber.js'
import * as dayjs from 'dayjs'
import { membraneTypeList } from '@/utils/constants.js'
export default {
  name: 'DeliverAdd',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    id: {
      type: String,
      default: ''
    }
  },
  computed: {
    dialogShow: {
      get() {
        if (this.visible) {
          this.getDetail()
        }
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  data() {
    var checkPrice = (rule, value, callback) => {
      if (isNaN(+value)) {
        callback(new Error('请输入数字值'))
      } else {
        if (value <= 0 || value > 999999) {
          callback(new Error('仅支持输入0~999999'))
        } else {
          callback()
        }
      }
    }
    return {
      membraneTypeList: membraneTypeList,
      dayjs: dayjs,
      goodsList: [],
      storeUsageList: [],
      refByYqShopList: [],
      tableParams: {
        tableOption: true,
        tableColumns: [
          {
            label: '入库数量',
            prop: 'increaseStockNum',
            addHtml: 'increaseStockNum'
          },
          {
            label: '入库仓库',
            prop: 'yqMerchantId',
            addHtml: 'yqMerchantId'
          },
          {
            label: '入库门店',
            prop: 'merchantId',
            addHtml: 'merchantId'
          }
        ]
      },
      rules: {
        yqMerchantId: [{ required: true, message: '请选择入库仓库', trigger: 'change' }],
        merchantId: [{ required: true, message: '请选择入库门店', trigger: 'change' }],
        increaseStockNum: [
          { required: true, message: '请输入入库数量', trigger: 'blur' },
          { validator: checkPrice, trigger: 'blur' }
        ]
      },
      detailInfo: {},
      innerVisible: false,
      innerParams: {
        tableOption: false,
        tableColumns: [
          {
            label: '卡号',
            prop: 'cardNum',
            width: 630
          }
        ]
      },
      tableData: []
    }
  },
  created() {},
  methods: {
    lookNumber(data) {
      this.innerVisible = true
      this.tableData = data.map(item => {
        return { cardNum: item }
      })
    },
    handleCalculate(data, key, index) {
      if (data[key] > this.detailInfo.deliveryDetailList[index].stockNum) {
        data[key] = this.detailInfo.deliveryDetailList[index].stockNum
        return
      }
      data[key] = data[key] ? new BigNumber(data[key]).dp(2).toNumber() : ''
    },
    getMerchantList() {
      this.$apis.purchaseShopping.getMerchantList({ mainPartnerMerchant: true }).then(res => {
        this.storeUsageList = res
        if (this.storeUsageList.length == 1) this.defaultSelect()
      })
    },
    defaultSelect() {
      let {
        detailInfo: { deliveryDetailList },
        storeUsageList
      } = this
      deliveryDetailList.forEach(item => {
        item.goodsWarehousingList[0].yqMerchantName = storeUsageList[0].merchantName
        item.goodsWarehousingList[0].yqMerchantId = storeUsageList[0].merchantNo
      })
      this.getRefByYqShopList(deliveryDetailList[0].goodsWarehousingList[0], storeUsageList[0].merchantNo)
    },
    getRefByYqShopList(data, value) {
      this.$apis.purchaseShopping.get4SRefByYqShopList({ scene: 1, merchantId: value }).then(res => {
        this.refByYqShopList = res
        if (data) {
          this.refByYqShopList.unshift({
            merchantName: data.yqMerchantName,
            merchantId: data.yqMerchantId
          })
        }
      })
    },
    handleSelect(data, id) {
      this.storeUsageList.forEach(item => {
        if (item.merchantNo == id) {
          data.yqMerchantName = item.merchantName
          data.merchantId = ''
        }
      })
      this.getRefByYqShopList(data, id)
    },
    handleStoreSelect(data, id) {
      this.refByYqShopList.forEach(item => {
        if (item.merchantId == id) {
          data.merchantName = item.merchantName
        }
      })
    },
    handleDetailClose() {
      this.dialogShow = false
    },
    getDetail() {
      this.$apis.delivery.getDeliveryDetail({ id: this.id }).then(res => {
        if (res.code == 0) {
          res.data.deliveryDetailList.forEach(item => {
            item.goodsWarehousingList = [
              {
                increaseStockNum: '',
                yqMerchantId: '',
                yqMerchantName: '',
                merchantId: '',
                merchantName: ''
              }
            ]
          })
          this.detailInfo = res.data
          this.getMerchantList()
        }
      })
    },
    handleDelete(index, line) {
      if (this.detailInfo.deliveryDetailList[index].goodsWarehousingList.length > 1) {
        this.detailInfo.deliveryDetailList[index].goodsWarehousingList.splice(line, 1)
      }
    },
    addLineTable(index) {
      let { storeUsageList } = this
      this.detailInfo.deliveryDetailList[index].goodsWarehousingList.push({
        increaseStockNum: '',
        yqMerchantId: storeUsageList.length == 1 ? storeUsageList[0].merchantNo : '',
        yqMerchantName: storeUsageList.length == 1 ? storeUsageList[0].merchantName : '',
        merchantId: '',
        merchantName: ''
      })
      let data = this.detailInfo.deliveryDetailList
      this.$set(data, index, data[index])
    },
    validateForm(form) {
      return new Promise(resolve => {
        form.validate(valid => {
          if (valid) {
            resolve()
          }
        })
      })
    },
    handleSave() {
      let num = 0
      this.$refs['addForm'].forEach(async item => {
        try {
          await this.validateForm(item)
          num++
        } catch (err) {
          console.log(err)
        }

        if (num == this.$refs['addForm'].length) {
          let deliveryDetailList = this.detailInfo.deliveryDetailList.map(item => {
            if (item.deliveryCardList.length == 0) {
              return item
            }
          })
          let params = {
            deliveryDetailList: deliveryDetailList
          }
          params.id = this.id
          this.$apis.delivery.addPurchaseOrder(params).then(res => {
            if (res.code == 0) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
              this.dialogShow = false
              this.$emit('handleSuccess')
            } else {
              this.$message({
                type: 'error',
                message: res.message
              })
            }
          })
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.detail-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #666666ff;
  font-size: 14px;
  margin-bottom: 16px;
  span {
    color: #333333ff;
  }
  .add-btn {
    font-size: 14px;
    color: #5850ff;
    cursor: pointer;
  }
}
.table-wrap {
  border: 1px solid #e5e5e5;
  padding: 16px;
  box-sizing: border-box;
  margin-top: 16px;
  /deep/ .el-form-item__error {
    padding-top: 2px;
    z-index: 9999999;
    position: static;
  }
  /deep/ td.el-table__cell {
    height: 64px;
  }
}
.lookNumber {
  font-size: 14px;
  color: #5850ff !important;
  cursor: pointer;
  margin-left: 8px;
}
.look-card-wrap{
  /deep/.el-table th.el-table__cell>.cell {
    padding: 0 16px;
    text-align: center;
}
/deep/.el-table__body td.el-table__cell {
    text-align: center;
}
}
</style>