addInventory.vue 9.94 KB
<!-- 创建盘点 -->
<template>
  <div>
    <d2-container>
      <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>
        <p>盘存</p>
        <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="inventory(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) + (membraneTypeList.includes(scope.scope.goodsType) ? '米'
                  : '件') }}</span>
              <span v-else-if="parseFloat(scope.scope.profitAndLoss) < 0" style="color:red">{{
                parseFloat(scope.scope.profitAndLoss).toFixed(2) + (membraneTypeList.includes(scope.scope.goodsType) ? '米'
                  : '件') }}</span>
              <span v-else>{{ parseFloat(scope.scope.profitAndLoss).toFixed(2) +
                (membraneTypeList.includes(scope.scope.goodsType) ? '米' : '件') }}</span>
            </span>
            <span v-else>-</span>
          </template>
          <div slot="auth-button" slot-scope="scope">
            <el-button type="text" @click="cancelInventory(scope.row, scope.$index)">
              取消
            </el-button>
          </div>
        </d2-table>
      </div>
      <d2-form ref="addInventoryForm" :origin-data="editData" :form-list="editForm" form-ref="inveFormRef"
               @handleAddConfirm="handleAddConfirm" @handleClose="handleAddClose">
      </d2-form>
    </d2-container>
    <!-- 盘点 -->
    <inventory-num-dialog :inventory-num-visible="inventoryNumVisible" :record-info="recordInfo"
                          v-if="inventoryNumVisible" @dialogClose="dialogClose" />
  </div>
</template>

<script>
import { deepClone } from '@/common/util'
import { mapActions, mapState } from 'vuex'
import { stockRemainPage, saveStockCheck } from '@api/stockManage'
import inventoryNumDialog from './inventoryNumDialog'
import { baseConfig } from '@/main'
export default {
  name: 'InventoryList',
  components: {
    inventoryNumDialog
  },
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      membraneTypeList: baseConfig.membraneTypeList,
      searchForm: {
        searchName: ''
      },
      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: 'checkStock',
          formatter: (cellValue) => {
            return (cellValue.checkStock || cellValue.checkStock == 0) ? parseFloat(cellValue.checkStock).toFixed(2) + (this.membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
          }
        }, {
          label: '盘盈盘亏',
          prop: 'profitAndLoss',
          addHtml: 'profitAndLoss'
        }, {
          label: '所属门店',
          prop: 'yqMerchantName',
          width: '200px'
        }
        ]
      },
      baseData: {
        // productTypeList: [],
        // yqMerchantList: []
      },

      editData: {
        thumbUrlList: []
      },
      editForm: [{
        formBlock: [
          {
            name: 'thumbUrlList',
            label: '凭证图片',
            type: 'photo',
            tips: ['请上传小于2M的图片'],
            maxPhotoNum: 1
          }, {
            name: 'remark',
            label: '备注说明',
            type: 'textarea',
            maxlength: 100
          }]
      }],

      inventoryNumVisible: false,
      recordInfo: null,
      chooseDataList: []
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  mounted() {
    // this.getBaseData()
  },

  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()
    },

    // 盘点
    inventory(row) {
      this.recordInfo = row
      this.inventoryNumVisible = true
    },

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

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

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

    handleAddConfirm(data) {
      if (this.chooseDataList.length == 0) {
        this.notice.warningTips('请选择盘存商品')
        return
      }
      var params = {}
      params.stockCheckDetailList = this.chooseDataList
      if (data.thumbUrlList.length > 0) {
        params.voucherPic = data.thumbUrlList[0].content
      }
      if (data.remark) {
        params.remark = data.remark
      }
      // return console.log(params);
      this.$confirm("盘点单保存后,系统自动按照盘点实际库存进行库存更新;是否确定保存?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          saveStockCheck(params).then(res => {
            this.notice.okTips()
            this.handleAddClose()
          })
        })
        .catch((err) => {
          console.log(err)
        })
    },

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

  }
}

</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>