diff --git a/pages/shop/publishCopyright/publishCopyright.js b/pages/shop/publishCopyright/publishCopyright.js index ab09158..91ae3c7 100644 --- a/pages/shop/publishCopyright/publishCopyright.js +++ b/pages/shop/publishCopyright/publishCopyright.js @@ -1,7 +1,8 @@ // pages/shop/publishCopyright/publishCopyright.js import Shop from '../../../net/api/shop' import { - upShopImgUrl + upShopImgUrl, + sImgPrefix } from '../../../net/mainUrl' const { isValidPhone @@ -48,7 +49,9 @@ Page({ msgType: 'info', msgShow: false, files: [], - showType: false + showType: false, + goodsId: '', + goods: null, }, /** @@ -71,7 +74,55 @@ Page({ selectFile: this.selectFile.bind(this), uploadFile: this.uploadFile.bind(this) }) - this.getDic() + const id = options.id + if (id && id != '') { + this.setData({ + goodsId: id + }) + this.doGetGoodsDetail() + } else { + this.getDic() + } + }, + //获取商品详情 + doGetGoodsDetail() { + wx.showLoading({ + title: '加载中...', + }) + const _self = this + Shop.doGetGoodsDetail(_self.data.goodsId) + .then(res => { + wx.hideLoading() + var tempFile = [{ + fileId: res.goodsLocalPhoto, + fileName: 'ceshi', + fileSize: 223, + fileUrl: sImgPrefix + res.goodsLocalPhoto, + url: sImgPrefix + res.goodsLocalPhoto + }] + _self.setData({ + rightName: res.goodsName, + rightPrice: res.goodsPrice, + rightStopDate: res.goodsLastTime, + orgName: res.goodsLeader, + orgPhone: res.goodsLeaderPhone, + cardNumber: res.goodsLeaderIdcard, + files: tempFile, + goods: res + }) + _self.getDic() + }) + .catch(err => { + wx.hideLoading() + _self.setData({ + msgHint: err.msg ? err.msg : '网络错误,请稍后重试', + msgType: 'error', + msgShow: true + }) + setTimeout(() => { + wx.navigateBack() + }, 1500); + }) }, inputRightName(e) { this.setData({ @@ -239,6 +290,7 @@ Page({ orgPhone: '' }) }, + //获取字典 getDic() { const _self = this const cre = Shop.doGetGoodsDic('0b00884a-f7a2-425f-93e5-599fbaad4bde') //软著分类 @@ -256,13 +308,43 @@ Page({ _self.data.rightType.forEach(item => { item.checked = false }) - //默认加载第一个area - _self.setData({ - selCreType: _self.data.creType[0], - selArea: _self.data.areaList[0], - rightType: _self.data.rightType - }) - _self.doGetArea(_self.data.selArea.areaId) + //判断是否是编辑 + if (_self.data.goodsId != '') { + _self.data.rightType.forEach(item => { + // selRightType + if (_self.data.goods.goodsType.indexOf(item.dataId) != -1) { + item.checked = true + _self.data.selRightType.push(item) + } + }) + var tempPersonType + _self.data.personType.forEach(item => { + if (_self.data.goods.goodsLeaderType == item.dataId) { + tempPersonType = item + } + }) + var tempCreType + _self.data.creType.forEach(item => { + if (_self.data.goods.goodsLeaderIdcardType == item.dataId) { + tempCreType = item + } + }) + _self.setData({ + rightType: _self.data.rightType, + selRightType: _self.data.selRightType, + selPersonType: tempPersonType, + selCreType: tempCreType + }) + _self.doGetProvince(_self.data.goods.goodsLeaderCity1) + } else { + //默认加载第一个area + _self.setData({ + selCreType: _self.data.creType[0], + selArea: _self.data.areaList[0], + rightType: _self.data.rightType + }) + _self.doGetArea(_self.data.selArea.areaId) + } } }) .catch(err => { @@ -277,6 +359,29 @@ Page({ }) }, + //获取省 + doGetProvince(id) { + wx.showLoading({ + title: '加载中...', + }) + const _self = this + Shop.doGetAreaDetail(id) + .then(res => { + wx.hideLoading() + _self.setData({ + selArea: res + }) + _self.doGetArea(_self.data.selArea.areaId) + }) + .catch(err => { + wx.hideLoading() + //重置selArea selCity + _self.setData({ + selArea: null, + selCity: null + }) + }) + }, //获取区域 doGetArea(pId) { wx.showLoading({ @@ -286,14 +391,26 @@ Page({ Shop.doGetAreaList(pId) .then(res => { wx.hideLoading() - console.log(res) if (res) { _self.setData({ - cityList: res, - selCity: res[0] + cityList: res }) + if (_self.data.goodsId != '') { + var tempCity + _self.data.cityList.forEach(item => { + if (_self.data.goods.goodsLeaderCity2 == item.areaId) { + tempCity = item + } + }) + _self.setData({ + selCity: tempCity + }) + } else { + _self.setData({ + selCity: res[0] + }) + } } - }) .catch(err => { wx.hideLoading() @@ -330,8 +447,8 @@ Page({ } } }, - //保存商品 - doSave() { + //发布新商品 + doConfirmPublish() { const isLegal = this.checkParams() if (isLegal) { const _self = this @@ -361,6 +478,48 @@ Page({ }) } }, + //修改新商品 + doConfirmUpdate() { + const isLegal = this.checkParams() + if (isLegal) { + const _self = this + const data = _self.buildParams() + wx.showLoading({ + title: '保存中...', + }) + Shop.doUpdateGoods(_self.data.goodsId, data) + .then(res => { + wx.hideLoading() + //修改成功 + _self.setData({ + msgType: 'success', + msgHint: '修改成功', + msgShow: true + }) + setTimeout(() => { + _self.backPageRefresh() + }, 1500); + }) + .catch(err => { + wx.hideLoading() + _self.setData({ + msgType: 'error', + msgHint: err.msg ? err.msg : '网络错误,请稍后重试', + msgShow: true + }) + }) + } + }, + //保存商品 + doSave() { + if (this.data.goodsId != '') { + //编辑 + this.doConfirmUpdate() + } else { + //新增 + this.doConfirmPublish() + } + }, //校验参数 checkParams() { const rules = [{ diff --git a/pages/shop/publishCopyright/publishCopyright.wxss b/pages/shop/publishCopyright/publishCopyright.wxss index b1797e7..e073c89 100644 --- a/pages/shop/publishCopyright/publishCopyright.wxss +++ b/pages/shop/publishCopyright/publishCopyright.wxss @@ -40,6 +40,7 @@ .section { margin-bottom: 15rpx; + margin-left: 20rpx; } .item { @@ -73,7 +74,7 @@ min-height: 70rpx; flex-direction: row; border-radius: 5rpx; - padding: 0rpx 15rpx 10rpx 10rpx; + padding: 0rpx 15rpx 10rpx 0rpx; border-bottom: 1rpx solid var(--divider-color); } @@ -85,7 +86,7 @@ height: 70rpx; flex-direction: row; border-radius: 5rpx; - padding: 0rpx 15rpx 10rpx 15rpx; + padding: 0rpx 15rpx 10rpx 0rpx; border-bottom: 1rpx solid var(--divider-color); } @@ -105,13 +106,10 @@ padding: 5rpx 15rpx; border-radius: 5rpx; font-size: 24rpx; + margin-right: 20rpx; color: var(--text-color); } -.select-item-item:nth-of-type(n+1) { - margin: 8rpx; -} - .desc { flex: 1; color: #999; diff --git a/pages/shop/sellGoodsDetail/sellGoodsDetail.js b/pages/shop/sellGoodsDetail/sellGoodsDetail.js index 3b5aef4..fb81030 100644 --- a/pages/shop/sellGoodsDetail/sellGoodsDetail.js +++ b/pages/shop/sellGoodsDetail/sellGoodsDetail.js @@ -18,7 +18,8 @@ Page({ typeNameList: [], cardTypeName: '', cityName: '', - leaderType: '' + leaderType: '', + needRefresh: false }, /** @@ -53,6 +54,14 @@ Page({ }, 1500); } }, + onShow() { + if (this.data.needRefresh) { + this.setData({ + needRefresh: false + }) + this.doGetGoodsDetail() + } + }, //获取商品详情 doGetGoodsDetail() { wx.showLoading({ @@ -193,7 +202,10 @@ Page({ }, //去编辑 doEdit() { - + const _self = this + wx.navigateTo({ + url: '/pages/shop/publishCopyright/publishCopyright?id=' + _self.data.goodsId, + }) }, //删除 doDel() {