fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!--
 * @Author: wuyue
 * @Date: 2022-12-09 16:29:16
 * @LastEditTime: 2022-12-22 14:09:05
 * @LastEditors: wuyue
 * @Descripttion:手动扣减
 * @version:
-->
<template>
  <div>
    <el-dialog :visible.sync="dialogVisible" title="手动扣减" :close-on-click-modal="false"
               :modal-append-to-body="false" v-if="dialogVisible">
      <el-form size="mini" :model="form" label-width="120px" ref="form" :rules="formRules">
        <el-form-item label="商品主编码:" prop="spuNum">
          {{row.spuNum}}
        </el-form-item>
        <el-form-item label="商品名称:" prop="spuName">
          {{row.spuName}}
        </el-form-item>
        <el-form-item label="库存扣减:" prop="spuName">
          <el-table border size="mini" :data="form.tableData">
            <el-table-column prop="stock" label="剩余库存"></el-table-column>
            <el-table-column label="扣减数量">
              <template slot-scope="scope">
                <el-form-item :prop="`tableData.${scope.$index}.returnStock`" :rules="formRules.reduceNumRules">
                  <el-input-number :min="0" :max="999999999" v-model="scope.row.returnStock"></el-input-number>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
          <span class="itemTip">提示:扣减数量不得超出剩余库存</span>
        </el-form-item>
        <el-form-item label="扣减原因:" prop="remark">
          <el-input v-model="form.remark" type="textarea" :autosize="{minRows:2,maxRows:4}"
                    placeholder="请输入扣减原因" clearable></el-input>
        </el-form-item>
        <el-form-item label="操作日志:" prop="spuName">
          <list-condition-template ref="table" :tableData="logData" :total="total" @page-info-change="handlePageInfoChange">
            <template slot="columns">
              <el-table-column prop="createTime" label="操作时间"></el-table-column>
              <el-table-column prop="beforeStock" label="剩余库存">
              </el-table-column>
              <el-table-column prop="stock" label="扣减数量">
                <template slot-scope="scope">
                  {{Math.abs(scope.row.stock)}}
                </template>
              </el-table-column>
              <el-table-column prop="remark" label="备注">
              </el-table-column>
              <el-table-column prop="createName" label="操作人"></el-table-column>
            </template>
          </list-condition-template>
        </el-form-item>
      </el-form>
      <div class="buttonPosition">
        <el-button size="mini" @click="submit" type="primary" :loading="loading">保存</el-button>
        <el-button size="mini" @click="dialogVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import channelInventoryApi from '@/api/stockManagement/channelInventory'
import { inputNumberValid } from '@/utils/validator'
 
export default {
  props: {
    row: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      dialogVisible: false,
      form: {
        spuName: null,
        spuNum: null,
        remark: null,
        tableData: []
      },
      formRules: {
        reduceNumRules: [{ required: true, validator: inputNumberValid }, {
          validator: (rule, value, callback) => {
            if (value > this.form.tableData[0].stock) {
              callback(new Error('扣减数量不得大于剩余库存'))
            } else {
              callback()
            }
          }
        },
        ],
        remark: [{ max: 120, message: '扣减原因最多只能输入 120 个字' }]
      },
      loading: false,
      logData: [],
      total: 0
    }
  },
  methods: {
    // 弹出框打开关闭事件
    toggleDialog() {
      this.dialogVisible = !this.dialogVisible
      if (this.dialogVisible) {
        this.$nextTick(() => {
          this.getStockLog()
          this.form.spuName = this.row.spuName
          this.form.spuNum = this.row.spuNum
          this.form.remark = null
          this.form.tableData = [{
            stock: this.row.stock,
            returnStock: undefined
          }]
        })
      }
    },
    /**
     * '分页信息改变时查询列表
     */
    handlePageInfoChange(pageInfo) {
      this.getStockLog(pageInfo)
    },
    // 获取库存日志
    async getStockLog(pageInfo = { pageNum: 1, pageSize: 10 }) {
      const params = {
        channel: this.row.channel,
        spuNums: [this.row.spuNum],
        stockType: 'RETURN_STOCK_OUTPUT',
        current: pageInfo.pageNum,
        size: pageInfo.pageSize,
      }
      const res = await channelInventoryApi.querySoldStockOrderDetail(params)
      if (res.data) {
        this.logData = res.data.records
        this.total = res.data.total
      }
    },
    /**
       * 提交
       */
    submit() {
      this.$refs.form.validate().then(async res => {
        this.loading = true
        try {
          const params = {
            channel: this.row.channel,
            returnStock: this.form.tableData[0].returnStock,
            remark: this.form.remark,
            spuNum: this.row.spuNum,
            spuName: this.row.spuName,
            spuType: this.row.spuType,
          }
          const res = await channelInventoryApi.returnStockChannel(params)
          if (res.data) {
            this.$parent.queryList()
            this.dialogVisible = false
          }
          this.loading = false
        } catch (error) {
          this.loading = false
        }
      })
    }
  }
}
</script>