自动选择最优优惠券;是否可开发票判断

develop
mice2333 4 years ago
parent b72eaf5f25
commit 7dc2339671

@ -1,238 +1,298 @@
// pages/user/make_order/make_order.js // pages/user/make_order/make_order.js
import Dialog from "@vant/weapp/dialog/dialog" import Dialog from "@vant/weapp/dialog/dialog"
import { import {
httpUtil, httpUtil,
http http
} from '../../../utils/util' } from '../../../utils/util'
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
rolled:true, rolled: true,
max_viewer_num:6 max_viewer_num: 6
}, },
roll_spread() { roll_spread() {
this.setData({ this.setData({
rolled: !this.data.rolled rolled: !this.data.rolled
}) })
}, },
viewer_nav(){ viewer_nav() {
wx.navigateTo({ wx.navigateTo({
url: '/pages/user/viewer_list/viewer_list?_add=1', url: '/pages/user/viewer_list/viewer_list?_add=1',
}) })
}, },
de(){ de() {
this.setData({fee_detail:!this.data.fee_detail}) this.setData({
}, fee_detail: !this.data.fee_detail
})
check(event){ },
this.setData({
checked: event.detail, check(event) {
}); this.setData({
}, checked: event.detail,
agreement(){ });
this.setData({show:true}) },
}, agreement() {
viewer_sel(event) { this.setData({
this.setData({ show: true
viewer_sel: event.detail })
}); },
}, viewer_sel(event) {
this.setData({
toggle(event) { viewer_sel: event.detail
const { });
index },
} = event.currentTarget.dataset;
const checkbox = this.selectComponent(`.checkboxes-${index}`); toggle(event) {
checkbox.toggle(); const {
}, index
} = event.currentTarget.dataset;
noop() {}, const checkbox = this.selectComponent(`.checkboxes-${index}`);
onSubmit() { checkbox.toggle();
if(this.data._info.show_info.is_real_name==1){ },
var tid = this.data.tid
var viewer_id = this.data.viewer_sel noop() {},
if (viewer_id && tid.split(',').length == viewer_id.length) { onSubmit() {
if(this.data.checked){ if (this.data._info.show_info.is_real_name == 1) {
this.setData({show1:true}) var tid = this.data.tid
}else{ var viewer_id = this.data.viewer_sel
wx.showToast({ if (viewer_id && tid.split(',').length == viewer_id.length) {
title: '请勾选服务条款', if (this.data.checked) {
icon: 'none', this.setData({
duration: 2000 show1: true
}) })
} } else {
} else { wx.showToast({
wx.showToast({ title: '请勾选服务条款',
title: '观演人数和座位数不符', icon: 'none',
icon: 'none', duration: 2000
duration: 2000 })
}) }
}}else if(this.data._info.show_info.is_real_name==2){ } else {
var tid = this.data.tid wx.showToast({
var viewer_id = this.data.viewer_sel title: '观演人数和座位数不符',
if (viewer_id && viewer_id.length==1) { icon: 'none',
if(this.data.checked){ duration: 2000
this.setData({show1:true}) })
}else{ }
wx.showToast({ } else if (this.data._info.show_info.is_real_name == 2) {
title: '请勾选服务条款', var tid = this.data.tid
icon: 'none', var viewer_id = this.data.viewer_sel
duration: 2000 if (viewer_id && viewer_id.length == 1) {
}) if (this.data.checked) {
} this.setData({
} else { show1: true
wx.showToast({ })
title: '观演人数和座位数不符', } else {
icon: 'none', wx.showToast({
duration: 2000 title: '请勾选服务条款',
}) icon: 'none',
}} duration: 2000
else{ })
if(this.data.checked){ }
this.setData({show1:true}) } else {
}else{ wx.showToast({
wx.showToast({ title: '观演人数和座位数不符',
title: '请勾选服务条款', icon: 'none',
icon: 'none', duration: 2000
duration: 2000 })
}) }
} } else {
} if (this.data.checked) {
}, this.setData({
pay() { show1: true
var tid = this.data.tid })
var viewer_id = this.data.viewer_sel } else {
var arr = "" wx.showToast({
for (var i in viewer_id) { title: '请勾选服务条款',
arr += "," + viewer_id[i] icon: 'none',
} duration: 2000
viewer_id = arr.substring(1) })
var order_data }
let coupon =this.data.coupon
if (coupon && coupon.coupon_id && "underfined" !== coupon.coupon_id) {
order_data = {
order_type:8,
tid,
viewer_id,
coupon_id: coupon.coupon_id
} }
} else { },
order_data = { pay() {
order_type:8, var tid = this.data.tid
tid, var viewer_id = this.data.viewer_sel
viewer_id var arr = ""
for (var i in viewer_id) {
arr += "," + viewer_id[i]
} }
} viewer_id = arr.substring(1)
http("/api/v1/order-submit", "post", order_data).then(res => { var order_data
wx.requestPayment({ let coupon = this.data.coupon
timeStamp: res.timestamp, if (coupon && coupon.coupon_id && "underfined" !== coupon.coupon_id) {
nonceStr: res.nonceStr, order_data = {
package: res.package, order_type: 8,
signType: res.signType, tid,
paySign: res.paySign, viewer_id,
success(res) { coupon_id: coupon.coupon_id
console.log(res) }
wx.showToast({ } else {
title: '支付成功!', order_data = {
icon: 'success', order_type: 8,
duration: 1000 tid,
}) viewer_id
setTimeout(function(){ }
wx.reLaunch({ }
url: '/pages/user/my_order/my_order' http("/api/v1/order-submit", "post", order_data).then(res => {
}) wx.requestPayment({
}, 500); timeStamp: res.timestamp,
}, nonceStr: res.nonceStr,
fail(res) { package: res.package,
wx.showToast({ signType: res.signType,
title: '支付未成功', paySign: res.paySign,
icon:'error', success(res) {
duration: 2000 console.log(res)
wx.showToast({
title: '支付成功!',
icon: 'success',
duration: 1000
})
setTimeout(function () {
wx.reLaunch({
url: '/pages/user/my_order/my_order'
})
}, 500);
},
fail(res) {
wx.showToast({
title: '支付未成功',
icon: 'error',
duration: 2000
})
setTimeout(function () {
wx.reLaunch({
url: '/pages/user/my_order/my_order'
})
}, 500);
}
}) })
setTimeout(function(){
wx.reLaunch({
url: '/pages/user/my_order/my_order'
})
}, 500);
}
}) })
})
}, },
// 使用最大减免优惠券
getRecommendCoupons(drama_id,tid){
http('/api/v1/coupon-list', "post", {drama_id,tid,mode:1}).then(Response => {
if (Response.coupon_list.length > 0) {
let coupon_list = Response.coupon_list
// 去除日期格式
let a = []
coupon_list.forEach((item) => {
item.end_date = item.end_date.replace(/[\u4e00-\u9fa5]/g, '')
a.push(item)
})
coupon_list = a
/** // 优惠券筛选策略
* 生命周期函数--监听页面加载 function couponSort(list, params) {
*/ let descList
onLoad: function (options) { if (arguments[2] == 'asc') {
http("/api/v1/order-confirm", "post", { descList = list.sort((a, b) => {
tid:options.tid return a[params] - b[params]
}).then(res => { })
let _info=res } else {
/* ??????自己算总价???????? */ descList = list.sort((a, b) => {
let tprice = 0 return b[params] - a[params]
for(let i in _info.ticket_info){ })
tprice+=_info.ticket_info[i].price*_info.ticket_info[i].tkt_num }
} let l = []
this.setData({ l.push(descList[0])
_info,tprice, descList.forEach((item, index) => {
tid: options.tid, if (index != 0 && item[params] == l[0][params]) {
drama_id: options.drama_id, l.push(item)
}) }
}) })
return l;
}
let recommendCoupons = couponSort(couponSort(couponSort(coupon_list, "subtract"), 'full'), 'end_date', 'asc')
if (recommendCoupons && recommendCoupons.length > 0) {
this.setData({
coupon: recommendCoupons[0]
})
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
http("/api/v1/order-confirm", "post", {
tid: options.tid
}).then(res => {
let _info = res
/* ??????自己算总价???????? */
let tprice = 0
for (let i in _info.ticket_info) {
tprice += _info.ticket_info[i].price * _info.ticket_info[i].tkt_num
}
}, this.getRecommendCoupons(options.drama_id,options.tid)
/** this.setData({
* 生命周期函数--监听页面初次渲染完成 _info,
*/ tprice,
onReady: function () { tid: options.tid,
drama_id: options.drama_id,
})
})
},
}, /**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
/** },
* 生命周期函数--监听页面显示
*/
onShow: function () {
}, /**
* 生命周期函数--监听页面显示
*/
onShow: function () {
/** },
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
}, /**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
/** },
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
}, /**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
/** },
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
}, /**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
/** },
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}, /**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
/** },
* 用户点击右上角分享
*/
onShareAppMessage: function () {
} /**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
}) })

@ -13,7 +13,12 @@
</view> </view>
<view class="line"> <view class="line">
<van-icon name="passed" color="green" /> 不支持退票 <van-icon name="passed" color="green" /> 不支持退票
<block wx:if="{{_info.show_info.is_invoice==0}}">
<van-icon name="close" color="red" /> 不可开发票
</block>
<block wx:elif="{{_info.show_info.is_invoice==1}}">
<van-icon name="passed" color="green" /> 可开发票 <van-icon name="passed" color="green" /> 可开发票
</block>
</view> </view>
</view> </view>
</view> </view>

@ -21,7 +21,7 @@
<van-icon name="/images/ui/ellipsis.png" style="vertical-align:middle;" /> <van-icon name="/images/ui/ellipsis.png" style="vertical-align:middle;" />
</navigator> </navigator>
</view> </view>
<scroll-view class="scroll-view_H" scroll-x="true"> <scroll-view class="scroll-view_H" scroll-x="true" >
<image class="scroll-item" wx:for="{{_li.list}}" data-abb_id="{{item.abb_id}}" src="{{item.pic}}" <image class="scroll-item" wx:for="{{_li.list}}" data-abb_id="{{item.abb_id}}" src="{{item.pic}}"
bindtap="detail" /> bindtap="detail" />
</scroll-view> </scroll-view>

@ -23,7 +23,12 @@
</view> </view>
<view class="line" style="font-weight:normal;"> <view class="line" style="font-weight:normal;">
<van-icon name="passed" color="green" /> 不支持退票 <van-icon name="passed" color="green" /> 不支持退票
<block wx:if="{{show_info.is_invoice==0}}">
<van-icon name="close" color="red" /> 不可开发票
</block>
<block wx:elif="{{show_info.is_invoice==1}}">
<van-icon name="passed" color="green" /> 可开发票 <van-icon name="passed" color="green" /> 可开发票
</block>
</view> </view>
</view> </view>
</view> </view>

Loading…
Cancel
Save