diff --git a/litemall-admin/src/api/feedback.js b/litemall-admin/src/api/feedback.js index b5089e69..0eefe7b0 100644 --- a/litemall-admin/src/api/feedback.js +++ b/litemall-admin/src/api/feedback.js @@ -38,4 +38,4 @@ export function deleteFeedback(data) { method: 'post', data }) -} \ No newline at end of file +} diff --git a/litemall-admin/src/router/index.js b/litemall-admin/src/router/index.js index 8447285c..bd75e85a 100644 --- a/litemall-admin/src/router/index.js +++ b/litemall-admin/src/router/index.js @@ -65,8 +65,8 @@ export const asyncRouterMap = [ { path: 'address', component: _import('user/address'), name: 'address', meta: { title: '收货地址', noCache: true }}, { path: 'collect', component: _import('user/collect'), name: 'collect', meta: { title: '会员收藏', noCache: true }}, { path: 'footprint', component: _import('user/footprint'), name: 'footprint', meta: { title: '会员足迹', noCache: true }}, - { path: 'history', component: _import('user/history'), name: 'history', meta: { title: '搜索历史', noCache: true }}, - { path: 'feedback', component: _import('user/feedback'), name: 'feedback', meta: { title: '意见反馈', noCache: true }} + { path: 'history', component: _import('user/history'), name: 'history', meta: { title: '搜索历史', noCache: true }}, + { path: 'feedback', component: _import('user/feedback'), name: 'feedback', meta: { title: '意见反馈', noCache: true }} ] }, diff --git a/litemall-wx-api/pom.xml b/litemall-wx-api/pom.xml index 5148b3a7..51849a25 100644 --- a/litemall-wx-api/pom.xml +++ b/litemall-wx-api/pom.xml @@ -49,12 +49,6 @@ weixin-java-miniapp - - com.alibaba - fastjson - 1.2.45 - - diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFeedbackController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFeedbackController.java index 66c220d4..c8e2b0dc 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFeedbackController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFeedbackController.java @@ -1,6 +1,6 @@ package org.linlinjava.litemall.wx.web; -import com.alibaba.fastjson.JSONObject; +import org.linlinjava.litemall.core.util.JacksonUtil; import org.linlinjava.litemall.core.util.RegexUtil; import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.db.domain.LitemallFeedback; @@ -12,17 +12,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; -import java.io.BufferedReader; -import java.io.IOException; import java.time.LocalDateTime; - /** * @author Yogeek * @date 2018/8/25 14:10 @@ -36,67 +30,33 @@ public class WxFeedbackController { @Autowired private LitemallFeedbackService feedbackService; @Autowired - protected HttpServletRequest request; - @Autowired private LitemallUserService userService; /** * 意见反馈 */ @PostMapping("submit") - @ResponseBody - public Object save(@LoginUser Integer userId){ - if(userId == null){ + public Object submit(@LoginUser Integer userId, @RequestBody LitemallFeedback feedback) { + if (userId == null) { return ResponseUtil.unlogin(); } + // 测试手机号码是否正确 + if (!RegexUtil.isMobileExact(feedback.getMobile())) { + return ResponseUtil.badArgument(); + } + LitemallUser user = userService.findById(userId); String username = user.getUsername(); - //获取客户端对象 - JSONObject feedbackJson = this.getJsonRequest(); + feedback.setId(null); + feedback.setUserId(userId); + feedback.setUsername(username); + feedback.setAddTime(LocalDateTime.now()); + //状态默认是0,1表示状态已发生变化 + feedback.setStatus(1); + feedbackService.add(feedback); - if (null != feedbackJson) { - LitemallFeedback feedback = new LitemallFeedback(); - - String mobile = feedbackJson.getString("mobile"); - // 测试手机号码是否正确 - if (!RegexUtil.isMobileExact(mobile)) { - return ResponseUtil.badArgument(); - } - String[] feedType = new String [] {"请选择反馈类型", "商品相关", "功能异常", "优化建议", "其他"}; - int index = feedbackJson.getInteger("index"); - String content = feedbackJson.getString("content"); - - feedback.setUserId(userId); - feedback.setUsername(username); - feedback.setMobile(mobile); - feedback.setAddTime(LocalDateTime.now()); - feedback.setFeedType(feedType[index]); - //状态默认是0,1表示状态已发生变化 - feedback.setStatus(1); - feedback.setContent(content); - feedbackService.add(feedback); - - return ResponseUtil.ok("感谢您的反馈"); - } - return ResponseUtil.badArgument(); - } - - private JSONObject getJsonRequest() { - JSONObject result = null; - StringBuilder sb = new StringBuilder(); - try (BufferedReader reader = request.getReader();) { - char[] buff = new char[1024]; - int len; - while ((len = reader.read(buff)) != -1) { - sb.append(buff, 0, len); - } - result = JSONObject.parseObject(sb.toString()); - } catch (IOException e) { - e.printStackTrace(); - } - - return result; + return ResponseUtil.ok(); } } diff --git a/litemall-wx/config/api.js b/litemall-wx/config/api.js index dea7c5a8..033f8ede 100644 --- a/litemall-wx/config/api.js +++ b/litemall-wx/config/api.js @@ -1,12 +1,12 @@ // 以下是业务服务器API地址 // 本机开发时使用 - var WxApiRoot = 'http://localhost:8080/wx/'; + var WxApiRoot = 'http://localhost:8082/wx/'; // 局域网测试使用 // var WxApiRoot = 'http://192.168.0.101:8080/wx/'; // 云平台部署时使用 // var WxApiRoot = 'http://122.152.206.172:8080/wx/'; // 云平台上线时使用 -// var WxApiRoot = 'https://www.menethil.com.cn/wx/'; + //var WxApiRoot = 'https://www.menethil.com.cn/wx/'; module.exports = { IndexUrl: WxApiRoot + 'home/index', //首页数据接口 @@ -75,6 +75,7 @@ module.exports = { OrderConfirm: WxApiRoot + 'order/confirm', //确认收货 OrderComment: WxApiRoot + 'order/comment', // 代评价商品信息 + FeedbackAdd: WxApiRoot + 'feedback/submit', //添加反馈 FootprintList: WxApiRoot + 'footprint/list', //足迹列表 FootprintDelete: WxApiRoot + 'footprint/delete', //删除足迹 diff --git a/litemall-wx/pages/cart/cart.wxml b/litemall-wx/pages/cart/cart.wxml index 092ce0ac..ad0c9fa2 100644 --- a/litemall-wx/pages/cart/cart.wxml +++ b/litemall-wx/pages/cart/cart.wxml @@ -50,9 +50,12 @@ 全选({{cartTotal.checkedGoodsCount}}) {{!isEditCart ? '¥'+cartTotal.checkedGoodsAmount : ''}} - {{!isEditCart ? '编辑' : '完成'}} - 删除所选 - 下单 + + {{!isEditCart ? '编辑' : '完成'}} + 删除({{cartTotal.checkedGoodsCount}}) + 下单 + + diff --git a/litemall-wx/pages/goods/goods.js b/litemall-wx/pages/goods/goods.js index e79d855d..4138ac48 100644 --- a/litemall-wx/pages/goods/goods.js +++ b/litemall-wx/pages/goods/goods.js @@ -5,646 +5,652 @@ var api = require('../../config/api.js'); var user = require('../../utils/user.js'); Page({ - data: { - id: 0, - goods: {}, - groupon: [], //该商品支持的团购规格 - grouponLink: {}, //参与的团购 - attribute: [], - issueList: [], - comment: [], - brand: {}, - specificationList: [], - productList: [], - relatedGoods: [], - cartGoodsCount: 0, - userHasCollect: 0, - number: 1, - checkedSpecText: '规格数量选择', - tmpSpecText: '请选择规格数量', - checkedSpecPrice: 0, - openAttr: false, - noCollectImage: '/static/images/icon_collect.png', - hasCollectImage: '/static/images/icon_collect_checked.png', - collectImage: '/static/images/icon_collect.png', - shareImage: '', - isGroupon: false, //标识是否是一个参团购买 - soldout: false - }, - - // 页面分享 - onShareAppMessage: function() { - let that = this; - return { - title: that.data.goods.name, - desc: '唯爱与美食不可辜负', - path: '/pages/index/index?goodId=' + this.data.id - } - }, - - shareFriendOrCircle: function () { - //var that = this; - if (this.data.openShare === false) { - this.setData({ - openShare: !this.data.openShare - }); - } else { - return false; - } - }, - - // 保存分享图 - saveShare: function() { - let that = this; - wx.downloadFile({ - url: that.data.shareImage, - success: function(res) { - console.log(res) - wx.saveImageToPhotosAlbum({ - filePath: res.tempFilePath, - success: function(res) { - wx.showModal({ - title: '存图成功', - content: '图片成功保存到相册了,可以分享到朋友圈了', - showCancel: false, - confirmText: '好的', - confirmColor: '#a78845', - success: function(res) { - if (res.confirm) { - console.log('用户点击确定'); - } - } - }) - }, - fail: function(res) { - console.log('fail') - } - }) - }, - fail: function() { - console.log('fail') - } - }) - }, - - //从分享的团购进入 - getGrouponInfo: function(grouponId) { - let that = this; - util.request(api.GroupOnJoin, { - grouponId: grouponId - }).then(function(res) { - if (res.errno === 0) { - that.setData({ - grouponLink: res.data.groupon, - id: res.data.goods.id - }); - //获取商品详情 - that.getGoodsInfo(); - } - }); - }, - - // 获取商品信息 - getGoodsInfo: function() { - let that = this; - util.request(api.GoodsDetail, { - id: that.data.id - }).then(function(res) { - if (res.errno === 0) { - - let _specificationList = res.data.specificationList - // 如果仅仅存在一种货品,那么商品页面初始化时默认checked - if (_specificationList.length == 1) { - if (_specificationList[0].valueList.length == 1) { - _specificationList[0].valueList[0].checked = true - - // 如果仅仅存在一种货品,那么商品价格应该和货品价格一致 - // 这里检测一下 - let _productPrice = res.data.productList[0].price; - let _goodsPrice = res.data.info.retailPrice; - if (_productPrice != _goodsPrice) { - console.error('商品数量价格和货品不一致'); - } - - that.setData({ - checkedSpecText: _specificationList[0].valueList[0].value, - tmpSpecText: '已选择:' + _specificationList[0].valueList[0].value, - }); - } - } - - that.setData({ - goods: res.data.info, - attribute: res.data.attribute, - issueList: res.data.issue, - comment: res.data.comment, - brand: res.data.brand, - specificationList: res.data.specificationList, - productList: res.data.productList, - userHasCollect: res.data.userHasCollect, - shareImage: res.data.shareImage, - checkedSpecPrice: res.data.info.retailPrice, - groupon: res.data.groupon - }); - - //如果是通过分享的团购参加团购,则团购项目应该与分享的一致并且不可更改 - if (that.data.isGroupon) { - let groupons = that.data.groupon; - for (var i = 0; i < groupons.length; i++) { - if (groupons[i].id != that.data.grouponLink.rulesId) { - groupons.splice(i, 1); - } - } - groupons[0].checked = true; - //重设团购规格 - that.setData({ - groupon: groupons - }); - - } - - if (res.data.userHasCollect == 1) { - that.setData({ - collectImage: that.data.hasCollectImage - }); - } else { - that.setData({ - collectImage: that.data.noCollectImage - }); - } - - WxParse.wxParse('goodsDetail', 'html', res.data.info.detail, that); - //获取推荐商品 - that.getGoodsRelated(); - } - }); - }, - - // 获取推荐商品 - getGoodsRelated: function() { - let that = this; - util.request(api.GoodsRelated, { - id: that.data.id - }).then(function(res) { - if (res.errno === 0) { - that.setData({ - relatedGoods: res.data.goodsList, - }); - } - }); - }, - - // 团购选择 - clickGroupon: function(event) { - let that = this; - - //参与团购,不可更改选择 - if (that.data.isGroupon) { - return; - } - - let specName = event.currentTarget.dataset.name; - let specValueId = event.currentTarget.dataset.valueId; - - let _grouponList = this.data.groupon; - for (let i = 0; i < _grouponList.length; i++) { - if (_grouponList[i].id == specValueId) { - if (_grouponList[i].checked) { - _grouponList[i].checked = false; - } else { - _grouponList[i].checked = true; - } - } else { - _grouponList[i].checked = false; - } - } - - this.setData({ - groupon: _grouponList, - }); - }, - - // 规格选择 - clickSkuValue: function(event) { - let that = this; - let specName = event.currentTarget.dataset.name; - let specValueId = event.currentTarget.dataset.valueId; - - //判断是否可以点击 - - //TODO 性能优化,可在wx:for中添加index,可以直接获取点击的属性名和属性值,不用循环 - let _specificationList = this.data.specificationList; - for (let i = 0; i < _specificationList.length; i++) { - if (_specificationList[i].name === specName) { - for (let j = 0; j < _specificationList[i].valueList.length; j++) { - if (_specificationList[i].valueList[j].id == specValueId) { - //如果已经选中,则反选 - if (_specificationList[i].valueList[j].checked) { - _specificationList[i].valueList[j].checked = false; - } else { - _specificationList[i].valueList[j].checked = true; - } - } else { - _specificationList[i].valueList[j].checked = false; - } - } - } - } - this.setData({ - specificationList: _specificationList, - }); - //重新计算spec改变后的信息 - this.changeSpecInfo(); - - //重新计算哪些值不可以点击 - }, - - //获取选中的团购信息 - getCheckedGrouponValue: function() { - let checkedValues = {}; - let _grouponList = this.data.groupon; - for (let i = 0; i < _grouponList.length; i++) { - if (_grouponList[i].checked) { - checkedValues = _grouponList[i]; - } - } - - return checkedValues; - }, - - //获取选中的规格信息 - getCheckedSpecValue: function() { - let checkedValues = []; - let _specificationList = this.data.specificationList; - for (let i = 0; i < _specificationList.length; i++) { - let _checkedObj = { - name: _specificationList[i].name, - valueId: 0, - valueText: '' - }; - for (let j = 0; j < _specificationList[i].valueList.length; j++) { - if (_specificationList[i].valueList[j].checked) { - _checkedObj.valueId = _specificationList[i].valueList[j].id; - _checkedObj.valueText = _specificationList[i].valueList[j].value; - } - } - checkedValues.push(_checkedObj); - } - - return checkedValues; - }, - - //判断规格是否选择完整 - isCheckedAllSpec: function() { - return !this.getCheckedSpecValue().some(function(v) { - if (v.valueId == 0) { - return true; - } - }); - }, - - getCheckedSpecKey: function() { - let checkedValue = this.getCheckedSpecValue().map(function(v) { - return v.valueText; - }); - return checkedValue; - }, - - // 规格改变时,重新计算价格及显示信息 - changeSpecInfo: function() { - let checkedNameValue = this.getCheckedSpecValue(); - - //设置选择的信息 - let checkedValue = checkedNameValue.filter(function(v) { - if (v.valueId != 0) { - return true; - } else { - return false; - } - }).map(function(v) { - return v.valueText; - }); - if (checkedValue.length > 0) { - this.setData({ - tmpSpecText: checkedValue.join(' ') - }); - } else { - this.setData({ - tmpSpecText: '请选择规格数量' - }); - } - - if (this.isCheckedAllSpec()) { - this.setData({ - checkedSpecText: this.data.tmpSpecText - }); - - // 规格所对应的货品选择以后 - let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey()); - if (!checkedProductArray || checkedProductArray.length <= 0) { - this.setData({ - soldout: true - }); - console.error('规格所对应货品不存在'); - return; - } - - let checkedProduct = checkedProductArray[0]; - if (checkedProduct.number > 0) { - this.setData({ - checkedSpecPrice: checkedProduct.price, - soldout: false - }); - } else { - this.setData({ - checkedSpecPrice: this.data.goods.retailPrice, - soldout: true - }); - } - - } else { - this.setData({ + data: { + id: 0, + goods: {}, + groupon: [], //该商品支持的团购规格 + grouponLink: {}, //参与的团购 + attribute: [], + issueList: [], + comment: [], + brand: {}, + specificationList: [], + productList: [], + relatedGoods: [], + cartGoodsCount: 0, + userHasCollect: 0, + number: 1, checkedSpecText: '规格数量选择', - checkedSpecPrice: this.data.goods.retailPrice, + tmpSpecText: '请选择规格数量', + checkedSpecPrice: 0, + openAttr: false, + openShare: false, + noCollectImage: '/static/images/icon_collect.png', + hasCollectImage: '/static/images/icon_collect_checked.png', + collectImage: '/static/images/icon_collect.png', + shareImage: '', + isGroupon: false, //标识是否是一个参团购买 soldout: false - }); - } + }, - }, + // 页面分享 + onShareAppMessage: function() { + let that = this; + return { + title: that.data.goods.name, + desc: '唯爱与美食不可辜负', + path: '/pages/index/index?goodId=' + this.data.id + } + }, - // 获取选中的产品(根据规格) - getCheckedProductItem: function(key) { - return this.data.productList.filter(function(v) { - if (v.specifications.toString() == key.toString()) { - return true; - } else { - return false; - } - }); - }, - - onLoad: function(options) { - // 页面初始化 options为页面跳转所带来的参数 - if (options.id) { - this.setData({ - id: parseInt(options.id) - }); - this.getGoodsInfo(); - } - - if (options.grouponId) { - this.setData({ - isGroupon: true, - }); - this.getGrouponInfo(options.grouponId); - } - }, - onShow: function() { - // 页面显示 - var that = this; - util.request(api.CartGoodsCount).then(function(res) { - if (res.errno === 0) { - that.setData({ - cartGoodsCount: res.data - }); - } - }); - }, - - //添加或是取消收藏 - addCollectOrNot: function() { - let that = this; - util.request(api.CollectAddOrDelete, { - type: 0, - valueId: this.data.id - }, "POST") - .then(function(res) { - let _res = res; - if (_res.errno == 0) { - if (_res.data.type == 'add') { - that.setData({ - collectImage: that.data.hasCollectImage + shareFriendOrCircle: function() { + //var that = this; + if (this.data.openShare === false) { + this.setData({ + openShare: !this.data.openShare }); - } else { - that.setData({ - collectImage: that.data.noCollectImage - }); - } - } else { - wx.showToast({ - image: '/static/images/icon_error.png', - title: _res.errmsg, - mask: true - }); + return false; + } + }, + + // 保存分享图 + saveShare: function() { + let that = this; + wx.downloadFile({ + url: that.data.shareImage, + success: function(res) { + console.log(res) + wx.saveImageToPhotosAlbum({ + filePath: res.tempFilePath, + success: function(res) { + wx.showModal({ + title: '存图成功', + content: '图片成功保存到相册了,可以分享到朋友圈了', + showCancel: false, + confirmText: '好的', + confirmColor: '#a78845', + success: function(res) { + if (res.confirm) { + console.log('用户点击确定'); + } + } + }) + }, + fail: function(res) { + console.log('fail') + } + }) + }, + fail: function() { + console.log('fail') + } + }) + }, + + //从分享的团购进入 + getGrouponInfo: function(grouponId) { + let that = this; + util.request(api.GroupOnJoin, { + grouponId: grouponId + }).then(function(res) { + if (res.errno === 0) { + that.setData({ + grouponLink: res.data.groupon, + id: res.data.goods.id + }); + //获取商品详情 + that.getGoodsInfo(); + } + }); + }, + + // 获取商品信息 + getGoodsInfo: function() { + let that = this; + util.request(api.GoodsDetail, { + id: that.data.id + }).then(function(res) { + if (res.errno === 0) { + + let _specificationList = res.data.specificationList + // 如果仅仅存在一种货品,那么商品页面初始化时默认checked + if (_specificationList.length == 1) { + if (_specificationList[0].valueList.length == 1) { + _specificationList[0].valueList[0].checked = true + + // 如果仅仅存在一种货品,那么商品价格应该和货品价格一致 + // 这里检测一下 + let _productPrice = res.data.productList[0].price; + let _goodsPrice = res.data.info.retailPrice; + if (_productPrice != _goodsPrice) { + console.error('商品数量价格和货品不一致'); + } + + that.setData({ + checkedSpecText: _specificationList[0].valueList[0].value, + tmpSpecText: '已选择:' + _specificationList[0].valueList[0].value, + }); + } + } + + that.setData({ + goods: res.data.info, + attribute: res.data.attribute, + issueList: res.data.issue, + comment: res.data.comment, + brand: res.data.brand, + specificationList: res.data.specificationList, + productList: res.data.productList, + userHasCollect: res.data.userHasCollect, + shareImage: res.data.shareImage, + checkedSpecPrice: res.data.info.retailPrice, + groupon: res.data.groupon + }); + + //如果是通过分享的团购参加团购,则团购项目应该与分享的一致并且不可更改 + if (that.data.isGroupon) { + let groupons = that.data.groupon; + for (var i = 0; i < groupons.length; i++) { + if (groupons[i].id != that.data.grouponLink.rulesId) { + groupons.splice(i, 1); + } + } + groupons[0].checked = true; + //重设团购规格 + that.setData({ + groupon: groupons + }); + + } + + if (res.data.userHasCollect == 1) { + that.setData({ + collectImage: that.data.hasCollectImage + }); + } else { + that.setData({ + collectImage: that.data.noCollectImage + }); + } + + WxParse.wxParse('goodsDetail', 'html', res.data.info.detail, that); + //获取推荐商品 + that.getGoodsRelated(); + } + }); + }, + + // 获取推荐商品 + getGoodsRelated: function() { + let that = this; + util.request(api.GoodsRelated, { + id: that.data.id + }).then(function(res) { + if (res.errno === 0) { + that.setData({ + relatedGoods: res.data.goodsList, + }); + } + }); + }, + + // 团购选择 + clickGroupon: function(event) { + let that = this; + + //参与团购,不可更改选择 + if (that.data.isGroupon) { + return; } - }); + let specName = event.currentTarget.dataset.name; + let specValueId = event.currentTarget.dataset.valueId; - }, - - //立即购买(先自动加入购物车) - addFast: function() { - var that = this; - if (this.data.openAttr == false) { - //打开规格选择窗口 - this.setData({ - openAttr: !this.data.openAttr - }); - } else { - - //提示选择完整规格 - if (!this.isCheckedAllSpec()) { - wx.showToast({ - image: '/static/images/icon_error.png', - title: '请选择完整规格' - }); - return false; - } - - //根据选中的规格,判断是否有对应的sku信息 - let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey()); - if (!checkedProductArray || checkedProductArray.length <= 0) { - //找不到对应的product信息,提示没有库存 - wx.showToast({ - image: '/static/images/icon_error.png', - title: '没有库存' - }); - return false; - } - - let checkedProduct = checkedProductArray[0]; - //验证库存 - if (checkedProduct.number <= 0) { - wx.showToast({ - image: '/static/images/icon_error.png', - title: '没有库存' - }); - return false; - } - - //验证团购是否有效 - let checkedGroupon = this.getCheckedGrouponValue(); - - //立即购买 - util.request(api.CartFastAdd, { - goodsId: this.data.goods.id, - number: this.data.number, - productId: checkedProduct.id - }, "POST") - .then(function(res) { - if (res.errno == 0) { - - // 如果storage中设置了cartId,则是立即购买,否则是购物车购买 - try { - wx.setStorageSync('cartId', res.data); - wx.setStorageSync('grouponRulesId', checkedGroupon.id); - wx.setStorageSync('grouponLinkId', that.data.grouponLink.id); - wx.navigateTo({ - url: '/pages/checkout/checkout' - }) - } catch (e) {} - - } else { - wx.showToast({ - image: '/static/images/icon_error.png', - title: res.errmsg, - mask: true - }); - } - }); - } - - - }, - - //添加到购物车 - addToCart: function() { - var that = this; - if (this.data.openAttr == false) { - //打开规格选择窗口 - this.setData({ - openAttr: !this.data.openAttr - }); - } else { - - //提示选择完整规格 - if (!this.isCheckedAllSpec()) { - wx.showToast({ - image: '/static/images/icon_error.png', - title: '请选择完整规格' - }); - return false; - } - - //根据选中的规格,判断是否有对应的sku信息 - let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey()); - if (!checkedProductArray || checkedProductArray.length <= 0) { - //找不到对应的product信息,提示没有库存 - wx.showToast({ - image: '/static/images/icon_error.png', - title: '没有库存' - }); - return false; - } - - let checkedProduct = checkedProductArray[0]; - //验证库存 - if (checkedProduct.number <= 0) { - wx.showToast({ - image: '/static/images/icon_error.png', - title: '没有库存' - }); - return false; - } - - //添加到购物车 - util.request(api.CartAdd, { - goodsId: this.data.goods.id, - number: this.data.number, - productId: checkedProduct.id - }, "POST") - .then(function(res) { - let _res = res; - if (_res.errno == 0) { - wx.showToast({ - title: '添加成功' - }); - that.setData({ - openAttr: !that.data.openAttr, - cartGoodsCount: _res.data - }); - if (that.data.userHasCollect == 1) { - that.setData({ - collectImage: that.data.hasCollectImage - }); + let _grouponList = this.data.groupon; + for (let i = 0; i < _grouponList.length; i++) { + if (_grouponList[i].id == specValueId) { + if (_grouponList[i].checked) { + _grouponList[i].checked = false; + } else { + _grouponList[i].checked = true; + } } else { - that.setData({ - collectImage: that.data.noCollectImage - }); + _grouponList[i].checked = false; } - } else { - wx.showToast({ - image: '/static/images/icon_error.png', - title: _res.errmsg, - mask: true - }); - } + } + this.setData({ + groupon: _grouponList, }); - } + }, - }, + // 规格选择 + clickSkuValue: function(event) { + let that = this; + let specName = event.currentTarget.dataset.name; + let specValueId = event.currentTarget.dataset.valueId; - cutNumber: function() { - this.setData({ - number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1 - }); - }, - addNumber: function() { - this.setData({ - number: this.data.number + 1 - }); - }, - onHide: function() { - // 页面隐藏 + //判断是否可以点击 - }, - onUnload: function() { - // 页面关闭 + //TODO 性能优化,可在wx:for中添加index,可以直接获取点击的属性名和属性值,不用循环 + let _specificationList = this.data.specificationList; + for (let i = 0; i < _specificationList.length; i++) { + if (_specificationList[i].name === specName) { + for (let j = 0; j < _specificationList[i].valueList.length; j++) { + if (_specificationList[i].valueList[j].id == specValueId) { + //如果已经选中,则反选 + if (_specificationList[i].valueList[j].checked) { + _specificationList[i].valueList[j].checked = false; + } else { + _specificationList[i].valueList[j].checked = true; + } + } else { + _specificationList[i].valueList[j].checked = false; + } + } + } + } + this.setData({ + specificationList: _specificationList, + }); + //重新计算spec改变后的信息 + this.changeSpecInfo(); - }, - switchAttrPop: function() { - if (this.data.openAttr == false) { - this.setData({ - openAttr: !this.data.openAttr - }); - } - }, - closeAttr: function() { - this.setData({ - openAttr: false, - }); - }, - openCartPage: function() { - wx.switchTab({ - url: '/pages/cart/cart' - }); - }, - onReady: function() { - // 页面渲染完成 + //重新计算哪些值不可以点击 + }, - }, - // 下拉刷新 - onPullDownRefresh() { - wx.showNavigationBarLoading() //在标题栏中显示加载 - this.getGoodsInfo(); - wx.hideNavigationBarLoading() //完成停止加载 - wx.stopPullDownRefresh() //停止下拉刷新 - }, - //根据已选的值,计算其它值的状态 - setSpecValueStatus: function() { + //获取选中的团购信息 + getCheckedGrouponValue: function() { + let checkedValues = {}; + let _grouponList = this.data.groupon; + for (let i = 0; i < _grouponList.length; i++) { + if (_grouponList[i].checked) { + checkedValues = _grouponList[i]; + } + } - }, + return checkedValues; + }, + + //获取选中的规格信息 + getCheckedSpecValue: function() { + let checkedValues = []; + let _specificationList = this.data.specificationList; + for (let i = 0; i < _specificationList.length; i++) { + let _checkedObj = { + name: _specificationList[i].name, + valueId: 0, + valueText: '' + }; + for (let j = 0; j < _specificationList[i].valueList.length; j++) { + if (_specificationList[i].valueList[j].checked) { + _checkedObj.valueId = _specificationList[i].valueList[j].id; + _checkedObj.valueText = _specificationList[i].valueList[j].value; + } + } + checkedValues.push(_checkedObj); + } + + return checkedValues; + }, + + //判断规格是否选择完整 + isCheckedAllSpec: function() { + return !this.getCheckedSpecValue().some(function(v) { + if (v.valueId == 0) { + return true; + } + }); + }, + + getCheckedSpecKey: function() { + let checkedValue = this.getCheckedSpecValue().map(function(v) { + return v.valueText; + }); + return checkedValue; + }, + + // 规格改变时,重新计算价格及显示信息 + changeSpecInfo: function() { + let checkedNameValue = this.getCheckedSpecValue(); + + //设置选择的信息 + let checkedValue = checkedNameValue.filter(function(v) { + if (v.valueId != 0) { + return true; + } else { + return false; + } + }).map(function(v) { + return v.valueText; + }); + if (checkedValue.length > 0) { + this.setData({ + tmpSpecText: checkedValue.join(' ') + }); + } else { + this.setData({ + tmpSpecText: '请选择规格数量' + }); + } + + if (this.isCheckedAllSpec()) { + this.setData({ + checkedSpecText: this.data.tmpSpecText + }); + + // 规格所对应的货品选择以后 + let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey()); + if (!checkedProductArray || checkedProductArray.length <= 0) { + this.setData({ + soldout: true + }); + console.error('规格所对应货品不存在'); + return; + } + + let checkedProduct = checkedProductArray[0]; + if (checkedProduct.number > 0) { + this.setData({ + checkedSpecPrice: checkedProduct.price, + soldout: false + }); + } else { + this.setData({ + checkedSpecPrice: this.data.goods.retailPrice, + soldout: true + }); + } + + } else { + this.setData({ + checkedSpecText: '规格数量选择', + checkedSpecPrice: this.data.goods.retailPrice, + soldout: false + }); + } + + }, + + // 获取选中的产品(根据规格) + getCheckedProductItem: function(key) { + return this.data.productList.filter(function(v) { + if (v.specifications.toString() == key.toString()) { + return true; + } else { + return false; + } + }); + }, + + onLoad: function(options) { + // 页面初始化 options为页面跳转所带来的参数 + if (options.id) { + this.setData({ + id: parseInt(options.id) + }); + this.getGoodsInfo(); + } + + if (options.grouponId) { + this.setData({ + isGroupon: true, + }); + this.getGrouponInfo(options.grouponId); + } + }, + onShow: function() { + // 页面显示 + var that = this; + util.request(api.CartGoodsCount).then(function(res) { + if (res.errno === 0) { + that.setData({ + cartGoodsCount: res.data + }); + } + }); + }, + + //添加或是取消收藏 + addCollectOrNot: function() { + let that = this; + util.request(api.CollectAddOrDelete, { + type: 0, + valueId: this.data.id + }, "POST") + .then(function(res) { + let _res = res; + if (_res.errno == 0) { + if (_res.data.type == 'add') { + that.setData({ + collectImage: that.data.hasCollectImage + }); + } else { + that.setData({ + collectImage: that.data.noCollectImage + }); + } + + } else { + wx.showToast({ + image: '/static/images/icon_error.png', + title: _res.errmsg, + mask: true + }); + } + + }); + + }, + + //立即购买(先自动加入购物车) + addFast: function() { + var that = this; + if (this.data.openAttr == false) { + //打开规格选择窗口 + this.setData({ + openAttr: !this.data.openAttr + }); + } else { + + //提示选择完整规格 + if (!this.isCheckedAllSpec()) { + wx.showToast({ + image: '/static/images/icon_error.png', + title: '请选择完整规格' + }); + return false; + } + + //根据选中的规格,判断是否有对应的sku信息 + let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey()); + if (!checkedProductArray || checkedProductArray.length <= 0) { + //找不到对应的product信息,提示没有库存 + wx.showToast({ + image: '/static/images/icon_error.png', + title: '没有库存' + }); + return false; + } + + let checkedProduct = checkedProductArray[0]; + //验证库存 + if (checkedProduct.number <= 0) { + wx.showToast({ + image: '/static/images/icon_error.png', + title: '没有库存' + }); + return false; + } + + //验证团购是否有效 + let checkedGroupon = this.getCheckedGrouponValue(); + + //立即购买 + util.request(api.CartFastAdd, { + goodsId: this.data.goods.id, + number: this.data.number, + productId: checkedProduct.id + }, "POST") + .then(function(res) { + if (res.errno == 0) { + + // 如果storage中设置了cartId,则是立即购买,否则是购物车购买 + try { + wx.setStorageSync('cartId', res.data); + wx.setStorageSync('grouponRulesId', checkedGroupon.id); + wx.setStorageSync('grouponLinkId', that.data.grouponLink.id); + wx.navigateTo({ + url: '/pages/checkout/checkout' + }) + } catch (e) {} + + } else { + wx.showToast({ + image: '/static/images/icon_error.png', + title: res.errmsg, + mask: true + }); + } + }); + } + + + }, + + //添加到购物车 + addToCart: function() { + var that = this; + if (this.data.openAttr == false) { + //打开规格选择窗口 + this.setData({ + openAttr: !this.data.openAttr + }); + } else { + + //提示选择完整规格 + if (!this.isCheckedAllSpec()) { + wx.showToast({ + image: '/static/images/icon_error.png', + title: '请选择完整规格' + }); + return false; + } + + //根据选中的规格,判断是否有对应的sku信息 + let checkedProductArray = this.getCheckedProductItem(this.getCheckedSpecKey()); + if (!checkedProductArray || checkedProductArray.length <= 0) { + //找不到对应的product信息,提示没有库存 + wx.showToast({ + image: '/static/images/icon_error.png', + title: '没有库存' + }); + return false; + } + + let checkedProduct = checkedProductArray[0]; + //验证库存 + if (checkedProduct.number <= 0) { + wx.showToast({ + image: '/static/images/icon_error.png', + title: '没有库存' + }); + return false; + } + + //添加到购物车 + util.request(api.CartAdd, { + goodsId: this.data.goods.id, + number: this.data.number, + productId: checkedProduct.id + }, "POST") + .then(function(res) { + let _res = res; + if (_res.errno == 0) { + wx.showToast({ + title: '添加成功' + }); + that.setData({ + openAttr: !that.data.openAttr, + cartGoodsCount: _res.data + }); + if (that.data.userHasCollect == 1) { + that.setData({ + collectImage: that.data.hasCollectImage + }); + } else { + that.setData({ + collectImage: that.data.noCollectImage + }); + } + } else { + wx.showToast({ + image: '/static/images/icon_error.png', + title: _res.errmsg, + mask: true + }); + } + + }); + } + + }, + + cutNumber: function() { + this.setData({ + number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1 + }); + }, + addNumber: function() { + this.setData({ + number: this.data.number + 1 + }); + }, + onHide: function() { + // 页面隐藏 + + }, + onUnload: function() { + // 页面关闭 + + }, + switchAttrPop: function() { + if (this.data.openAttr == false) { + this.setData({ + openAttr: !this.data.openAttr + }); + } + }, + closeAttr: function() { + this.setData({ + openAttr: false, + }); + }, + closeShare: function() { + this.setData({ + openShare: false, + }); + }, + openCartPage: function() { + wx.switchTab({ + url: '/pages/cart/cart' + }); + }, + onReady: function() { + // 页面渲染完成 + + }, + // 下拉刷新 + onPullDownRefresh() { + wx.showNavigationBarLoading() //在标题栏中显示加载 + this.getGoodsInfo(); + wx.hideNavigationBarLoading() //完成停止加载 + wx.stopPullDownRefresh() //停止下拉刷新 + }, + //根据已选的值,计算其它值的状态 + setSpecValueStatus: function() { + + }, }) \ No newline at end of file diff --git a/litemall-wx/pages/index/index.json b/litemall-wx/pages/index/index.json index 6731ba36..a0d6cacf 100644 --- a/litemall-wx/pages/index/index.json +++ b/litemall-wx/pages/index/index.json @@ -1,6 +1,5 @@ { - "navigationBarTitleText": "", - + "navigationBarTitleText": "首页", "usingComponents": { "zan-capsule": "../../lib/zanui-weapp/capsule/index" } diff --git a/litemall-wx/pages/ucenter/address/address.wxss b/litemall-wx/pages/ucenter/address/address.wxss index 53996100..6071ad25 100644 --- a/litemall-wx/pages/ucenter/address/address.wxss +++ b/litemall-wx/pages/ucenter/address/address.wxss @@ -90,18 +90,31 @@ page{ } .add-address{ - background: #b4282d; - text-align: center; - width: 100%; - height: 99rpx; - line-height: 99rpx; - position: fixed; - border-radius: 0; - border: none; - color: #fff; - font-size: 29rpx; - bottom: 0; - left:0; + border: none; + right: 0; + display: flex; + justify-content: center; + align-items: center; + width: 90%; + height: 90rpx; + line-height: 98rpx; + position: absolute; + bottom: 0; + left: 0; + border-radius: 0; + padding: 0; + margin: 0; + margin-left: 5%; + text-align: center; + /* padding-left: -5rpx; */ + font-size: 25rpx; + color: #f4f4f4; + border-top-left-radius: 50rpx; + border-bottom-left-radius: 50rpx; + border-top-right-radius: 50rpx; + border-bottom-right-radius: 50rpx; + letter-spacing: 3rpx; + background-image: linear-gradient(to right, #9a9ba1 0%, #9a9ba1 100%); } .empty-view{ diff --git a/litemall-wx/pages/ucenter/feedback/feedback.js b/litemall-wx/pages/ucenter/feedback/feedback.js index b2e277e6..e860e864 100644 --- a/litemall-wx/pages/ucenter/feedback/feedback.js +++ b/litemall-wx/pages/ucenter/feedback/feedback.js @@ -1,47 +1,108 @@ var util = require('../../../utils/util.js'); +var check = require('../../../utils/check.js'); var api = require('../../../config/api.js'); - - var app = getApp(); Page({ data: { array: ['请选择反馈类型', '商品相关', '功能异常', '优化建议', '其他'], index: 0, - content:'', - contentLength:0, - mobile:'' + content: '', + contentLength: 0, + mobile: '', + hasPicture: false, + picUrls: [], + files: [] }, - bindPickerChange: function (e) { - console.log('picker发送选择改变,携带值为', e.detail.value); + chooseImage: function (e) { + if (this.data.files.length >= 5) { + util.showErrorToast('只能上传五张图片') + return false; + } + + var that = this; + wx.chooseImage({ + count: 1, + sizeType: ['original', 'compressed'], + sourceType: ['album', 'camera'], + success: function (res) { + that.setData({ + files: that.data.files.concat(res.tempFilePaths) + }); + that.upload(res); + } + }) + }, + upload: function (res) { + var that = this; + const uploadTask = wx.uploadFile({ + url: api.StorageUpload, + filePath: res.tempFilePaths[0], + name: 'file', + success: function (res) { + var _res = JSON.parse(res.data); + if (_res.errno === 0) { + var url = _res.data.url + that.data.picUrls.push(url) + that.setData({ + hasPicture: true, + picUrls: that.data.picUrls + }) + } + }, + fail: function (e) { + wx.showModal({ + title: '错误', + content: '上传失败', + showCancel: false + }) + }, + }) + + uploadTask.onProgressUpdate((res) => { + console.log('上传进度', res.progress) + console.log('已经上传的数据长度', res.totalBytesSent) + console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend) + }) + + }, + previewImage: function (e) { + wx.previewImage({ + current: e.currentTarget.id, // 当前显示图片的http链接 + urls: this.data.files // 需要预览的图片http链接列表 + }) + }, + bindPickerChange: function(e) { this.setData({ index: e.detail.value }); }, - mobileInput: function (e) { - let that = this; + mobileInput: function(e) { this.setData({ - mobile: e.detail.value, + mobile: e.detail.value }); - console.log(that.data.mobile); }, - contentInput: function (e) { - - let that = this; + contentInput: function(e) { this.setData({ contentLength: e.detail.cursor, content: e.detail.value, }); - console.log(that.data.content); }, - cleanMobile:function(){ - let that = this; + clearMobile: function(e) { + this.setData({ + mobile: '' + }); + }, + submitFeedback: function(e) { + if (!app.globalData.hasLogin) { + wx.navigateTo({ + url: "/pages/auth/login/login" + }); + } - }, - sbmitFeedback : function(e){ let that = this; - if (that.data.index == 0){ + if (that.data.index == 0) { util.showErrorToast('请选择反馈类型'); return false; } @@ -55,55 +116,69 @@ Page({ util.showErrorToast('请输入手机号码'); return false; } + + if (!check.isValidPhone(this.data.mobile)) { + this.setData({ + mobile: '' + }); + util.showErrorToast('请输入手机号码'); + return false; + } + wx.showLoading({ title: '提交中...', - mask:true, - success: function () { + mask: true, + success: function() { } }); - console.log(that.data); + util.request(api.FeedbackAdd, { + mobile: that.data.mobile, + feedType: that.data.array[that.data.index], + content: that.data.content, + hasPicture: that.data.hasPicture, + picUrls: that.data.picUrls + }, 'POST').then(function(res) { + wx.hideLoading(); - util.request(api.FeedbackAdd, { mobile: that.data.mobile, index: that.data.index, content: that.data.content},'POST').then(function (res) { if (res.errno === 0) { - console.log(res.data); - - wx.hideLoading(); - wx.showToast({ - title: res.data, + title: '感谢您的反馈!', icon: 'success', duration: 2000, - complete: function () { - console.log('重新加载'); + complete: function() { that.setData({ index: 0, content: '', contentLength: 0, - mobile: '' + mobile: '', + hasPicture: false, + picUrls: [], + files: [] }); } }); } else { - util.showErrorToast(res.data); + util.showErrorToast(res.errmsg); } - + }); }, - onLoad: function (options) { - }, - onReady: function () { + onLoad: function(options) { }, - onShow: function () { + onReady: function() { }, - onHide: function () { + onShow: function() { + + }, + onHide: function() { // 页面隐藏 }, - onUnload: function () { + onUnload: function() { // 页面关闭 } }) \ No newline at end of file diff --git a/litemall-wx/pages/ucenter/feedback/feedback.json b/litemall-wx/pages/ucenter/feedback/feedback.json index 0e0dcd23..fc30db1c 100644 --- a/litemall-wx/pages/ucenter/feedback/feedback.json +++ b/litemall-wx/pages/ucenter/feedback/feedback.json @@ -1,3 +1,3 @@ { - + "navigationBarTitleText": "意见反馈" } \ No newline at end of file diff --git a/litemall-wx/pages/ucenter/feedback/feedback.wxml b/litemall-wx/pages/ucenter/feedback/feedback.wxml index 81e91665..75dc62ce 100644 --- a/litemall-wx/pages/ucenter/feedback/feedback.wxml +++ b/litemall-wx/pages/ucenter/feedback/feedback.wxml @@ -10,18 +10,26 @@ -