123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- // pages/confirmOrder/confirmOrder.js
- const getReq = require('./../../config.js').getReq
- let appInstance = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- goods_id: '',
- ifcart: '',
- num: '',
- datas: {},
- goods_list: [],
- firstLoad: true,
- defaultAddress: null,
- cart_id: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let goods_id = options.goods_id || ''
- let iscart = options.iscart || ''
- let num = options.num || ''
- let cart_id = options.cart_id || ''
- this.setData({
- goods_id,
- ifcart: iscart,
- num,
- cart_id
- })
- this.getDatas(goods_id, iscart, num, cart_id)
- },
- getDatas(goods_id, ifcart, num, cart_id) {
- wx.showLoading({
- title: '加载中',
- })
- var self = this
- let goods_datas = '';
- if (ifcart == 0) {
- goods_datas = goods_id + '|' + num;
- }
- else {
- goods_datas = cart_id;
- }
- getReq({
- act: 'member_buy',
- op: 'step_first',
- curpage: 1,
- cart_id: goods_datas,
- ifcart,
- }, function (res) {
- wx.hideLoading()
- if (res.code == 200) {
- let datas = res.datas
- let goods_list = self.getGoodsList(datas.summary, datas.goods_list)
- let { true_name, mob_phone, area_info, address, address_id } = datas.address
- appInstance.checkDefaultAddress({
- true_name,
- mob_phone,
- area_info,
- address,
- address_id
- })
- self.setData({
- datas,
- goods_list,
- firstLoad: false,
- defaultAddress: datas.address
- })
- }
- else {
-
- wx.showToast({
- icon: 'none',
- title: res.message,
- duration: 2000
- })
- appInstance.globalData.fcodeErr = res.message
- wx.navigateBack()
- }
- }, function () {
- wx.navigateBack()
- })
- },
- getGoodsList(summary, goods_list) {
- let newGoodsList = []
- goods_list.map((item, index) => {
- summary.filter((list, key) => {
- if (item.goods_id == list.goods_id) {
- let goods_item = list
- goods_item.goods_num = item.goods_num
- newGoodsList.push(goods_item)
- return true
- }
- })
- })
- return newGoodsList
- },
- toPay() {
- if (!this.data.defaultAddress) {
- wx.showToast({
- icon: 'none',
- title: '请填写收货地址',
- duration: 1500
- })
- return
- }
- let goods_id = this.data.goods_id
- let goods_num = this.data.num
- let iscart = this.data.ifcart
- let cart_id = this.data.cart_id
- let vat_hash = this.data.datas['payinfo'].vat_hash
- let offpay_hash = this.data.datas['payinfo'].offpay_hash
- let offpay_hash_batch = this.data.datas['payinfo'].offpay_hash_batch
- let address_id = this.data.defaultAddress.address_id ? this.data.defaultAddress.address_id : this.data.datas['address'].address_id
- let ifcart = cart_id ? 1 : 0
- let cartids = cart_id ? cart_id : (goods_id + '|' + goods_num)
- getReq({
- act: 'member_buy',
- op: 'step_second',
- payment: 'jspay',
- usebonus: 1,
- ifcart,
- cart_id: cartids,
- address_id,
- invoice_id: 0,
- vat_hash,
- offpay_hash,
- offpay_hash_batch
- }, function (res) {
- wx.hideLoading()
- console.log(res)
- if (res.code == 200) {
- }
- else {
- wx.showToast({
- icon: 'none',
- title: res.message,
- duration: 2000
- })
- wx.navigateBack()
- }
- }, function (err) {
- wx.navigateBack()
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if (!this.data.firstLoad) {
- let defaultAddress = appInstance.globalData.defaultAddress
- console.log(defaultAddress)
- this.setData({
- defaultAddress
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|