商品发布接口对接

This commit is contained in:
zmj 2024-04-20 18:02:16 +08:00
parent b52f4fca4c
commit b22db99e63
5 changed files with 195 additions and 75 deletions

View File

@ -106,7 +106,6 @@
</template>
<script>
import form from "../../../uni_modules/uview-ui/libs/config/props/form";
import {
productCreate,
productUpdate
@ -119,6 +118,13 @@
import {
formatDate
} from "../../../libs/uniApi";
import {
serialize,
Toast,
Loading,
hideLoading,
Modal
} from "@/libs/uniApi.js";
export default {
components: {
uploadImgVideo,
@ -146,22 +152,78 @@
],
selfAttr: "",
formData: {
// store_name: "",
imageList: [],
cate_name: "",
cate_id: "",
attrValue: [{
// // store_name: "",
// imageList: [],
// cate_name: "",
// cate_id: "",
// attrValue: [{
// "price": "",
// "unit_name": "",
// "wholesale_unit_name": "",
// "wholesale_price": '',
// "stock": "",
// open: true,
// spec_type: ''
// }],
// image: '',
// slider_image: [],
// delivery_way: [],
// attr: [],
// // product_attribute: [],
"store_name": "",
"imageList": [
],
"attrValue": [{
"price": "",
"unit_name": "",
"wholesale_unit_name": "",
"wholesale_price": '',
"cost": "",
"stock": "",
"ot_price": "",
"procure_price": "",
"bar_code": "",
"weight": "",
"volume": "",
"extension_one": "",
"extension_two": "",
open: true,
spec_type: '单规格'
spec_type: ""
}],
image: '',
slider_image: [],
// product_attribute: [],
"cate_name": "",
"unit_name": "",
"cate_id": '',
"mer_cate_id": [
],
"mer_cate_name": "",
"spec_type": "0",
"attr": [],
"specifica": "",
"delivery_way": [
],
"delivery_free": "1",
"temp_id": "",
"tempName": "",
"once_min_count": "",
"image": "",
"slider_image": [
""
],
"is_good": 0,
"is_gift_bag": 0,
"sort": "",
"once_count": "",
"video_link": "",
"content": {
"title": "",
"image": [
]
},
"stock": ""
},
showPouple: false,
fileList6: [],
@ -264,13 +326,16 @@
},
async submit() {
let data = uni.$u.deepClone(this.formData)
data.imageList = data.imageList.map(item => item.url)
data.image = data.imageList[0]
data.slider_image = data.imageList.splice(0, 1)
data.store_name = data.cate_name
productCreate(this.mer_id, data)
.then(res => {
hideLoading();
console.log("提交成功")
// hideLoading();
Modal('提交成功', '点击确定,前往商品列表页面').then(() => {
if (this.import == 1) {
uni.$emit('importAttrValueOK', this.setFormData.import_id);
@ -292,7 +357,8 @@
this.mer_id = option.mer_id
this.isWholeSale = this.$store.state.app.userInfo?.mer_info?.wholesale == 2;
if (option.data) {
this.formData.cate_name = JSON.parse(option.data).label
this.formData.cate_name = JSON.parse(option.data).label.includes('--') ? JSON.parse(option.data).label
.split('--')[1] : JSON.parse(option.data).label;
this.formData.cate_id = JSON.parse(option.data).value
}
},

View File

@ -47,16 +47,17 @@
<view class="card" style="padding: 14rpx 30rpx;">
<u-form-item label="商品分类" prop="userInfo.name" ref="item1" labelPosition="left" required>
<view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right"
@click="navgo(`/pages/product/addGoodDetail/goodsType?mer_id=${mer_id}`)">
@click="navgo(`/pages/product/addGoodDetail/goodsType?mer_id=${mer_id}&&formData=${JSON.stringify(formData)}`)">
<view style="margin-right: 10rpx;line-height: 25rpx;">{{ formData.cate_name|| '请选择'}}</view>
<u-icon name="arrow-right"></u-icon>
</view>
</u-form-item>
<u-form-item label="商品属性" prop="userInfo.name" ref="item1" labelPosition="left">
<view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right"
@click="navgo(`/pages/product/addGoodDetail/goodsAttr?attr=${JSON.stringify(formData.attribute) }`)">
@click="navgo(`/pages/product/addGoodDetail/goodsAttr?formData=${JSON.stringify(formData)}&&mer_id=${mer_id}`)">
<view style="margin-right: 10rpx;line-height: 25rpx;">
{{Object.values(formData.attribute).length ?"已设置":"未设置"}}
{{Object.values(formData.product_attribute).address ?"已设置":"未设置"}}
<!-- {{Object.values(formData.product_attribute) }} -->
</view>
<u-icon name="arrow-right"></u-icon>
</view>
@ -66,9 +67,9 @@
规格与价格
</view>
<view class="card" style="min-height: 100rpx;padding: 14rpx 30rpx;">
<u-form-item label="规格与价格" prop="userInfo.name" ref="item1" labelPosition="left" required border-bottom>
<u-form-item label="规格与价格" prop="userInfo.name" ref="item1" labelPosition="left" required>
<view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right"
@click="navgo(`/pages/product/addGoodDetail/goodsPrice?attrValue=${JSON.stringify(formData.attrValue)}`)">
@click="navgo(`/pages/product/addGoodDetail/goodsPrice?formData=${JSON.stringify(formData)}&&mer_id=${mer_id}`)">
<view style="margin-right: 10rpx;line-height: 25rpx;">去设置</view>
<u-icon name="arrow-right"></u-icon>
</view>
@ -92,13 +93,11 @@
批发价
</view>
<view style="font-size: 28rpx;color:#777777 ;">
<!-- 8/ -->
{{item.wholesale_price}}/{{item.wholesale_unit_name}}
</view>
</view>
</u-form-item>
</view>
</view>
<view class='tips'>
服务与承诺
@ -168,13 +167,20 @@
</template>
<script>
import {
serialize,
Toast,
Loading,
hideLoading,
Modal
} from "@/libs/uniApi.js";
import {
HTTP_REQUEST_URL
} from '@/config/app.js';
import {
formatDate
} from '../../../libs/uniApi';
productCreate,
productUpdate
} from '@/api/product.js';
import uploadImgVideo from "../addGood/components/uploadImgVideo.vue"
export default {
components: {
@ -222,6 +228,15 @@
"stock": "20",
store_info: "",
attribute: {},
product_attribute: {
address: "",
leval: "",
pack: "",
attr: [{
label: "",
value: ''
}]
}
},
mer_id: "",
maxLength: 30,
@ -372,16 +387,41 @@
showlayFn() {
uni.navigateBack()
},
submit() {
console.log(this.formData)
},
// submit() {
// console.log(this.formData)
// },
getAttr(object) {
this.formData.attribute = object
this.formData.product_attribute = object
},
getAttrValue(object) {
this.formData.attrValue = object
console.log(this.formData.attrValue)
},
async submit() {
let data = uni.$u.deepClone(this.formData)
data.imageList = data.imageList.map(item => item.url)
data.image = data.imageList[0]
data.slider_image = data.imageList.splice(0, 1)
data.store_name = data.cate_name
productCreate(this.mer_id, data)
.then(res => {
hideLoading();
Modal('提交成功', '点击确定,前往商品列表页面').then(() => {
if (this.import == 1) {
uni.$emit('importAttrValueOK', this.setFormData.import_id);
uni.navigateBack();
} else uni.redirectTo({
url: `/pages/product/goodsOnSale/index?mer_id=${this.mer_id}&type=6`
})
}).catch(() => {
uni.navigateBack()
})
})
.catch(rej => {
// Toast(rej);
});
console.log(this.formData)
}
},

View File

@ -10,7 +10,9 @@
<u-form-item label="产地" prop="userInfo.name" ref="item1">
<view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right"
@click="showPouple=true,popType='place',getLocation()">
<view style="margin-right: 10rpx;line-height: 25rpx;">{{formData.address||'请选择'}}</view>
<view style="margin-right: 10rpx;line-height: 25rpx;">
{{formData.product_attribute.address||'请选择'}}
</view>
<u-icon name="arrow-right"></u-icon>
</view>
</u-form-item>
@ -18,27 +20,30 @@
<u-form-item label="商品等级" prop="userInfo.name" ref="item1">
<view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right"
@click="showPouple=true,popType='leval'">
<view style="margin-right: 10rpx;line-height: 25rpx;">{{formData.leval||'请选择'}}</view>
<view style="margin-right: 10rpx;line-height: 25rpx;">
{{formData.product_attribute.leval||'请选择'}}
</view>
<u-icon name="arrow-right"></u-icon>
</view>
</u-form-item>
<u-form-item label="货品包装" prop="userInfo.name" ref="item1">
<view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right"
@click="showPouple=true,popType='packing'">
<view style="margin-right: 10rpx;line-height: 25rpx;">{{formData.pack||'请选择'}}</view>
<view style="margin-right: 10rpx;line-height: 25rpx;">{{formData.product_attribute.pack||'请选择'}}
</view>
<u-icon name="arrow-right"></u-icon>
</view>
</u-form-item>
</view>
<view class="description" style="display: flex;justify-content: space-between;align-items: center">
<text>产品属性</text>
<view class="attr-custom" @click="formData.attr.push({label:'',value:''})">
<view class="attr-custom" @click="formData.product_attribute.attr.push({label:'',value:''})">
<u-icon name="plus" color='#20B128' style="margin-right: 8rpx;font-weight: bold;"></u-icon>
</view>
</view>
<view class="label-cls"
style="display: flex;padding: 20rpx 20rpx 20rpx 2rpx;justify-content: space-between;margin-bottom: 30rpx;"
v-for="(item,index) in formData.attr">
v-for="(item,index) in formData.product_attribute.attr">
<view class="" style="display: flex;width: 70%;align-items: center;">
<u--input placeholder="请填写属性名称" border="surround" v-model="item.label"></u--input>
<u-line direction="col" length="40rpx" color="#CECECE"></u-line>
@ -46,7 +51,7 @@
<u-line direction="col" length="40rpx" color="#CECECE"></u-line>
</view>
<view style="color: #777777;display: flex; align-items: center;"
@click="formData.attr.splice(index, 1);">
@click="formData.product_attribute.attr.splice(index, 1);">
<u-icon name="trash" style='margin-right: 8rpx;'></u-icon>
</view>
</view>
@ -69,7 +74,7 @@
<!-- 地区 -->
<view v-if="popType=='place'">
<view class="Positioning " style="color: #989898;margin-bottom: 30rpx;">
<view class="" style="display: flex;">
<view class="" style="display: flex;" @click="confirm">
<u-icon name="map" style='margin-right: 8rpx;'></u-icon>
<text>{{address.province}}{{address.city}}{{address.district}}</text>
</view>
@ -117,8 +122,9 @@
<view v-if="popType=='leval'" style="height: 500rpx;">
<u-transition :show="!show" mode="slide-right">
<view class="goods-leval">
<view class="goods-leval-li" :class="{act:formData.leval==item}" v-for='item in levalList'
@click="formData.leval=item,showPouple=false">
<view class="goods-leval-li" :class="{act:formData.product_attribute.leval==item}"
v-for='item in levalList'
@click="formData.product_attribute.leval=item,showPouple=false">
{{item}}
</view>
<view class="goods-leval-li " style="display: flex;color:#38BE41;" @click="show=true">
@ -139,7 +145,7 @@
<u-transition :show="!show" mode="slide-right">
<view class="goods-leval">
<view class="goods-leval-li" :class="{act:formData.pack==item}" v-for='item in packList'
@click="formData.pack=item,showPouple=false">
@click="formData.product_attribute.pack=item,showPouple=false">
{{item}}
</view>
@ -216,15 +222,15 @@
showPouple: false,
showSex: false,
positionType: 0,
data: {},
formData: {
address: "",
leval: "",
pack: "",
attr: [{
label: "",
value: ''
}]
// address: "",
// leval: "",
// pack: "",
// attr: [{
// label: "",
// value: ''
// }]
},
model1: {
@ -252,10 +258,11 @@
},
confirm() {
if (this.popType == 'place') {
this.formData.address = this.address.province + this.address.city + this.address.district
this.formData.product_attribute.address = this.address.province + this.address.city + this.address
.district
} else if (this.popType == 'leval') {
this.levalList.push(this.selfLeval)
this.formData.leval = this.levalList[this.levalList.length - 1]
this.formData.product_attribute.leval = this.levalList[this.levalList.length - 1]
this.selfLeval = ''
} else if (this.popType == 'packing') {
@ -335,21 +342,23 @@
});
},
submit() {
let pages = getCurrentPages(); //
let nowPage = pages[pages.length - 1]; //
let prevPage = pages[pages.length - 2]; //
let object = this.formData
prevPage.getAttr(object) // otherFun,object
uni.navigateBack()
let that = this
uni.navigateTo({
url: `/pages/product/addGoodDetail/addGoodDetail?formData=${JSON.stringify(that.formData) }&&mer_id=${that.mer_id}`
})
}
},
onLoad(option) {
getProvince().then(res => {
this.provinceList = res.data
})
if (Object.values(JSON.parse(option.attr)).length) {
this.formData = JSON.parse(option.attr)
}
this.formData = JSON.parse(option.formData)
console.log(this.formData)
// if (Object.values(JSON.parse(option.attr)).length) {
// this.formData = JSON.parse(option.attr)
// }
}
};

View File

@ -7,8 +7,8 @@
<view class="card" v-for="(item,index) in attrValue">
<view class="card-head card-li">
<text style="font-size: 32rpx;font-family: PingFangFamily;">规格{{index+1}}</text>
<view class="" style="width: 200rpx;">
<u--input placeholder="请输入规格名称" v-model="item.spec_type"></u--input>
<view class="" style="width: 300rpx;">
<u--input placeholder="请输入规格名称" inputAlign='right' v-model="item.spec_type"></u--input>
</view>
</view>
<u-line direction="row" style="margin: 30rpx 0;" color="#ECECEC"></u-line>
@ -23,7 +23,7 @@
<u--input style=" flex: 2;width:100rpx;background-color: #F6F6F6;" placeholder="请输入计量单位"
v-model="item.unit_name"></u--input>
</view>
<view class=""
<view class="" v-if='isWholeSale'
style="display: flex;align-items: center;justify-content: space-between;margin-top: 30rpx;">
<u--input style="flex: 2; background-color: #F6F6F6;" placeholder="请输批发价格"
v-model="item.wholesale_price"></u--input>
@ -37,15 +37,15 @@
<u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line>
<view class=" card-li">
<text style="font-size: 32rpx;">商品库存</text>
<view class="" style="width: 200rpx;">
<u--input placeholder="请填写库存数量" v-model="item.stock"></u--input>
<view class="" style="width: 300rpx;">
<u--input placeholder="请填写库存数量" inputAlign='right' v-model="item.stock"></u--input>
</view>
</view>
<u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line>
<view class=" card-li">
<text style="font-size: 32rpx;">条形码</text>
<view class="" style="width: 200rpx;">
<u--input placeholder="请填写商品条形码" v-model="item.bar_code"></u--input>
<view class="" style="width: 300rpx;">
<u--input placeholder="请填写商品条形码" inputAlign='right' v-model="item.bar_code"></u--input>
</view>
</view>
<u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line>
@ -69,8 +69,11 @@
export default {
data() {
return {
mer_id: "",
isWholeSale: "",
text: "",
value: "",
formData: {},
attrValue: [{
spec_type: "",
"price": "100",
@ -86,7 +89,7 @@
"volume": "",
"extension_one": "",
"extension_two": "",
open: false
open: true
},
],
@ -94,18 +97,18 @@
},
methods: {
submit() {
let pages = getCurrentPages(); //
let nowPage = pages[pages.length - 1]; //
let prevPage = pages[pages.length - 2]; //
let object = this.attrValue
prevPage.getAttrValue(object) // otherFun,object
uni.navigateBack()
this.formData.attrValue = this.attrValue
let that = this
uni.navigateTo({
url: `/pages/product/addGoodDetail/addGoodDetail?formData=${JSON.stringify(that.formData) }&&mer_id=${that.mer_id}`
})
}
},
onLoad(option) {
if (Object.values(JSON.parse(option.attrValue)).length) {
this.attrValue = JSON.parse(option.attrValue)
this.isWholeSale = this.$store.state.app.userInfo?.mer_info?.wholesale == 2;
if (option.formData) {
this.formData = JSON.parse(option.formData)
this.attrValue = this.formData.attrValue
}
}

View File

@ -9,7 +9,7 @@
常用分类
</view>
<view class="types">
<view class="types-li" v-for="(item,index) in searchList" @click='hdChose(item)'>
<view class="types-li" v-for="(item,index) in typeList" @click='hdChose(item)'>
{{item.label}}
</view>
@ -52,11 +52,13 @@
keyword: "",
mer_id: "",
searchList: [],
hotList: []
hotList: [],
typeList: []
}
},
methods: {
hdChange() {
console.log(this.searchList)
categorySearch(this.mer_id, {
keyword: this.keyword
}).then(res => {
@ -90,7 +92,7 @@
})
)
this.searchList = res.data.active_cate.map(item => ({
this.typeList = res.data.active_cate.map(item => ({
label: item.cate_name,
value: item.store_category_id