1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558 |
- var util = require('../../utils/util.js');
- var user = require('../../utils/user.js');
- var api = require('../../config/api.js');
- var check = require('../../utils/check.js');
- var app = getApp();
- Page({
- data: {
- traceId: '', //视频号的traceid
- requireOrder: 0, //视频号 是否需要推单,1:需要,0:不需要
- increaseSumPrice: 0,
- isRecommend: false,
- isNoMatch: true,
- codeShow: false,
- recCode: '',
- recommendTips: '',
- memberDiscount: '',
- isMember: false,
- orderId: '',
- payFailShow: false,
- choosePopup: false,
- noSerTimes: '',
- popupType: 1, //1单次预约 2 选择服务频次 3选择首次预约时间
- // timeList: check.getTimeList(1),
- timeList: [],
- // dateList: util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24 * 0), 1, 21),
- dateList: [],
- // firstAppointList:util.getDateList(new Date(new Date().getTime()+60*60*1000*24),7),
- firstAppointList: [],
- timeIndex: '', //选中的时间段
- dateIndex: 0, //单次预约选中的日期
- firstDateIndex: 0, //首次预约时间
- activeTab: 1, //频次
- weekIndex: 0, //选中的周几
- weekArrList: [{
- id: 1,
- week: '周一',
- num: 0
- },
- {
- id: 2,
- week: '周二',
- num: 0
- },
- {
- id: 3,
- week: '周三',
- num: 0
- },
- {
- id: 4,
- week: '周四',
- num: 0
- },
- {
- id: 5,
- week: '周五',
- num: 0
- },
- {
- id: 6,
- week: '周六',
- num: 0
- },
- {
- id: 0,
- week: '周日',
- num: 0
- },
- ],
- selectedWeekList: [],
- selectedDateList: [],
- selectTimeIndex: 'null', //选中的时间段
- oneTimeAppoint: '2021-04-22 周一 13:00-14:00',
- isNeedAppoint: false, //是否需要预约
- isFinishAppoint: false, //已选择预约
- isOneAppoint: true, //单次卡
- appointFailTip: false, //预约失败提示
- bookStartDate: '', //可预约时间段
- bookEndDate: '',
- multiIndex: [0, 0, 0, 0, 0, 0],
- multiArray: [],
- array: [],
- year: "",
- month: "",
- day: "",
- startHour: "",
- endHour: "",
- orderData: "", //此时间为预计上门时间
- checkedGoodsList: [],
- checkedAddress: {},
- availableCouponLength: 0, // 可用的优惠券数量
- goodsTotalPrice: 0.00, //商品总价
- freightPrice: 0.00, //快递费
- couponPrice: 0.00, //优惠券的价格
- grouponPrice: 0.00, //团购优惠价格
- orderTotalPrice: 0.00, //订单总价
- actualPrice: 0.00, //实际需要支付的总价
- cartId: 0,
- addressId: 0,
- addressMsg: '',
- couponId: 0,
- userCouponId: 0,
- message: '',
- grouponLinkId: 0, //参与的团购
- grouponRulesId: 0, //团购规则ID
- nurseId: 0, //安心包认证id
- petinfo: null, //宠物保险内容
- shareId: 0,
- userInfo: {},
- remarkDisable: false,
- fraId: '', //加盟商id
- rId: '', //阿姨推荐码
- channelId: 5, //渠道id
- goodsType: 1, //商品类型 如果是6 可以不填写预约时间,
- serviceDuration: '',
- noonType: 1,
- selectTimeValue: '',
- date: '',
- week: '',
- time: '',
- selectweek: '一周一次',
- weekday: '周一',
- selecttime: ''
- },
- //获取checkou信息
- getCheckoutInfo: function (appType) {
- let that = this;
- util.request(api.CartCheckout, {
- cartId: that.data.cartId,
- addressId: that.data.addressId,
- couponId: that.data.couponId,
- userCouponId: that.data.userCouponId,
- grouponRulesId: that.data.grouponRulesId,
- shareId: that.data.shareId,
- }).then(function (res) {
- if (res.errno === 0) {
- that.setData({
- isRecommend: res.data.checkedGoodsList[0].goods.attribute != 1,
- isMember: res.data.isMember,
- memberDiscount: res.data.memberDiscount,
- checkedGoodsList: res.data.checkedGoodsList,
- checkedAddress: res.data.checkedAddress,
- availableCouponLength: res.data.availableCouponLength,
- actualPrice: res.data.actualPrice,
- couponPrice: res.data.couponPrice,
- grouponPrice: res.data.grouponPrice,
- freightPrice: res.data.freightPrice,
- goodsTotalPrice: res.data.goodsTotalPrice,
- orderTotalPrice: res.data.orderTotalPrice,
- addressId: res.data.addressId,
- addressMsg: res.data.addressMsg,
- couponId: res.data.couponId,
- userCouponId: res.data.userCouponId,
- grouponRulesId: res.data.grouponRulesId,
- isNeedAppoint: appType == "1" ? true : false, //0需要预约 服务类商品,1保险 2中介 3买约分离次卡res.data.checkedGoodsList[0].goods.type === 0 ||
- isOneAppoint: res.data.checkedGoodsList[0].product.serviceTimes == 1 ? true : false, //1为单次,其余为多次
- popupType: res.data.checkedGoodsList[0].product.serviceTimes == 1 ? 1 : 2,
- bookStartDate: res.data.bookStartDate,
- bookEndDate: res.data.bookEndDate,
- goodsType: res.data.goodsType,
- increaseSumPrice: res.data.increaseSumPrice,
- serviceDuration: res.data.serviceDuration
- });
- let serviceDuration = res.data.checkedGoodsList[0].product.serviceDuration;
- if (that.data.popupType == 2) {
- let timeList = [];
- if (res.data.timeRange != null && res.data.timeRange.length > 0) {
- res.data.timeRange.forEach((time, index) => {
- timeList.push({
- id: index + 1,
- time: time
- })
- })
- } else
- timeList = check.getTimeList(serviceDuration);
- that.setData({
- timeList: timeList
- });
- }
- if (res.data.addressId == null && res.data.addressMsg != null) {
- wx.showToast({
- title: res.data.addressMsg,
- icon: 'none'
- })
- }
- // that.LimitCanAppointmentDate();
- }
- wx.hideLoading();
- });
- },
- LimitCanAppointmentDate() { //特殊商品 如果需要限制可预约的时间范围 在次方法中实现
- if (this.data.checkedGoodsList[0].goodsId == 1190332) {
- let dates = [];
- this.data.dateList.forEach(item => {
- if (item.date < '2022-04-01')
- dates.push(item);
- })
- this.setData({
- dateList: dates
- })
- }
- //控制可预约时间范围
- let that = this;
- if (that.data.bookStartDate) {
- let dates = [];
- let dateIndex = -1;
- that.data.dateList.forEach((item, index) => {
- if (item.date < that.data.bookStartDate || item.date > that.data.bookEndDate) {
- item.isBook = false;
- item.mark = "不可约";
- } else {
- //设置第一个可预约的时间index
- if (dateIndex < 0) dateIndex = index;
- }
- dates.push(item);
- })
- that.setData({
- dateList: dates,
- dateIndex: dateIndex
- })
- }
- console.info(that.data.dateList)
- console.info(that.data.dateIndex)
- //设置默认起始可预约 index:dateIndex 近7天如果有周六 周日 不允许预约
- //存在一种情况 如果今天是周四,如果起始index=2 则周日允许预约 虽然页面显示为”约满"
- // if(this.data.dateList[3].id==0) {
- // console.info(" dateIndex:4")
- // this.setData({
- // dateIndex:4
- // })
- // }else{
- // if(this.data.dateList[2].id==0) {
- // console.info(" dateIndex:3")
- // this.setData({
- // dateIndex:3
- // })
- // }
- // }
- },
- selectAddress() {
- wx.navigateTo({
- url: '/pages/ucenter/address/address',
- })
- },
- selectCoupon() {
- wx.navigateTo({
- url: '/pages/ucenter/couponSelect/couponSelect',
- })
- },
- bindMessageInput: function (e) {
- this.setData({
- message: e.detail.value
- });
- },
- bindCodeInput: function (e) {
- this.setData({
- recCode: e.detail.value
- });
- if (e.detail.value.length == 5) {
- // 校验服务者真实性
- this.recCodeCheck();
- // this.setData({
- // codeShow:true
- // })
- } else {
- this.setData({
- codeShow: false
- });
- }
- },
- recCodeCheck() {
- wx.showLoading({
- title: '加载中',
- });
- util.request(api.checkRecommend, {
- recCode: this.data.recCode
- }, "GET")
- .then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- if (res.data) {
- this.setData({
- codeShow: true,
- isNoMatch: false,
- recommendTips: '推荐人:' + res.data
- });
- } else {
- this.setData({
- codeShow: true,
- isNoMatch: true,
- recommendTips: '未匹配到推荐者,请您和推荐人核对'
- });
- }
- } else {
- this.setData({
- codeShow: false,
- });
- wx.showToast({
- title: res.errmsg,
- icon: 'none',
- duration: 2000
- });
- }
- }).catch(function (err) {
- wx.hideLoading();
- this.setData({
- codeShow: false,
- });
- wx.showToast({
- title: err.errMsg,
- icon: 'none'
- })
- });
- },
- onReady: function () {
- // 页面渲染完成
- },
- onShow: function () {
- // console.log(this.data.dateList);
- // 页面显示
- user.checkLogin().then(res => {
- app.globalData.hasLogin = true;
- console.info("session 未过期")
- }).catch(() => {
- console.info("session 过期")
- app.globalData.hasLogin = false;
- wx.navigateTo({
- url: '/pages/auth/login/login',
- })
- });
- wx.showLoading({
- title: '加载中...',
- });
- try {
- var cartId = wx.getStorageSync('cartId');
- if (cartId === "") {
- cartId = 0;
- }
- var addressId = wx.getStorageSync('addressId');
- if (addressId === "") {
- addressId = 0;
- } else if (typeof addressId === 'number') {} else if ((typeof addressId === 'string' && addressId.indexOf("{") !== -1) || addressId.length > 20) {
- addressId = JSON.parse(addressId).id;
- }
- var couponId = wx.getStorageSync('couponId');
- if (couponId === "") {
- couponId = 0;
- }
- var userCouponId = wx.getStorageSync('userCouponId');
- if (userCouponId === "") {
- userCouponId = 0;
- }
- var grouponRulesId = wx.getStorageSync('grouponRulesId');
- if (grouponRulesId === "") {
- grouponRulesId = 0;
- }
- var grouponLinkId = wx.getStorageSync('grouponLinkId');
- if (grouponLinkId === "") {
- grouponLinkId = 0;
- }
- //客户点选的预约动作
- var appType = wx.getStorageSync('appType');
- console.info(appType)
- this.setData({
- cartId: cartId,
- addressId: addressId,
- couponId: couponId,
- userCouponId: userCouponId,
- grouponRulesId: grouponRulesId,
- grouponLinkId: grouponLinkId
- });
- this.getCheckoutInfo(appType);
- } catch (e) {
- // Do something when catch error
- console.log(e);
- }
- },
- onHide: function () {
- // 页面隐藏
- },
- onUnload: function () {
- // 页面关闭
- //清空宠物保险的缓存数据
- console.info('checkout onload')
- //wx.setStorageSync('petinfo'+this.data.cartId, null);
- },
- submitOrder: function () {
- let that = this;
- if (that.data.addressId <= 0) {
- //所选地址无服务门店,或选择其他地址
- let errmsg = that.data.addressMsg == '' ? '请选择收货地址' : that.data.addressMsg;
- //util.showErrorToast(errmsg);
- wx.showModal({
- title: '提示',
- content: errmsg,
- showCancel: false,
- });
- return;
- }
- // 检查是否已经预约
- if (that.data.goodsType != 6 && that.data.goodsType != 4 && that.data.isNeedAppoint && !that.data.isFinishAppoint) {
- // util.showErrorToast('请先预约服务时间');
- wx.showToast({
- title: '请先预约服务时间',
- icon: 'none',
- duration: 2000
- });
- return;
- }
- wx.showLoading({
- title: '检测中',
- });
- that.submitInfo();
- },
- submitInfo() {
- // 如果是多次卡先预估,单次卡不用预估
- if (!this.data.isOneAppoint) {
- let weeks = [];
- this.data.selectedDateList.forEach(item => {
- let obj = {
- dayOfWeek: this.data.weekArrList[item.week].id,
- startTime: item.time.split('-')[0],
- endTime: item.time.split('-')[1]
- };
- weeks.push(obj);
- });
- let tempStartDate = null;
- if (this.data.firstAppointList.length != 0 && this.data.firstAppointList.length >= this.data.firstDateIndex) {
- tempStartDate = this.data.firstAppointList[this.data.firstDateIndex].date;
- }
- let params = {
- weeks: weeks,
- type: this.data.activeTab,
- startDate: tempStartDate, //this.data.firstAppointList[this.data.firstDateIndex].date,
- lng: this.data.checkedAddress.lng,
- lat: this.data.checkedAddress.lat,
- shopId: this.data.checkedAddress.shopId,
- goodId: this.data.checkedGoodsList[0].goodsId
- };
- console.log(params);
- this.orderPay(params);
- } else {
- let weeks = [];
- if (this.data.isNeedAppoint && this.data.goodsType != 6 && this.data.goodsType != 4) {
- weeks = [{
- dayOfWeek: (new Date(this.data.dateList[this.data.dateIndex].bookdate)).getDay(),
- startTime: this.data.timeList[this.data.timeIndex].begin,
- endTime: this.data.timeList[this.data.timeIndex].end
- }];
- }
- let params = {
- weeks: weeks,
- type: 0,
- startDate: this.data.isNeedAppoint ? this.data.dateList[this.data.dateIndex].bookdate : null,
- lng: this.data.checkedAddress.lng,
- lat: this.data.checkedAddress.lat,
- shopId: this.data.checkedAddress.shopId,
- goodId: this.data.checkedGoodsList[0].goodsId
- };
- console.log(params);
- this.orderPay(params);
- }
- },
- orderPay(orderData) {
- let that = this;
- var orderInfo = {
- cartId: this.data.cartId,
- addressId: this.data.addressId,
- couponId: this.data.couponId,
- userCouponId: this.data.userCouponId,
- message: this.data.message,
- orderDate: this.data.orderData,
- grouponRulesId: this.data.grouponRulesId,
- grouponLinkId: this.data.grouponLinkId,
- nurseId: this.data.nurseId,
- petinfo: this.data.petinfo,
- shareId: this.data.shareId,
- recCode: this.data.recCode ? this.data.recCode : this.data.rId, //服务者推荐id(如果填写推荐码 以填写为准)
- fraId: this.data.fraId, //加盟商id
- channelId: this.data.channelId, //渠道码
- //预约参数信息
- orderDate: orderData,
- requireOrder: this.data.requireOrder,
- traceId: this.data.traceId //视频号
- };
- if (this.data.codeShow && !this.data.isNoMatch) {
- orderInfo.recCode = this.data.recCode;
- }
- console.log(orderInfo);
- util.request(api.OrderSubmit, orderInfo, 'POST').then(res => {
- //视频号,校验 wx.checkBeforeAddOrder
- wx.checkBeforeAddOrder({
- success(res) {
- console.log("checkBeforeAddOrder-success:", res);
- if (res.data.errcode == 0) {
- that.setData({
- traceId: res.data.traceId,
- requireOrder: res.data.requireOrder
- })
- }
- },
- fail(res) {
- console.log("checkBeforeAddOrder-fail:", res);
- }
- })
- if (res.errno === 0) {
- console.log(res.data.isNeedPay);
- if (res.data.isNeedPay == false) {
- console.log("跳过支付");
- util.redirect('/pages/ucenter/order/order');
- return;
- }
- // 下单成功,重置couponId
- wx.setStorageSync('couponId', 0);
- const orderId = res.data.orderId;
- this.setData({
- orderId: orderId
- });
- const grouponLinkId = res.data.grouponLinkId;
- util.request(api.OrderPrepay, {
- orderId: orderId
- }, 'POST').then(res => {
- if (res.errno === 0) {
- const payParam = res.data;
- console.log("支付过程开始");
- if (this.data.requireOrder == 1) {
- //视频号支付
- wx.requestOrderPayment({
- 'timeStamp': payParam.timeStamp,
- 'nonceStr': payParam.nonceStr,
- 'package': payParam.packageValue,
- 'signType': payParam.signType,
- 'paySign': payParam.paySign,
- 'success': res => {
- console.log("支付过程成功");
- if (grouponLinkId) {
- setTimeout(() => {
- wx.redirectTo({
- url: '/pages/groupon/grouponDetail/grouponDetail?id=' + grouponLinkId
- })
- }, 1000);
- } else {
- wx.redirectTo({
- url: '/pages/checkout/payResult/payResult?status=1&orderId=' + orderId + '&actualPrice=' + this.data.actualPrice
- });
- }
- },
- 'fail': res => {
- console.log("支付过程失败");
- // wx.redirectTo({
- // url: '/pages/checkout/payResult/payResult?status=0&orderId=' + orderId
- // });
- // 弹出支付失败
- this.setData({
- payFailShow: true,
- remarkDisable: true
- });
- },
- 'complete': function (res) {
- console.log("支付过程结束")
- }
- });
- } else {
- wx.requestPayment({
- 'timeStamp': payParam.timeStamp,
- 'nonceStr': payParam.nonceStr,
- 'package': payParam.packageValue,
- 'signType': payParam.signType,
- 'paySign': payParam.paySign,
- 'success': res => {
- console.log("支付过程成功");
- if (grouponLinkId) {
- setTimeout(() => {
- wx.redirectTo({
- url: '/pages/groupon/grouponDetail/grouponDetail?id=' + grouponLinkId
- })
- }, 1000);
- } else {
- wx.redirectTo({
- url: '/pages/checkout/payResult/payResult?status=1&orderId=' + orderId + '&actualPrice=' + this.data.actualPrice
- });
- }
- },
- 'fail': res => {
- console.log("支付过程失败");
- // 弹出支付失败
- this.setData({
- payFailShow: true,
- remarkDisable: true
- });
- },
- 'complete': function (res) {
- console.log("支付过程结束")
- }
- });
- }
- } else {
- // 弹出支付失败
- this.setData({
- payFailShow: true,
- remarkDisable: true
- });
- }
- });
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- });
- },
- surplusMonth: function (year) {
- var date = new Date();
- var year2 = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- var hour = date.getHours()
- var minute = date.getMinutes()
- var second = date.getSeconds()
- var monthDatas = [];
- if (year == year2) {
- var surplusMonth = 12 - month;
- monthDatas.push(month + "月")
- for (var i = month; i < 12; i++) {
- monthDatas.push(i + 1 + "月")
- }
- } else {
- for (var i = 0; i < 12; i++) {
- monthDatas.push(i + 1 + "月")
- }
- }
- return monthDatas;
- },
- //天数计算
- surplusDay: function (year, month, day) {
- var days = 31;
- var dayDatas = [];
- var date = new Date();
- var year2 = date.getFullYear()
- var month2 = date.getMonth() + 1
- switch (parseInt(month)) {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- days = 31;
- break;
- //对于2月份需要判断是否为闰年
- case 2:
- if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
- days = 29;
- break;
- } else {
- days = 28;
- break;
- }
- case 4:
- case 6:
- case 9:
- case 11:
- days = 30;
- break;
- }
- if (year == year2 && month == month2) {
- // dayDatas.push(day + "日")
- for (var i = day; i < days; i++) {
- dayDatas.push(i + 1 + "日")
- }
- } else {
- console.log(month + "月" + days + "天")
- for (var i = 0; i < days; i++) {
- dayDatas.push(i + 1 + "日")
- }
- }
- return dayDatas;
- },
- //时间计算
- surplusHour: function (year, month, day, hour) {
- var date = new Date();
- var year2 = date.getFullYear()
- var month2 = date.getMonth() + 1
- var day2 = date.getDate();
- var hourEnd = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21];
- var hours = [
- ['09时', '10时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时'],
- ['10时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时', '21时']
- ];
- return hours;
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- userInfo: app.globalData.userInfo
- });
- let that = this;
- if (options.nurseId) {
- this.setData({
- nurseId: options.nurseId
- })
- }
- var rId = wx.getStorageSync('rId');
- if (rId) {
- this.setData({
- rId: rId,
- recCode: rId
- })
- }
- var fraId = wx.getStorageSync('fraId');
- if (fraId) {
- this.setData({
- fraId: fraId
- })
- }
- var channelId = wx.getStorageSync('channelId');
- if (channelId) {
- this.setData({
- channelId: parseInt(channelId)
- })
- }
- if (typeof options.shareId != 'undefined' && options.shareId > 0) {
- that.setData({
- shareId: options.shareId
- })
- }
- //视频号,校验 wx.checkBeforeAddOrder
- wx.checkBeforeAddOrder({
- success(res) {
- console.log("checkBeforeAddOrder-success:", res);
- if (res.data.errcode == 0) {
- that.setData({
- traceId: res.data.traceId,
- requireOrder: res.data.requireOrder
- })
- }
- },
- fail(res) {
- console.log("checkBeforeAddOrder-fail:", res);
- }
- })
- var date = new Date();
- var year = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- var hour = date.getHours()
- var surplusMonth = that.surplusMonth(year);
- console.log(surplusMonth)
- var surplusDay = this.surplusDay(year, month, day);
- console.log(surplusDay)
- var surplusHour = this.surplusHour(year, month, day, hour)
- console.log(surplusHour)
- //初始化picker
- that.setData({
- multiArray: [
- [year + '年', (year + 1) + '年', (year + 2) + '年'],
- surplusMonth,
- surplusDay,
- surplusHour[0],
- ['~'],
- surplusHour[1]
- ],
- year: year,
- month: month,
- day: day,
- startHour: surplusHour[0][0],
- endHour: surplusHour[1][0],
- })
- },
- varietiesChange: function (e) {
- var Varieties = this.data.array[parseInt(e.detail.value)]
- console.log(Varieties)
- this.setData({
- Varieties: Varieties
- })
- },
- warehouseChange: function (e) {
- var Warehouse = this.data.array[parseInt(e.detail.value)]
- console.log(Warehouse)
- this.setData({
- Warehouse: Warehouse
- })
- },
- //某一列的值改变时触发
- bindMultiPickerColumnChange: function (e) {
- var date = new Date();
- var year1 = date.getFullYear()
- var month1 = date.getMonth() + 1
- var day1 = date.getDate()
- var hour1 = date.getHours()
- console.log("当前月份" + this.data.month + '修改的列为', e.detail.column, ',值为', e.detail.value);
- var data = {
- multiArray: this.data.multiArray,
- multiIndex: this.data.multiIndex,
- year: this.data.year,
- month: this.data.month,
- day: this.data.day,
- startHour: this.data.startHour,
- endHour: this.data.startHour,
- };
- data.multiIndex[e.detail.column] = e.detail.value;
- switch (e.detail.column) {
- case 0:
- var yearStr = data.multiArray[e.detail.column][e.detail.value];
- var year = yearStr.substring(0, yearStr.length - 1)
- data.year = parseInt(year);
- var surplusMonth = this.surplusMonth(year);
- data.multiArray[1] = surplusMonth;
- if (data.year == year1) {
- data.month = month1;
- } else {
- data.month = 1;
- }
- if (data.year == year1 && month1 == data.month) {
- data.day = day1;
- } else {
- data.day = 1;
- }
- var surplusDay = this.surplusDay(data.year, data.month, data.day);
- data.multiArray[2] = surplusDay;
- var surplusHour;
- if (data.year == year1 && month1 == data.month && data.day == day1) {
- surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
- } else {
- surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
- }
- console.log(surplusHour)
- data.multiArray[3] = surplusHour[0];
- data.multiArray[5] = surplusHour[1];
- data.startHour = surplusHour[0];
- data.endHour = surplusHour[1];
- data.multiIndex[1] = 0;
- data.multiIndex[2] = 0;
- data.multiIndex[3] = 0;
- data.multiIndex[5] = 0;
- break;
- case 1:
- console.log('选择月份' + data.multiArray[e.detail.column][e.detail.value]);
- var monthStr = data.multiArray[e.detail.column][e.detail.value];
- var month = monthStr.substring(0, monthStr.length - 1);
- data.month = month;
- data.day = 1;
- if (data.year == year1 && month1 == data.month) {
- data.day = day1;
- } else {
- data.day = 1;
- }
- var surplusDay = this.surplusDay(data.year, data.month, data.day);
- data.multiArray[2] = surplusDay;
- var surplusHour;
- if (data.year == year1 && month1 == data.month && data.day == day1) {
- surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
- } else {
- surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
- }
- data.multiArray[3] = surplusHour[0];
- data.multiArray[5] = surplusHour[1];
- data.startHour = surplusHour[0];
- data.endHour = surplusHour[1];
- data.multiIndex[2] = 0;
- data.multiIndex[3] = 0;
- data.multiIndex[5] = 0;
- break;
- case 2:
- console.log('选择日' + data.multiArray[e.detail.column][e.detail.value]);
- var dayStr = data.multiArray[e.detail.column][e.detail.value];
- var day = dayStr.substring(0, dayStr.length - 1);
- data.day = day;
- var surplusHour;
- if (data.year == year1 && month1 == data.month && data.day == day1) {
- surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
- } else {
- surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
- }
- data.multiArray[3] = surplusHour[0];
- data.multiArray[5] = surplusHour[1];
- data.startHour = surplusHour[0];
- data.endHour = surplusHour[1];
- data.multiIndex[3] = 0;
- data.multiIndex[5] = 0;
- break;
- case 3:
- console.log('起始时间' + data.multiArray[e.detail.column][e.detail.value]);
- var hourStr = data.multiArray[e.detail.column][e.detail.value];
- var hour = hourStr.substring(0, hourStr.length - 1);
- data.startHour = hour;
- console.log('起始时间' + hour + " day1:" + day1);
- /*var endhours2 = [];
- var end = ['09时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时', '20时'];
- for (var i = e.detail.value; i < end.length; i++) {
- endhours2.push(end[i]);
- }
- data.multiArray[5] = endhours2; */
- if (e.detail.value > data.multiIndex[5])
- data.multiIndex[5] = e.detail.value;
- break;
- case 5:
- var hourStr = data.multiArray[e.detail.column][e.detail.value];
- var hour = hourStr.substring(0, hourStr.length - 1);
- data.endHour = hour;
- if (e.detail.value < data.multiIndex[3])
- data.multiIndex[3] = e.detail.value;
- //console.log('index:'+data.multiIndex[3]+'value:'+e.detail.value+'结束时间' + data.multiArray[e.detail.column][e.detail.value]);
- break;
- }
- this.setData(data)
- },
- //value 改变时触发 change 事件
- bindMultiPickerChange: function (e) {
- console.info(e);
- console.info(this.data.multiArray);
- console.info(this.data);
- console.info(this.data.multiIndex);
- var dateStr =
- this.data.multiArray[0][this.data.multiIndex[0]] +
- this.data.multiArray[1][this.data.multiIndex[1]] +
- this.data.multiArray[2][this.data.multiIndex[2]] +
- this.data.multiArray[3][this.data.multiIndex[3]] +
- this.data.multiArray[4][this.data.multiIndex[4]] +
- this.data.multiArray[5][this.data.multiIndex[5]];
- console.log('picker发送选择改变,携带值为', dateStr)
- this.setData({
- orderData: dateStr
- })
- },
- onClose() {
- this.setData({
- choosePopup: false,
- remarkDisable: false,
- });
- },
- dateCheck(e) {
- let index = e.currentTarget.dataset.index;
- let date = e.currentTarget.dataset.date;
- let week = e.currentTarget.dataset.week;
- let isbook = e.currentTarget.dataset.isbook;
- console.info("dateCheck:" + index);
- this.setData({
- dateIndex: index
- });
- let period = this.data.dateList[this.data.dateIndex].period;
- let current = (this.data.noonType == 1 ? '上午' : '下午');
- let list = period.filter(item => {
- return item.ofTime == current;
- });
- let bookdate = this.data.dateList[this.data.dateIndex].bookdate
- let weekOfDay = this.data.dateList[this.data.dateIndex].weekOfDay
- this.setData({
- timeList: list,
- date: bookdate,
- week: weekOfDay
- });
- let isNoTime = list.every(item => {
- return item.timeMsg && item.timeMsg != null;
- });
- if (isNoTime) {
- this.setData({
- timeIndex: -1,
- selectTimeValue: ''
- });
- }
- },
- noonTab(e) {
- let noon = e.currentTarget.dataset.noon;
- this.setData({
- timeIndex: -1,
- noonType: noon,
- selectTimeValue: '',
- });
- let period = this.data.dateList[this.data.dateIndex].period;
- let current = (this.data.noonType == 1 ? '上午' : '下午');
- let list = period.filter(item => {
- return item.ofTime == current;
- });
- this.setData({
- timeList: list
- });
- },
- timeCheck(e) {
- let index = e.currentTarget.dataset.index;
- let toastMsg = e.currentTarget.dataset.toastmsg;
- let msg = e.currentTarget.dataset.msg;
- if (msg == null || msg == '') {
- let time = (this.data.timeList[index].begin).split(':')[0];
- let bookTime = this.data.timeList[index].begin + '-' + this.data.timeList[index].end
- this.setData({
- timeIndex: index,
- selectTimeValue: Number(time),
- time: bookTime
- });
- } else {
- wx.showToast({
- title: toastMsg,
- icon: 'none'
- })
- }
- },
- weekCheck(e) {
- let index = e.currentTarget.dataset.index;
- let weekday = e.currentTarget.dataset.weekday;
- console.log("weekday", weekday);
- this.setData({
- weekIndex: index,
- weekday: weekday
- });
- },
- timeSelect(e) {
- let index = e.currentTarget.dataset.index;
- let time = e.currentTarget.dataset.time;
- if (this.data.activeTab != 2) {
- let weekList = this.data.weekArrList;
- weekList.forEach(item => {
- item.num = 0;
- });
- this.setData({
- weekArrList: weekList,
- selecttime: time
- });
- let itemData = "weekArrList[" + this.data.weekIndex + "].num";
- let selectedDateList = [];
- let dateItem = {
- week: this.data.weekIndex,
- time: time,
- weekStr: this.data.weekArrList[this.data.weekIndex].week
- };
- selectedDateList.push(dateItem);
- // console.log(this.data);
- this.setData({
- selectTimeIndex: index,
- [itemData]: 1,
- selectedWeekList: [this.data.weekIndex],
- selectedDateList: selectedDateList
- });
- console.log("111",this.data.selectedDateList);
- } else {
- // 如果选中的时间段小于2个
- if (this.data.selectedDateList.length < 2) {
- let itemData = "weekArrList[" + this.data.weekIndex + "].num";
- let num = this.data.weekArrList[this.data.weekIndex].num;
- let selectedDateList = this.data.selectedDateList;
- selectedDateList.push({
- week: this.data.weekIndex,
- time: time,
- weekStr: this.data.weekArrList[this.data.weekIndex].week
- });
- let selectedWeekList = this.data.selectedWeekList;
- if (selectedWeekList.indexOf(this.data.weekIndex) == -1) {
- selectedWeekList.push(this.data.weekIndex);
- }
- this.setData({
- selecttime: time,
- [itemData]: num + 1,
- selectTimeIndex: index,
- // selectedWeekList:selectedWeekList,
- selectedWeekList: [this.data.weekIndex],
- selectedDateList: selectedDateList
- });
- console.log("222",this.data.selectedDateList);
- } else {
- // 删除第一个
- let firstTimeSelected = this.data.selectedDateList[0];
- let firstWeekSelectedIndex = firstTimeSelected.week;
- // let firstWeekSelected=this.data.weekArrList[firstWeekSelectedIndex];
- let itemDataDel = "weekArrList[" + firstWeekSelectedIndex + "].num";
- let numDel = this.data.weekArrList[firstWeekSelectedIndex].num;
- let selectedDateListDel = this.data.selectedDateList;
- selectedDateListDel.shift();
- this.setData({
- selecttime: time,
- [itemDataDel]: numDel - 1,
- // selectTimeIndex:index,
- selectedDateList: selectedDateListDel
- });
- // 加入新选中的
- let itemData = "weekArrList[" + this.data.weekIndex + "].num";
- let num = this.data.weekArrList[this.data.weekIndex].num;
- let selectedDateList = this.data.selectedDateList;
- selectedDateList.push({
- week: this.data.weekIndex,
- time: time,
- weekStr: this.data.weekArrList[this.data.weekIndex].week
- });
- this.setData({
- [itemData]: num + 1,
- // selectTimeIndex:index,
- selectedDateList: selectedDateList
- });
- let weekListNew = [];
- this.data.selectedDateList.forEach(item => {
- if (weekListNew.indexOf(item.week) == -1) {
- weekListNew.push(item.week);
- }
- });
- this.setData({
- selectedWeekList: weekListNew,
- });
- console.log("333",this.data.selectedDateList);
- }
- // console.log(this.data);
- }
- },
- firstDateCheck(e) {
- let index = e.currentTarget.dataset.index;
- this.setData({
- firstDateIndex: index
- });
- },
- onTabChange(e) {
- let weekList = this.data.weekArrList;
- weekList.forEach(item => {
- item.num = 0;
- });
- if (e.detail.name == '1') {
- this.setData({
- selectweek: '一周1次'
- })
- } else if (e.detail.name == '2') {
- this.setData({
- selectweek: '一周2次'
- })
- } else {
- this.setData({
- selectweek: '两周1次'
- })
- }
- console.log("selectweek", this.data.selectweek);
- this.setData({
- weekArrList: weekList,
- activeTab: e.detail.name,
- selectTimeIndex: 'null',
- selectedWeekList: [],
- selectedDateList: []
- });
- },
- showAppoint() {
- if (this.data.addressId == 0) {
- util.showErrorToast("请选择服务地址");
- return;
- }
- this.setData({
- choosePopup: true,
- remarkDisable: true,
- popupType: (this.data.popupType == 3 ? 2 : this.data.popupType),
- isFinishAppoint: false
- });
- if (this.data.popupType == '1') {
- this.getDayTime();
- }
- },
- confirmTime() {
- console.log(this.data.activeTab);
- console.log(this.data);
- if (this.data.popupType == 1) {
- if (this.data.timeIndex === '' || this.data.timeIndex < 0) {
- wx.showToast({
- title: '请选择服务时间',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- let date = this.data.dateList[this.data.dateIndex].bookdate;
- let week = this.data.dateList[this.data.dateIndex].weekOfDay;
- let time = this.data.timeList[this.data.timeIndex].begin + '-' + this.data.timeList[this.data.timeIndex].end;
- console.log(week, time);
- this.setData({
- oneTimeAppoint: date + ' ' + week + ' ' + time,
- choosePopup: false,
- remarkDisable: false,
- isFinishAppoint: true
- });
- } else if (this.data.popupType == 2) {
- if (this.data.activeTab == 2) {
- if (this.data.selectedDateList.length < 1) {
- wx.showToast({
- title: '请选择服务时间',
- icon: 'none',
- duration: 2000
- });
- } else if (this.data.selectedDateList.length == 1) {
- wx.showToast({
- title: '请选择第二次服务时间',
- icon: 'none',
- duration: 2000
- });
- } else {
- // 选择频次
- let futureDateList = util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24), 1);
- let minIndex = Math.min.apply(null, this.data.selectedWeekList);
- console.log(minIndex);
- console.log((this.data.weekArrList[minIndex]).id);
- let beginDate = futureDateList.filter(item => {
- return (new Date(item.date)).getDay() == (this.data.weekArrList[minIndex]).id
- });
- console.log(beginDate);
- let inter = 7;
- let firstAppointList = util.getDateList(new Date(new Date(beginDate[0].date).getTime()), inter);
- this.setData({
- popupType: 3,
- firstAppointList: firstAppointList
- })
- }
- } else {
- if (this.data.selectedDateList.length == 0) {
- wx.showToast({
- title: '请选择服务时间',
- icon: 'none',
- duration: 2000
- });
- } else {
- // 选择频次
- let futureDateList = util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24), 1);
- let minIndex = Math.min.apply(null, this.data.selectedWeekList);
- console.log(minIndex);
- let beginDate = futureDateList.filter(item => {
- return (new Date(item.date)).getDay() == (this.data.weekArrList[minIndex]).id
- });
- console.log(beginDate);
- let inter = (this.data.activeTab == 3 ? 14 : 7);
- let firstAppointList = util.getDateList(new Date(new Date(beginDate[0].date).getTime()), inter);
- this.setData({
- popupType: 3,
- firstAppointList: firstAppointList
- })
- }
- }
- } else if (this.data.popupType == 3) {
- let firstTime = this.data.firstAppointList[this.data.firstDateIndex].date;
- console.log(firstTime);
- console.log(this.data.selectedDateList);
- // this.orderAppoint();
- this.setData({
- choosePopup: false,
- remarkDisable: false,
- isFinishAppoint: true,
- popupType: 2,
- });
- }
- },
- orderAppoint() {
- // 如果是多次卡先预估,单次卡不用预估
- let weeks = [];
- this.data.selectedDateList.forEach(item => {
- let obj = {
- dayOfWeek: this.data.weekArrList[item.week].id,
- startTime: item.time.split('-')[0],
- endTime: item.time.split('-')[1]
- };
- weeks.push(obj);
- });
- let params = {
- weeks: weeks,
- type: this.data.activeTab,
- startDate: this.data.firstAppointList[this.data.firstDateIndex].date,
- lng: this.data.checkedAddress.lng,
- lat: this.data.checkedAddress.lat,
- shopId: this.data.checkedAddress.shopId,
- goodId: this.data.checkedGoodsList[0].goodsId
- };
- wx.showLoading({
- title: '加载中',
- });
- util.request(api.OrderAppoint, params, "POST")
- .then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- // this.orderPay(params);
- this.setData({
- choosePopup: false,
- remarkDisable: false,
- isFinishAppoint: true,
- popupType: 2,
- });
- } else {
- // util.showErrorToast(res.errmsg);
- wx.showToast({
- title: res.errmsg,
- icon: 'none',
- duration: 2000
- });
- }
- }).catch(function (err) {
- console.log(err);
- wx.hideLoading();
- wx.showToast({
- title: err.errMsg,
- icon: 'none'
- })
- });
- },
- cancelPay() {
- this.setData({
- payFailShow: false,
- remarkDisable: false
- });
- wx.navigateBack({
- delta: 1,
- })
- },
- rePay() {
- wx.showLoading({
- title: '支付中',
- })
- this.setData({
- payFailShow: false,
- remarkDisable: false
- });
- util.request(api.OrderPrepay, {
- orderId: this.data.orderId
- }, 'POST').then(res => {
- if (res.errno === 0) {
- const payParam = res.data;
- console.log("支付过程开始")
- wx.requestPayment({
- 'timeStamp': payParam.timeStamp,
- 'nonceStr': payParam.nonceStr,
- 'package': payParam.packageValue,
- 'signType': payParam.signType,
- 'paySign': payParam.paySign,
- 'success': res => {
- console.log("支付过程成功");
- wx.redirectTo({
- url: '/pages/checkout/payResult/payResult?status=1&orderId=' + this.data.orderId + '&actualPrice=' + this.data.actualPrice
- });
- },
- 'fail': res => {
- console.log("支付过程失败")
- util.showErrorToast('支付失败');
- },
- 'complete': res => {
- wx.hideLoading();
- console.log("支付过程结束");
- }
- })
- } else {
- wx.hideLoading();
- };
- }).catch(res => {
- wx.hideLoading();
- });
- },
- goBuyMember() {
- wx.navigateTo({
- url: "/pages/member/buyMember/buyMember"
- });
- },
- getDayStock() {
- if (this.data.dateIndex < 0) {
- return false;
- }
- let params = {
- day: this.data.dateList[this.data.dateIndex].date,
- goodsId: this.data.checkedGoodsList[0].goodsId,
- lng: this.data.checkedAddress.lng,
- lat: this.data.checkedAddress.lat,
- productId: this.data.checkedGoodsList[0].product.id,
- serviceDuration: this.data.serviceDuration
- }
- wx.showLoading({
- title: '加载中',
- });
- util.request(api.EveryDayStock, params, "GET")
- .then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- this.setData({
- timeList: res.data,
- timeIndex: 0
- });
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none',
- duration: 2000
- });
- this.setData({
- timeList: [],
- timeIndex: ''
- });
- }
- }).catch(function (err) {
- console.log(err);
- wx.hideLoading();
- wx.showToast({
- title: err.errMsg,
- icon: 'none'
- });
- this.setData({
- timeList: [],
- timeIndex: ''
- });
- });
- },
- getDayTime() {
- let params = {
- days: 30,
- productId: this.data.checkedGoodsList[0].productId,
- serviceDuration: this.data.serviceDuration
- }
- wx.showLoading({
- title: '加载中',
- });
- util.request(api.everyDayTime, params, "GET")
- .then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- this.setData({
- dateList: res.data,
- dateIndex: 0,
- timeIndex: -1,
- noonType: 1
- });
- let period = res.data[0].period;
- let list = period.filter(item => {
- return item.ofTime == '上午';
- });
- this.setData({
- timeList: list
- });
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none',
- duration: 2000
- });
- this.setData({
- timeList: [],
- timeIndex: ''
- });
- }
- }).catch(function (err) {
- console.log(err);
- wx.hideLoading();
- wx.showToast({
- title: err.errMsg,
- icon: 'none'
- });
- this.setData({
- timeList: [],
- timeIndex: ''
- });
- });
- },
- });
|