123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005 |
- // pages/confirmProjectOrder/confirmProjectOrder.js
- import {
- get,
- post
- } from '../../utils/http'
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- currentCoupon: -1,
- visible: false,
- CouPonIndex: [],
- needSelect: false,
- coupSelectType: '',
- productDiscount: '',
- isSelectCoup: [], // 选择的优惠券
- // 下面是支付的数据
- pay_methon: 1,
- payNow: false,
- switchPay: 'product',
- showMoney: 0, // 价值总额
- showRuleText: 10086,
- dotSelectCard: false,
- marks: {
- // 优惠券类型,1直接抵扣券,2满减券,3全额减免券,4卡券
- 1: '抵扣券',
- 2: '满减券',
- 3: '全额减免券',
- 4: '项目卡券'
- },
- orderDiscount: 0,
- priceSet: 0,
- cardList: [], // 我的次卡对应项目列表
- selectCodeList: [], //选择的次卡的列表
- visibleCard: false,
- card_data: [], //选择次卡的项目id
- selectCardProjectList: [], //选择次卡的项目列表
- selectCoupPrice: 0, //选择优惠券之后的价格
- discountList: [], //折扣列表
- level: '', //用户充值折扣等级 (0是未拥有等级)
- levelList: {
- 1: '0.98',
- 4: '0.95',
- 7: '0.90',
- }, //折扣列表
- levelPrice: '', //充值等级折扣优惠价格
- },
- // 获取用户充值折扣等级
- getLevel() {
- get('/v2/api/user/discount_level', {}, (res) => {
- if (res.code == 200) {
- if (res.data == 0) {
- this.setData({
- level: 0
- })
- return
- }
- let getValue = (item, val) => {
- return item[val]
- }
- this.setData({
- level: Number(getValue(this.data.levelList, res.data))
- })
- this.setData({
- tolevel: (this.data.level * 10).toFixed(1)
- })
- }
- })
- },
- clickRuleText(e) {
- let that = this
- let index = e.currentTarget.dataset.index
- if (this.data.showRuleText == index) {
- that.setData({
- showRuleText: 10086
- })
- } else {
- that.setData({
- showRuleText: index
- })
- }
- },
- /**
- * 点击使用按钮、勾选按钮
- */
- checkSelect: function (e) {
- // let index = e.currentTarget.dataset.index
- let CouPonIndex = this.data.productDiscount
- let selectIndex = e.currentTarget.dataset.index
- let project_list = this.data.orderDetails.project_list //这里是项目列表
- let project_ids = this.data.productDiscount[selectIndex].project_ids
- let _ids = 'productDiscount[' + selectIndex + '].project_ids'
- let isReturn = false
- //去掉已选择次卡的项目id
- this.data.card_data.forEach(res => {
- if (project_ids.indexOf(res.id) > -1) {
- project_ids.forEach((e, i) => {
- if (res.id == e) {
- project_ids.splice(i, 1)
- }
- })
- }
- })
- this.setData({
- _ids: project_ids
- })
- if (this.data.productDiscount[selectIndex].type != 4 && this.data.card_data.length != 0) {
- wx.showToast({
- title: '该项目已选择次卡',
- icon: 'none'
- })
- return
- }
- this.data.selectCardProjectList.forEach(res => {
- if (this.data.productDiscount[selectIndex].project_ids.indexOf(res.id) > -1) {
- wx.showToast({
- title: '该项目已选择次卡',
- icon: 'none'
- })
- isReturn = true
- }
- })
- if (isReturn) {
- return
- }
- let curreValue = !CouPonIndex[selectIndex].isSelect
- // 判断是否是不相同的项目券
- if (this.data.productDiscount[selectIndex].type != 4) {
- this.setData({
- priceSet: 0,
- showMoney: this.data.orderDetails.price
- })
- for (let i = 0; i < CouPonIndex.length; i++) {
- CouPonIndex[i].isSelect = false
- }
- for (let i = 0; i < project_list.length; i++) {
- project_list[i].cardId = ''
- }
- } else if (this.data.coupSelectType != 4) {
- for (let i = 0; i < CouPonIndex.length; i++) {
- CouPonIndex[i].isSelect = false
- }
- for (let i = 0; i < project_list.length; i++) {
- project_list[i].cardId = ''
- }
- } else {
- let numberSelect = 0
- for (let i = 0; i < CouPonIndex.length; i++) {
- if (CouPonIndex[i].isSelect) {
- numberSelect = numberSelect + 1
- }
- }
- console.log('numberSelect')
- console.log(numberSelect)
- if (numberSelect == this.data.orderDetails.project_list.length && curreValue) {
- wx.showToast({
- title: '最多选择' + this.data.orderDetails.project_list.length + '项目券!',
- icon: 'none'
- })
- return
- }
- }
- CouPonIndex[selectIndex].isSelect = curreValue
- if (!curreValue) {
- for (let j = 0; j < project_list.length; j++) {
- if (project_list[j].cardId && project_list[j].cardId == this.data.productDiscount[selectIndex].id) { // 如果是取消选择,那么也要取消绑定项目的id
- project_list[j].cardId = ''
- }
- }
- CouPonIndex[selectIndex].projectids = ''
- }
- let orderDetails1 = this.data.orderDetails
- orderDetails1.project_list = project_list
- this.setData({
- orderDetails: orderDetails1,
- productDiscount: CouPonIndex,
- coupSelectType: this.data.productDiscount[selectIndex].type
- })
- console.log(this.data.CouPonIndex)
- this.selectCoup()
- },
- // 计算总额
- calculateMoney() {
- let that = this
- let initPrice = 0
- if (this.data.selectCardProjectList.length > 0) {
- this.data.selectCardProjectList.forEach(res => {
- initPrice = Number(initPrice) + Number(res.price)
- })
- }
- console.log(initPrice, 'initPrice');
- let money = this.data.selectCardProjectList.length > 0 ? Number(this.data.orderDetails.price - initPrice) : this.data.orderDetails.price
- console.log(money, 'moneymoney');
- let isSelectCoup = this.data.isSelectCoup
- let project_list = this.data.orderDetails.project_list //这里是项目列表
- // if (isSelectCoup.length == 0) {
- // that.setData({
- // showMoney: money.toFixed(2)
- // })
- // return
- // }
- // 如果是项目
- if (isSelectCoup.length > 0) {
- if (isSelectCoup[0].type == 4) {
- let numberHaveCardId = 0
- for (let i = 0; i < project_list.length; i++) {
- if (project_list[i].cardId) {
- money = money - project_list[i].price
- numberHaveCardId = numberHaveCardId + 1
- }
- }
- } else if (isSelectCoup[0].type == 3) {
- for (let i = 0; i < project_list.length; i++) {
- money = money - project_list[i].price
- }
- } else {
- money = money - isSelectCoup[0].price
- }
- }
- /**
- * type:1项目,2设备分类,3耗材
- * discount_type:折扣条件,1数量/类型,2金额
- */
- let notSelectId = []
- this.data.isSelectCoup.forEach(item => {
- notSelectId.push(item.projectids)
- })
- //去除选择优惠券或者次卡的项目
- let _project_list = project_list.filter(res => {
- return notSelectId.toString().indexOf(res.id) && res.isCard == false
- })
- let _money = money
- console.log(money, 'money===', _money);
- let devicePrice = 0 //满足折扣设备的项目总金额
- let productPrice = 0 //耗材总金额
- //满足折扣设备的项目
- let deviceList = _project_list.filter(item => {
- return item.device_type_id == item.device_id
- })
- if (deviceList.length > 0) {
- deviceList.forEach(item => {
- devicePrice = devicePrice + Number(item.price)
- })
- }
- //拥有耗材的项目
- let productList = _project_list.filter(item => {
- return item.product_name != ""
- })
- console.log(productList, 'productList');
- if (productList.length > 0) {
- productList.forEach(item => {
- productPrice = productPrice + Number(item.product_price)
- })
- }
- let _priceSet = this.data.priceSet
- if (this.data.discountList.length > 0) {
- let discountList = this.data.discountList
- //计算所有的折扣金额
- discountList.forEach(item => {
- let priceSet = 0,
- initmoney = money,
- _initmoney = money
- if (item.type == 1 && item.discount_type == 1 && _project_list.length >= item.num) {
- initmoney = initmoney * item.discount_rate / 10
- priceSet = _initmoney - initmoney
- item["priceSet"] = priceSet
- } else if (item.type == 1 && item.discount_type == 2 && money > Number(item.amount)) {
- initmoney = initmoney * item.discount_rate / 10
- priceSet = _initmoney - initmoney
- item["priceSet"] = priceSet
- } else if (item.type == 2 && item.discount_type == 2 && devicePrice > Number(item.amount)) {
- //满足条件的项目折扣
- initmoney = (initmoney - devicePrice) + devicePrice * item.discount_rate / 10
- priceSet = _initmoney - initmoney
- item["priceSet"] = priceSet
- } else if (item.type == 3 && item.discount_type == 1 && productList.length >= item.num) {
- //满足条件的项目折扣
- initmoney = (initmoney - productPrice) + productPrice * item.discount_rate / 10
- priceSet = _initmoney - initmoney
- item["priceSet"] = priceSet
- } else if (item.type == 3 && item.discount_type == 2 && productPrice >= item.amount) {
- //满足条件的项目折扣
- initmoney = (initmoney - productPrice) + productPrice * item.discount_rate / 10
- priceSet = _initmoney - initmoney
- item["priceSet"] = priceSet
- }
- })
- console.log(discountList, 'discountList');
- //排序,最优折扣放第一位
- discountList = discountList.sort(this.compare("priceSet"))
- let discountInfo = discountList[0]
- if (discountInfo.type == 1 && discountInfo.discount_type == 1 && _project_list.length >= discountInfo.num) {
- money = money * discountInfo.discount_rate / 10
- _priceSet = _money - money
- } else if (discountInfo.type == 1 && discountInfo.discount_type == 2 && money > Number(discountInfo.amount)) {
- money = money * discountInfo.discount_rate / 10
- _priceSet = _money - money
- } else if (discountInfo.type == 2 && discountInfo.discount_type == 2 && devicePrice > Number(discountInfo.amount)) {
- //满足条件的项目折扣
- money = (money - devicePrice) + devicePrice * discountInfo.discount_rate / 10
- _priceSet = _money - money
- } else if (discountInfo.type == 3 && discountInfo.discount_type == 1 && productList.length >= discountInfo.num) {
- //满足条件的项目折扣
- money = (money - productPrice) + productPrice * discountInfo.discount_rate / 10
- _priceSet = _money - money
- } else if (discountInfo.type == 3 && discountInfo.discount_type == 2 && productPrice >= discountInfo.amount) {
- //满足条件的项目折扣
- money = (money - productPrice) + productPrice * discountInfo.discount_rate / 10
- _priceSet = _money - money
- }
- }
- console.log(_priceSet, '_priceSet');
- that.setData({
- showMoney: Number(money).toFixed(2) < 0 ? 0.00 : Number(money).toFixed(2),
- priceSet: Number(_priceSet).toFixed(2)
- })
- },
- //排序
- compare(property) {
- return function (obj1, obj2) {
- var value1 = obj1[property];
- var value2 = obj2[property];
- return value2 - value1; // 降序
- }
- },
- // 支付的操作
- onClosePay() {
- this.setData({
- payNow: false
- })
- },
- /**
- * 关闭弹框
- */
- onClose() {
- this.setData({
- visible: false
- })
- },
- // 关闭次卡弹窗
- onCloseCard() {
- this.setData({
- visibleCard: false
- })
- },
- // 点击x关闭次卡弹窗
- onCancelCard() {
- this.setData({
- visibleCard: false
- })
- },
- showCoup() {
- if (this.data.dotSelectCard) {
- wx.showToast({
- title: '本订单已使用优惠券!',
- icon: 'none'
- })
- return
- }
- this.setData({
- visible: true
- })
- },
- // 打开次卡窗口
- showCard() {
- this.setData({
- visibleCard: true,
- selectCoupPrice: this.data.showMoney
- })
- },
- // 选中次卡触发
- cardSel(e) {
- console.log(this.data.selectCardProjectList, e.currentTarget.dataset, 'e.currentTarget.dataset')
- let index = e.currentTarget.dataset.index
- let item = e.currentTarget.dataset.item
- let selList = this.data.cardList
- let isselectCard = false
- let isRepeat = false
- this.data.cardList.forEach(res => {
- if (JSON.stringify(item.project_ids) == JSON.stringify(res.project_ids) && res.isSelectCard && res.id != item.id) {
- isRepeat = true
- }
- })
- if (isRepeat) {
- wx.showToast({
- title: '不可重复选择相同次卡',
- icon: 'none'
- })
- return
- }
- this.data.orderDetails.project_list.forEach((res, i) => {
- if (res.cardId && this.data.cardList[index].project_ids.indexOf(res.id) > -1) {
- isselectCard = true
- }
- })
- if (isselectCard) {
- wx.showToast({
- title: '该项目已选择优惠券',
- icon: 'none'
- })
- return
- }
- let isProjectList = []
- //判断是否重复选择次卡
- let isTrueCode = false
- this.data.cardList.forEach(res => {
- if (res.isSelectCard) {
- isProjectList = isProjectList.concat(res.project_ids)
- }
- })
- if (e.currentTarget.dataset.item.isSelectCard) {
- e.currentTarget.dataset.item.project_ids.forEach((_item, index) => {
- isProjectList.forEach((item, i) => {
- if (_item == item) {
- isProjectList.splice(i, 1)
- }
- })
- })
- }
- if (this.includes(isProjectList, e.currentTarget.dataset.item.project_ids)) {
- isTrueCode = true
- }
- if (isTrueCode) {
- wx.showToast({
- title: '请勿重复选择次卡',
- icon: 'none'
- })
- return
- }
- console.log(isProjectList, 'isProjectList');
- let selValue = !selList[index].isSelectCard
- selList[index].isSelectCard = selValue
- this.setData({
- cardList: selList
- })
- },
- includes(arr1, arr2) {
- return arr2.every(val => arr1.includes(val));
- },
- onConfirmCard() {
- let price = this.data.orderDetails.price //订单价格
- let card_data = []
- let card_data_info = {}
- let selectCodeList = []
- let selectCardProjectList = []
- //选择次卡&价格计算
- let projectId = []
- this.data.orderDetails.project_list.forEach((res, i) => {
- if (res.cardId) {
- price = price - res.price
- }
- this.data.cardList.forEach(item => {
- //如果已选择优惠券
- console.log(res.cardId, 'cardId.length', item.isSelectCard);
- if (item.project_ids.indexOf(res.id) > -1 && projectId.indexOf(res.id) == -1 && item.isSelectCard) {
- projectId.push(res.id)
- price = price - res.price
- price = price < 0 ? 0 : price
- selectCardProjectList.push(res)
- selectCardProjectList = Array.from(new Set(selectCardProjectList))
- selectCodeList.push(item)
- card_data_info = {
- id: res.id,
- card_id: item.id
- }
- card_data.push(card_data_info)
- let _item = 'orderDetails.project_list[' + i + '].isCard'
- this.setData({
- [_item]: true
- })
- }
- })
- })
- let priceSet = 0
- if (selectCodeList.length == 0 && this.data.discountList.length > 0) {
- priceSet = this.data.discountList[0].priceSet.toFixed(2)
- price = this.data.orderDetails.price - priceSet
- }
- this.setData({
- card_data: card_data,
- showMoney: price,
- visibleCard: false,
- selectCodeList: selectCodeList,
- selectCardProjectList: selectCardProjectList,
- priceSet: priceSet
- })
- this.calculateMoney() //计算总额
- },
- onCancelCoupon() {
- this.setData({
- visible: false
- })
- },
- onConfirmCoupon() {
- // let currentChangeCoupon = this.data.couponList[this.data.currentCoupon]
- this.setData({
- visible: false,
- // currentChangeCoupon
- },
- () => {
- // this.calculateOrderPayMoney()
- }
- )
- },
- selectCoup() {
- let that = this
- let isSelectCoups = []
- for (let i = 0; i < this.data.productDiscount.length; i++) {
- if (this.data.productDiscount[i].isSelect) {
- let selectCoup = that.data.productDiscount[i]
- isSelectCoups.push(selectCoup)
- }
- }
- this.setData({
- isSelectCoup: isSelectCoups
- })
- console.log(isSelectCoups)
- that.theMoneyBest()
- },
- /**
- * 获取订单详情
- */
- getOrderData() {
- let that = this
- get('v2/api/order/info', {
- id: this.data.orderDetailsId
- }, (res) => {
- res.data.project_list.forEach(item => {
- item.isCard = false
- })
- if (res.data.discount != 0) {
- let newsPrice = res.data.price
- res.data.price = newsPrice * 1 + res.data.discount_price * 1
- this.setData({
- dotSelectCard: true,
- orderDetails: res.data,
- showMoney: newsPrice,
- priceSet: res.data.discount_price
- }, )
- return
- }
- if (res.data.coupon_list.length > 0) {
- res.data.coupon_list[0].type = 0
- }
- this.setData({
- orderDetails: res.data,
- showMoney: res.data.price,
- isSelectCoup: res.data.coupon_list,
- dotSelectCard: res.data.coupon_list.length !== 0 ? true : false,
- }, )
- that.productDiscount()
- if (res.data.type == "one") {
- return
- }
- that.orderDiscount()
- })
- },
- // 这里是立即支付的接口
- // v2/api/order/pay
- payNow: function () {
- // 计算折扣
- this.setData({
- levelPrice: (this.data.showMoney * this.data.level).toFixed(2)
- })
- this.setData({
- toLevelPrice: (this.data.showMoney - this.data.levelPrice).toFixed(2)
- })
- this.setData({
- payNow: true,
- })
- },
- // 活动折扣类型,非必填,0无折扣(默认),50新人五折活动,100仪器免费使用权益
- paybtm() {
- let isSelectCoup = this.data.isSelectCoup
- let coupType = isSelectCoup.length > 0 ? isSelectCoup[0].type : 5
- let coupData = []
- // 卡券,项目券数据包,id:订单项目ID,coupon_id:优惠券ID,如:[{"id":1220,coupon_id:199}]
- // 支付方式,amount余额支付,weixin微信支付
- if (coupType == 4) {
- for (let i = 0; i < isSelectCoup.length; i++) {
- let notData = {
- id: isSelectCoup[i].projectids,
- coupon_id: isSelectCoup[i].id,
- }
- coupData.push(notData)
- }
- }
- let dataTo = {
- id: this.data.orderDetails.id,
- pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
- }
- if (coupType == 4) {
- dataTo.coupon_data = JSON.stringify(coupData)
- } else if (coupType != 5) {
- dataTo.coupon_id = isSelectCoup[0].id
- }
- if (this.data.card_data.length != 0) {
- dataTo.card_data = JSON.stringify(this.data.card_data)
- }
- if (this.data.priceSet != 0 && !this.data.dotSelectCard && this.data.card_data.length == 0) {
- dataTo.discount = this.data.orderDiscount
- }
- let that = this
- console.log(dataTo)
- post('v2/api/order/pay', dataTo, (res) => {
- that.setData({
- payNow: false
- })
- if (res.data.pay_status == 1) {
- // wx.showToast({
- // title: '支付成功!',
- // icon: "none"
- // })
- that.payOkey()
- return
- }
- if (that.data.pay_methon == 2) {
- // wx.showToast({
- // title: '支付成功!',
- // icon: "none"
- // })
- that.payOkey()
- 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') {
- // wx.showToast({
- // title: '支付成功!',
- // icon: "none"
- // })
- that.payOkey()
- }
- },
- fail(res) {
- this.orderDiscount()
- this.getOrderData()
- wx.showToast({
- title: '支付失败!',
- icon: "none"
- })
- }
- })
- })
- },
- payOkey() {
- wx.showToast({
- title: '支付成功!',
- icon: "none"
- })
- let that = this
- setTimeout(function () {
- that.toDetails()
- }, 1000); //延迟时间 这里是1秒
- },
- toDetails() {
- wx.redirectTo({
- url: '/pages/orderDetailsProject/orderDetailsProject?id=' + this.data.orderDetails.id,
- })
- },
- pay_methonw() {
- this.setData({
- pay_methon: 1
- })
- },
- pay_methonc() {
- this.setData({
- pay_methon: 2
- })
- },
- //
- // 卡券,项目券数据包,id:订单项目ID,coupon_id:优惠券ID,如:[{"id":1220,coupon_id:199}]
- theMoneyBest() {
- let that = this
- let project_list = this.data.orderDetails.project_list //这里是项目列表
- let isSelectCoup = this.data.isSelectCoup //这里选择了的卡券列表
- let selectProjectList = [] // 适合的卡券列表
- // let CouPonIndex = this.data.CouPonIndex // 卡券选择的Id
- let productDiscount = this.data.productDiscount // 卡券列表
- console.log(productDiscount)
- if (isSelectCoup.length == 0) {
- this.setData({
- priceSet: 0,
- showMoney: this.data.orderDetails.price
- })
- that.onShowPrice()
- return
- }
- // debugger
- if (isSelectCoup[0].type == 4) {
- for (let i = 0; i < isSelectCoup.length; i++) { // 首先遍历卡券
- if (!isSelectCoup[i].projectids) { // 如果卡券没绑定项目
- console.log('没绑定过!')
- let selectIndexMoney = 0 // 初始值
- let selectIndex = 111 // 初始金额
- for (let j = 0; j < project_list.length; j++) { // 遍历项目
- if (isSelectCoup[i].project_ids.indexOf(project_list[j].id) != -1 && !project_list[j].cardId) { // 如果卡券能够使用这个项目并且这个项目没有被绑定过
- console.log('project_list[j].price')
- console.log(project_list[j].price)
- console.log(selectIndexMoney)
- console.log(project_list[j].price > selectIndexMoney)
- if (project_list[j].price * 1 > selectIndexMoney * 1) {
- selectIndex = j
- selectIndexMoney = project_list[j].price
- console.log('--' + selectIndexMoney)
- }
- // selectProjectList.push(project_list[i])
- }
- }
- if (selectIndex != 111) {
- isSelectCoup[i].projectids = project_list[selectIndex].id
- isSelectCoup[i].projectName = project_list[selectIndex].name
- project_list[selectIndex].cardId = isSelectCoup[i].id
- } else {
- for (let k = 0; k < productDiscount.length; k++) {
- if (productDiscount[k].id == isSelectCoup[i].id) {
- // isSelectCoup.
- productDiscount[k].isSelect = false
- // isSelectCoup.splice(isSelectCoup.length-1,1);
- wx.showToast({
- title: '没有适合的项目!',
- icon: "none"
- })
- }
- }
- }
- if (selectIndex == 111) {
- isSelectCoup.splice(isSelectCoup.length - 1, 1);
- }
- }
- }
- let orderDetails1 = this.data.orderDetails
- orderDetails1.project_list = project_list
- this.setData({
- // CouPonIndex: CouPonIndex,
- productDiscount: productDiscount,
- isSelectCoup: isSelectCoup,
- orderDetails: orderDetails1,
- })
- }
- this.calculateMoney() //计算总额
- },
- /**
- * 获取订单详情
- */
- productDiscount() {
- let that = this
- let ids = ''
- // for (let i = 0; i < this.data.orderDetails.project_list.length; i++) {
- // ids = ids + ',' + this.data.orderDetails.project_list[i].id
- // }
- let storeData = getApp().globalData.storeData
- let storeId = storeData.id || wx.getStorageSync('store_id')
- get('v2/api/order/coupon', {
- id: this.data.orderDetails.id,
- store_id: storeId,
- page: 1,
- limit: 200,
- }, (res) => {
- let showLine = res.data.list
- let CouPonIndex = []
- for (let i = 0; i < showLine.length; i++) {
- if (showLine[i].full_price * 1 < that.data.orderDetails.price * 1 || showLine[i].full_price * 1 == that.data.orderDetails.price * 1) {
- showLine[i].isSelect = false
- CouPonIndex.push(showLine[i])
- }
- }
- this.setData({
- productDiscount: CouPonIndex,
- // CouPonIndex: CouPonIndex
- }, )
- })
- },
- /**
- * 获取当前用户折扣
- */
- orderDiscount() {
- get('/v3/api/order/discount', {
- id: this.data.orderDetailsId
- }, (res) => {
- this.setData({
- discountList: res.data.list
- }, )
- this.onShowPrice()
- })
- },
- // 计算折扣价格
- onShowPrice() {
- if (this.data.discountList.length == 0) {
- return
- }
- this.calculateMoney()
- // let money = Number(this.data.orderDetails.price) * Number(this.data.discountList[0].discount_rate) / 10
- // this.setData({
- // priceSet: (Number(this.data.orderDetails.price) - money).toFixed(2),
- // showMoney: money.toFixed(2)
- // })
- // orderDiscount
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- // 获取用户折扣等级
- this.getLevel()
- if (options.q) {
- let conUrlAll = decodeURIComponent(options.q)
- this.setData({
- orderDetailsId: conUrlAll.replace('https://test-img.ijolijoli.com/wxmini/pay?id=', '')
- })
- } else {
- this.setData({
- orderDetailsId: options.id
- })
- }
- this.getOrderData()
- // 获取项目可用的次卡列表
- this.getAvaCardList()
- let lat1 = app.address.latitude
- let lng1 = app.address.longitude
- this.setData({
- lat1: lat1,
- lng1: lng1,
- })
- },
- onCopy: function (e) {
- let content = e.currentTarget.dataset.no
- var that = this;
- wx.setClipboardData({
- data: content,
- success: function (res) {
- wx.showToast({
- title: '复制成功!',
- icon: "none"
- })
- }
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getAmount()
- },
- /**
- * 获取我的储值
- * api/user
- */
- getAmount() {
- get('api/user/amount', {}, (res) => {
- if (res.data) {
- this.setData({
- inserllAmount: res.data.amount
- })
- }
- })
- },
- // 获取项目可用的次卡列表
- getAvaCardList() {
- console.log(this, 'shit')
- get('v2/api/order/card', {
- page: 1,
- limit: 200,
- id: this.data.orderDetailsId
- }, (res) => {
- console.log(res, 'getAvaCardList')
- res.data.list.forEach((item) => {
- item.isSelectCard = false
- })
- this.setData({
- cardList: res.data.list,
- })
- }, (error) => {
- console.log("请求失败", error)
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|