123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721 |
- // pages/confirmorder/confirmorder.js
- const app = getApp();
- const api = require('../../api/api');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- navbarData: {
- showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
- title: '确认订单', //导航栏 中间的标题
- capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页)
- },
- tabType: 'wuliu', //tab类型
- showBottomBar: true, //显示底部栏
- showReceiptPlace: false, //显示选择收货地址
- showSelfMention: false, //显示自取点
- showPayTypePicker: false, //显示支付方式选择器
- payTypes: [], //支付方式列表
- payType: [0], //支付方式
- showEMTPopup: false, //显示EMT支付弹出层
- showOrderSuccessful: false, //显示下单成功弹出层
- btnDisabled: false, //确认支付按钮禁用
- /* 表单 */
- id: 0, //拼团id
- gang_name: '', //拼团名称
- head_phone: '', //团长手机号
- all_scribe_price: 0, //划线价格总价
- all_price: 0, //总价
- shopcart: [], //购物车
- remarks: '', //备注
- logistics_mode: 0, //物流方式(0没有物流,1取货点自提,2送货或者自提)
- expected_arrival_time: '', //预计到货时间
- head_email: '', //团长邮箱
- order_number: '', //订单号
- ziquAddress: [], //自取点列表
- ziquIndex: 0,
- peisongAddress: [], //配送列表
- peisongIndex: 0,
- order_id: 0, //订单ID
- wxpayservice: '', //微信支付手续费
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // console.log(options);
- let that = this;
- that.setData({
- id: Number(options.id),
- all_scribe_price: Number(options.all_scribe_price),
- all_price: Number(options.all_price),
- gang_name: options.gang_name,
- logistics_mode: Number(options.logistics_mode),
- head_phone: options.head_phone,
- expected_arrival_time: options.expected_arrival_time,
- shopcart: wx.getStorageSync('shopcart')
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- let that = this;
- // 获取自取点列表
- if (that.data.logistics_mode == 1 || that.data.logistics_mode == 2) {
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- wx.request({
- url: api.Gang_point,
- header: {
- 'Authorization': wx.getStorageSync('token')
- },
- data: {
- id: that.data.id
- },
- method: 'POST',
- success(res) {
- wx.hideLoading()
- console.log(res);
- if (res.data.code === 1) {
- that.setData({
- ziquAddress: res.data.data
- })
- } else {
- wx.showToast({
- title: res.data.msg,
- mask: true,
- icon: 'none'
- })
- }
- },
- fail(err) {
- wx.hideLoading()
- wx.showToast({
- title: '发起网络请求失败',
- icon: 'none',
- mask: true
- })
- },
- complete() {
- // wx.hideLoading()
- }
- })
- }
- // 获取收货地址列表
- if (that.data.logistics_mode == 2) {
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- wx.request({
- url: api.Address_list,
- header: {
- 'Authorization': wx.getStorageSync('token')
- },
- method: 'POST',
- success(res) {
- wx.hideLoading()
- console.log(res);
- if (res.data.code === 1) {
- that.setData({
- peisongAddress: res.data.data
- })
- } else {
- wx.showToast({
- title: res.data.msg,
- mask: true,
- icon: 'none'
- })
- }
- },
- fail(err) {
- wx.hideLoading()
- wx.showToast({
- title: '发起网络请求失败',
- icon: 'none',
- mask: true
- })
- },
- complete() {
- // wx.hideLoading()
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- // 切换tab
- switchTab(e) {
- console.log(e);
- this.setData({
- tabType: e.currentTarget.dataset.type
- })
- },
- // 打开收货地址弹出层
- openReceiptPlace() {
- this.setData({
- showReceiptPlace: true,
- showBottomBar: false
- })
- },
- // 关闭收货地址弹出层
- closeReceiptPlace() {
- this.setData({
- showReceiptPlace: false,
- showBottomBar: true
- })
- },
- // 打开自取点弹出层
- openSelfMention() {
- this.setData({
- showSelfMention: true,
- showBottomBar: false
- })
- },
- // 关闭自取点弹出层
- closeSelfMention() {
- this.setData({
- showSelfMention: false,
- showBottomBar: true
- })
- },
- // 下单
- openPayTypePicker() {
- let that = this;
- // 第一次下单
- if (that.data.order_id == 0) {
- let logistics_mode = 0; //收货方式
- if (that.data.logistics_mode == 1) { //只有自取
- logistics_mode = 1;
- }
- if (that.data.logistics_mode == 2) {
- if (that.data.tabType == 'wuliu') {
- logistics_mode = 0;
- } else if (that.data.tabType == 'ziqu') {
- logistics_mode = 1;
- }
- }
- // 商品列表处理
- let arr = that.data.shopcart;
- for (let i = 0; i < arr.length; i++) {
- if (arr[i].type == 'guige') {
- let guige_index = arr[i].guige_index; //当前规格索引
- let specifications = [];
- specifications.push(arr[i].specifications[guige_index]); //当前规格
- arr[i].commodity_number = arr[i].count; //商品数量
- arr[i].commodity_price = arr[i].specifications[guige_index].price; //商品价格
- arr[i].specifications = specifications; //商品规格
- delete arr[i].price;
- delete arr[i].scribe_price;
- delete arr[i].sold;
- delete arr[i].stock;
- delete arr[i].purchase_restrictions_second;
- delete arr[i].step_price;
- delete arr[i].count;
- delete arr[i].type;
- delete arr[i].guige_index;
- } else if (arr[i].type == 'step') {
- let step_index = arr[i].step_index; //当前阶梯价索引
- let step_price = [];
- step_price.push(arr[i].step_price[step_index]); //当前阶梯价
- arr[i].commodity_number = arr[i].count; //商品数量
- arr[i].commodity_price = arr[i].step_price[step_index].price; //商品价格
- arr[i].step_price = step_price; //商品阶梯价
- delete arr[i].price;
- delete arr[i].scribe_price;
- delete arr[i].sold;
- delete arr[i].stock;
- delete arr[i].purchase_restrictions_second;
- delete arr[i].count;
- delete arr[i].type;
- delete arr[i].step_index;
- delete arr[i].specifications;
- }
- }
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- let discount = that.data.all_scribe_price - that.data.all_price;
- if (discount < 0) {
- discount = -discount;
- }
- if (logistics_mode == 0) {
- wx.request({
- url: api.Order_add,
- header: {
- 'Authorization': wx.getStorageSync('token')
- },
- data: {
- id: that.data.id,
- logistics_mode: logistics_mode,
- original_price: that.data.all_scribe_price,
- discount: discount,
- payment_amount: that.data.all_price,
- remarks: that.data.remarks,
- commodity_list: arr,
- consignee: that.data.peisongAddress[that.data.peisongIndex].receiving_name,
- phone: that.data.peisongAddress[that.data.peisongIndex].receiving_phone,
- receiving_address: that.data.peisongAddress[that.data.peisongIndex].receiving_address
- },
- method: 'POST',
- success(res) {
- wx.hideLoading()
- console.log(res);
- if (res.data.code === 1) {
- let order_id = res.data.data;
- that.setData({
- order_id
- })
- that.getOrder_payment_method(order_id);
- } else {
- wx.showToast({
- title: res.data.msg,
- mask: true,
- icon: 'none'
- })
- }
- },
- fail(err) {
- wx.hideLoading()
- wx.showToast({
- title: '发起网络请求失败',
- icon: 'none',
- mask: true
- })
- },
- complete() {
- // wx.hideLoading()
- }
- })
- } else if (logistics_mode == 1) {
- wx.request({
- url: api.Order_add,
- header: {
- 'Authorization': wx.getStorageSync('token')
- },
- data: {
- id: that.data.id,
- logistics_mode: logistics_mode,
- original_price: that.data.all_scribe_price,
- discount: that.data.all_scribe_price - that.data.all_price,
- payment_amount: that.data.all_price,
- remarks: that.data.remarks,
- commodity_list: arr,
- self_access_point: that.data.ziquAddress[that.data.ziquIndex].address,
- point_remarks: that.data.ziquAddress[that.data.ziquIndex].remarks,
- reserved_phone: that.data.ziquAddress[that.data.ziquIndex].phone
- },
- method: 'POST',
- success(res) {
- wx.hideLoading()
- console.log(res);
- if (res.data.code === 1) {
- let order_id = res.data.data;
- that.setData({
- order_id
- })
- that.getOrder_payment_method(order_id);
- } else {
- wx.showToast({
- title: res.data.msg,
- mask: true,
- icon: 'none'
- })
- }
- },
- fail(err) {
- wx.hideLoading()
- wx.showToast({
- title: '发起网络请求失败',
- icon: 'none',
- mask: true
- })
- },
- complete() {
- // wx.hideLoading()
- }
- })
- }
- } else {
- // 重复点击下单
- let order_id = Number(that.data.order_id);
- that.getOrder_payment_method(order_id);
- }
- },
- // 获取用户支付方式
- getOrder_payment_method(order_id) {
- let that = this;
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- wx.request({
- url: api.Order_payment_method,
- header: {
- 'Authorization': wx.getStorageSync('token')
- },
- data: {
- id: Number(order_id)
- },
- method: 'POST',
- success(res) {
- wx.hideLoading()
- console.log(res);
- if (res.data.code === 1) {
- that.setData({
- payTypes: res.data.data,
- showPayTypePicker: true,
- showBottomBar: false
- })
- } else {
- wx.showToast({
- title: res.data.msg,
- mask: true,
- icon: 'none'
- })
- }
- },
- fail(err) {
- wx.hideLoading()
- wx.showToast({
- title: '发起网络请求失败',
- icon: 'none',
- mask: true
- })
- },
- complete() {
- // wx.hideLoading()
- }
- })
- },
- // 关闭支付方式弹出层
- closePayTypePicker() {
- this.setData({
- showPayTypePicker: false,
- showBottomBar: true
- })
- },
- // 支付方式改变
- payTypeChanged(e) {
- let that = this;
- that.setData({
- payType: e.detail.value
- })
- // if(that.data.payTypes[that.data.payType[0]].payment_name == '微信支付') {
- // let all_price = that.data.all_price;
- // all_price = all_price * (1 + that.data.wxpayservice);
- // all_price = all_price.toFixed(2);
- // that.setData({
- // all_price
- // })
- // }
- },
- // 打开EMT支付弹出层
- openEMTPopup() {
- this.setData({
- showPayTypePicker: false,
- showEMTPopup: true,
- showBottomBar: false
- })
- },
- // 关闭EMT支付弹出层
- closeEMTPopup() {
- this.setData({
- showEMTPopup: false,
- showBottomBar: true
- })
- },
- // 确认支付
- confirmPay() {
- let that = this;
- let payType = that.data.payTypes[that.data.payType[0]];
- let id = that.data.order_id; //订单ID
- let payment_method = payType.payment_method; //支付方式(0微信支付,1EMT支付,2线下支付)
- let payment_price = that.data.all_price; //支付金额
- // 如果支付方式为微信支付-获取微信支付手续费
- if (payType.payment_name == '微信支付') {
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- wx.request({
- url: api.Service,
- header: {
- 'Authorization': wx.getStorageSync('token')
- },
- method: 'POST',
- success(res) {
- wx.hideLoading();
- // console.log(res);
- that.setData({
- wxpayservice: Number(res.data.data)
- })
- payment_price = payment_price * (1 + that.data.wxpayservice);
- payment_price = payment_price.toFixed(2);
- that.zhenDePay(id, payment_method, payment_price);
- },
- fail(err) {
- wx.hideLoading()
- }
- })
- }else{
- that.zhenDePay(id, payment_method, payment_price);
- }
- },
- // 真的要支付吗?在这里?就现在?
- zhenDePay(id, payment_method, payment_price) {
- let that = this;
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- wx.request({
- url: api.Order_payment,
- header: {
- 'Authorization': wx.getStorageSync('token')
- },
- data: {
- id: Number(id),
- payment_method: Number(payment_method),
- payment_price: payment_price
- },
- method: 'POST',
- success(res) {
- wx.hideLoading()
- console.log(res);
- if (res.data.code === 1) {
- if (res.data.msg == 'EMT支付') {
- that.setData({
- head_email: res.data.data.email,
- order_number: res.data.data.order_number
- })
- that.openEMTPopup()
- }
- if (res.data.msg == '线下支付') {
- that.setData({
- showPayTypePicker: false,
- showBottomBar: true
- })
- wx.navigateTo({
- url: '/pages/orderdetail/orderdetail?id=' + id,
- })
- }
- if (res.data.msg == '微信支付') {
- wx.requestPayment({
- appId: res.data.data.payParams.appId,
- nonceStr: res.data.data.payParams.nonceStr,
- package: res.data.data.payParams.package,
- paySign: res.data.data.payParams.paySign,
- timeStamp: res.data.data.payParams.timeStamp,
- signType: res.data.data.payParams.signType,
- success(res) {
- wx.hideLoading()
- console.log(res);
- wx.showToast({
- title: '支付成功',
- mask: true,
- success() {
- setTimeout(() => {
- that.setData({
- showPayTypePicker: false,
- showBottomBar: true
- })
- wx.navigateTo({
- url: '/pages/orderdetail/orderdetail?id=' + id,
- })
- }, 1500)
- }
- })
- },
- fail(res) {
- wx.hideLoading()
- console.log(res);
- if (res.errMsg.search('cancel')) {
- wx.showToast({
- title: '用户取消支付',
- icon: 'error',
- mask: true
- })
- } else if (res.errMsg.search('offline')) {
- wx.showToast({
- title: '网络断开连接',
- icon: 'error',
- mask: true
- })
- }
- }
- })
- }
- } else {
- wx.showToast({
- title: res.data.msg,
- mask: true,
- icon: 'none'
- })
- }
- },
- fail(err) {
- wx.hideLoading()
- wx.showToast({
- title: '发起网络请求失败',
- icon: 'none',
- mask: true
- })
- },
- complete() {
- // wx.hideLoading()
- }
- })
- },
- // 打开下单成功弹窗
- openOrderSuccessfulPopup() {
- this.setData({
- showOrderSuccessful: true
- })
- },
- // 关闭下单成功弹窗
- closeOrderSuccessfulPopup() {
- this.setData({
- showOrderSuccessful: false
- })
- },
- // 输入备注
- inputRemarks(e) {
- this.setData({
- remarks: e.detail.value
- })
- },
- // 选择配送地址
- choosePeisongAddress(e) {
- this.setData({
- peisongIndex: e.currentTarget.dataset.index,
- showReceiptPlace: false,
- showBottomBar: true
- })
- },
- // 选择自取地址
- chooseZiquAddress(e) {
- this.setData({
- ziquIndex: e.currentTarget.dataset.index,
- showSelfMention: false,
- showBottomBar: true
- })
- },
- // 联系团长
- callHead() {
- let that = this;
- wx.makePhoneCall({
- phoneNumber: that.data.head_phone,
- })
- },
- // 复制团长邮箱
- copyHeadEmail() {
- wx.setClipboardData({
- data: this.data.head_email,
- })
- },
- // 复制订单号
- copyOrderNumber() {
- wx.setClipboardData({
- data: this.data.order_number,
- })
- },
- // EMT已支付
- EMTpaid() {
- let id = this.data.order_id; //订单ID
- wx.navigateTo({
- url: '/pages/orderdetail/orderdetail?id=' + id,
- })
- },
- // 新增收货地址
- addAddress() {
- wx.navigateTo({
- url: '/pages/addaddress/addaddress?type=add',
- })
- },
- // 编辑收货地点
- editAddress(e) {
- let index = e.currentTarget.dataset.index
- // console.log(e.currentTarget.dataset.index);
- let address = this.data.peisongAddress[index];
- wx.setStorageSync('address', address);
- wx.navigateTo({
- url: '/pages/addaddress/addaddress?type=edit',
- })
- },
- // 获取微信支付手续费
- getWXPayServiceCharge() {
- let that = this;
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- wx.request({
- url: api.Service,
- header: {
- 'Authorization': wx.getStorageSync('token')
- },
- method: 'POST',
- success(res) {
- wx.hideLoading()
- that.setData({
- wxpayservice: res.data.data
- })
- },
- fail(err) {
- wx.hideLoading()
- }
- })
- },
- })
|