diff --git a/app.js b/app.js new file mode 100644 index 0000000..98ac40d --- /dev/null +++ b/app.js @@ -0,0 +1,166 @@ +//app.js +App({ + gw: { + hostUrl: 'https://www.1haojiazheng.cn', + mapUrl:'https://api.map.baidu.com' + }, + onLaunch: function () { + // 展示本地存储能力 + var logs = wx.getStorageSync('logs') || [] + logs.unshift(Date.now()) + wx.setStorageSync('logs', logs) + + // 登录 + wx.login({ + success: res => { + var code = res.code; + this.getSessionKey(code); + + } + }) + + + }, + getSessionKey: function (code) { + var that = this; + wx.request({ + url: this.gw.hostUrl + '/mall/wxa/auth/session', + method: 'post', + data: { + code: code, + state: '5' + }, + header: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + success: function (res) { + //--init data + var data = res.data; + if (data.code != 0) { + wx.showToast({ + title: data.msg, + icon: 'none', + duration: 2000 + }); + return false; + } + + // that.globalData.userInfo['sessionId'] = data.response.session_key; + that.globalData.openid = data.response.openid; + that.onLoginUser(); + + // that.prepareOrder(); + // 获取用户信息 + wx.getSetting({ + success: res => { + // if (res.authSetting['scope.userInfo']) { + // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 + wx.getUserInfo({ + success: res => { + // 可以将 res 发送给后台解码出 unionId + that.globalData.userInfo = res.userInfo; + + + // this.onLoginUser(); + // 发送 res.code 到后台换取 openId, sessionKey, unionId + that.commitUserInfo(that.globalData.openid, res.encryptedData, res.iv); + + + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + if (that.userInfoReadyCallback) { + that.userInfoReadyCallback(res) + } + } + }) + // } + } + }) + }, + fail: function (e) { + wx.showToast({ + title: '网络异常!err:getsessionkeys', + icon:'none', + duration: 2000 + }); + }, + }); + }, + onLoginUser: function () { + var that = this; + wx.request({ + url: this.gw.hostUrl + '/mall/wxa/auth/login', + method: 'post', + data: { + openid: this.globalData.openid + }, + header: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + success: function (res) { + //--init data + var data = res.data; + var status = data.code; + if (status != 0) { + wx.showToast({ + title: data.msg, + icon: 'none', + duration: 3000 + }); + return false; + } + that.globalData.sessionId= data.response.sessionId; + wx.setStorageSync('sessionId', data.response.sessionId); + console.log('sessionId : ' + data.response.sessionId); + + }, + fail: function (e) { + wx.showToast({ + title: '网络异常!err:authlogin', + icon: 'none', + duration: 2000 + }); + }, + }); + }, + commitUserInfo: function (openid, encryptedData, iv) { + var that = this; + wx.request({ + url: this.gw.hostUrl + '/mall/wxa/auth/userinfo', + method: 'POST', + data: { + openid: openid, + encryptedData: encryptedData, + iv: iv + }, + header: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + success: function (res) { + //--init data + var data = res.data; + var status = data.code; + if (status != 0) { + wx.showToast({ + title: data.msg, + icon: 'none', + duration: 3000 + }); + return false; + } + }, + fail: function (e) { + wx.showToast({ + title: '网络异常!err:authlogin', + icon: 'none', + duration: 2000 + }); + }, + }); + }, + globalData: { + userInfo: null, + sessionId: '', + openid: '' + } +}) \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..b1e7e3b --- /dev/null +++ b/app.json @@ -0,0 +1,51 @@ +{ + "pages": [ + "pages/jz/jz", + "pages/index/index", + "pages/logs/logs", + "pages/detail/detail", + "pages/create_order/create_order", + "pages/mcenter/mcenter", + "pages/order/order", + "pages/pay/pay", + "pages/mypage/mypage", + "pages/remark/remark", + "pages/addr/addr", + "pages/login/login", + "pages/serviceDesc/serviceDesc", + "pages/two_code/two_code", + "pages/out/out", + "pages/agreement/agreement" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#000", + "navigationBarTitleText": "白飞飞", + "navigationBarTextStyle": "white" + }, + "tabBar": { + "color": "#65646b", + "borderStyle": "#65646b", + "selectedColor": "#06c1ae", + "list": [ + { + "pagePath": "pages/jz/jz", + "text": "首页", + "iconPath": "images/index_gray.png", + "selectedIconPath": "images/index_green.png" + }, + { + "pagePath": "pages/order/order", + "text": "订单", + "iconPath": "images/order_gray.png", + "selectedIconPath": "images/order_green.png" + }, + { + "pagePath": "pages/mcenter/mcenter", + "text": "我的", + "iconPath": "images/my_gray.png", + "selectedIconPath": "images/my_green.png" + } + ] + } +} \ No newline at end of file diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..f41d96b --- /dev/null +++ b/app.wxss @@ -0,0 +1,13 @@ +/**app.wxss**/ +.container { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 200rpx 0; + box-sizing: border-box; +} +page{ + background: #F3F3F3; +} \ No newline at end of file diff --git a/images/addr.png b/images/addr.png new file mode 100644 index 0000000..ec9daee Binary files /dev/null and b/images/addr.png differ diff --git a/images/address.png b/images/address.png new file mode 100644 index 0000000..86ef3ed Binary files /dev/null and b/images/address.png differ diff --git a/images/agreement.png b/images/agreement.png new file mode 100644 index 0000000..44885c3 Binary files /dev/null and b/images/agreement.png differ diff --git a/images/banner1.png b/images/banner1.png new file mode 100644 index 0000000..ae19ee9 Binary files /dev/null and b/images/banner1.png differ diff --git a/images/banner2.png b/images/banner2.png new file mode 100644 index 0000000..8bd50fa Binary files /dev/null and b/images/banner2.png differ diff --git a/images/index_gray.png b/images/index_gray.png new file mode 100644 index 0000000..f795360 Binary files /dev/null and b/images/index_gray.png differ diff --git a/images/index_green.png b/images/index_green.png new file mode 100644 index 0000000..6eadb72 Binary files /dev/null and b/images/index_green.png differ diff --git a/images/inner-back.png b/images/inner-back.png new file mode 100644 index 0000000..181497a Binary files /dev/null and b/images/inner-back.png differ diff --git a/images/my_gray.png b/images/my_gray.png new file mode 100644 index 0000000..1a575a8 Binary files /dev/null and b/images/my_gray.png differ diff --git a/images/my_green.png b/images/my_green.png new file mode 100644 index 0000000..72a54a6 Binary files /dev/null and b/images/my_green.png differ diff --git a/images/order.png b/images/order.png new file mode 100644 index 0000000..514bcbd Binary files /dev/null and b/images/order.png differ diff --git a/images/order_gray.png b/images/order_gray.png new file mode 100644 index 0000000..0e6d289 Binary files /dev/null and b/images/order_gray.png differ diff --git a/images/order_green.png b/images/order_green.png new file mode 100644 index 0000000..ad3295c Binary files /dev/null and b/images/order_green.png differ diff --git a/images/phone.png b/images/phone.png new file mode 100644 index 0000000..bb8d7ba Binary files /dev/null and b/images/phone.png differ diff --git a/images/service.png b/images/service.png new file mode 100644 index 0000000..06885ef Binary files /dev/null and b/images/service.png differ diff --git a/images/title-icon.png b/images/title-icon.png new file mode 100644 index 0000000..01d177e Binary files /dev/null and b/images/title-icon.png differ diff --git a/images/two_code.jpg b/images/two_code.jpg new file mode 100644 index 0000000..a5fd278 Binary files /dev/null and b/images/two_code.jpg differ diff --git a/libs/bmap-wx.min.js b/libs/bmap-wx.min.js new file mode 100644 index 0000000..2f4d563 --- /dev/null +++ b/libs/bmap-wx.min.js @@ -0,0 +1 @@ +"use strict";function _classCallCheck(t,a){if(!(t instanceof a))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,a){for(var e=0;e { + this.setData({ popErrorMsg: '' }); + clearTimeout(fadeOutTimeout); + }, 3000); + }, + onLoad: function (options) { + let item = JSON.parse(options.jsonStr); + if (app.globalData.userInfo) { + this.setData({ + userInfo: app.globalData.userInfo, + hasUserInfo: true, + price: item.price, + title: item.name, + product: item, + }) + } else if (this.data.canIUse) { + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + app.userInfoReadyCallback = res => { + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + } else { + // 在没有 open-type=getUserInfo 版本的兼容处理 + wx.getUserInfo({ + success: res => { + app.globalData.userInfo = res.userInfo + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + } + }, + getUserInfo: function (e) { + console.log(e) + app.globalData.userInfo = e.detail.userInfo + this.setData({ + userInfo: e.detail.userInfo, + hasUserInfo: true + }) + } +}) \ No newline at end of file diff --git a/pages/addr/addr.json b/pages/addr/addr.json new file mode 100644 index 0000000..3f48472 --- /dev/null +++ b/pages/addr/addr.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "地址信息" +} \ No newline at end of file diff --git a/pages/addr/addr.wxml b/pages/addr/addr.wxml new file mode 100644 index 0000000..35e8ec0 --- /dev/null +++ b/pages/addr/addr.wxml @@ -0,0 +1,18 @@ +{{popErrorMsg}} + + + {{item.title}} + + x + + + + + {{item}} + + + + + + + diff --git a/pages/addr/addr.wxss b/pages/addr/addr.wxss new file mode 100644 index 0000000..5438e8d --- /dev/null +++ b/pages/addr/addr.wxss @@ -0,0 +1,94 @@ +/* pages/addr/addr.wxss */ +.box{ + height:90rpx; + background:#fff; + padding:0 42rpx; + display:flex; + flex-direction:row; + line-height:90px; + align-items:baseline; + position: relative; +} +.text{ + height: 90rpx; + line-height: 90rpx; + font-size: 30rpx; + color: #333; + width: 23%; +} +.inputBox{ + width:72%; + font-size: 30rpx; +} +.top58{ + margin-top: 58rpx; +} +.top1{ + margin-top: 1rpx; +} +.sug_info{ + position:absolute; + z-index:1000; + background:#fff; + top:90rpx; + width:100%; + margin:0px; + overflow: hidden; + overflow-y: scroll; + right:0rpx; + left:0rpx; + max-height: 540rpx; +} +.detailAddr{ + font-size:30rpx; + padding:0 25rpx; + line-height:90rpx; + height: 90rpx; +} +.icon{ + width: 50rpx; + height: 50rpx; + margin-left:42rpx; +} +.smallBox{ + height:90rpx; + background:#fff; + display:flex; + flex-direction:row; + line-height:90px; + align-items:center; + position: relative; + border-top: thin solid #eee; +} +.subBtn{ + width: 90%; + margin: 40rpx auto; + text-align: center; + color: #fff; + background: #1eba84; + border-radius:5px; +} +.ad_popError{ + background: #de352d; + color: #fff; + height: 58rpx; + line-height: 58rpx; + font-size: 24rpx; + text-align: center; + position: absolute; + left: 0; + top: 0; + width: 100%; + z-index:3; +} +.clear{ + font-size: 24rpx; + width:30rpx; + border: 2rpx solid #333; + border-radius:50%; + height: 30rpx; + line-height: 30rpx; + text-align: center; + background: #eee; + color: #333; +} \ No newline at end of file diff --git a/pages/agreement/agreement.js b/pages/agreement/agreement.js new file mode 100644 index 0000000..70a7035 --- /dev/null +++ b/pages/agreement/agreement.js @@ -0,0 +1,38 @@ +//获取应用实例 +const app = getApp() + + +Page({ + data: { + showImg:'../../images/agreement.png', + }, + //事件处理函数 + onLoad: function (options) { + if (app.globalData.userInfo) { + this.setData({ + userInfo: app.globalData.userInfo, + hasUserInfo: true + }) + } else if (this.data.canIUse) { + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + app.userInfoReadyCallback = res => { + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + } else { + // 在没有 open-type=getUserInfo 版本的兼容处理 + wx.getUserInfo({ + success: res => { + app.globalData.userInfo = res.userInfo + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + } + } +}) diff --git a/pages/agreement/agreement.json b/pages/agreement/agreement.json new file mode 100644 index 0000000..b61c196 --- /dev/null +++ b/pages/agreement/agreement.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "订单确认" +} \ No newline at end of file diff --git a/pages/agreement/agreement.wxml b/pages/agreement/agreement.wxml new file mode 100644 index 0000000..8f9c674 --- /dev/null +++ b/pages/agreement/agreement.wxml @@ -0,0 +1,3 @@ + + + diff --git a/pages/agreement/agreement.wxss b/pages/agreement/agreement.wxss new file mode 100644 index 0000000..030d3cf --- /dev/null +++ b/pages/agreement/agreement.wxss @@ -0,0 +1,4 @@ +image{ + width: 100%; + height: 7000rpx; +} \ No newline at end of file diff --git a/pages/create_order/create_order.js b/pages/create_order/create_order.js new file mode 100644 index 0000000..4b306a2 --- /dev/null +++ b/pages/create_order/create_order.js @@ -0,0 +1,224 @@ +//index.js +//获取应用实例 +const app = getApp() + + +Page({ + data: { + items: [ + { name: '陈晓旭', phone: '18775242654', address1: '广州市 天河区 东圃大马路时代TIT广场A栋423' } + ], + read: true, + remark:'', + clock:300, + }, + imageOnload(ev) { + console.log('图片加载成功,width: ${ev.detail.width}; height: ${ev.detail.height}'); + }, + imageOnloadError() { + console.log('图片加载失败'); + }, + formSubmit: function (e) { + console.log('form发生了submit事件,携带数据为:', e.detail.value) + }, + formReset: function () { + console.log('form发生了reset事件') + }, + //事件处理函数 + loading: function (e) { + let str = JSON.stringify(e.currentTarget.dataset.item); + wx.navigateTo({ + url: '../detail/detail?jsonStr=' + str + }) + }, + changeAddr: function (e) { + let str = JSON.stringify(e.currentTarget.dataset.item); + wx.navigateTo({ + url: '../addr/addr?jsonStr=' + str + }) + }, + goRemark: function (e) { + let str = JSON.stringify(e.currentTarget.dataset.item); + wx.navigateTo({ + url: '../remark/remark?jsonStr=' + str+'&&remark='+this.data.remark + }) + }, + checkboxChange: function (e) { + this.setData({ + read: !this.data.read + }) + }, + goLook: function (e) { + wx.navigateTo({ + url: '../agreement/agreement' + }) + }, + pay: function (e) { + // let str = JSON.stringify(e.currentTarget.dataset.item); + let str = e.currentTarget.dataset.item; + console.log(str.goodsNo); + let that=this; + wx.showToast({ + title: '正在调起支付', + icon: 'loading' + }) + wx.request({//获取orderNo + url: app.gw.hostUrl + '/mall/wxa/order/new', + method: 'post', + data: { + addressId:'', + goodsNo:str.goodsNo, + sourceType: 0, + goodsNum: 1, + couponNo: '', + remark:that.data.remark + }, + header: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'sessionId': wx.getStorageSync('sessionId') + }, + success: function (res) { + //--init data + let data = res.data; + let status = data.code; + if (status != 0) { + wx.showToast({ + title: data.msg, + icon: 'none', + duration: 2000 + }) + return; + } + that.setData({ + orderNo:data.response.orderNo + }) + + wx.request({//获取微信支付想要的数据 + url: app.gw.hostUrl + '/mall/wxa/order/pay', + method: 'put', + data: { + openid: app.globalData.openid, + orderNo: data.response.orderNo, + paymentType: 8 + }, + header: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'sessionId': wx.getStorageSync('sessionId') + }, + success: function (res) { + //--init data + let data = res.data; + let status = data.code; + if (status != 0) { + wx.showToast({ + title: data.msg, + icon: 'none', + duration: 2000 + }) + return; + } + console.log(data.response); + let dr = data.response.weixinTransParameters; + console.log(dr); + wx.requestPayment({//微信支付 + "timeStamp": dr.timeStamp, + "nonceStr": dr.nonceStr, + "package": dr.package, + "signType": dr.signType, + "paySign": dr.paySign, + "success": function (res) { + console.log(res); + wx.showToast({ + title: '支付成功', + icon: 'success', + duration: 2000 + }) + wx.switchTab({//跳转到订单页面 + url: '../order/order' , + success: function (e) { + var page = getCurrentPages().pop(); + if (page == undefined || page == null) return; + console.log(page); + page.onShow(); + } + }) + }, + "fail": function (res) { + console.log(res); + if(res.errMsg=='requestPayment:fail cancel'){ + wx.showToast({ + title: '取消支付', + icon: 'none', + duration: 2000 + }) + }else{ + wx.showToast({ + title: '支付出错', + icon: 'none', + duration: 2000 + }) + } + } + }) + }, + fail: function (e) { + wx.showToast({ + title: '网络异常!err:authlogin', + icon: 'none', + duration: 2000 + }) + }, + }); + }, + fail: function (e) { + wx.showToast({ + title: '网络异常!err:authlogin', + icon: 'none', + duration: 2000 + }) + }, + }); + }, + onLoad: function (options) { + let item = JSON.parse(options.jsonStr); + console.log(item); + this.setData({ + product: item, + }) + if (app.globalData.userInfo) { + this.setData({ + userInfo: app.globalData.userInfo, + hasUserInfo: true, + product: item, + }) + } else if (this.data.canIUse) { + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + app.userInfoReadyCallback = res => { + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + } else { + // 在没有 open-type=getUserInfo 版本的兼容处理 + wx.getUserInfo({ + success: res => { + app.globalData.userInfo = res.userInfo + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + } + }, + getUserInfo: function (e) { + console.log(e) + app.globalData.userInfo = e.detail.userInfo + this.setData({ + userInfo: e.detail.userInfo, + hasUserInfo: true + }) + } +}) diff --git a/pages/create_order/create_order.json b/pages/create_order/create_order.json new file mode 100644 index 0000000..3a8b61c --- /dev/null +++ b/pages/create_order/create_order.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "订单确认" +} \ No newline at end of file diff --git a/pages/create_order/create_order.wxml b/pages/create_order/create_order.wxml new file mode 100644 index 0000000..234723f --- /dev/null +++ b/pages/create_order/create_order.wxml @@ -0,0 +1,54 @@ + + + 订单金额: + + ¥{{product.totalPrice/100}} + + + + + + + {{product.serviceAreaStr}} + + + + + 订单备注: + + + {{remark==""?'选填,可填写服务需求':remark}} + + > + + + + + 我已阅读并确认服务协议 + + + + 还需支付 + ¥{{product.payPrice/100}} + + + + 立即支付 + + \ No newline at end of file diff --git a/pages/create_order/create_order.wxss b/pages/create_order/create_order.wxss new file mode 100644 index 0000000..6f40162 --- /dev/null +++ b/pages/create_order/create_order.wxss @@ -0,0 +1,162 @@ +/* 通用class */ +.box{ + margin-top: 20rpx; + background: #fff; + height: 100rpx; + line-height: 100rpx; + display:flex; + flex-direction:row; + justify-content:space-between; +} +.addrText{ + flex-direction: row; + color: #333; + font-size: 30rpx; +} +.addrNote{ + font-size: 28rpx; + width: 100%; + color: #999999; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.text{ + flex-direction: row; + color: #333; + font-size: 30rpx; + width: 30%; + padding-left: 35rpx; +} +.icon-note{ + display:flex; + flex-direction: row; + justify-content:space-between; + margin-right: 35rpx; + width: 70%; +} +.note{ + margin-right: 10rpx; + font-size: 28rpx; + color: #999999; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + width: 90%; + text-align: right; +} + +/* 单独class */ +.price-box{ + margin-top: 10rpx; +} +.price-title{ + flex-direction:row; + font-size: 30rpx; + color:#666; + margin-left: 35rpx; +} +.price{ + flex-direction:row; + float: right; + font-size: 38rpx; + color:#333; + margin-right: 39rpx; +} +.msg{ + display: inline-block; + /* width: 75%; */ + width: 100%; + padding:20rpx 35rpx 0; +} +.person-msg{ + /* height: 160rpx; */ + height: 210rpx; + margin-top: 10rpx; + line-height: 60rpx; +} +.name{ + display: inline-block; + color: #333; + font-size: 36rpx; +} +.phone{ + display: inline-block; + color: #333; + font-size: 36rpx; + margin-left: 35rpx; +} +.changeAddr{ + display: inline-block; + color:#EE5050; + font-size: 28rpx; + margin-left: 35rpx; +} +.address{ + display: inline-block; + color: #666; + font-size: 30rpx; + height: 36rpx; + line-height: 36rpx; + width: 100%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.icon-msg{ + height: 160rpx; + line-height: 160rpx; + margin-right: 35rpx; +} +.agreement-box{ + margin: 25rpx 35rpx; + font-size: 28rpx; + color:#999999; +} +.agreement{ + display: inline-block; + color: #D61A1A; +} +.footer{ + position: fixed; + bottom: 0rpx; + width: 100%; + font-size:32rpx; +} +.pay-box{ + width: 50%; + display: inline-block; + color: #333; + text-align: center; +} +.go-pay{ + width: 50%; + display: inline-block; + background: #E32424; + color: #fff; + text-align: center; +} +.pay-text{ + display: inline-block; +} +.pay-price{ + display: inline-block; + color: #D61A1A; + font-weight: bold; +} +.no-pay{ + width: 50%; + float: right; + position:fixed; + bottom: 0px; + right: 0px; + z-index: 100; + height: 101rpx; + background: rgba(255,255,255,0.6); +} +.lookDetail{ + color:#666; + font-size:16px; + text-align:center; + margin:0 auto; +} \ No newline at end of file diff --git a/pages/detail/detail.js b/pages/detail/detail.js new file mode 100644 index 0000000..3c19197 --- /dev/null +++ b/pages/detail/detail.js @@ -0,0 +1,169 @@ +//index.js +//获取应用实例 +const app = getApp() + +var WxParse = require('../../wxParse/wxParse.js');//主要为了能够显示获取的html代码 + +Page({ + data: { + items:[ + {name:'陈晓旭',phone:'18775242654',address1:'广州市 天河区 东圃大马路时代TIT广场A栋423'} + ], + nowDate: new Date().getTime(), + serviceImg:'http://jz.qianniao56.com/attachs/editor/2017/08/01/thumb_59802a98d9fdb.png', + read:true + }, + imageOnload(ev) { + console.log('图片加载成功,width: ${ev.detail.width}; height: ${ev.detail.height}'); + }, + imageOnloadError() { + console.log('图片加载失败'); + }, + formSubmit: function (e) { + console.log('form发生了submit事件,携带数据为:', e.detail.value) + }, + formReset: function () { + console.log('form发生了reset事件') + }, + //事件处理函数 + loading: function (e) { + let str = e.currentTarget.dataset.item; + wx.navigateTo({ + url: '../serviceDesc/serviceDesc?jsonStr=' + str + }) + console.log(str); + }, + createOrder:function(e){ + if (wx.getStorageSync('sessionId')==''){ + wx.navigateTo({ + url: '../login/login' + }) + }else{ + var that = this; + var user = app.globalData.userInfo; + wx.request({ + url: app.gw.hostUrl + '/mall/wxa/order/prepare', + method: 'post', + data: { + goodsNo: that.data.product.goodsNo, + goodsNum: 1, + couponNo: '' + }, + header: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'sessionId': wx.getStorageSync('sessionId') + }, + success: function (res) { + //--init data + let data = res.data; + let status = data.code; + let str = JSON.stringify(data.response); + if (status != 0) { + wx.showToast({ + title: data.msg, + icon: 'none', + duration: 3000 + }); + return; + } + wx.navigateTo({ + url: '../create_order/create_order?jsonStr=' + str + }) + }, + fail: function (e) { + wx.showToast({ + title: '网络异常!err:authlogin', + icon: 'none', + duration: 2000 + }); + }, + }); + } + }, + onLoad: function (options) { + let item = options.jsonStr; + var that = this; + console.log(options.jsonStr); + wx.request({ + url: app.gw.hostUrl + '/mall/web/goods/detail', + method: 'get', + data: { + goodsNo: item + }, + header: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + success: function (res) { + //--init data + var data = res.data; + var status = data.code; + if (status != 0) { + wx.showToast({ + title: data.msg, + icon: 'none', + duration: 3000 + }); + return; + } + /** + * WxParse.wxParse(bindName , type, data, target,imagePadding) + * 1.bindName绑定的数据名(必填) + * 2.type可以为html或者md(必填) + * 3.data为传入的具体数据(必填) + * 4.target为Page对象,一般为this(必填) + * 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选) + */ + that.setData({ + product: data.response + }) + let notice = data.response.notice; + let serviceDesc = data.response.serviceDesc; + console.log(notice); + WxParse.wxParse('notice', 'html', notice, that); + WxParse.wxParse('serviceDesc', 'html', serviceDesc, that, 5); + }, + fail: function (e) { + wx.showToast({ + title: '网络异常!err:authlogin', + icon: 'none', + duration: 2000 + }); + }, + }); + if (app.globalData.userInfo) { + this.setData({ + userInfo: app.globalData.userInfo, + hasUserInfo: true, + goodsNo: item + }) + } else if (this.data.canIUse) { + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + app.userInfoReadyCallback = res => { + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + } else { + // 在没有 open-type=getUserInfo 版本的兼容处理 + wx.getUserInfo({ + success: res => { + app.globalData.userInfo = res.userInfo + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + } + }, + getUserInfo: function (e) { + console.log(e) + app.globalData.userInfo = e.detail.userInfo + this.setData({ + userInfo: e.detail.userInfo, + hasUserInfo: true + }) + } +}) diff --git a/pages/detail/detail.json b/pages/detail/detail.json new file mode 100644 index 0000000..e5e14f2 --- /dev/null +++ b/pages/detail/detail.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "商品详情" +} \ No newline at end of file diff --git a/pages/detail/detail.wxml b/pages/detail/detail.wxml new file mode 100644 index 0000000..4facc55 --- /dev/null +++ b/pages/detail/detail.wxml @@ -0,0 +1,57 @@ + + + + + + + + + + + + {{product.name}} + ¥ {{product.price/100}}/套 + + + + 该套餐内含{{product.serviceCount}}次服务 + 已售:{{product.soldNum}}套 + + + + + + + + 下单须知 + +