重写添加商品页面(进行中)

This commit is contained in:
weipengfei 2023-11-18 19:04:13 +08:00
parent fe899f95f1
commit 3d93e06173
1 changed files with 152 additions and 41 deletions

View File

@ -42,8 +42,8 @@
</view>
<!-- 商品详情 -->
<commodityComponent v-if="showCommodity" :key="showCommodity" :showCommodity="showCommodity" :product_id="product_id" :merId="merId"
:code="code" @lastStep="lastStep">
<commodityComponent ref="commodityRef" v-if="showCommodity" :key="showCommodity" :showCommodity="showCommodity"
:product_id="product_id" :merId="merId" :code="code" @lastStep="lastStep">
</commodityComponent>
<view class="popup_group">
@ -74,7 +74,9 @@
</uni-popup>
<!-- 规格设置 -->
<priceComponent :product_id="product_id" :bar_code="code" @updateCode = "updateCode" v-if="showCommodity"></priceComponent>
<priceComponent ref="priceRef" :product_id="product_id" :bar_code="code" @updateCode="updateCode"
v-if="showCommodity">
</priceComponent>
<view class="popup_group">
<!-- <view class="popup_group_item" @click="showMoreInfo=!showMoreInfo">
@ -153,8 +155,17 @@
attrList,
templateList,
productDetail,
getDeliveryType
getDeliveryType,
productCreate,
productUpdate
} from '@/api/product.js';
import {
serialize,
Toast,
Loading,
hideLoading,
Modal
} from "@/libs/uniApi.js";
import avatar from "@/components/yq-avatar/yq-avatar.vue";
import platfrom from "./components/platform.vue";
import commodityComponent from "./components/commodity.vue";
@ -177,8 +188,20 @@
setFormData: {
store_name: '',
imageList: [],
cate_name: '', //
cate_name: '', //
unit_name: '', //
cate_id: '', // id
mer_cate_id: '', //
mer_cate_name: '', //
spec_type: '0', // 0. 1
attr: [], //
specifica: '', //
setSpecificaValue: '', //
setSpecificaValue2: '',
delivery_way: [1, 2], // 1 2
delivery_free: '1', // 0 1
temp_id: '', // ID
tempName: '' //
},
platformClassificationData: [], //
merchantClassification: [], //
@ -211,14 +234,54 @@
this.initData();
this.initClasiffy();
},
onBackPress() {
},
onBackPress() {},
onShow() {
this.setFormData = Object.assign(this.setFormData, {
"store_name": "方法",
"imageList": [
"https://lihai001.oss-cn-chengdu.aliyuncs.com/def/457c6202311181745387896.jpeg",
"https://lihai001.oss-cn-chengdu.aliyuncs.com/def/185e2202311181745434402.jpeg"
],
"cate_name": "丧葬服务",
"unit_name": "给",
"cate_id": 445,
"keyword": "22"
})
this.$nextTick(() => {
this.$refs.commodityRef.addGoodsSecoundData = {
"is_good": 1,
"is_gift_bag": 0,
"sort": "20",
"once_count": "",
"video_link": "https://lihai001.oss-cn-chengdu.aliyuncs.com/media/7ce3d202311181816166215.mp4"
}
this.$refs.commodityRef.goodsDis = {
"store_name": "",
"imageList": [
"https://lihai001.oss-cn-chengdu.aliyuncs.com/def/fb73d202311181751262661.png"
]
}
this.$refs.priceRef.singleSpecification = {
"price": "1",
"cost": "1",
"stock": "11",
"ot_price": "",
"procure_price": "",
"bar_code": "666",
"weight": "10",
"volume": "5",
"image": "",
"extension_one": "",
"extension_two": ""
}
})
},
beforeDestroy() {
beforeDestroy() {},
watch: {
'setFormData.imageList'(val) {
this.setFormData.image = val.length ? val[0] : '';
this.setFormData.slider_image = val.length ? serialize(val).splice(1) : [];
}
},
methods: {
//
@ -454,7 +517,55 @@
//
submitCreatedGoods() {
console.log('创建商品');
console.log('商品数据', this.setFormData);
console.log('是否推荐', this.$refs.commodityRef.addGoodsSecoundData);
console.log('商品详情', this.$refs.commodityRef.goodsDis, this.$refs.commodityRef.store_name);
console.log('价格库存', this.$refs.priceRef.singleSpecification);
let postData = {
...this.setFormData,
...this.$refs.commodityRef.addGoodsSecoundData,
content: {
title: this.$refs.commodityRef.goodsDis?.store_name || '',
image: this.$refs.commodityRef.goodsDis?.imageList || []
},
video_link: this.$refs.commodityRef.addGoodsSecoundData.video_link,
attrValue: this.$refs.priceRef.singleSpecification
};
postData.stock = postData.attrValue[0]?.stock||0;
// return console.log('', postData);
Loading();
if (this.product_id) {
productUpdate(this.merId, this.product_id, postData)
.then(res => {
hideLoading()
Modal('提交成功', '点击确定,返回商品管理', {
showCancel: false
}).then(() => {
uni.removeStorageSync('singleSpecification')
uni.redirectTo({
url: '/pages/product/goodsOnSale/index?mer_id=' + this.merId
})
})
})
.catch(rej => {
Toast(rej);
});
} else {
productCreate(this.merId, postData)
.then(res => {
hideLoading();
Modal('提交成功', '点击确定,返回商品管理', {
showCancel: false,
}).then(() => {
uni.redirectTo({
url: '/pages/product/goodsOnSale/index?mer_id=' + this.merId
})
})
})
.catch(rej => {
Toast(rej);
});
}
},
}
};