You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
4.8 KiB
165 lines
4.8 KiB
//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
|
|
})
|
|
},
|
|
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,
|
|
goodsVersion: that.data.product.goodsVersion,
|
|
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);
|
|
console.log(str)
|
|
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) {
|
|
var that = this;
|
|
wx.request({
|
|
url: app.gw.hostUrl + '/mall/web/goods/detail?goodsNo=' + options.goodsNo,
|
|
method: 'get',
|
|
header: {
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
},
|
|
success: function (res) {
|
|
//--init data
|
|
console.log(res);
|
|
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;
|
|
WxParse.wxParse('notice', 'html', notice, that);
|
|
WxParse.wxParse('serviceDesc', 'html', serviceDesc, that, 5);
|
|
},
|
|
fail: function (e) {
|
|
wx.showToast({
|
|
title: '网络异常!',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
},
|
|
});
|
|
if (app.globalData.userInfo) {
|
|
this.setData({
|
|
userInfo: app.globalData.userInfo,
|
|
hasUserInfo: true,
|
|
goodsNo: options.goodsNo
|
|
})
|
|
} 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
|
|
})
|
|
}
|
|
})
|