inventoryList.vue 9.04 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 :id="tableParams.btnId"
                     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"
                v-if="!userInfo.beSuper && userInfo.beYQMerchant">
            <auth-button category="Button"
                         :show-btn-ids="['9080401']" />
          </span> -->
          <auth-button category="Button"
                       :show-btn-ids="['9080402']" />
        </d2-table-header>
        <d2-table ref="recordTable"
                  :get-list-api="getListApi"
                  :search-form="searchFormSearch"
                  :table-params="tableParams"
                  :before-search-fn="beforeSearchFn">
          <div slot="img"
               slot-scope="scope"
               v-if="scope.scope.voucherPic">
            <img class="pro-img"
                 :src="scope.scope.voucherPic"
                 @click="handleEnlargeImg(scope.scope.voucherPic)">
          </div>
          <auth-button slot="auth-button"
                       slot-scope="scope"
                       :data="scope.scope" />
        </d2-table>
      </div>
    </d2-container>
    <!-- 查看 -->
    <inventory-detail-dialog :inventory-detail-visible="inventoryDetailVisible"
                             :record-info="recordInfo"
                             v-if="inventoryDetailVisible"
                             @dialogClose="dialogClose" />
    <!-- 预览图片 -->
    <el-dialog :visible="imgVisible"
               :before-close="handleCloseImg">
      <img width="100%"
           :src="previewImgUrl"
           alt="图片">
    </el-dialog>
  </div>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { mapActions, mapState } from 'vuex'
import { getProductTypeBySceneId } from '@api/product'
import { getyqMerchantList, stockCheckPage, getServicemerchantrefList } from '@api/stockManage'
import inventoryDetailDialog from './inventoryDetailDialog'
export default {
  name: 'InventoryList',
  components: {
    inventoryDetailDialog
  },
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      searchForm: {
        checkTime: '',
        checkCode: '',
        yqMerchantId: '',
        merchantId: ''
      },
      searchFormSearch: {},
      searchSelectObj: {
        orderOrTrade: {
          attr: 'inputtedOrderCode',
          value: ''
        }
      },
      showFormData: [{
        label: '盘点单号',
        name: 'checkCode',
        type: 'input',
        maxlength: '20',
        isClear: true
      }, {
        label: '盘点时间',
        name: 'checkTime',
        type: 'datePicker',
        isClear: true,
        pickerOptions: 'rangePickerOptions'
      }, {
        label: '盘点仓库',
        name: 'yqMerchantId',
        type: 'select',
        optionList: [],
        optionId: 'merchantNo',
        optionLabel: 'merchantName',
        optionsName: 'yqMerchantList',
        changeAttr: (value, targetItem) => {
          value
            ? this.getServicemerchantrefList(value)
            : (this.baseData.merchantIdList = [])
          this.searchForm.merchantId = ''
          this.getOptionsList()
        }
      }, {
        label: '盘点门店',
        name: 'merchantId',
        type: 'select',
        noDataText: '请先选择盘点仓库',
        optionList: [],
        optionId: 'merchantId',
        optionLabel: 'merchantName',
        optionsName: 'merchantIdList'
      }],
      getListApi: stockCheckPage,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '盘点单号',
          prop: 'checkCode',
          width: '200px'
        }, {
          label: '盘点时间',
          prop: 'checkTime',
          width: '150px',
          formatter: (cellValue) => {
            return cellValue.checkTime ? Util.dateFormate(cellValue.checkTime, 'YYYY-MM-DD HH:mm:ss') : ''
          }
        }, {
          label: '盘点人',
          prop: 'operator',
          width: '150px'
        }, {
          label: '盘点仓库',
          prop: 'yqMerchantName'
        }, {
          label: '盘点门店',
          prop: 'merchantName'
        }, {
          label: '备注',
          prop: 'remark'
        }, {
          label: '凭证',
          prop: 'voucherPic',
          width: '100px',
          addHtml: 'img'
        }
        ]
      },
      baseData: {
        productTypeList: [],
        yqMerchantList: [],
        merchantIdList: []
      },

      inventoryDetailVisible: false,
      recordInfo: null,
      imgVisible: false,
      previewImgUrl: ''
    }
  },
  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()
    })
  },

  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)
        if (this.searchFormSearch.checkTime) {
          this.searchFormSearch.checkTimeStart = Util.dateFormate(this.searchFormSearch.checkTime[0], 'YYYY-MM-DD HH:mm:ss')
          this.searchFormSearch.checkTimeEnd = Util.dateFormate(this.searchFormSearch.checkTime[1], 'YYYY-MM-DD') + ' 23:59:59'
        }
        delete this.searchFormSearch.checkTime
        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])
        }
      })
    },

    // 获取仓库门店
    getServicemerchantrefList(merchantId) {
      getServicemerchantrefList({
        yqMerchantId: merchantId
      }).then(res => {
        this.baseData.merchantIdList = res || []
        // 总店
        const _headOffice = this.baseData.yqMerchantList.find(item => item.merchantNo === merchantId)
        _headOffice.merchantId = _headOffice.merchantNo
        // 门店选项中加入总店
        this.baseData.merchantIdList.push(_headOffice)
        this.getOptionsList()
      })
    },

    // handleSearch() {
    //   this.$refs.recordTable.refreshTable()
    // },
    handleReset() {
      this.searchForm = {
        checkTime: '',
        checkCode: '',
        yqMerchantId: '',
        merchantId: ''
      }
      this.baseData.merchantIdList = []
      this.getOptionsList()
      this.$refs.recordTable.refreshTable()
    },

    gotoAdd() {
      // this.close({ tagName: '/orderList' })
      this.$router.push({ name: 'addInventory' })
    },

    handleExport() {
      var params = this.searchFormSearch
      params.method = 'dj.smartcarlife.api.stock.check.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.inventoryDetailVisible = true
    },

    dialogClose(flag) {
      this.inventoryDetailVisible = !this.inventoryDetailVisible
    },

    handleEnlargeImg(url) {
      if (url) {
        this.previewImgUrl = url
        this.imgVisible = !this.imgVisible
      }
    },

    handleCloseImg() {
      this.imgVisible = !this.imgVisible
    }

  }
}

</script>
<style scoped>
.count-txt {
  font-weight: 700;
  color: #2a58ad;
  margin: 0 2px;
}
.leftSpan {
  display: inline-block;
  box-sizing: border-box;
  margin-right: 10px;
}
.pro-img {
  width: 36px;
  height: 36px;
  cursor: pointer;
}
</style>