123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- let app = getApp();
- let host = app.globalData.servsers; // 请求的url
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- goodsList: [],
- host: app.globalData.servsers,
- amount: '',
- address: {}, // 地址为空
- },
- onLoad() {
- let that = this;
- wx.request({
- url: host + '/adressapi/getdefaustAdress',
- method: 'get',
- data: {
- user_id: app.globalData.user_id
- },
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success(res) {
- console.log(res, "获取默认地址")
- that.setData({
- address: res.data
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- let goodsList = [],
- that = this;
- let address = wx.getStorageSync('accountAddress');
- console.log(address, "addressaddress")
- if (address) {
- that.setData({
- address: address
- })
- }
- goodsList = [...wx.getStorageSync('goodsList')];
- that.setData({
- goodsList: goodsList,
- amount: wx.getStorageSync('amount')
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- submitOrder() {
- if (!this.data.address.consignee) {
- wx.showToast({
- title: '您还没有添加收货地址',
- icon: 'none'
- })
- return;
- }
- wx.showLoading({
- title: '结算中...'
- })
- let that = this,
- goodsList = that.data.goodsList,
- address = that.data.address;
- //生成订单
- goodsList.forEach(res => {
- res['userId'] = app.globalData.user_id; //'oovpNwjlsY6xx8ceCebFa1dOLd9E',
- res['adress'] = address.adress;
- res['area'] = address.area;
- res['city'] = address.city;
- res['province'] = address.province;
- res['consignee'] = address.consignee;
- res['phone'] = address.phone;
- res['openId'] = app.globalData.openid;
- delete res.imgArray
- });
- wx.request({
- url: host + '/createNewOrderCustomer',
- method: 'post',
- data: {
- shopCarList: JSON.stringify(goodsList)
- },
- success(el) {
- let res = el.data;
- console.log(res)
- wx.requestPayment({
- timeStamp: res.timeStamp,
- nonceStr: res.nonceStr,
- package: res.package,
- signType: res.signType,
- paySign: res.paySign,
- success(res) {
- console.log(res, "结算结果")
- if (res.errMsg === 'requestPayment:ok') {
- // wx.showToast({
- // title: '支付成功',
- // })
- wx.redirectTo({
- url: '/customized/pages/result/result?state=true',
- })
- } else {
- wx.redirectTo({
- url: '/customized/pages/result/result?state=false',
- })
- }
- },
- fail(err) {
- wx.showToast({
- title: err.errMsg,
- icon: 'error'
- })
- console.log(err)
- },
- complete() {
- wx.hideLoading()
- }
- })
- }
- })
- },
- addressBtn() {
- wx.navigateTo({
- url: '/customized/pages/address/address',
- })
- }
- })
|