陶杰
2024-08-22 4aa0bd47801606b4d0e0a6a2ed8fe92a7e5f2444
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<template>
    <view class="flow-manage">
        <view class="top-buttons" v-if="type==='all'">
            <view @click.stop="clickButton('add')" class="button button-add"></view>
            <view @click.stop="clickButton('in')" class="button button-search-in"></view>
            <view @click.stop="clickButton('unpass')" class="button button-search-unpass"></view>
            <view @click.stop="clickButton('inpass')" class="button button-search-inpass" style="flex:5"></view>
            <view @click.stop="clickButton('delete')" class="button button-search-delete" style="margin-top: -1rpx;">
            </view>
 
        </view>
        <view class="p15" style="min-height: calc(100vh - 500rpx);">
            <no-data v-if="!list||list.length==0" style="width: 100%;"></no-data>
            <view v-for="(item,index) in list" :key="index" class="m-b-24 flow-manage-list">
                <view class="flow-manage-list-item">
                    <view class="flex m-r-6">
                        <view class="img flower-img m-r-6">
                            <image class="flower-img img100 " :src="item.cover"
                                :class="[!item.stock?'component-stock-zero':'']" @click="previewImg(item.cover)">
 
                            </image>
                            <view class="status" :class="[!item.stock?'zero':'']" v-if="item.statusStr">
                                {{ item.statusStr}}
                            </view>
                        </view>
 
                        <view class="flex1">
                            <view class=" flex">
                                <view class="title">{{item.name}}<span class="level">{{item.levelStr}}</span></view>
                                <view class="m-l-a m-r-0">
                                    {{item.categoryStr || '-'}}
                                </view>
                            </view>
                            <view class="each-list">
                                <view class="each-item">
                                    <view class="label">状态</view>
                                    <view class="value">{{item.statusStr || '-'}}</view>
 
                                </view>
                                <view class="each-item">
                                    <view class="label">颜色</view>
                                    <view class="value">{{item.color || '-'}}</view>
 
                                </view>
                                <view class="each-item">
                                    <view class="label">规格</view>
                                    <view class="value">{{item.unit || '-'}}</view>
 
                                </view>
                                <view class="each-item">
                                    <view class="label">库存</view>
                                    <view class="value">{{item.stock || 0}}</view>
 
                                </view>
                                <view class="each-item">
                                    <view class="label">销量</view>
                                    <view class="value">{{item.sales || 0}}</view>
                                </view>
                                <view class="each-item">
                                    <view class="label">价格</view>
                                    <view class="value">{{item.price||'-'}}</view>
                                </view>
                            </view>
                        </view>
                    </view>
                    <view class="line-gray">
 
                    </view>
                    <view class="buttons">
                        <view class="button" @click.stop="toDetail(item)">编辑</view>
 
                        <view class="button" @click.stop="buttonStatus(item,'off')"
                            v-if="item.status=='UP'||item.status=='up'">下架</view>
                        <view class="button" @click.stop="buttonStatus(item,'up')"
                            v-if="item.status=='OFF'||item.status=='off'||item.status=='FORCE_OFF'">上架</view>
                        <view class="button" @click.stop="openValue(item,'price')">价格</view>
                        <view class="button" @click.stop="openValue(item,'stock')">库存</view>
                        <view class="button" @click.stop="toDetailAdd(item)">复制</view>
 
                        <view class="button t-red" @click.stop="buttonDelete(item)">删除</view>
 
                    </view>
                </view>
            </view>
        </view>
 
        <!-- 判断是否到底了,自动吧 -->
        <footer-msg :more="page.total>0&&page.total>page.current*page.size"></footer-msg>
 
        <uni-popup ref="popup_input" type="bottom" :mask-click="false">
            <view class="component-popup_input white w-fit" style="padding-bottom: 0rpx;padding: 0px;">
                <view class="p20" style="padding-bottom: 10rpx;">
                    <view class="title" v-if="currentInputKey=='price'">
                        修改价格
                    </view>
                    <view class="title" v-if="currentInputKey=='stock'">
                        修改库存
                    </view>
 
                    <!-- 输入框-->
                    <view class="flex w-fit ">
 
                        <u-input v-model="content" :placeholder="inputplaceholder" type="digit"
                            style="max-width: 390rpx;background-color: #F2F2F2;" v-if="currentInputKey=='price'" />
                        <view v-if="currentInputKey=='price'" class="m-l-10" style="line-height: 78rpx;">元</view>
 
                        <u-input v-model="content" :placeholder="inputplaceholder" type="number"
                            style="max-width: 390rpx;background-color: #F2F2F2;" v-if="currentInputKey=='stock'" />
                    </view>
                </view>
                <!-- 提交按钮 -->
                <view class="line-gray" style="margin-bottom: 0px;"></view>
                <view class="flex  flex-wrap-normal">
                    <u-button type="default" class="w-fit  flex1 " text="取消"
                        @click="()=>{$refs.popup_input.close()}"></u-button>
                    <view class="component-line-vert"></view>
                    <u-button type="default" class="w-fit flex1 topic-font" t text="确定" @click="submitValue"></u-button>
                </view>
            </view>
        </uni-popup>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                type: 'all',
                query: {
                    type: ''
                },
                content: '',
                currentInputDto: {},
                currentInputKey: '',
                inputplaceholder: '',
            }
        },
        onShow() {
            if (this.sign['flower']) {
                this.$store.dispatch('sign_clear', 'flower');
                this.refreshList()
            }
        },
        async onLoad(options) {
            this.type = options.type || 'all'
            var title = ''
            this.page.size = 5
            //todo 根据type切换查询条件
            if (this.type === 'delete') {
                this.listApi = '/api/supplier/flower/list/rc'
                title = '商品管理-已删除'
            } else {
 
                this.listApi = '/api/supplier/flower/list'
                this.query.status = ''
                if (this.type === 'inpass') {
                    this.query.status = 'PENDING'
                    title = '商品管理-待审核'
                }
                if (this.type === 'in') {
                    this.query.status = 'UP'
                    title = '商品管理-已上架'
                }
                if (this.type === 'unpass') {
                    this.query.status = 'DRAFT,OFF,FORCE_OFF'
                    title = '商品管理-仓库中'
                }
                if (this.type === 'rejectpass') {
                    this.query.status = 'REJECT'
                    title = '商品管理-未审核通过'
                }
            }
            if (title) {
                uni.setNavigationBarTitle({
                    title: title
                })
            }
            await this.$store.dispatch('sign_clear', 'flower');
            this.getList()
        },
        onReachBottom() {
            console.log('onReachBottom')
            this.getMore()
        },
        async onPullDownRefresh() {
            this.page.current = 1
            await this.getList()
            uni.stopPullDownRefresh()
        },
        methods: {
            async openValue(item, key) {
                this.content = item[key] || ''
                this.currentInputDto = item
                this.currentInputKey = key
                this.inputplaceholder = key == 'price' && '请输入价格(元)' || key == 'stock' && '请输入库存(整数)' || '请输入'
                this.$refs.popup_input.open('top')
            },
            async submitValue() {
                let item = this.currentInputDto,
                    key = this.currentInputKey
                const res = await this.$message.confirm(`确定修改此商品的${key==='price'&&'价格'|| key==='stock'&&'库存'}吗`, {
                    editable: false
                })
 
                if (!this.content) {
                    this.$message.showToast('输入不能为空')
                    return
                }
                var value = ''
                if (key == 'price') {
                    value = parseFloat(this.content).toFixed(2)
                } else {
                    value = parseInt(this.content)
                }
                if (isNaN(value)) {
                    this.$message.showToast('输入格式不正确')
                    return
                }
                if (key == 'price') {
                    if (value <= 0) {
                        this.$message.showToast('价格需要大于0')
                        return
                    }
                } else {
                    if (value < 0) {
                        this.$message.showToast('库存不能小于0')
                        return
                    }
                }
 
                var dto = {
                    id: item.id,
                }
                dto[key] = value
 
 
                this.$message.showLoading()
                this.$http.request('post', '/api/supplier/flower/list/' + key, {
                    data: dto
                }).then(res => {
                    if (res.code == 0) {
                        this.$message.showToast('操作成功')
                        item[key] = value
                        this.$refs.popup_input.close()
 
                    }
                }).finally(() => {
                    this.$message.hideLoading()
                })
            },
            async buttonStatus(item, status) {
                await this.$message.confirm(`确定${status==='off'?'下架':'上架'}此商品吗`)
                this.$message.showLoading()
                this.$http.request('get', '/api/supplier/flower/list/' + status, {
                    params: {
                        id: item.id
                    }
                }).then(res => {
                    this.$message.hideLoading()
                    if (res.code == 0) {
                        this.$message.showToast('操作成功')
                        item.status = (status == 'off' ? 'OFF' : 'UP')
                        item.statusStr = (status == 'off' ? '下架' : '上架')
                    }
                }).catch(e => {
                    this.$message.hideLoading()
                }).finally(() => {})
            },
            async buttonDelete(item) {
                await this.$message.confirm('确定删除此商品吗')
                this.$message.showLoading()
                this.$http.request('get', '/api/supplier/flower/list/delete', {
                    params: {
                        id: item.id
                    }
                }).then(res => {
                    if (res.code == 0) {
                        this.$message.showToast('删除成功')
                        this.refreshList()
                    }
                }).finally(() => {
                    this.$message.hideLoading()
                })
            },
            toDetail(item) {
                uni.navigateTo({
                    url: '/sub_pages/supplier/flower-manage/flower-add?id=' + item.id
                })
            },
            toDetailAdd(item) {
                uni.navigateTo({
                    url: '/sub_pages/supplier/flower-manage/flower-add?copyId=' + item.id
                })
            },
            clickButton(type) {
                if (type == 'add') {
                    //添加页面
                    uni.navigateTo({
                        url: '/sub_pages/supplier/flower-manage/flower-add'
                    })
                } else {
                    uni.navigateTo({
                        url: '/sub_pages/supplier/flower-manage/flower-manage?type=' + type
                    })
                }
            },
        }
    }
</script>
 
<style lang="scss" scoped>
    .flow-manage {
        overflow-y: scroll;
 
        // min-height: ;
        .flow-manage-list {
            // padding: 20rpx 30rpx;
            padding: 22rpx 22rpx 20rpx 22rpx;
            background-color: #fff;
 
            .flow-manage-list-item {
                .title {
                    font-weight: 600;
                    font-size: 28rpx;
                    color: #000000;
                    line-height: 40rpx;
 
                    .level {
                        font-weight: 400;
                        font-size: 28rpx;
                        color: #20613D;
                        line-height: 40rpx;
                        margin-left: 20rpx;
                    }
                }
 
                .buttons {
                    display: flex;
 
                    .button {
                        margin: 0 auto;
                        width: 98rpx;
                        line-height: 48rpx;
                        border-radius: 24rpx;
                        border: 2rpx solid #CECECE;
                        text-align: center;
                        font-size: 24rpx;
                        color: #666666;
                        line-height: 34rpx;
                    }
                }
 
                .flower-img {
                    width: 128rpx;
                    height: 118rpx;
                    min-width: 128rpx;
                    min-height: 118rpx;
                    position: relative;
 
                    .status {
                        position: absolute;
                        min-width: 66rpx;
                        height: 34rpx;
                        background: #20613D;
                        left: 0;
                        top: 0;
                        border-top-left-radius: 8rpx;
                        border-bottom-right-radius: 8rpx;
                        color: #FFFFFF;
                        line-height: 34rpx;
                        font-size: 22rpx;
                        text-align: center;
                    }
 
                    .status.zero {
                        // background: unset;
                        // font-size: 24rpx;
 
                    }
                }
 
                .each-list {
                    display: flex;
                    flex-wrap: wrap;
                    margin-top: 6rpx;
 
                    .each-item {
                        min-width: 30%;
                        max-width: 40%;
                        text-align: center;
                        margin-left: 0rpx;
                        margin-right: auto;
                        display: flex;
 
                        .label {
                            font-weight: 400;
                            font-size: 24rpx;
                            color: #666666;
                            text-align: left;
                            padding-right: 10rpx;
                        }
 
                        .label::after {
                            content: ": "
                        }
 
                        .value {
                            font-weight: 400;
                            font-size: 24rpx;
                            color: #666666;
                        }
                    }
                }
            }
        }
 
        .top-buttons {
            display: flex;
            padding: 22rpx 42rpx;
            background-color: #fff;
 
            .button {
                // flex:1;
                margin: 0 auto;
                width: 90rpx;
                height: 146rpx;
                background-size: 100% 100%;
                text-align: center;
                // min-width: 90rpx;
                flex: 4;
                // max-width: 90rpx;
                margin-left: 14rpx;
                margin-right: 14rpx;
                font-weight: 400;
 
            }
 
            .button:first-child {
                margin-left: 0rpx
            }
 
            .button:last-child {
                margin-right: 0rpx
            }
 
            .button-add {
                background-image: url('@/static/images/supplier/flower/flower-mange-icon-add-flower.png');
 
            }
 
            .button-search-in {
                background-image: url('@/static/images/supplier/flower/flower-mange-icon-flower-in.png');
 
            }
 
            .button-search-unpass {
                background-image: url('@/static/images/supplier/flower/flower-mange-icon-flower-unpass.png');
 
            }
 
            .button-search-inpass {
                background-image: url('@/static/images/supplier/flower/flower-mange-icon-flower-inpass.png');
 
            }
 
            .button-search-delete {
                background-image: url('@/static/images/supplier/flower/flower-mange-icon-flower-delete.png');
 
            }
        }
    }
</style>