addAllocation.vue 11.4 KB
<!-- 创建调拨 -->
<template>
  <div>
    <d2-container>
      <div class="header" slot="header" style="padding: 10px 20px;">
        <el-form :inline="true" :model="editAllocationForm" ref="editAllocationFormRef" :rules="formRules"
                 class="demo-form-inline">
          <el-form-item label="调出门店:" prop="callOutYqMerchantId">
            <el-select v-model="editAllocationForm.callOutYqMerchantId" style="width:300px">
              <el-option v-for="item in callOutYqMerchantList" :key="item.merchantNo" :label="item.merchantName"
                         :value="item.merchantNo" />
            </el-select>
          </el-form-item>
          <el-form-item label="调入门店:" prop="callInYqMerchantId">
            <el-select v-model="editAllocationForm.callInYqMerchantId" filterable style="width:300px">
              <el-option v-for="item in callInYqMerchantList" :key="item.merchantId" :label="item.merchantName"
                         :value="item.merchantId" />
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="d2-container-content">
        <div class="header" slot="header" style="padding: 15px 0;">
          <!-- <d2-search ref="showSearch"
                   class="show-search"
                   :search-form="searchForm"
                     :form-data="showFormData" /> -->
          <div>
            <el-input v-model="searchForm.searchName" style="width:200px;" placeholder="请输入商品名称/系列" maxlength="20"
                      clearable />
            <!-- <el-button :id="tableParams.btnId"
                     size="small"
                     type="primary">
            查询
            </el-button> -->
            <el-button @click="handleSearch" size="small" type="primary" style="marginLeft:15px">
              查询
            </el-button>
          </div>
        </div>
        <d2-table ref="recordTable" :get-list-api="getListApi" :search-form="searchFormSearch" :table-params="tableParams"
                  :before-search-fn="beforeSearchFn">
          <div slot="auth-button" slot-scope="scope">
            <el-button type="text" @click="allocation(scope.scope)" :disabled="setDisabled(scope.scope)">
              选择
            </el-button>
          </div>
        </d2-table>
      </div>
      <div class="d2-container-content">
        <p>调拨确认单</p>
        <d2-table ref="recordTable2" :table-data="chooseDataList" :table-params="tableParams2" :has-page="false">
          <!-- <template slot="profitAndLoss"
                    slot-scope="scope">
            <span v-if="scope.scope.profitAndLoss || scope.scope.profitAndLoss == 0">
              <span v-if="parseFloat(scope.scope.profitAndLoss) > 0"
                    style="color:blue">{{ '+' + parseFloat(scope.scope.profitAndLoss).toFixed(2) + (scope.scope.goodsType == 1 ? '米' : '件') }}</span>
              <span v-else-if="parseFloat(scope.scope.profitAndLoss) < 0"
                    style="color:red">{{ parseFloat(scope.scope.profitAndLoss).toFixed(2) + (scope.scope.goodsType == 1 ? '米' : '件') }}</span>
              <span
                    v-else>{{ parseFloat(scope.scope.profitAndLoss).toFixed(2) + (scope.scope.goodsType == 1 ? '米' : '件') }}</span>
            </span>
            </span>
            <span v-else>-</span>
            </template> -->
          <div slot="auth-button" slot-scope="scope">
            <el-button type="text" @click="cancelAllocation(scope.row, scope.$index)">
              取消
            </el-button>
          </div>
        </d2-table>
      </div>
      <d2-form ref="addAllocationForm" :origin-data="editData" :form-list="editForm" form-ref="inveFormRef"
               @handleAddConfirm="handleAddConfirm" @handleClose="handleAddClose">
      </d2-form>
    </d2-container>
    <!-- 调拨 -->
    <allocation-num-dialog :allocation-num-visible="allocationNumVisible" :record-info="recordInfo"
                           v-if="allocationNumVisible" @dialogClose="dialogClose" />
  </div>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { mapActions, mapState } from 'vuex'
import { stockRemainPage, saveStockAllocate, yqRelatedList } from '@api/stockManage'
import allocationNumDialog from './allocationNumDialog'
import { baseConfig } from '@/main'
export default {
  name: 'InventoryList',
  components: {
    allocationNumDialog
  },
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      callOutYqMerchantList: [this.$store.state.d2admin.user.info.merchant],
      membraneTypeList: baseConfig.membraneTypeList,
      callInYqMerchantList: [],
      searchForm: {
        searchName: '',
        stockFlag: true
      },
      searchFormSearch: {},
      searchSelectObj: {
      },
      showFormData: [{
        // label: '商品名称/系列',
        placeholder: '请输入商品名称/系列',
        name: 'searchName',
        type: 'input',
        maxlength: '20',
        isClear: true
      }],
      getListApi: stockRemainPage,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '商品名称',
          prop: 'goodsName',
          width: '160px'
        }, {
          label: '商品编码',
          prop: 'productCode',
          width: '250px'
        }, {
          label: '系列',
          prop: 'sourceMaterialName',
          width: '250px'
        }, {
          label: '所属分类',
          prop: 'goodsTypeName',
          width: '250px'
        }, {
          label: '库存',
          prop: 'stock',
          formatter: (cellValue) => {
            return (cellValue.stock || cellValue.stock == 0) ? parseFloat(cellValue.stock).toFixed(2) + (this.membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
          }
        }, {
          label: '所属门店',
          prop: 'yqMerchantName',
          width: '200px'
        }
        ]
      },
      tableParams2: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '商品名称',
          prop: 'goodsName',
          width: '160px'
        }, {
          label: '商品编码',
          prop: 'productCode',
          width: '250px'
        }, {
          label: '系列',
          prop: 'sourceMaterialName',
          width: '250px'
        }, {
          label: '所属分类',
          prop: 'goodsTypeName',
          width: '250px'
        }, {
          label: '库存',
          prop: 'stock',
          formatter: (cellValue) => {
            return (cellValue.stock || cellValue.stock == 0) ? parseFloat(cellValue.stock).toFixed(2) + (this.membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
          }
        }, {
          label: '调拨库存',
          prop: 'allocateNumber ',
          formatter: (cellValue) => {
            return (cellValue.allocateNumber || cellValue.allocateNumber == 0) ? parseFloat(cellValue.allocateNumber).toFixed(2) + (this.membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
          }
        }
        ]
      },
      baseData: {
        // productTypeList: [],
        // yqMerchantList: []
      },

      editData: {
        // thumbUrlList: [],
      },
      editForm: [{
        formBlock: [
          {
            name: 'remark',
            label: '备注说明',
            type: 'textarea',
            maxlength: 100
          }]
      }],

      editAllocationForm: {
        callOutYqMerchantId: '',
        callInYqMerchantId: ''
      },

      allocationNumVisible: false,
      recordInfo: null,
      chooseDataList: [],
      formRules: {
        callOutYqMerchantId: [{
          required: true,
          message: '请选择调出门店',
          trigger: 'change'
        }],
        callInYqMerchantId: [{
          required: true,
          message: '请选择调入门店',
          trigger: 'change'
        }]
      }
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  mounted() {
    this.editAllocationForm.callOutYqMerchantId = this.callOutYqMerchantList[0].merchantNo
    // 调入门店
    yqRelatedList({ includeSelf: false }).then(res => {
      this.callInYqMerchantList = res
      // this.getOptionsList()
    })
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get',
      close: 'd2admin/page/close'
    }),
    ...mapActions('d2admin/user', ['actionSetDownloadList']),

    // async getBaseData() {
    //   this.getOptionsList()
    // },

    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = deepClone(this.searchForm)
        resolve()
      })
    },

    // getOptionsList() {
    //   this.showFormData.forEach((item, index) => {
    //     if (item.type === 'select') {
    //       if (this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部') {
    //         const temp = {}
    //         temp[this.showFormData[index].optionId] = ''
    //         temp[this.showFormData[index].optionLabel] = '全部'
    //         this.baseData[item.optionsName].unshift(temp)
    //       }
    //       this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
    //     }
    //   })
    // },

    handleSearch() {
      this.$refs.recordTable.refreshTable()
    },

    // 调拨
    allocation(row) {
      this.recordInfo = row
      this.allocationNumVisible = true
    },

    // 设置禁选
    setDisabled(row) {
      const index = this.chooseDataList.findIndex(item => item.id == row.id)
      if (index == -1) {
        return false
      } else {
        return true
      }
    },

    dialogClose(chooseData) {
      this.allocationNumVisible = !this.allocationNumVisible
      console.log(chooseData)
      if (chooseData) {
        this.chooseDataList.push(chooseData)
      }
    },

    // 取消
    cancelAllocation(row, index) {
      this.chooseDataList.splice(index, 1)
    },

    handleAddConfirm(data) {
      this.$refs.editAllocationFormRef.validate(valid => {
        if (valid) {
          if (this.chooseDataList.length == 0) {
            this.notice.warningTips('请选择调拨商品')
            return
          }
          var params = {}
          params.stockCheckDetailList = this.chooseDataList
          if (data.remark) {
            params.remark = data.remark
          }
          params = {
            ...params,
            ...this.editAllocationForm
          }
          this.$confirm("调拨单保存后,系统自动按照调拨数量对调出和调入门店进行库存更新;是否确定保存?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
            .then(() => {
              saveStockAllocate(params).then(res => {
                this.notice.okTips()
                this.handleAddClose()
              })
            })
            .catch((err) => {
              console.log(err)
            })
        }
      })
    },

    handleAddClose(isRefresh = false) {
      this.close({ tagName: '/addAllocation' })
      this.$router.push({ name: 'allocationList' })
    }

  }
}

</script>
<style scoped>
.count-txt {
  font-weight: 700;
  color: #2a58ad;
  margin: 0 2px;
}

.leftSpan {
  display: inline-block;
  box-sizing: border-box;
  margin-right: 10px;
}
</style>