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

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

@ -35,15 +35,15 @@
</view>
</view>
</view>
<u-popup ref="select_popup" class="pop" :show="show" mode="center" closeOnClickOverlay bgColor='transparent'>
<image :src="image"></image>
<image src="@/static/images/guanbi.png" class="guanbi" @click="close"></image>
</u-popup>
<u-popup ref="select_popup" class="pop" :show="show" mode="center" closeOnClickOverlay bgColor='transparent'>
<image :src="image"></image>
<image src="@/static/images/guanbi.png" class="guanbi" @click="close"></image>
</u-popup>
</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">
@ -58,32 +58,34 @@
<view><span class="iconfont">&#xe6bd;</span></view>
</view>
</view>
<view class="popup_group_item">
<view class="popup_group_item_label">商品单位</view>
<view class="popup_group_item_value"><input v-model="setFormData.unit_name" type="text"
placeholder="请填写商品单位" /></view>
</view>
</view>
<!-- 选择平台分类弹框 -->
<uni-popup ref="select_platform" type="bottom">
<platfrom @close="closePlatfrom" :classifiedData="platformClassificationData" @getPlatData="getPlatData">
</platfrom>
</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">
<!-- <view class="popup_group_item" @click="showMoreInfo=!showMoreInfo">
<view class="popup_group_item_label">更多信息</view>
<view class="popup_group_item_value" :class="showMoreInfo?'icon_bottom':'icon_top'">
<view><span class="iconfont">&#xe6bd;</span></view>
</view>
</view> -->
<block >
<block>
<view class="input_content">
<!-- <view class="input_content_describe" style="border-top: none">
<view class="input_content_describe_title">
@ -99,7 +101,7 @@
placeholderClass="placeholderClass" maxlength="200" />
</view>
</view> -->
<view class="input_content_keyword">
<view class="input_content_keyword_label">关键字</view>
<view class="input_content_keyword_value"><input v-model="setFormData.keyword" type="text" value=""
@ -118,25 +120,25 @@
</checkbox-group>
</view>
</block>
</view>
</view>
<view class="handle">
<view class="handle_button" @click="submitCreatedGoods">提交</view>
</view>
<uni-popup ref="tempId" type="bottom">
<linkage-assembly selectProductTitle="选择运费模板" :form="setFormData" :classifiedData="classified['temp_id']"
:selectProductItem="productItem" :mer_id="merId" @getLinkageData="getTempIdData" @multipleList="multipleList"
@close="$refs.tempId.close()" @scrolltolower="scrolltolower"></linkage-assembly>
</uni-popup>
<!-- 图片选择器 -->
<avatar @upload="doUpload" @getName="getImgName" quality="1" ref="avatar" selWidth="250upx" selHeight="250upx">
</avatar>
</view>
</template>
@ -153,14 +155,23 @@
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";
import priceComponent from "./components/price.vue";
export default {
components:{
components: {
avatar,
platfrom,
commodityComponent,
@ -174,11 +185,23 @@
code: '', //
show: false, //
image: false, //
setFormData:{
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: [], //
@ -207,18 +230,58 @@
onLoad(opt) {
this.merId = Number(opt.mer_id);
this.product_id = opt.product_id;
if(!opt.product_id)this.showCommodity=true;
if (!opt.product_id) this.showCommodity = true;
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: {
//
@ -253,7 +316,7 @@
}
productDetail(this.merId, this.product_id).then(res => {
setStorage('editGoodsDetils', res.data);
if(res.data.content_arr.length>0) res.data.content = res.data.content_arr;
if (res.data.content_arr.length > 0) res.data.content = res.data.content_arr;
this.$store.commit('setStorage', res.data);
let editGoodsDetils = res.data;
Object.keys(this.setFormData).forEach(item => {
@ -288,8 +351,8 @@
editGoodsDetils.temp && (this.setFormData.tempName = editGoodsDetils.temp.name);
setStorage('canChange', true);
hideLoading();
this.showCommodity = true;
this.showCommodity = true;
});
},
//
@ -301,15 +364,15 @@
this.brand = (await categoryBrandlist(this.merId)).data;
//
let { data } = await categoryList(this.merId);
data.forEach((item1)=>{
item1.children.forEach((item2)=>{
data.forEach((item1) => {
item1.children.forEach((item2) => {
item2.children = null;
})
})
this.platformClassificationData = data;
},
//
updateCode(e){
updateCode(e) {
this.code = e + '';
},
//
@ -450,11 +513,59 @@
this.$refs.tempId.open();
});
},
//
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);
});
}
},
}
};