diff --git a/common/js/request.js b/common/js/request.js index 152556e..f2e1c7c 100644 --- a/common/js/request.js +++ b/common/js/request.js @@ -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) { - resObj = JSON.parse(resStr); + 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; } } diff --git a/pages/my/master-occupancy.vue b/pages/my/master-occupancy.vue index 1531b33..acea66c 100644 --- a/pages/my/master-occupancy.vue +++ b/pages/my/master-occupancy.vue @@ -404,10 +404,8 @@ success: (res) => { // 上传图片 this.$request.uploadFile(res.tempFilePaths[0]).then((uploadRes) => { - // 成功后才存入缓存 - if (uploadRes.code === 0) { - imgList.push(uploadRes.url); - } + // 存入缓存 + imgList.push(uploadRes.url); }); } }); diff --git a/pages/my/new-serv.vue b/pages/my/new-serv.vue index 89bd3d5..f3ef1c4 100644 --- a/pages/my/new-serv.vue +++ b/pages/my/new-serv.vue @@ -9,11 +9,11 @@
服务名称 - + 服务描述 - + @@ -29,15 +29,15 @@ - {{item.name}} + {{item.goodsCategoryName}} - + - + @@ -105,6 +105,25 @@ 上门费 + + + 商品封面图上传 + + + + + + + + + + + + + + + 详情图上传 @@ -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; + } + }); + // 0是轮播图,1是详情图 + 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{