123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272 |
- var util = require('../../../utils/jmsUtil.js');
- var user = require('../../../utils/user.js');
- var mall = require('../../../api/mall.js');
- var check = require('../../../utils/check.js');
- var app = getApp();
- Page({
- data: {
- addressShow: false,
- addressList:[],
- address:{
- detail:'',
- name:'',
- tel:''
- },
- // shopAddress:'',//门店地址
- buyNumber:'',
- memberDiscount: '',
- isMember: false,
- orderId: '',
- payFailShow: false,
- choosePopup: false,
- noSerTimes: '',
- popupType: 1, //1单次预约 2 选择服务频次 3选择首次预约时间
- timeList: check.getTimeList(1),
- dateList: util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24), 1, 60),
- // firstAppointList:util.getDateList(new Date(new Date().getTime()+60*60*1000*24),7),
- firstAppointList: [],
- timeIndex: 0, //选中的时间段
- 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, //预约失败提示
- 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, //实际需要支付的总价
- couponAmount:0,
- cartId: 0,
- addressId: 0,
- couponId: 0,
- userCouponId: 0,
- message: '',
- grouponLinkId: 0, //参与的团购
- grouponRulesId: 0, //团购规则ID
- nurseId: 0, //安心包认证id
- petinfo: null, //宠物保险内容
- shareId: 0,
- userInfo: {},
- remarkDisable: false,
- code:'',
- },
- //获取checkou信息
- getCheckoutInfo: function () {
- let that = this;
- wx.showLoading({
- title: '加载中...',
- });
- util.request(mall.CartCheckout, {
- cartIds: [that.data.cartId],
- // addressId: that.data.addressId,
- // couponId: that.data.couponId,
- // userCouponId: that.data.userCouponId,
- // grouponRulesId: that.data.grouponRulesId,
- // shareId: that.data.shareId,
- },'POST').then(res=> {
-
- wx.hideLoading();
- console.log(res);
- if (res.errno == 0) {
- that.setData({
- // isMember: res.data.isMember,
- // memberDiscount: res.data.memberDiscount,
- checkedGoodsList: res.data.skus,
- // shopAddress:res.data.address,
- buyNumber:res.data.buyNumber,
- actualPrice: res.data.price,
- couponAmount:res.data.couponAmount,
- addressId:res.data.addressId
- // checkedAddress: res.data.checkedAddress,
- // availableCouponLength: res.data.availableCouponLength,
- // 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,
-
- });
- if (res.data.addressId) {
- this.getAddressList();
- }
-
- // that.LimitCanAppointmentDate();
- }else{
- util.showErrorToast(res.errmsg);
- }
-
- });
- },
- 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
- })
- }
- //设置默认起始可预约 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
- // })
- // }
- // }
- },
- checkNurse() {
- //是否包含安心包产品 如果含有 需要填写安心包产品内容
- let that = this;
- let isNurse = false;
- var list = that.data.checkedGoodsList;
- for (var i = 0; i < that.data.checkedGoodsList.length; i++) {
- // console.log(that.data.checkedGoodsList[i].goods);
- // 0 服务类商品 1保险 2中介 3买约分离次卡
- // if(that.data.checkedGoodsList[i].goods.categoryId==1036016){
- if (that.data.checkedGoodsList[i].goods.type == 1) {
- isNurse = true;
- break;
- }
- }
- return isNurse;
- },
- checkInstance() { //是否为宠物保险
- let that = this;
- var isIns = false;
- var list = that.data.checkedGoodsList;
- console.info(that.data.checkedGoodsList);
- for (var i = 0; i < that.data.checkedGoodsList.length; i++) {
- if (that.data.checkedGoodsList[i].goods.type == 1) {
- isIns = true;
- break;
- }
- }
- return isIns;
- },
- 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
- });
- },
- 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',
- // })
- // });
-
- 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;
- }
- this.setData({
- cartId: cartId,
- addressId: addressId,
- couponId: couponId,
- userCouponId: userCouponId,
- grouponRulesId: grouponRulesId,
- grouponLinkId: grouponLinkId
- });
- this.getCheckoutInfo();
- } 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;
-
- //门店和商品是否符合
- util.request(mall.OrderCheck, {
- addressId: that.data.addressId,
- shopId: that.data.checkedAddress.shopId,
- cart: this.data.cartId
- }).then(function (res) {
- if (res.errno === 0) {
- that.submitInfo();
- // if (res.data==false) {
- // wx.showModal({
- // title: '提醒',
- // // content: '收货地址需在'+app.globalData.city+',请修改'
- // content: '收货地址需在服务范围内,请修改地址'
- // });
- // that.submitInfo();
- // }else{
- // that.submitInfo();
- // }
- } else {
- wx.showModal({
- title: '提醒',
- // content: '收货地址需在'+app.globalData.city+',请修改'
- content: res.errmsg
- });
- }
- }).catch(res => {
- util.showErrorToast(res.errmsg)
- });
- },
- submitInfo() {
- //是否含有保姆安心包产品
- var isnurse = this.checkNurse();
- if (isnurse && this.data.nurseId == 0) { //跳转安心包注册页
- wx.navigateTo({
- url: '/pages/auth/register/register',
- })
- return;
- }
- 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,
- //预约参数信息
- };
- //是宠物保险
- var isInsure = this.checkInstance();
- if (isInsure) {
- //缓存order数据,在宠物保险页提交
- wx.setStorageSync('orderInfo', orderInfo);
- wx.navigateTo({
- url: '/pages/goods/pet/index?id=' + this.data.cartId,
- })
- return;
- }
- // 如果是多次卡先预估,单次卡不用预估
- if (!this.data.isOneAppoint) {
- // this.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 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) {
- 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);
- }
- },
- async getWxCode(){
- let res=await user.login();
- console.log(res);
- this.setData({
- code:res.code
- });
- },
- async orderPay() {
- if(this.data.addressId==null||this.data.addressId==''){
- if(this.data.address.detail==''){
- util.showErrorToast('请输入收货地址');
- return false;
- }
- if(this.data.address.name==''){
- util.showErrorToast('请输入联系人');
- return false;
- }
- if(this.data.address.tel==''){
- util.showErrorToast('请输入联系电话');
- return false;
- }
- let reg=/^1\d{10}$/;
- if(!reg.test(this.data.address.tel)){
- util.showErrorToast('电话号码格式不正确');
- return false;
- }
- }
- var orderInfo = {
- cartId: [this.data.cartId],
- addressId:this.data.addressId,
- receiverAddress:this.data.address.detail,
- receiverName:this.data.address.name,
- receiverPhone:this.data.address.tel
-
- };
- await this.getWxCode();
-
- util.request(mall.OrderSubmit, orderInfo, 'POST').then(res => {
- if (res.errno === 0) {
- console.log(res);
-
- const orderId = res.data;
- this.setData({
- orderId: orderId
- });
-
- util.request(mall.OrderPrepay, {
- orderId: orderId,
- code:this.data.code
- }, '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/mall/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
- });
- },
- 'complete': function (res) {
- console.log("支付过程结束")
- }
- });
- } else {
- // 弹出支付失败
- this.setData({
- payFailShow: true
- });
- // wx.redirectTo({
- // url: '/pages/checkout/payResult/payResult?status=0&orderId=' + orderId
- // });
- }
- });
- } else {
- 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
- })
- }
- 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;
- if (this.data.checkedGoodsList[0].goodsId == 1190332) {
- this.setData({
- dateIndex: index
- });
- } else if (index >= 7 || (index >= 2 && index < 7 && (week != '周六' && week != '周日'))) { //前三天不可预约
- this.setData({
- dateIndex: index
- });
- }
- },
- timeCheck(e) {
- let index = e.currentTarget.dataset.index;
- 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() {
- 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
- })
- }
- },
- confirmTime() {
- console.log(this.data.activeTab);
- console.log(this.data);
- if (this.data.popupType == 1) {
- 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,
- 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,
- // 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(mall.OrderAppoint, params, "POST")
- .then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- // this.orderPay(params);
- this.setData({
- choosePopup: 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
- });
- },
- async rePay() {
- await this.getWxCode();
-
- util.request(mall.OrderPrepay, {
- orderId: this.data.orderId,
- code:this.data.code
- }, '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("支付过程成功");
- this.setData({
- payFailShow: false
- })
- wx.redirectTo({
- url: '/pages/mall/payResult/payResult?status=1&orderId=' + this.data.orderId + '&actualPrice=' + this.data.actualPrice
- });
- },
- 'fail': res => {
- console.log("支付过程失败")
- this.setData({
- payFailShow: false
- });
- util.showErrorToast('支付失败');
- },
- 'complete': res => {
- console.log("支付过程结束");
- }
- });
- }else{
- util.showErrorToast(res.errmsg);
- }
- });
- },
- goBuyMember() {
- wx.navigateTo({
- url: "/pages/member/buyMember/buyMember"
- });
- },
- addressConfirm(e) {
- let address = e.currentTarget.dataset.address;
-
- this.setData({
- checkedAddress: address,
- addressShow: false,
- addressId:address.id
- });
-
- },
- getAddressList() {
- util.request(mall.AddressList).then((res) => {
- if (res.errno === 0) {
- this.setData({
- addressList: res.data
- });
- let current = this.data.addressList.filter((item) => {
- return item.id == this.data.addressId;
- });
- if (current.length > 0) {
- this.setData({
- checkedAddress: current[0]
- });
- }
- }
- });
- },
- addressSelect() {
- this.setData({
- addressShow: true
- });
- },
- onAddressClose() {
- this.setData({
- addressShow: false
- })
- },
- goAddAddress(){
- this.setData({
- addressId:0,
- addressShow: false
- })
- },
- bindinputAddress(event) {
- let detail = event.detail.value.replace(/[,,]/g, '');
- this.setData({
- 'address.detail': detail
- });
-
- },
- bindinputMobile(event) {
- let tel = event.detail.value;
- this.setData({
- 'address.tel': tel
- });
- },
- bindinputName(event) {
- let name = event.detail.value;
- this.setData({
- 'address.name': name
- });
- },
- });
|