12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502 |
- import {
- get,
- post
- } from '../../utils/http'
- import {
- PROJECT_TYPE
- } from '../../utils/global'
- var WxParse = require('../../components/local/wxParse/wxParse.js')
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- visible: false,
- visibleLandscape: false,
- detail: null,
- productDetail: null, // 项目耗材下单 - 产品信息
- projectOrderData: null, // 项目耗材下单 - 绑定的订单信息
- couponList: [],
- currentCoupon: -1,
- currentChangeCoupon: null,
- memberDiscountStatus: -1, // 是否可使用会员折扣 0 不是会员 1 是会员
- memberStatus: -1, // 是否为会员 0 不是会员 1 是会员
- recommendMemberCard: null, // 推荐开通的会员卡
- array: ['使用', '不使用'],
- memberCardCurrentDiscount: -1, // 是否可以使用会员抵扣,0使用,1不使用,-1不可选择
- source: 'project', // project, product, goods
- projectProducts: [], // 指定项目的耗材推荐产品(升级产品)
- selectProductId: 0, // 选择的项目耗材id
- selectProductIndex: -1, // 选择的项目耗材下标
- selectCardId: 0, // 选择的会员卡ID
- moneyData: {}, // 金额数据
- orderId: 0,
- wxParseMemberRules: false, // 是否已解析
- pay_methon: 1,
- payNow: false,
- switchPay: 'product',
- inFirstIn: false,
- card_sum: 0, //次卡分配总数量
- cardDetail: [], //固定次卡分配信息列表
- Ac_cardDetail: [], //非固定次卡分配信息列表
- card_type: null, //是否可以分配次数
- finshCardDetail: {}, //分配完成的产品列表
- all_cardDetail: [], //获取分配全部信息
- selectExchange: 0, //是否选中加购产品
- exchangePrice: '', //选中后的价格
- cardExchangeList: '', //加购产品列表
- cardExchangeId: '', //加购产品id
- toExchangePrice:'', //加购产品总价格
- level: '', //用户充值折扣等级 (0是未拥有等级)
- levelPrice: '', //充值等级折扣优惠价格
- },
- knowSubmit: function () {
- this.setData({
- inFirstIn: false
- })
- },
- noneEnoughPeople() {
- },
- pay_methonw() {
- this.setData({
- pay_methon: 1
- })
- },
- // 获取用户充值折扣等级
- getLevel() {
- get('/v2/api/user/discount_level', {}, (res) => {
- res.data = Number(res.data)
- if (res.code == 200) {
- if (res.data == 0) {
- this.setData({
- level: 0
- })
- return
- }
- this.setData({
- level: Number(res.data*0.1)
- })
- this.setData({
- tolevel: (this.data.level * 10).toFixed(1)
- })
- }
- })
- },
- pay_methonc() {
- this.setData({
- pay_methon: 2
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- // 获取用户折扣等级
- this.getLevel()
- this.getCardExchangeList(options.storeId, JSON.parse(options.data).id)
- let source = options.source || 'project'
- let productData = options.productData || null
- if (productData) {
- productData = JSON.parse(productData)
- }
- let userInfo = getApp().globalData.userInfo
- this.setData({
- exchangePrice: JSON.parse(options.data).price,
- detail: JSON.parse(options.data),
- productDetail: productData,
- timeData: JSON.parse(options.timeData),
- deviceData: JSON.parse(options.deviceData),
- selectProductId: productData && productData.id ? productData.id : 0, // 复用了项目下单的耗材推荐产品
- projectOrderData: options.projectOrderData ?
- JSON.parse(options.projectOrderData) : null,
- source: source,
- memberStatus: userInfo.is_vip || 0,
- storeId: options.storeId
- })
- // 产品类型 数据类型,1项目,2项目耗材,3美妆产品,4卡券产品分类, 默认1
- if (source == 'project') {
- // 项目
- this.getDiscount()
- } else if (source == 'product') {
- // 项目耗材
- this.getDiscount()
- } else if (['goods'].indexOf(source) > -1) {
- // 美妆产品
- this.getGoodsDiscount()
- } else if (source == 'cardgoods') {
- // 卡券产品
- this.getCardgoodsDiscount()
- } else if (source == 'product_with_project_order') {
- // 项目-升级产品(项目耗材)
- this.getProductWithProjectOrderDiscount()
- } else if (source == 'secondaryCard') {
- // 次卡
- // 发起请求获取次卡分配产品
- this.getCardProjectInfo()
- } else {
- // 默认为项目
- this.getDiscount()
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getAmount()
- let version4 = wx.getStorageSync('version4')
- if (!version4 || version4 != 1) {
- this.setData({
- inFirstIn: true
- })
- wx.setStorageSync('version4', 1)
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {},
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {},
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {},
- /**
- * 复制订单号
- */
- onCopyOrderNum(e) {
- wx.setClipboardData({
- data: e.currentTarget.dataset.num || '',
- success(res) {
- console.log(res)
- }
- })
- },
- /**
- * 打开优惠券
- */
- onCouponOpen() {
- if (
- this.data.couponList.length > 0 &&
- this.data.memberCardCurrentDiscount != 0
- ) {
- this.setData({
- visible: true
- })
- }
- },
- /**
- * 选择优惠券
- */
- onCouponChange(e) {
- let couponIndex = e.detail.checkStatus ? e.currentTarget.dataset.index : -1
- // 优惠券和会员卡互斥逻辑
- this.setData({
- currentCoupon: couponIndex,
- currentChangeCoupon: couponIndex == -1 ? null : this.data.couponList[couponIndex],
- memberCardCurrentDiscount: couponIndex != -1 ? -1 : this.data.memberCardCurrentDiscount // 会员卡与优惠券互斥逻辑
- },
- () => {
- this.calculateOrderPayMoney()
- }
- )
- },
- /**
- * 关闭弹框
- */
- onClose() {
- this.setData({
- visible: false
- })
- },
- onCancelCoupon() {
- this.setData({
- visible: false
- })
- },
- onConfirmCoupon() {
- let currentChangeCoupon = this.data.couponList[this.data.currentCoupon]
- this.setData({
- visible: false,
- currentChangeCoupon
- },
- () => {
- this.calculateOrderPayMoney()
- }
- )
- },
- /**
- * 订单支付
- */
- payOrder(orderId) {
- let that = this
- let uri = 'api/pay/project'
- if (that.data.source == 'goods') {
- uri = 'api/pay/goods'
- } else if (that.data.source == 'cardgoods') {
- uri = 'api/pay/cardgoods'
- } else if (that.data.source == 'secondaryCard') {
- uri = 'v2/api/order/card/pay'
- }
- post(
- uri, {
- pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
- order_id: orderId
- },
- (res) => {
- that.setData({
- payNow: false
- })
- if (that.data.pay_methon == 2) {
- that.goToOrder('支付成功')
- return
- }
- wx.requestPayment({
- timeStamp: res.data.pay_data.timeStamp,
- nonceStr: res.data.pay_data.nonceStr,
- package: res.data.pay_data.package,
- signType: res.data.pay_data.signType,
- paySign: res.data.pay_data.paySign,
- success(res) {
- if (res.errMsg == 'requestPayment:ok') {
- that.goToOrder('支付成功')
- }
- },
- fail(res) {
- that.goToOrder('支付失败')
- }
- })
- }
- )
- },
- /**
- * 订单支付 - 升级产品支付
- */
- payProductOrder(orderId) {
- let that = this
- post(
- 'api/pay/product', {
- pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
- order_id: orderId
- },
- (res) => {
- that.setData({
- payNow: false
- })
- if (that.data.pay_methon == 2) {
- that.goToOrder('支付成功')
- return
- }
- wx.requestPayment({
- timeStamp: res.data.pay_data.timeStamp,
- nonceStr: res.data.pay_data.nonceStr,
- package: res.data.pay_data.package,
- signType: res.data.pay_data.signType,
- paySign: res.data.pay_data.paySign,
- success(res) {
- if (res.errMsg == 'requestPayment:ok') {
- that.goToOrder('支付成功')
- }
- },
- fail(res) {
- that.goToOrder('支付失败')
- }
- })
- }
- )
- },
- onPay: function () {
- this.setData({
- payNow: true,
- switchPay: 'project',
- })
- },
- payNow() {
- switch (this.data.switchPay) {
- case 'project':
- this.payNowProduct()
- break;
- case 'product':
- this.onProductPayNow()
- break;
- case 'goods':
- this.onGoodsPayNow()
- break
- case 'cardgoods':
- this.onCardgoodsPayNow()
- break
- case 'secondaryCard':
- this.onSecondaryCardPayNow()
- break
- default:
- break;
- }
- },
- /**
- * 支付
- */
- payNowProduct() {
- let that = this
- this.checkFirst()
- .then((res) => {
- this.addOrder().then((res) => {
- console.log(res)
- that.setData({
- orderId: res.order_id
- }, () => {
- that.methonPayOrder(res.order_id)
- })
- })
- })
- .catch((rej) => {
- that.setData({
- payNow: false
- })
- wx.navigateTo({
- url: '/pages/disclaimer/disclaimer'
- })
- })
- },
- onClosePay() {
- this.setData({
- payNow: false
- })
- },
- /**
- * 订单支付
- */
- methonPayOrder(orderId) {
- let that = this
- let uri = 'api/pay/project'
- post(
- uri, {
- pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
- order_id: orderId
- },
- (res) => {
- that.setData({
- payNow: false
- })
- if (that.data.pay_methon == 2) {
- that.goToOrder('支付成功')
- return
- }
- wx.requestPayment({
- timeStamp: res.data.pay_data.timeStamp,
- nonceStr: res.data.pay_data.nonceStr,
- package: res.data.pay_data.package,
- signType: res.data.pay_data.signType,
- paySign: res.data.pay_data.paySign,
- success(res) {
- if (res.errMsg == 'requestPayment:ok') {
- that.goToOrder('支付成功')
- }
- },
- fail(res) {
- that.goToOrder('支付失败')
- }
- })
- }
- )
- },
- onGoodsPay() {
- this.setData({
- payNow: true,
- switchPay: 'goods'
- })
- },
- /**
- * 美妆产品-订单
- */
- onGoodsPayNow() {
- let {
- detail,
- currentChangeCoupon,
- memberCardCurrentDiscount,
- selectCardId
- } = this.data
- let discount_type
- let that = this
- if (memberCardCurrentDiscount == 0) {
- discount_type = 1
- } else if (currentChangeCoupon) {
- discount_type = 2
- } else {
- discount_type = 0
- }
- post(
- 'api/goods/buy', {
- goods_id: detail.id,
- coupon_id: currentChangeCoupon ? currentChangeCoupon.id : '',
- store_id: detail.store_id,
- card_id: selectCardId,
- discount_type
- },
- (res) => {
- let orderId = res.data.order_id
- let payStatus = res.data.pay_status //订单状态,1已支付,0未支付,需要调用支付接口
- this.setData({
- orderId: orderId
- }, () => {
- if (payStatus == 1) {
- that.goToOrder('支付成功')
- return
- }
- that.payOrder(orderId)
- })
- }
- )
- },
- onCardgoodsPay() {
- this.setData({
- payNow: true,
- switchPay: 'cardgoods'
- })
- },
- /**
- * 购买-卡券产品【下单】
- */
- onCardgoodsPayNow() {
- let {
- detail,
- currentChangeCoupon,
- memberCardCurrentDiscount,
- selectCardId
- } = this.data
- let discount_type
- let that = this
- if (memberCardCurrentDiscount == 0) {
- discount_type = 1
- } else if (currentChangeCoupon) {
- discount_type = 2
- } else {
- discount_type = 0
- }
- post(
- 'api/cardgoods/buy', {
- goods_id: detail.id,
- coupon_id: currentChangeCoupon ? currentChangeCoupon.id : '',
- store_id: detail.store_id,
- card_id: selectCardId,
- discount_type
- },
- (res) => {
- let orderId = res.data.order_id
- let payStatus = res.data.pay_status //订单状态,1已支付,0未支付,需要调用支付接口
- this.setData({
- orderId: orderId
- }, () => {
- if (payStatus == 1) {
- that.goToOrder('支付成功')
- return
- }
- that.payOrder(orderId)
- })
- }
- )
- },
- onSecondaryCardPay() {
- // 计算充值折扣
- this.setData({
- levelPrice: (this.data.detail.price * this.data.level+Number(this.data.toExchangePrice)).toFixed(2)
- })
- this.setData({
- toLevelPrice: (this.data.detail.price - this.data.levelPrice+Number(this.data.toExchangePrice)).toFixed(2)
- })
- // 判断是否有次卡分配
- if (this.data.card_type == 2) {
- // 判断分配次数是否分配完毕
- let num = 0
- this.data.Ac_cardDetail.map(item => {
- num += item.total_time
- })
- this.setData({
- card_sum: num
- })
- // 如果没有分配完毕就提示
- if (this.data.card_sum != 0) {
- wx.showToast({
- title: '您还有剩余次数',
- icon: 'error'
- })
- return
- }
- // 筛选分配后的数据
- let group = []
- this.data.Ac_cardDetail.map(item => {
- let vote = {}
- vote.id = item.id
- let project_list = []
- vote.project_list = project_list
- item.project_list.map(item1 => {
- let vote1 = {}
- if (item1.time != 0) {
- vote1.project_id = item1.project_id
- vote1.time = item1.time
- project_list.push(vote1)
- }
- })
- group.push(vote)
- })
- this.setData({
- finshCardDetail: group
- })
- }
- this.setData({
- payNow: true,
- switchPay: 'secondaryCard'
- })
- },
- /**
- * 次卡下单
- */
- onSecondaryCardPayNow() {
- console.log({
- group: '',
- id: this.data.all_cardDetail.id,
- store_id: this.data.all_cardDetail.store_id,
- group_type: this.data.card_type,
- plus_id: this.data.cardExchangeId
- });
- let {
- detail
- } = this.data
- let that = this
- post(
- // 判断是否有次卡分配
- 'v2/api/order/card/add',
- this.data.card_type == 2 ? {
- group: this.data.finshCardDetail,
- store_id: this.data.all_cardDetail.store_id,
- id: this.data.all_cardDetail.id,
- group_type: this.data.card_type,
- share_user_id: app.globalData.shareUserId || '',
- } : {
- group: '',
- id: this.data.all_cardDetail.id,
- store_id: this.data.all_cardDetail.store_id,
- group_type: this.data.card_type,
- plus_id: this.data.cardExchangeId,
- share_user_id: app.globalData.shareUserId || '',
- },
- (res) => {
- console.log(res);
- let orderId = res.data.order_id
- let payStatus = res.data.pay_status //订单状态,1已支付,0未支付,需要调用支付接口
- // 因为要订阅消息,不能在回调函数里调用该方法所以修改
- this.setData({
- orderId: orderId
- })
- if (payStatus == 1) {
- that.goToOrder('支付成功')
- return
- }
- that.payOrder(orderId)
- // this.setData({
- // orderId: orderId
- // }, () => {
- // if (payStatus == 1) {
- // that.goToOrder('支付成功')
- // return
- // }
- // that.payOrder(orderId)
- // })
- }
- )
- },
- /**
- * 确认订单
- */
- getOrderInfo(order_id) {
- get(
- 'api/order/info', {
- order_id
- },
- (res) => {
- this.setData({
- detail: res.data
- })
- console.log(res)
- }
- )
- },
- /**
- * 获取预约订单折扣
- * api/order/get_discount
- */
- getDiscount() {
- let {
- memberCardCurrentDiscount,
- source
- } = this.data
- get(
- 'api/order/get_discount', {
- project_id: this.data.detail.id,
- order_day: this.data.timeData.order_day,
- order_time_id: this.data.timeData.time_id
- },
- (res) => {
- // 是否可以使用会员抵扣,member_status:1 可以抵扣,0不能抵扣
- if (res.data.member_status == 1) {
- memberCardCurrentDiscount = 0 // 是否可以使用会员抵扣,0使用,1不使用,-1不可选择
- }
- this.setData({
- couponList: res.data.coupon_list, // type: 类型,1抵扣券,2满减券,3全额券
- memberDiscountStatus: res.data.member_status, // 是否可以使用会员抵扣,1可以抵扣,0不能抵扣
- recommendMemberCard: res.data.member_card, // 推荐开通的会员卡
- memberCardCurrentDiscount,
- currentPayMoney: this.data.detail.price
- },
- () => {
- this.calculateOrderPayMoney()
- }
- )
- }
- )
- // 项目确认订单 - 获取指定项目的升级产品
- if (source == 'project') {
- this.getProjectProducts()
- }
- },
- /**
- * 选择会员抵扣
- */
- bindPickerChange(e) {
- let {
- memberCardCurrentDiscount,
- currentCoupon,
- currentChangeCoupon
- } =
- this.data
- this.setData({
- memberCardCurrentDiscount: e.detail.value,
- currentCoupon: memberCardCurrentDiscount == 0 ? -1 : currentCoupon,
- currentChangeCoupon: memberCardCurrentDiscount == 0 ? null : currentChangeCoupon
- },
- () => {
- this.calculateOrderPayMoney()
- }
- )
- },
- onSubmitCh(ids, source) {
- let that = this
- wx.showModal({
- title: '提示',
- content: '支付成功! 是否进行消息提醒',
- success: function (res) {
- if (res.confirm) {
- that.onSubmitTrue(ids, source)
- } else if (res.cancel) {
- that.messageAgree(ids)
- setTimeout(() => {
- wx.reLaunch({
- // url: '/pages/order/order?current=1'
- url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
- })
- }, 1000)
- }
- }
- });
- },
- onSubmitTrue(ids, source) {
- console.log("source")
- console.log(source)
- let that = this
- wx.requestSubscribeMessage({
- tmplIds: ids,
- success(res) {
- console.log(res)
- that.messageAgree(ids)
- wx.reLaunch({
- // url: '/pages/order/order?current=1'
- url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
- })
- },
- fail(rej) {
- console.log(rej)
- that.messageAgree(ids)
- wx.showToast({
- title: JSON.stringify(rej),
- icon: 'error'
- })
- setTimeout(() => {
- wx.reLaunch({
- // url: '/pages/order/order?current=1'
- url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
- })
- }, 1000)
- }
- })
- },
- /**
- * 获取我的储值
- * api/user
- */
- getAmount() {
- get('api/user/amount', {}, (res) => {
- if (res.data) {
- this.setData({
- inserllAmount: res.data.amount
- })
- }
- })
- },
- /**
- * 跳转订单列表
- */
- goToOrder(text) {
- let that = this
- let {
- source
- } = this.data
- // 此处按照接口定义,当选择项目耗材,且无项目时,下单用的是project
- if (source == 'product') {
- source = 'project'
- }
- wx.showToast({
- title: text,
- icon: text == '支付成功' ? 'success' : 'error'
- })
- if (text == '支付成功') {
- // 只有项目购买,需要订阅消息
- if (source != 'project') {
- wx.reLaunch({
- url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
- })
- // 获取下发权限
- wx.requestSubscribeMessage({
- tmplIds: ['RNife3ZhTYYpUuT26ylGQj8W0v07IPo2TGe941iR3y8'],
- success(res) {
- console.log(res);
- let status = ''
- if (res['RNife3ZhTYYpUuT26ylGQj8W0v07IPo2TGe941iR3y8'] == 'reject') {
- status = 2
- } else {
- status = 1
- }
- get('/v2/api/activity/push', {
- type: 2,
- status,
- }, res => {})
- },
- })
- return
- }
- get('api/message/ids', {}, (res) => {
- let ids = res.data.ids
- if (that.data.pay_methon == 2) {
- that.onSubmitCh(ids, source)
- return
- }
- wx.requestSubscribeMessage({
- tmplIds: ids,
- success(res) {
- console.log(res)
- that.messageAgree(ids)
- wx.reLaunch({
- // url: '/pages/order/order?current=1'
- url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
- })
- },
- fail(rej) {
- console.log(rej)
- that.messageAgree(ids)
- wx.showToast({
- title: JSON.stringify(rej),
- icon: 'error'
- })
- setTimeout(() => {
- wx.reLaunch({
- // url: '/pages/order/order?current=1'
- url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
- })
- }, 1000)
- }
- })
- })
- } else {
- let failUrl = `/pages/order/order?current=0`
- if (['goods', 'cardgoods'].indexOf(source) > -1) {
- failUrl = `/pages/goods/orderList/orderList?current=0`
- }
- setTimeout(() => {
- wx.reLaunch({
- url: failUrl
- // url: `/pages/paySuccess/paySuccess?current=0&source=${source}&order_id=${that.data.orderId}`
- })
- }, 1000)
- }
- },
- /**
- * 是否首次购买
- */
- checkFirst() {
- return new Promise((resolve, reject) => {
- if (wx.getStorageSync('agree')) {
- resolve()
- } else {
- get('api/order/check_first', {}, (res) => {
- if (res.data.order_status == 1) {
- resolve()
- } else {
- reject()
- }
- })
- }
- })
- },
- /**
- * 提交订单
- * /api/order/add
- */
- addOrder() {
- let {
- deviceData,
- timeData,
- currentChangeCoupon,
- detail,
- memberCardCurrentDiscount,
- selectCardId,
- selectProductId
- } = this.data
- let discount_type
- let that = this
- return new Promise((resolve, reject) => {
- if (memberCardCurrentDiscount == 0) {
- discount_type = 1
- } else if (currentChangeCoupon) {
- discount_type = 2
- } else {
- discount_type = 0
- }
- post(
- 'api/order/add', {
- project_id: detail.id,
- store_id: detail.store_id,
- device_id: deviceData ? deviceData.id : '',
- order_day: timeData ? timeData.order_day : '',
- order_time_id: timeData ? timeData.time_id : '',
- coupon_id: currentChangeCoupon ? currentChangeCoupon.id : '',
- discount_type,
- card_id: selectCardId,
- product_id: selectProductId,
- product_coupon_id: currentChangeCoupon ? currentChangeCoupon.id : ''
- },
- (res) => {
- console.log(res)
- that.setData({
- orderId: res.data.order_id
- })
- if (res.data.pay_status == 1) {
- that.goToOrder('支付成功')
- } else {
- resolve(res.data)
- }
- }
- )
- })
- },
- // 统一集合的地方
- onProductPay() {
- this.setData({
- payNow: true,
- switchPay: 'product',
- })
- },
- /**
- * 单独购买升级产品【下单】
- * /api/product/buy
- *
- */
- onProductPayNow() {
- let {
- selectProductId,
- projectOrderData,
- memberCardCurrentDiscount,
- currentChangeCoupon
- } = this.data
- let discount_type
- let that = this
- if (memberCardCurrentDiscount == 0) {
- discount_type = 1
- } else if (currentChangeCoupon) {
- discount_type = 2
- } else {
- discount_type = 0
- }
- this.checkFirst()
- .then(() => {
- new Promise((resolve, reject) => {
- post(
- 'api/product/buy', {
- product_id: selectProductId,
- order_id: projectOrderData.order_id,
- coupon_id: currentChangeCoupon ? currentChangeCoupon.id : '',
- discount_type
- },
- (res) => {
- console.log(res)
- that.setData({
- orderId: res.data.order_id
- })
- if (res.data.pay_status == 1) {
- that.goToOrder('支付成功')
- } else {
- that.payProductOrder(res.data.order_id)
- }
- }
- )
- })
- })
- .catch((rej) => {
- wx.navigateTo({
- url: '/pages/disclaimer/disclaimer'
- })
- })
- },
- /**
- * 用户允许消息通知
- * /api/message/agree
- */
- messageAgree(ids) {
- post(
- 'api/message/agree', {
- order_id: this.data.orderId,
- ids
- },
- () => {}
- )
- },
- /**
- * 点击打开会员卡弹框
- */
- onOpenLandscape() {
- let that = this
- if (that.data.wxParseMemberRules) {
- that.setData({
- visibleLandscape: true
- })
- return
- }
- this.getmemberRules()
- .then((memberRules) => {
- WxParse.wxParse('article', 'html', memberRules, that, 5)
- that.setData({
- visibleLandscape: true,
- wxParseMemberRules: true
- })
- })
- .catch(() => {})
- },
- /**
- * 点击关闭会员卡弹框
- */
- onCloseLandscape() {
- this.setData({
- visibleLandscape: false
- })
- },
- /**
- * 勾选会员卡
- */
- selectMemberCard(e) {
- let that = this
- this.setData({
- selectCardId: that.data.selectCardId ? 0 : e.currentTarget.dataset.id,
- memberCardCurrentDiscount: that.data.selectCardId ? -1 : 0,
- memberStatus: that.data.selectCardId ? -1 : 1,
- currentCoupon: that.data.selectCardId ? -1 : that.data.currentCoupon,
- currentChangeCoupon: that.data.selectCardId ?
- null : that.data.currentChangeCoupon
- },
- () => {
- that.calculateOrderPayMoney()
- }
- )
- },
- /**
- * 勾选升级产品
- */
- selectProjectProduct(e) {
- let {
- selectProductIndex
- } = this.data
- let productId = e.currentTarget.dataset.id
- let index = e.currentTarget.dataset.index
- this.setData({
- selectProductId: selectProductIndex == index ? 0 : productId,
- selectProductIndex: selectProductIndex == index ? -1 : index
- },
- () => {
- this.calculateOrderPayMoney()
- }
- )
- },
- /**
- * 获取指定项目的升级产品
- */
- getProjectProducts() {
- get('api/project/products', {
- project_id: this.data.detail.id
- }, (res) => {
- this.setData({
- projectProducts: res.data.list && res.data.list.length > 0 ? res.data.list : []
- })
- })
- },
- /**
- * 获取-美妆产品折扣
- */
- getGoodsDiscount() {
- let memberCardCurrentDiscount = this.data.memberCardCurrentDiscount
- get(
- 'api/goods/get_discount', {
- goods_id: this.data.detail.id
- },
- (res) => {
- this.setData({
- couponList: res.data.coupon_list, // type: 类型,1抵扣券,2满减券,3全额券
- memberCardCurrentDiscount,
- currentPayMoney: this.data.detail.price
- },
- () => {
- this.calculateOrderPayMoney()
- }
- )
- }
- )
- },
- /**
- * 获取-卡券产品折扣
- */
- getCardgoodsDiscount() {
- let memberCardCurrentDiscount = this.data.memberCardCurrentDiscount
- get(
- 'api/cardgoods/get_discount', {
- goods_id: this.data.detail.id
- },
- (res) => {
- this.setData({
- couponList: res.data.coupon_list, // type: 类型,1抵扣券,2满减券,3全额券,4卡券(效果和“全额券”一样)
- memberCardCurrentDiscount,
- currentPayMoney: this.data.detail.price
- },
- () => {
- this.calculateOrderPayMoney()
- }
- )
- }
- )
- },
- /**
- * 获取-项目升级产品的折扣信息
- */
- getProductWithProjectOrderDiscount() {
- let {
- selectProductId
- } = this.data
- get(
- 'api/product/get_discount', {
- product_id: selectProductId
- },
- (res) => {
- this.setData({
- couponList: res.data.coupon_list // type: 类型,1抵扣券,2满减券,3全额券,4卡券(效果和“全额券”一样)
- },
- () => {
- this.calculateOrderPayMoney()
- }
- )
- }
- )
- },
- /**
- * 获取会员守则
- */
- getmemberRules() {
- let memberRules = getApp().globalData.memberRules
- return new Promise((resolve, reject) => {
- if (memberRules) {
- resolve(memberRules)
- } else {
- get(
- 'api/agreement', {},
- (res) => {
- memberRules = res.data.member_rules
- memberRules = this.removeCss(memberRules)
- getApp().globalData.memberRules = memberRules
- resolve(memberRules)
- },
- () => {
- reject()
- }
- )
- }
- })
- },
- /**
- * 去除富文本图片默认样式
- */
- removeCss(content) {
- let reg = /(style|class)="[^"]+"/gi
- let img = /<img[^>]+>/gi
- let res
- if (img.test(content)) {
- res = content.match(img)
- for (let i = 0; i < res.length; i++) {
- content = content.replace(res[i], res[i].replace(reg, ''))
- }
- }
- // (/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"')
- return content.replace(/\<img/gi, '<img class="richImg" ')
- },
- /**
- * 计算汇总价格
- * memberCardCurrentDiscount 为1时会员卡可抵扣全额抵扣(项目)
- * 会员
- * 项目可以全额抵扣
- * 美妆产品、项目耗材 会员价
- *
- * @param detail 项目(美妆产品共用)
- * @param recommendMemberCard 推荐开通的会员卡
- * @param memberCardCurrentDiscount 是否可以使用会员抵扣,0使用,1不使用,-1不可选择
- * @param selectCardId 选中需要购买的会员卡ID
- * @param currentChangeCoupon 优惠券对象
- * @param productDetail 项目耗材下单时的耗材详情
- * @param projectProducts 项目下单推荐的项目耗材
- * @returns
- */
- calculateOrderPayMoney() {
- let {
- detail,
- selectCardId,
- source,
- memberStatus,
- recommendMemberCard,
- productDetail,
- memberCardCurrentDiscount,
- currentCoupon,
- currentChangeCoupon,
- projectProducts,
- selectProductIndex
- } = this.data
- let projectWithGoodsPrice = 0 // 项目价格 / 美妆产品价格 (项目是会员抵扣,美妆产品是会员价)
- let payMoney = 0 // 需要支付的价格
- let productPrice = 0 // 项目耗材价格
- let memberCardPrice = 0 // 会员卡卡费
- let couponMoney = 0 // 优惠券金额
- let memberDiscountMoney = 0 // 会员折扣金额(项目)
- let projectProductMoney = 0 // 项目下单推荐的项目耗材
- // 处理优惠券、会员卡折扣互斥逻辑(优先会员卡)
- if (memberCardCurrentDiscount == 0) {
- // 使用了会员卡折扣
- currentChangeCoupon = null
- currentCoupon = -1
- this.setData({
- currentCoupon,
- currentChangeCoupon
- })
- }
- if (currentCoupon != -1) {
- // 使用了优惠券
- memberCardCurrentDiscount = -1
- this.setData({
- memberCardCurrentDiscount
- })
- }
- // 项目耗材下单
- if (productDetail) {
- productPrice = parseFloat(productDetail.price ? productDetail.price : 0.0)
- if (productDetail.is_member) {
- productPrice = parseFloat(
- productDetail.member_price ? productDetail.member_price : 0.0
- )
- }
- }
- // 项目价格(美妆产品价格)
- projectWithGoodsPrice = detail.price ? parseFloat(detail.price) : 0
- // 已是会员 项目是会员抵扣,美妆产品是会员价
- if (memberStatus == 1 || detail.is_member == 1) {
- // 美妆产品,享受会员价
- projectWithGoodsPrice = detail.member_price ?
- parseFloat(detail.member_price) :
- 0 // 项目价格(美妆产品价格)
- // 项目下单(project) + 耗材下单且购买一个项目(product) 显示原价,是否能用会员抵扣,交给用户选择
- if (source == 'project' || source == 'product') {
- projectWithGoodsPrice = detail.price ? parseFloat(detail.price) : 0
- }
- }
- // 如果是单独购买项目耗材,不要计算项目的金额
- if (source == 'product_with_project_order') {
- projectWithGoodsPrice = 0
- }
- // 项目下单时勾选了推荐的耗材
- if (selectProductIndex != -1) {
- let selectProductItem = projectProducts[selectProductIndex]
- projectProductMoney = selectProductItem ?
- memberStatus ?
- parseFloat(selectProductItem.member_price) :
- parseFloat(selectProductItem.price) :
- 0
- }
- // 勾选了购买会员卡,计算会员卡费
- if (selectCardId) {
- memberCardPrice = recommendMemberCard.price ?
- parseFloat(recommendMemberCard.price) :
- 0
- }
- // 是否可以使用会员抵扣,0使用,1不使用,-1不可选择
- if (memberCardCurrentDiscount == 0) {
- memberDiscountMoney = projectWithGoodsPrice
- }
- // 选择了优惠券
- if (currentChangeCoupon) {
- // 类型,1抵扣券,2满减券,3全额券,4卡券(效果和“全额券”一样)
- let couponType = currentChangeCoupon.type
- couponMoney = projectWithGoodsPrice // 全额抵扣券 、 卡券
- if (couponType == 1) {
- couponMoney = currentChangeCoupon.price ?
- parseFloat(currentChangeCoupon.price) :
- 0
- } else if (couponType == 2) {
- couponMoney =
- currentChangeCoupon.full_price &&
- projectWithGoodsPrice >= parseFloat(currentChangeCoupon.full_price) ?
- parseFloat(currentChangeCoupon.price) :
- 0
- }
- }
- // 要支付的金额 = 项目(美妆产品)价格 - 优惠券金额 - 会员卡优惠金额
- payMoney = projectWithGoodsPrice - couponMoney - memberDiscountMoney
- payMoney = payMoney > 0 ? payMoney : 0
- // 项目耗材价格(项目耗材单独下单)
- payMoney = payMoney + productPrice
- payMoney = payMoney > 0 ? payMoney : 0
- // 项目耗材价格(项目下单时勾选了推荐的耗材产品)
- payMoney = payMoney + projectProductMoney
- // 会员卡卡费 (卡费不参与折扣)
- payMoney = payMoney + memberCardPrice
- payMoney = payMoney > 0 ? payMoney : 0
- this.setData({
- moneyData: {
- payMoney: String(payMoney.toFixed(2)), // 需要支付的价格
- projectWithGoodsPrice: String(projectWithGoodsPrice.toFixed(2)), // 项目价格 / 美妆产品价格
- productPrice: String(productPrice.toFixed(2)), // 项目耗材价格
- memberCardPrice: String(memberCardPrice.toFixed(2)), // 会员卡卡费
- couponMoney: String(couponMoney.toFixed(2)), // 优惠券抵扣金额
- memberDiscountMoney: String(memberDiscountMoney.toFixed(2)), // 会员折扣金额(项目)
- projectProductMoney: String(projectProductMoney.toFixed(2)) // 项目下单推荐的项目耗材
- }
- })
- return payMoney
- },
- // 次卡详情点击减少
- onReduce(e) {
- let index = e.currentTarget.dataset.index
- // 根据id获取数组下标
- let indexId = e.currentTarget.dataset.id
- let num = this.data.Ac_cardDetail[indexId].project_list[index].time
- num = num - 1
- if (num < 0) {
- num = 0
- return
- }
- let dataNum = `Ac_cardDetail[${indexId}].project_list[${index}].time`
- let total = this.data.Ac_cardDetail[indexId].total_time
- total = total + 1
- let total_time = `Ac_cardDetail[${indexId}].total_time`
- this.setData({
- [dataNum]: num,
- [total_time]: total
- })
- },
- // 次卡详情点击添加
- onLationAdd(e) {
- let index = e.currentTarget.dataset.index
- // 根据id获取数组下标
- let indexId = e.currentTarget.dataset.id
- if (this.data.Ac_cardDetail[indexId].total_time == 0) {
- return
- }
- let num = this.data.Ac_cardDetail[indexId].project_list[index].time
- num = num + 1
- let dataNum = `Ac_cardDetail[${indexId}].project_list[${index}].time`
- let total = this.data.Ac_cardDetail[indexId].total_time
- total = total - 1
- let total_time = `Ac_cardDetail[${indexId}].total_time`
- this.setData({
- [dataNum]: num
- })
- this.setData({
- [total_time]: total
- })
- },
- // 点击选择次卡分配
- selectCardRadio(e){
- let index = e.currentTarget.dataset.index
- // 根据id获取数组下标
- let indexId = e.currentTarget.dataset.id
- let data = this.data.Ac_cardDetail[indexId].project_list
- let total_time = this.data.Ac_cardDetail[indexId].total_time
- let time = this.data.Ac_cardDetail[indexId].project_list[index].time
- let sum = 0
- data.forEach(itemA=>{
- if(itemA.time==1){
- sum = sum+1
- }
- })
- if(total_time==0&&time==0){
- wx.showToast({
- title: '您已超过选择次数',
- icon:'none'
- })
- return
- }
- let total_time_select = `Ac_cardDetail[${indexId}].total_time`
- let item = `Ac_cardDetail[${indexId}].project_list[${index}].time`
- this.setData({
- [item]:this.data.Ac_cardDetail[indexId].project_list[index].time==0?1:0,
- [total_time_select]:this.data.Ac_cardDetail[indexId].project_list[index].time==0?total_time-1:total_time+1
- })
- console.log(this.data.Ac_cardDetail[indexId].project_list[index].time);
- },
- //次卡分配产品详情获取
- getCardProjectInfo() {
- get('v2/api/card/project_list', {
- id: this.data.detail.id,
- store_id: this.data.storeId
- },
- (res) => {
- console.log(res, 'product');
- // 计算总分配次数(用来判断是否判断完毕)
- let a = 0
- // 给每一个可分配数组添加一个标识(便于产品数量加减)
- res.data.group.map(item => {
- item.Idindex = a++
- item.total = item.total_time
- })
- this.setData({
- cardDetail: res.data.projects,
- card_type: res.data.type,
- Ac_cardDetail: res.data.group,
- all_cardDetail: res.data
- })
- }
- )
- },
- // 选中加购产品
- selectExchange(e) {
- let index = e.currentTarget.dataset.index
- let sum = Number(this.data.cardExchangeList[index].price) + Number(this.data.detail.price)
- let id = this.data.cardExchangeList[index].id
- this.setData({
- selectExchange: this.data.selectExchange == 0 ? 1 : 0
- })
- if(this.data.selectExchange==1){
- this.setData({
- toExchangePrice:this.data.cardExchangeList[index].price
- })
- }else{
- this.setData({
- toExchangePrice:0
- })
- }
- this.setData({
- exchangePrice: String(sum.toFixed(2)),
- cardExchangeId: id
- })
- },
- // 获取次卡可换购列表
- getCardExchangeList(storeId, id) {
- get('/v2/api/card/plus', {
- store_id: storeId,
- card_id: id
- }, (res) => {
- if (res.code == 200) {
- this.setData({
- cardExchangeList: res.data.list
- })
- }
- })
- }
- })
|