rk
昨天 c313a253b1fcdc75b6be5db575fc2b29fb407021
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    width="60%"
  >
    <el-tabs v-model="activeTab">
      <el-tab-pane label="就地寄存" name="local">
        <div class="price-tip">根据行李尺寸以及存放天数收费(不足一天按一天计价)</div>
        <div class="price-items">
          <div class="price-item" v-for="(item, index) in jiudiTableData" :key="index">
            <span class="price-label">其中{{item.categoryName}}每天收费</span>
            <el-input style="width: 200px;" v-model="item.unitPrice" type="number" placeholder="请输入"></el-input>
            <span class="price-unit">元</span>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="异地寄存" name="remote">
        <div class="remote-config-title">异地寄送配置</div>
        <div class="remote-header">
          <span class="remote-tip">根据行李尺寸、配送里程及配送价格收取费用(不足1公里按1公里计价)</span>
        </div>
        <el-table :data="remoteTableData" border stripe>
          <el-table-column prop="categoryName" label="行李尺寸"></el-table-column>
          <el-table-column label="起送里程(公里)">
            <template slot-scope="{row}">
              <el-input v-model="row.startDistance" type="number" placeholder="请输入"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="起送价格(元)">
            <template slot-scope="{row}">
              <el-input v-model="row.startPrice" type="number" placeholder="请输入"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="续送里程(公里)">
            <template slot-scope="{row}">
              <el-input v-model="row.extraDistance" type="number" placeholder="请输入"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="续送价格(元)">
            <template slot-scope="{row}">
              <el-input v-model="row.extraPrice" type="number" placeholder="请输入"></el-input>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="预计时效" name="time">
        <div class="remote-config-title">预计时效规则</div>
        <div class="remote-header">
          <span class="remote-tip">根据配送里程预计配送时长并展示在小程序下单页面</span>
        </div>
        <el-table :data="timeTableData" border stripe>
          <el-table-column label="起送里程(公里)">
            <template slot-scope="{row}">
              <el-input v-model="row.startDistance" type="number" placeholder="请输入"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="起送时长(小时)">
            <template slot-scope="{row}">
              <el-input v-model="row.startTime" type="number" placeholder="请输入"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="续送里程(公里)">
            <template slot-scope="{row}">
              <el-input v-model="row.continueDistance" type="number" placeholder="请输入"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="续送时长(小时)">
            <template slot-scope="{row}">
              <el-input v-model="row.continueTime" type="number" placeholder="请输入"></el-input>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="门店注册押金" name="deposit">
        <div class="price-tip">根据所在城市以及注册类型不同,平台收取不同数额押金。押金会在门店退网后线下原额退还(门店线上微信支付的押金因微信官方要求具有时效性)</div>
        <div class="price-items">
          <div class="price-item" v-for="(item, index) in storeDepositData" :key="index">
            <span class="price-label">其中{{item.fieldTypeName}}收取押金</span>
            <el-input style="width: 200px;" v-model="item.depositAmount" type="number" placeholder="请输入"></el-input>
            <span class="price-unit">元</span>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="分成比例" name="share">
        <div class="price-tip">根据订单中不同运营角色而独立配置不同分成比例</div>
        <div class="price-items">
          <div class="price-item" v-for="(item, index) in shareTableData" :key="index">
            <span class="price-label">{{item.fieldType === 4 ? '在订单中作为配送员时,' : '其中门店类型为'}}{{item.fieldTypeName}}分成比例为</span>
            <el-input style="width: 100px;" v-model="item.ratio" type="number" placeholder="请输入"></el-input>
            <span class="price-unit">%</span>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="confirm" :loading="isWorking">确定</el-button>
    </div>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import {
  localStorage,
  remoteDelivery,
  estimatedDelivery,
  storeDeposit,
  revenueShare,
  batchSave,
  batchSaveRemoteDelivery,
  batchSaveEstimatedDelivery,
  batchSaveStoreDeposit,
  batchSaveRevenueShare
} from '@/api/business/pricingRule'
export default {
  name: 'OperaCityPriceRuleWindow',
  extends: BaseOpera,
  components: { GlobalWindow },
  data () {
    return {
      activeTab: 'local',
 
      jiudiTableData: [],
      remoteTableData: [],
      timeTableData: [],
      storeDepositData: [],
      shareTableData: [],
 
      form: {
        cityId: null
      }
    }
  },
  created () {
    this.config({
      api: '/business/pricingRule',
      'field.id': 'id'
    })
  },
  methods: {
    open (title, target) {
      this.title = title
      this.visible = true
      this.activeTab = 'local'
      this.jiudiTableData = []
      this.remoteTableData = []
      this.timeTableData = []
      this.storeDepositData = []
      this.shareTableData = []
      this.form = {
        cityId: target
      }
      this.fetchPriceRule()
      this.fetchRemoteDelivery()
      this.fetchEstimatedDelivery()
      this.fetchStoreDeposit()
      this.fetchRevenueShare()
    },
    // 查询就地存取规则列表
    fetchPriceRule () {
      localStorage(this.form.cityId)
        .then(data => {
          this.jiudiTableData = data
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
    },
    // 查询异地寄送规则列表
    fetchRemoteDelivery () {
      remoteDelivery(this.form.cityId)
        .then(data => {
          this.remoteTableData = data
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
    },
    // 查询预计时效
    fetchEstimatedDelivery () {
      estimatedDelivery(this.form.cityId)
        .then(data => {
          this.timeTableData = data
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
    },
    // 查询门店注册押金规则列表
    fetchStoreDeposit () {
      storeDeposit(this.form.cityId)
        .then(data => {
          this.storeDepositData = data
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
    },
    // 查询分成比例规则列表
    fetchRevenueShare () {
      revenueShare(this.form.cityId)
        .then(data => {
          this.shareTableData = data
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
    },
    // 保存所有规则
    confirm () {
      if (!this.validateLocalStorage()) return
      if (!this.validateRemoteDelivery()) return
      if (!this.validateEstimatedDelivery()) return
      if (!this.validateStoreDeposit()) return
      if (!this.validateRevenueShare()) return
 
      this.isWorking = true
      Promise.all([
        batchSave({ cityId: this.form.cityId, items: this.jiudiTableData }),
        batchSaveRemoteDelivery({ cityId: this.form.cityId, items: this.remoteTableData }),
        batchSaveEstimatedDelivery({ cityId: this.form.cityId, items: this.timeTableData }),
        batchSaveStoreDeposit({ cityId: this.form.cityId, items: this.storeDepositData }),
        batchSaveRevenueShare({ cityId: this.form.cityId, items: this.shareTableData })
      ])
        .then(() => {
          this.visible = false
          // this.$tip.apiSuccess('保存成功')
          this.$emit('success')
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
        .finally(() => {
          this.isWorking = false
        })
    },
    // 校验就地寄存
    validateLocalStorage () {
      for (const item of this.jiudiTableData) {
        if (item.unitPrice === null || item.unitPrice === undefined || item.unitPrice === '') {
          this.$message.error('请填写所有就地寄存的收费金额')
          return false
        }
      }
      return true
    },
    // 校验异地寄存
    validateRemoteDelivery () {
      for (const item of this.remoteTableData) {
        if (item.startDistance === null || item.startDistance === undefined || item.startDistance === '' ||
            item.startPrice === null || item.startPrice === undefined || item.startPrice === '' ||
            item.extraDistance === null || item.extraDistance === undefined || item.extraDistance === '' ||
            item.extraPrice === null || item.extraPrice === undefined || item.extraPrice === '') {
          this.$message.error('请填写所有异地寄送的配置信息')
          return false
        }
      }
      return true
    },
    // 校验预计时效
    validateEstimatedDelivery () {
      const item = this.timeTableData[0]
      if (!item || item.startDistance === null || item.startDistance === undefined || item.startDistance === '' ||
          item.startTime === null || item.startTime === undefined || item.startTime === '' ||
          item.continueDistance === null || item.continueDistance === undefined || item.continueDistance === '' ||
          item.continueTime === null || item.continueTime === undefined || item.continueTime === '') {
        this.$message.error('请填写预计时效的所有配置信息')
        return false
      }
      return true
    },
    // 校验门店注册押金
    validateStoreDeposit () {
      for (const item of this.storeDepositData) {
        if (item.depositAmount === null || item.depositAmount === undefined || item.depositAmount === '') {
          this.$message.error('请填写所有门店注册押金的金额')
          return false
        }
      }
      return true
    },
    // 校验分成比例
    validateRevenueShare () {
      for (const item of this.shareTableData) {
        if (item.ratio === null || item.ratio === undefined || item.ratio === '') {
          this.$message.error('请填写所有分成比例')
          return false
        }
      }
      return true
    }
  }
}
</script>
 
<style scoped>
.price-tip {
  margin-bottom: 20px;
  color: #666;
  font-size: 14px;
}
.price-items {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.price-item {
  display: flex;
  align-items: center;
  gap: 10px;
}
.price-label {
  flex-shrink: 0;
  font-weight: 500;
}
.price-unit {
  color: #666;
  white-space: nowrap;
}
.dialog-footer {
  text-align: right;
  padding: 0 20px;
  box-sizing: border-box;
  border-top: 1px solid #eee;
}
.remote-config-title {
  font-weight: bold;
  margin-bottom: 15px;
}
.remote-header {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
}
.remote-tip {
  color: #666;
  font-size: 14px;
}
.remote-pagination {
  margin-top: 15px;
  text-align: right;
}
</style>