12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376 |
- 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: {
- 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),
- // firstAppointList:util.getDateList(new Date(new Date().getTime()+60*60*1000*24),7),
- firstAppointList: [],
- timeIndex: '', //选中的时间段
- dateIndex: 2, //单次预约选中的日期
- 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,
- 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:''
- },
- //获取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,
- 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].goods.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
- });
- }
- 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;
- }
- 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');
- 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) {
- util.showErrorToast('请选择收货地址');
- 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: (this.data.dateList[this.data.dateIndex]).id,
- startTime: (this.data.timeList[this.data.timeIndex].time.split('-'))[0],
- endTime: (this.data.timeList[this.data.timeIndex].time.split('-'))[1]
- }];
- }
- let params = {
- weeks: weeks,
- type: 0,
- startDate: this.data.dateList[this.data.dateIndex].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);
- }
- },
- orderPay(orderData) {
- 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
- };
- if (this.data.codeShow && !this.data.isNoMatch) {
- orderInfo.recCode = this.data.recCode;
- }
- console.log(orderInfo);
- util.request(api.OrderSubmit, orderInfo, 'POST').then(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("支付过程开始");
- 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("支付过程失败");
- // wx.redirectTo({
- // url: '/pages/checkout/payResult/payResult?status=0&orderId=' + orderId
- // });
- // 弹出支付失败
- this.setData({
- payFailShow: true,
- remarkDisable: true
- });
- },
- 'complete': function (res) {
- console.log("支付过程结束")
- }
- });
- } else {
- // 弹出支付失败
- this.setData({
- payFailShow: true,
- remarkDisable: true
- });
- // wx.redirectTo({
- // url: '/pages/checkout/payResult/payResult?status=0&orderId=' + orderId
- // });
- }
- });
- } else {
- wx.showToast({
- title: res.errmsg,
- icon:'none'
- })
- // util.showErrorToast(res.errmsg);
- }
- });
- },
- 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
- })
- }
- 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)
- if (this.data.checkedGoodsList[0].goodsId == 1190332) {
- this.setData({
- dateIndex: index
- });
- } else if (isbook) { //前三天不可预约
- this.setData({
- dateIndex: index
- });
- this.getDayStock();
- }
- },
- timeCheck(e) {
- let index = e.currentTarget.dataset.index;
- // let stock = e.currentTarget.dataset.stock;
- // if (stock > 0) {
- this.setData({
- timeIndex: index
- });
- // }
- },
- weekCheck(e) {
- let index = e.currentTarget.dataset.index;
- this.setData({
- weekIndex: index,
- // selectTimeIndex:'null'
- });
- },
- 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,
- });
- 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(this.data);
- } 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({
- [itemData]: num + 1,
- selectTimeIndex: index,
- // selectedWeekList:selectedWeekList,
- selectedWeekList: [this.data.weekIndex],
- selectedDateList: 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({
- [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(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;
- });
- 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') {
- // let index = 2;
- // let length = this.data.dateList.length;
- // let list = this.data.dateList;
- // for (let i = 0; i < length; i++) {
- // if (i < 7 && i >= 2 && list[i].week != '周六' && list[i].week != '周日') {
- // index = i;
- // break;
- // }
- // }
- // console.log(index);
- // this.setData({
- // dateIndex: index
- // })
- // 获取时间段
- this.getDayStock();
- }
- },
- confirmTime() {
- console.log(this.data.activeTab);
- console.log(this.data);
- if (this.data.popupType == 1) {
- if (this.data.timeIndex === '') {
- wx.showToast({
- title: '请选择服务时间',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- let date = this.data.dateList[this.data.dateIndex].date;
- let week = this.data.dateList[this.data.dateIndex].week;
- let time = this.data.timeList[this.data.timeIndex].time;
- 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,
- // noSerTimes: res.data,
- // appointFailTip: (res.data >= 1 ? true : false)
- });
- // this.setData({
- // choosePopup:false,
- // isFinishAppoint:true
- // });
- }
- },
- 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,
- // noSerTimes: res.data,
- // appointFailTip: (res.data >= 1 ? true : false)
- });
- } 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
- });
- // let validList = this.data.timeList.filter(item => {
- // return item.stock > 0
- // });
- // if (validList.length > 0) {
- // this.setData({
- // timeIndex: validList[0].id - 1
- // });
- // } else {
- // this.setData({
- // timeIndex: ''
- // });
- // }
- } 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: ''
- });
- });
- },
- });
|