绿满眶商城微信小程序-uniapp
zxl
4 天以前 c9928dd4f6d25e2339ea1400f59ec58674a927a7
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
<template>
    <view>
        <view class="container">
            <view class="item" v-for="item in skuList" :key="item.id">
                <text class="label">{{ item.simpleSpecs }}</text>
                <input class="input" placeholder="请输入库存数量" :value="item.quantity" @input="onInput"
                    :data-id="item.id" />
            </view>
        </view>
        <button type="default" class="btn" @click="updateSkus()">
            <u-icon name="plus-circle"></u-icon>
            更新
        </button>
    </view>
</template>
<script>
 
import * as API_GOODS from "@/api/goods.js";
export default {
    data() {
        return {
            routerVal: {},
            skuParams: [],
            skuList: []
        }
    },
    onShow() {
        var goodsId = this.routerVal.goodsId
        let params = {
            goodsId: goodsId,
            pageSize: 100
        };
        API_GOODS.getGoodsSkuData(params).then((res) => {
            this.skuList = res.data.result.records
            res.data.result.records.forEach(item => {
                this.skuParams.push({ skuId: item.id, quantity: item.quantity })
            });
        })
    },
    onLoad(option) {
        uni.showLoading({
            title: "加载中",
        });
        this.routerVal = option;
 
        uni.hideLoading();
    },
    methods: {
        onInput(e) {
            var id = e.currentTarget.dataset.id
            for (let index = 0; index < this.skuParams.length; index++) {
                if (this.skuParams[index].skuId == id)
                    this.skuParams[index].quantity = e.detail.value
            }
        },
        updateSkus() {
            API_GOODS.updateStocks(this.skuParams).then((res) => {
                if (res.data.code == 200) {
                    uni.showToast({
                        title: "更新成功",
                        icon: "success",
                        duration: 2000,
                    });
                    setTimeout(() => {
                        uni.navigateBack({
                            delta: 1,
                        });
                    })
                }
            })
        }
    }
}
</script>
<style lang="scss" scoped>
/* WXSS 文件 */
.container {
    padding: 20px;
}
 
.item {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}
 
.label {
    width: 80px;
    text-align: right;
    margin-right: 15px;
}
 
.input {
    flex: 1;
    border: 1px solid #ddd;
    padding: 10px;
    border-radius: 4px;
}
 
.btn {
    background: $light-color;
    position: fixed;
    width: 690rpx;
    bottom: 60rpx;
    height: 80rpx;
    left: 30rpx;
    font-size: 30rpx;
    line-height: 80rpx;
 
    .u-icon {
        margin-right: 10rpx;
    }
}
</style>