add.vue 8.72 KB
<!-- 创建盘点 -->
<template>
  <div class="addWrap">
    <div class="d2-container-content">
      <div style="padding: 15px 0">
        <div>
          <el-input v-model="searchForm.searchName" style="width: 200px" placeholder="请输入商品名称/系列" maxlength="20" clearable />
          <el-button @click="handleSearch" size="small" type="primary" style="marginleft: 15px">查询</el-button>
        </div>
      </div>
      <p class="title">盘存</p>
      <GLTable ref="recordTable" :getListApi="getListApi" :searchForm="searchFormSearch" :tableParams="tableParams" :beforeSearchFn="beforeSearchFn">
        <div slot="auth-button" slot-scope="scope">
          <el-button type="text" @click="inventory(scope.scope)" :disabled="setDisabled(scope.scope)">盘点</el-button>
        </div>
      </GLTable>
    </div>
    <div class="d2-container-content">
      <p class="title">盘存确认单</p>
      <GLTable ref="recordTable2" :tableData="chooseDataList" :tableParams="tableParams2" :hasPage="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>
      </GLTable>
    </div>
    <glsx-form ref="addInventoryForm" :origin-data="editData" :form-list="editForm" form-ref="inveFormRef" @handleAddConfirm="handleAddConfirm" @handleClose="handleAddClose"></glsx-form>
    <!-- 盘点 -->
    <inventory-num-dialog :inventory-num-visible="inventoryNumVisible" :record-info="recordInfo"
      v-if="inventoryNumVisible" @dialogClose="dialogClose" />
  </div>
</template>

<script>
import inventoryNumDialog from './inventoryNumDialog'
import { membraneTypeList } from '@/utils/constants.js'
export default {
  name: 'InventoryList',
  components: {
    inventoryNumDialog
  },
  data() {
    return {
      membraneTypeList: membraneTypeList,
      searchForm: {
        searchName: ''
      },
      searchFormSearch: {},
      searchSelectObj: {},
      getListApi: this.$apis.stockManage.stockRemainPage,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '商品名称',
            prop: 'goodsName',
            width: '160px'
          },
          {
            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: '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: []
    }
  },

  methods: {
    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = this.$common.utils.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(() => {
          this.$apis.stockManage.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>

.d2-container-content{
  background: #fff;
   padding: 20px;
   margin-bottom: 20px;
}
.count-txt {
  font-weight: 700;
  color: #2a58ad;
  margin: 0 2px;
}
.title {
  font-weight: 600;
  font-size: 16px;
  color: #333333;
  padding:17px 0;
}
.leftSpan {
  display: inline-block;
  box-sizing: border-box;
  margin-right: 10px;
}
</style>