<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>
|