商品发布接口对接

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

View File

@ -47,16 +47,17 @@
<view class="card" style="padding: 14rpx 30rpx;"> <view class="card" style="padding: 14rpx 30rpx;">
<u-form-item label="商品分类" prop="userInfo.name" ref="item1" labelPosition="left" required> <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" <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> <view style="margin-right: 10rpx;line-height: 25rpx;">{{ formData.cate_name|| '请选择'}}</view>
<u-icon name="arrow-right"></u-icon> <u-icon name="arrow-right"></u-icon>
</view> </view>
</u-form-item> </u-form-item>
<u-form-item label="商品属性" prop="userInfo.name" ref="item1" labelPosition="left"> <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" <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;"> <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> </view>
<u-icon name="arrow-right"></u-icon> <u-icon name="arrow-right"></u-icon>
</view> </view>
@ -66,9 +67,9 @@
规格与价格 规格与价格
</view> </view>
<view class="card" style="min-height: 100rpx;padding: 14rpx 30rpx;"> <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" <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> <view style="margin-right: 10rpx;line-height: 25rpx;">去设置</view>
<u-icon name="arrow-right"></u-icon> <u-icon name="arrow-right"></u-icon>
</view> </view>
@ -92,13 +93,11 @@
批发价 批发价
</view> </view>
<view style="font-size: 28rpx;color:#777777 ;"> <view style="font-size: 28rpx;color:#777777 ;">
<!-- 8/ -->
{{item.wholesale_price}}/{{item.wholesale_unit_name}} {{item.wholesale_price}}/{{item.wholesale_unit_name}}
</view> </view>
</view> </view>
</u-form-item> </u-form-item>
</view> </view>
</view> </view>
<view class='tips'> <view class='tips'>
服务与承诺 服务与承诺
@ -168,13 +167,20 @@
</template> </template>
<script> <script>
import {
serialize,
Toast,
Loading,
hideLoading,
Modal
} from "@/libs/uniApi.js";
import { import {
HTTP_REQUEST_URL HTTP_REQUEST_URL
} from '@/config/app.js'; } from '@/config/app.js';
import { import {
formatDate productCreate,
} from '../../../libs/uniApi'; productUpdate
} from '@/api/product.js';
import uploadImgVideo from "../addGood/components/uploadImgVideo.vue" import uploadImgVideo from "../addGood/components/uploadImgVideo.vue"
export default { export default {
components: { components: {
@ -222,6 +228,15 @@
"stock": "20", "stock": "20",
store_info: "", store_info: "",
attribute: {}, attribute: {},
product_attribute: {
address: "",
leval: "",
pack: "",
attr: [{
label: "",
value: ''
}]
}
}, },
mer_id: "", mer_id: "",
maxLength: 30, maxLength: 30,
@ -372,16 +387,41 @@
showlayFn() { showlayFn() {
uni.navigateBack() uni.navigateBack()
}, },
submit() { // submit() {
console.log(this.formData) // console.log(this.formData)
}, // },
getAttr(object) { getAttr(object) {
this.formData.attribute = object this.formData.product_attribute = object
}, },
getAttrValue(object) { getAttrValue(object) {
this.formData.attrValue = object this.formData.attrValue = object
console.log(this.formData.attrValue) 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"> <u-form-item label="产地" prop="userInfo.name" ref="item1">
<view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right" <view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right"
@click="showPouple=true,popType='place',getLocation()"> @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> <u-icon name="arrow-right"></u-icon>
</view> </view>
</u-form-item> </u-form-item>
@ -18,27 +20,30 @@
<u-form-item label="商品等级" prop="userInfo.name" ref="item1"> <u-form-item label="商品等级" prop="userInfo.name" ref="item1">
<view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right" <view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right"
@click="showPouple=true,popType='leval'"> @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> <u-icon name="arrow-right"></u-icon>
</view> </view>
</u-form-item> </u-form-item>
<u-form-item label="货品包装" prop="userInfo.name" ref="item1"> <u-form-item label="货品包装" prop="userInfo.name" ref="item1">
<view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right" <view style="display: flex;align-items: center;font-size: 28rpx;color:#777777 ;" slot="right"
@click="showPouple=true,popType='packing'"> @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> <u-icon name="arrow-right"></u-icon>
</view> </view>
</u-form-item> </u-form-item>
</view> </view>
<view class="description" style="display: flex;justify-content: space-between;align-items: center"> <view class="description" style="display: flex;justify-content: space-between;align-items: center">
<text>产品属性</text> <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> <u-icon name="plus" color='#20B128' style="margin-right: 8rpx;font-weight: bold;"></u-icon>
</view> </view>
</view> </view>
<view class="label-cls" <view class="label-cls"
style="display: flex;padding: 20rpx 20rpx 20rpx 2rpx;justify-content: space-between;margin-bottom: 30rpx;" 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;"> <view class="" style="display: flex;width: 70%;align-items: center;">
<u--input placeholder="请填写属性名称" border="surround" v-model="item.label"></u--input> <u--input placeholder="请填写属性名称" border="surround" v-model="item.label"></u--input>
<u-line direction="col" length="40rpx" color="#CECECE"></u-line> <u-line direction="col" length="40rpx" color="#CECECE"></u-line>
@ -46,7 +51,7 @@
<u-line direction="col" length="40rpx" color="#CECECE"></u-line> <u-line direction="col" length="40rpx" color="#CECECE"></u-line>
</view> </view>
<view style="color: #777777;display: flex; align-items: center;" <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> <u-icon name="trash" style='margin-right: 8rpx;'></u-icon>
</view> </view>
</view> </view>
@ -69,7 +74,7 @@
<!-- 地区 --> <!-- 地区 -->
<view v-if="popType=='place'"> <view v-if="popType=='place'">
<view class="Positioning " style="color: #989898;margin-bottom: 30rpx;"> <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> <u-icon name="map" style='margin-right: 8rpx;'></u-icon>
<text>{{address.province}}{{address.city}}{{address.district}}</text> <text>{{address.province}}{{address.city}}{{address.district}}</text>
</view> </view>
@ -117,8 +122,9 @@
<view v-if="popType=='leval'" style="height: 500rpx;"> <view v-if="popType=='leval'" style="height: 500rpx;">
<u-transition :show="!show" mode="slide-right"> <u-transition :show="!show" mode="slide-right">
<view class="goods-leval"> <view class="goods-leval">
<view class="goods-leval-li" :class="{act:formData.leval==item}" v-for='item in levalList' <view class="goods-leval-li" :class="{act:formData.product_attribute.leval==item}"
@click="formData.leval=item,showPouple=false"> v-for='item in levalList'
@click="formData.product_attribute.leval=item,showPouple=false">
{{item}} {{item}}
</view> </view>
<view class="goods-leval-li " style="display: flex;color:#38BE41;" @click="show=true"> <view class="goods-leval-li " style="display: flex;color:#38BE41;" @click="show=true">
@ -139,7 +145,7 @@
<u-transition :show="!show" mode="slide-right"> <u-transition :show="!show" mode="slide-right">
<view class="goods-leval"> <view class="goods-leval">
<view class="goods-leval-li" :class="{act:formData.pack==item}" v-for='item in packList' <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}} {{item}}
</view> </view>
@ -216,15 +222,15 @@
showPouple: false, showPouple: false,
showSex: false, showSex: false,
positionType: 0, positionType: 0,
data: {},
formData: { formData: {
address: "", // address: "",
leval: "", // leval: "",
pack: "", // pack: "",
attr: [{ // attr: [{
label: "", // label: "",
value: '' // value: ''
}] // }]
}, },
model1: { model1: {
@ -252,10 +258,11 @@
}, },
confirm() { confirm() {
if (this.popType == 'place') { 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') { } else if (this.popType == 'leval') {
this.levalList.push(this.selfLeval) 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 = '' this.selfLeval = ''
} else if (this.popType == 'packing') { } else if (this.popType == 'packing') {
@ -335,21 +342,23 @@
}); });
}, },
submit() { submit() {
let pages = getCurrentPages(); // let that = this
let nowPage = pages[pages.length - 1]; // uni.navigateTo({
let prevPage = pages[pages.length - 2]; // url: `/pages/product/addGoodDetail/addGoodDetail?formData=${JSON.stringify(that.formData) }&&mer_id=${that.mer_id}`
let object = this.formData })
prevPage.getAttr(object) // otherFun,object
uni.navigateBack()
} }
}, },
onLoad(option) { onLoad(option) {
getProvince().then(res => { getProvince().then(res => {
this.provinceList = res.data this.provinceList = res.data
}) })
if (Object.values(JSON.parse(option.attr)).length) { this.formData = JSON.parse(option.formData)
this.formData = JSON.parse(option.attr) 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" v-for="(item,index) in attrValue">
<view class="card-head card-li"> <view class="card-head card-li">
<text style="font-size: 32rpx;font-family: PingFangFamily;">规格{{index+1}}</text> <text style="font-size: 32rpx;font-family: PingFangFamily;">规格{{index+1}}</text>
<view class="" style="width: 200rpx;"> <view class="" style="width: 300rpx;">
<u--input placeholder="请输入规格名称" v-model="item.spec_type"></u--input> <u--input placeholder="请输入规格名称" inputAlign='right' v-model="item.spec_type"></u--input>
</view> </view>
</view> </view>
<u-line direction="row" style="margin: 30rpx 0;" color="#ECECEC"></u-line> <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="请输入计量单位" <u--input style=" flex: 2;width:100rpx;background-color: #F6F6F6;" placeholder="请输入计量单位"
v-model="item.unit_name"></u--input> v-model="item.unit_name"></u--input>
</view> </view>
<view class="" <view class="" v-if='isWholeSale'
style="display: flex;align-items: center;justify-content: space-between;margin-top: 30rpx;"> style="display: flex;align-items: center;justify-content: space-between;margin-top: 30rpx;">
<u--input style="flex: 2; background-color: #F6F6F6;" placeholder="请输批发价格" <u--input style="flex: 2; background-color: #F6F6F6;" placeholder="请输批发价格"
v-model="item.wholesale_price"></u--input> v-model="item.wholesale_price"></u--input>
@ -37,15 +37,15 @@
<u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line> <u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line>
<view class=" card-li"> <view class=" card-li">
<text style="font-size: 32rpx;">商品库存</text> <text style="font-size: 32rpx;">商品库存</text>
<view class="" style="width: 200rpx;"> <view class="" style="width: 300rpx;">
<u--input placeholder="请填写库存数量" v-model="item.stock"></u--input> <u--input placeholder="请填写库存数量" inputAlign='right' v-model="item.stock"></u--input>
</view> </view>
</view> </view>
<u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line> <u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line>
<view class=" card-li"> <view class=" card-li">
<text style="font-size: 32rpx;">条形码</text> <text style="font-size: 32rpx;">条形码</text>
<view class="" style="width: 200rpx;"> <view class="" style="width: 300rpx;">
<u--input placeholder="请填写商品条形码" v-model="item.bar_code"></u--input> <u--input placeholder="请填写商品条形码" inputAlign='right' v-model="item.bar_code"></u--input>
</view> </view>
</view> </view>
<u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line> <u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line>
@ -69,8 +69,11 @@
export default { export default {
data() { data() {
return { return {
mer_id: "",
isWholeSale: "",
text: "", text: "",
value: "", value: "",
formData: {},
attrValue: [{ attrValue: [{
spec_type: "", spec_type: "",
"price": "100", "price": "100",
@ -86,7 +89,7 @@
"volume": "", "volume": "",
"extension_one": "", "extension_one": "",
"extension_two": "", "extension_two": "",
open: false open: true
}, },
], ],
@ -94,18 +97,18 @@
}, },
methods: { methods: {
submit() { submit() {
let pages = getCurrentPages(); // this.formData.attrValue = this.attrValue
let nowPage = pages[pages.length - 1]; // let that = this
let prevPage = pages[pages.length - 2]; // uni.navigateTo({
let object = this.attrValue url: `/pages/product/addGoodDetail/addGoodDetail?formData=${JSON.stringify(that.formData) }&&mer_id=${that.mer_id}`
prevPage.getAttrValue(object) // otherFun,object })
uni.navigateBack()
} }
}, },
onLoad(option) { onLoad(option) {
this.isWholeSale = this.$store.state.app.userInfo?.mer_info?.wholesale == 2;
if (Object.values(JSON.parse(option.attrValue)).length) { if (option.formData) {
this.attrValue = JSON.parse(option.attrValue) this.formData = JSON.parse(option.formData)
this.attrValue = this.formData.attrValue
} }
} }

View File

@ -9,7 +9,7 @@
常用分类 常用分类
</view> </view>
<view class="types"> <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}} {{item.label}}
</view> </view>
@ -52,11 +52,13 @@
keyword: "", keyword: "",
mer_id: "", mer_id: "",
searchList: [], searchList: [],
hotList: [] hotList: [],
typeList: []
} }
}, },
methods: { methods: {
hdChange() { hdChange() {
console.log(this.searchList)
categorySearch(this.mer_id, { categorySearch(this.mer_id, {
keyword: this.keyword keyword: this.keyword
}).then(res => { }).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, label: item.cate_name,
value: item.store_category_id value: item.store_category_id