接口对接

This commit is contained in:
donqi 2022-06-01 00:37:46 +08:00
parent 83ffcf10c8
commit 701d63672d
3 changed files with 124 additions and 29 deletions

View File

@ -7,9 +7,9 @@ export default {
uni.addInterceptor('request', {
invoke(args) {
// request 触发前拼接 url
// args.url = 'https://www.opsoul.com' + args.url;
args.url = 'http://127.0.0.1:80' + args.url;
// args.url = 'http://10.45.137.214:80' + args.url;
args.url = 'https://www.opsoul.com' + args.url;
// args.url = 'http://127.0.0.1:80' + args.url;
// args.url = 'http://10.45.111.215:80' + args.url;
if (args.data) {
args.data.deptId = globalData.deptId;
args.data.from = globalData.from;
@ -224,11 +224,22 @@ export default {
name: 'uploadFile'
})
let resStr = res[1].data;
let resObj = {};
let resObj = null;
if (resStr != null && resStr.length > 0) {
try {
resObj = JSON.parse(resStr);
} catch(e) {
console.log(e)
}
return resObj;
}
if (!resObj || resObj.code !== 0) {
uni.showToast({
icon: 'error',
title: '上传失败'
})
return '';
}
return resObj.url;
},
async listByStep(params = {goodsCategoryId : null}) {
let res = await uni.request({
@ -261,5 +272,13 @@ export default {
data: params
})
return res[1].data;
},
async addGoods(params) {
let res = await uni.request({
url: '/goods/goods/addGoods',
method: 'POST',
data: params
})
return res[1].data;
}
}

View File

@ -404,10 +404,8 @@
success: (res) => {
//
this.$request.uploadFile(res.tempFilePaths[0]).then((uploadRes) => {
//
if (uploadRes.code === 0) {
//
imgList.push(uploadRes.url);
}
});
}
});

View File

@ -9,11 +9,11 @@
<form @submit="submit">
<view class="cu-form-group">
<view class="title">服务名称</view>
<input name="servName" :value="formData.servName" :v-model="formData.servName" placeholder="请编辑上架标题(供客户搜索)"></input>
<input name="servName" v-model="formData.servName" placeholder="请编辑上架标题(供客户搜索)"></input>
</view>
<view class="cu-form-group">
<view class="title">服务描述</view>
<input name="servDesc" :value="formData.servDesc" :v-model="formData.servDesc" placeholder="让客户更清晰的上架内容描述"></input>
<input name="servDesc" v-model="formData.servDesc" placeholder="让客户更清晰的上架内容描述"></input>
</view>
<view class="solid-top">
<view class="cu-form-group">
@ -29,15 +29,15 @@
<view class="flex">
<view class="flex-sub">
<checkbox style="transform:scale(1)" class="main-color margin-right-xs" :value="index" :checked="item.checked"></checkbox>
<text>{{item.name}}</text>
<text>{{item.goodsCategoryName}}</text>
</view>
<view class="flex-sub">
<input class="radius-input" @input="inputSpecs($event, index, 'title')" :value="item.title" placeholder="自编辑购买标题"></input>
<input class="radius-input" @input="inputSpecs($event, index, 'goodsStandardName')" :value="item.goodsStandardName" placeholder="自编辑购买标题"></input>
</view>
</view>
<view class="flex margin-top-xs">
<view class="flex-sub">
<input class="radius-input" @input="inputSpecs($event, index, 'price')" :value="item.price" placeholder="价格(平6%+¥5销10%+¥18)"></input>
<input class="radius-input" @input="inputSpecs($event, index, 'goodsPrice')" :value="item.goodsPrice" placeholder="价格(平6%+¥5销10%+¥18)"></input>
</view>
</view>
<view class="flex margin-top-xs">
@ -105,6 +105,25 @@
<view class="title">上门费</view>
<input type="digit" name="doorPrice" :value="formData.doorPrice" :v-model="formData.doorPrice" placeholder="单位:元/次"></input>
</view>
<view class="cu-bar bg-white solid-top">
<view class="action text-black">
商品封面图上传
</view>
</view>
<view class="cu-form-group">
<view class="grid col-4 grid-square flex-sub">
<view class="bg-img" v-for="(item,index) in formData.coverImgList" :key="index" @tap="viewImage($event, formData.coverImgList)"
:data-url="item">
<image :src="item" mode="aspectFill"></image>
<view class="cu-tag bg-red" @tap.stop="delImg($event, formData.coverImgList)" :data-index="index">
<text class='cuIcon-close'></text>
</view>
</view>
<view class="solids" @tap="chooseImgList($event, 'coverImgList')" v-if="formData.coverImgList.length === 0">
<text class='cuIcon-cameraadd'></text>
</view>
</view>
</view>
<view class="cu-bar bg-white solid-top">
<view class="action text-black">
详情图上传
@ -187,7 +206,8 @@
imgList: [],
detailDesc: '',
descImgList: [],
video: {}
coverImgList: [],
video: ''
},
categoryList: [],
categoryMultiIndex: [0, 0, 0],
@ -269,7 +289,9 @@
}
this.formData.category = chosenCategory;
this.formData.specsList = await this.$api.data('specsList');
//
let res = await this.$request.listByStep({goodsCategoryId: chosenCategory[2].goodsCategoryId});
this.formData.specsList = res.data;
},
async categoryColChange(e) {
let colObj = e.detail;
@ -308,7 +330,7 @@
async regionColChange(e) {
let colObj = e.detail;
if (colObj.column == 0) {
//
//
let subAreaList = await this.$request.areaListByStep({parentCode: this.regionList[0][colObj.value].areaCode});
subAreaList = subAreaList.data;
this.regionList.pop();
@ -348,11 +370,18 @@
sizeType: ['original', 'compressed'], //
sourceType: ['album'], //
success: (res) => {
if (this.formData[imgListField].length != 0) {
this.formData[imgListField] = this.formData[imgListField].concat(res.tempFilePaths)
} else {
this.formData[imgListField] = res.tempFilePaths
uni.showLoading({
title: '上传中',
mask:true
});
res.tempFilePaths.forEach((tmpUrl, index) => {
this.$request.uploadFile(tmpUrl).then((url) => {
this.formData[imgListField].push(url);
if (index === res.tempFilePaths.length - 1) {
uni.hideLoading();
}
});
});
}
});
},
@ -376,13 +405,62 @@
})
},
async selectVideo(e) {
let res = await this.$request.uploadFile(e.tempFilePaths[0]);
if (res.code === 0) {
this.formData.video = res.url;
}
uni.showLoading({
title: '上传中',
mask:true
});
this.formData.video = await this.$request.uploadFile(e.tempFilePaths[0]);
uni.hideLoading();
},
submit() {
async submit() {
console.log(this.formData)
let goodsStandardList = this.formData.specsList.filter((item) => {
if (item.checked) {
return item;
}
});
let goodsAreaList = this.formData.districtList.filter((item) => {
if (item.checked) {
item.countryAreaId = item.areaId;
return item;
}
});
// 01
let goodsImgsList = [];
this.formData.imgList.forEach((url) => {
goodsImgsList.push({
imgUrl: url,
imgType: 0
});
});
this.formData.descImgList.forEach((url) => {
goodsImgsList.push({
imgUrl: url,
imgType: 1
});
});
let params = {
goodsName: this.formData.servName,
deptGoodsCategoryId: this.formData.category[2].goodsCategoryId,
goodsStandardList: goodsStandardList,
goodsAreaList: goodsAreaList,
goodsImgUrl: this.formData.coverImgList[0],
goodsImgsList: goodsImgsList,
goodsVideoUrl: this.formData.video,
status: 0,
remark: this.formData.detailDesc
}
console.log("格式化后的请求参数:" + params)
let res = await this.$request.addGoods(params);
if (res.code === 0) {
uni.showToast({
icon: 'success'
})
uni.navigateBack({
delta: -1
})
}
}
},
}
@ -393,7 +471,7 @@
display: none;
}
.certern-height {
height: 520rpx;
max-height: 520rpx;
overflow: hidden;
}
.long-btn{