stockList.vue 9.97 KB
<!-- 库存管理 -->
<template>
  <div>
    <d2-container>
      <div class="header"
           slot="header"
           style="padding: 10px 20px;">
        <d2-search ref="showSearch"
                   class="show-search"
                   :search-form="searchForm"
                   :form-data="showFormData" />
        <div class="up-btns">
          <el-button @click="handleSearch"
                     size="small"
                     type="primary">
            查询
          </el-button>
          <el-button size="small"
                     @click="handleReset">
            重置
          </el-button>
        </div>
      </div>
      <div class="d2-container-content">
        <d2-table-header>
          <span slot="left"
                class="leftSpan">合计:当前库存<span class="count-txt">{{ statisticsData }}</span></span>
          <div>
            <auth-button category="Button" />
          </div>
        </d2-table-header>
        <d2-table ref="recordTable"
                  :get-list-api="getListApi"
                  :search-form="searchFormSearch"
                  :table-params="tableParams"
                  :before-search-fn="beforeSearchFn">
          <auth-button slot="auth-button"
                       slot-scope="scope"
                       :data="scope.scope" />
        </d2-table>
      </div>
    </d2-container>
    <!-- 查看 -->
    <stock-month-dialog :stock-month-visible="stockMonthVisible"
                        :record-info="recordInfo"
                        v-if="stockMonthVisible"
                        @dialogClose="dialogClose" />
    <stockDetailDialog :visible.sync="stockDetailDialogVisible"
                       :record-info="recordInfo"
                       v-if="stockDetailDialogVisible">
    </stockDetailDialog>
    <statementOfAccountDialog :visible.sync="statementOfAccountDialogVisible"
                              v-if="statementOfAccountDialogVisible"
                              :yq-merchant-list="baseData.yqMerchantList"
                              @handleRelateProConfirm="handleRelateProConfirm">
    </statementOfAccountDialog>
  </div>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { mapActions, mapState } from 'vuex'
import { getProductTypeBySceneId } from '@api/product'
import { getyqMerchantList, getMerchantGoodsStockMonthReport, stockMonthReportCount } from '@api/stockManage'
import stockMonthDialog from './stockMonthDialog'
import stockDetailDialog from './stockDetailDialog'
import statementOfAccountDialog from './statementOfAccountDialog'
import { baseConfig } from '@/main'
export default {
  name: 'StockList',
  components: {
    stockMonthDialog,
    stockDetailDialog,
    statementOfAccountDialog
  },
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      membraneTypeList: baseConfig.membraneTypeList,
      searchForm: {
        upgradeGoodsName: '',
        yqMerchantId: '',
        goodsType: '',
        goodsSeries: ''
      },
      searchFormSearch: {},
      searchSelectObj: {
        orderOrTrade: {
          attr: 'inputtedOrderCode',
          value: ''
        }
      },
      showFormData: [{
        label: '商品名称',
        name: 'upgradeGoodsName',
        type: 'input',
        maxlength: '20',
        isClear: true
      },
      {
        label: '商品编号',
        name: 'productCode',
        type: 'input',
        maxlength: '40',
        isClear: true
      }, {
        label: '系列',
        name: 'goodsSeries',
        type: 'input',
        maxlength: '20',
        isClear: true
      }, {
        label: '所属分类',
        name: 'goodsType',
        type: 'select',
        optionList: [],
        optionId: 'categoryType',
        optionLabel: 'categoryName',
        optionsName: 'productTypeList'
      }, {
        label: '所属仓库',
        name: 'yqMerchantId',
        type: 'select',
        optionList: [],
        optionId: 'merchantNo',
        optionLabel: 'merchantName',
        optionsName: 'yqMerchantList'
      }, {
        label: '所属商户',
        name: 'partnerMerchantName',
        type: 'input',
        maxlength: '20',
        isClear: true
      }],
      getListApi: getMerchantGoodsStockMonthReport,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '商品名称',
          prop: 'upgradeGoodsName',
          width: '160px'
        }, {
          label: '商品编码',
          prop: 'productCode',
          width: '250px'
        }, {
          label: '系列',
          prop: 'goodsSeries',
          width: '250px'
        }, {
          label: '所属分类',
          prop: 'goodsTypeName',
          width: '250px'
        }, {
          label: '上月结存库存',
          prop: 'lastMonthRemainStock',
          formatter: (cellValue) => {
            return (cellValue.lastMonthRemainStock || cellValue.lastMonthRemainStock == 0) ? parseFloat(cellValue.lastMonthRemainStock).toFixed(2) + (this.membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
          }
        }, {
          label: '上月结存金额',
          prop: 'lastMonthRemainMoney',
          formatter: (cellValue) => {
            return (cellValue.lastMonthRemainMoney || cellValue.lastMonthRemainMoney == 0) ? '¥' + cellValue.lastMonthRemainMoney.toFixed(2) : '-'
          }
        }, {
          label: '当前库存',
          prop: 'stock',
          formatter: (cellValue) => {
            return (cellValue.stock || cellValue.stock == 0) ? parseFloat(cellValue.stock).toFixed(2) + (this.membraneTypeList.includes(cellValue.goodsType) == 1 ? '米' : '件') : '-'
          }
        }, {
          label: '所属仓库',
          prop: 'yqMerchantName',
          width: '200px'
        }, {
          label: '所属商户',
          prop: 'partnerMerchantName',
          width: '200px'
        }
        ]
      },
      baseData: {
        productTypeList: [],
        yqMerchantList: []
      },
      stockDetailDialogVisible: false,
      stockMonthVisible: false,
      recordInfo: null,
      statisticsData: {},
      statementOfAccountDialogVisible: false
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  mounted() {
    // this.getBaseData()
    // 获取全部类目
    getProductTypeBySceneId({ sceneType: '' }).then(res => {
      this.baseData.productTypeList = res
      this.getOptionsList()
    })

    // 获取当前登录账号可见的园区店列表
    getyqMerchantList({ mainPartnerMerchant: true }).then(res => {
      this.baseData.yqMerchantList = res
      this.getOptionsList()
    })

    this.stockMonthReportCount()
  },

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

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

    // 库存记录统计
    stockMonthReportCount() {
      stockMonthReportCount(this.searchFormSearch).then(res => {
        this.statisticsData = res
      })
    },

    // 库存对账单
    handleStatementOfAccount() {
      this.statementOfAccountDialogVisible = true
    },

    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = deepClone(this.searchForm)
        this.searchFormSearch.dataMonth = Util.dateFormate(new Date(), "YYYY-MM")

        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(true, true)
      this.stockMonthReportCount()
    },
    handleReset() {
      this.searchForm = {
        upgradeGoodsName: '',
        yqMerchantId: '',
        goodsType: '',
        goodsSeries: ''
      }
      this.$refs.recordTable.refreshTable()
      this.stockMonthReportCount()
    },

    // 库存对账单导出
    handleRelateProConfirm(data) {
      var params = data
      params.method = 'dj.api.smartcarlife.merchantShopGoodsStock.statement.exportAsync'
      console.log(params)
      // return
      const list = [
        ...this.dowloadList,
        {
          name: '库存对账单',
          exportParam: JSON.stringify(params),
          status: 'waiting',
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: 'dowloadList' })
      this.statementOfAccountDialogVisible = false
    },

    handleExport() {
      var params = this.searchFormSearch
      params.method = 'dj.api.smartcarlife.MerchantGoodsStockMonthReport.export.async'
      const list = [
        ...this.dowloadList,
        {
          name: '库存列表',
          exportParam: JSON.stringify(params),
          status: 'waiting',
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: 'dowloadList' })
    },

    // 查看
    look(row) {
      this.recordInfo = row
      this.stockMonthVisible = true
    },
    handleDetail(row) {
      this.recordInfo = row
      console.log(row, 'row')
      this.stockDetailDialogVisible = true
    },
    dialogClose(flag) {
      this.stockMonthVisible = !this.stockMonthVisible
      // if (flag) {
      //   this.$refs.recordTable.refreshTable()
      // }
    }

  }
}

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