checkout.js 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. var util = require('../../utils/util.js');
  2. var user = require('../../utils/user.js');
  3. var api = require('../../config/api.js');
  4. var check = require('../../utils/check.js');
  5. var app = getApp();
  6. Page({
  7. data: {
  8. memberDiscount:'',
  9. isMember:false,
  10. orderId:'',
  11. payFailShow:false,
  12. choosePopup:false,
  13. noSerTimes:'',
  14. popupType:1,//1单次预约 2 选择服务频次 3选择首次预约时间
  15. timeList:check.getTimeList(1),
  16. dateList:util.getDateList(new Date(new Date().getTime()+60*60*1000*24),1,60),
  17. // firstAppointList:util.getDateList(new Date(new Date().getTime()+60*60*1000*24),7),
  18. firstAppointList:[],
  19. timeIndex:0,//选中的时间段
  20. dateIndex:2,//单次预约选中的日期
  21. firstDateIndex:0,//首次预约时间
  22. activeTab:1,//频次
  23. weekIndex:0,//选中的周几
  24. weekArrList:[
  25. {id:1,week:'周一',num:0},
  26. {id:2,week:'周二',num:0},
  27. {id:3,week:'周三',num:0},
  28. {id:4,week:'周四',num:0},
  29. {id:5,week:'周五',num:0},
  30. {id:6,week:'周六',num:0},
  31. {id:0,week:'周日',num:0},
  32. ],
  33. selectedWeekList:[],
  34. selectedDateList:[],
  35. selectTimeIndex:'null',//选中的时间段
  36. oneTimeAppoint:'2021-04-22 周一 13:00-14:00',
  37. isNeedAppoint:false,//是否需要预约
  38. isFinishAppoint:false,//已选择预约
  39. isOneAppoint:true,//单次卡
  40. appointFailTip:false,//预约失败提示
  41. multiIndex: [0, 0, 0, 0, 0, 0],
  42. multiArray: [],
  43. array: [],
  44. year: "",
  45. month: "",
  46. day: "",
  47. startHour: "",
  48. endHour: "",
  49. orderData: "",//此时间为预计上门时间
  50. checkedGoodsList: [],
  51. checkedAddress: {},
  52. availableCouponLength: 0, // 可用的优惠券数量
  53. goodsTotalPrice: 0.00, //商品总价
  54. freightPrice: 0.00, //快递费
  55. couponPrice: 0.00, //优惠券的价格
  56. grouponPrice: 0.00, //团购优惠价格
  57. orderTotalPrice: 0.00, //订单总价
  58. actualPrice: 0.00, //实际需要支付的总价
  59. cartId: 0,
  60. addressId: 0,
  61. couponId: 0,
  62. userCouponId: 0,
  63. message: '',
  64. grouponLinkId: 0, //参与的团购
  65. grouponRulesId: 0, //团购规则ID
  66. nurseId:0,//安心包认证id
  67. petinfo:null,//宠物保险内容
  68. shareId:0,
  69. userInfo:{}
  70. },
  71. //获取checkou信息
  72. getCheckoutInfo: function () {
  73. let that = this;
  74. util.request(api.CartCheckout, {
  75. cartId: that.data.cartId,
  76. addressId: that.data.addressId,
  77. couponId: that.data.couponId,
  78. userCouponId: that.data.userCouponId,
  79. grouponRulesId: that.data.grouponRulesId,
  80. shareId:that.data.shareId,
  81. }).then(function (res) {
  82. if (res.errno === 0) {
  83. that.setData({
  84. isMember:res.data.isMember,
  85. memberDiscount:res.data.memberDiscount,
  86. checkedGoodsList: res.data.checkedGoodsList,
  87. checkedAddress: res.data.checkedAddress,
  88. availableCouponLength: res.data.availableCouponLength,
  89. actualPrice: res.data.actualPrice,
  90. couponPrice: res.data.couponPrice,
  91. grouponPrice: res.data.grouponPrice,
  92. freightPrice: res.data.freightPrice,
  93. goodsTotalPrice: res.data.goodsTotalPrice,
  94. orderTotalPrice: res.data.orderTotalPrice,
  95. addressId: res.data.addressId,
  96. couponId: res.data.couponId,
  97. userCouponId: res.data.userCouponId,
  98. grouponRulesId: res.data.grouponRulesId,
  99. isNeedAppoint: res.data.checkedGoodsList[0].goods.type===0?true:false,//0需要预约 服务类商品,1保险 2中介 3买约分离次卡
  100. isOneAppoint:res.data.checkedGoodsList[0].goods.serviceTimes==1?true:false,//1为单次,其余为多次
  101. popupType:res.data.checkedGoodsList[0].goods.serviceTimes==1?1:2
  102. });
  103. let serviceDuration=res.data.checkedGoodsList[0].goods.serviceDuration;
  104. let timeList=check.getTimeList(serviceDuration);
  105. that.setData({
  106. timeList:timeList
  107. });
  108. //是否为保险类商品
  109. console.info(res.data.checkedAddress)
  110. //console.info(res.data.couponId)
  111. // var isIns=false;
  112. // res.data.checkedGoodsList.forEach(element=>{
  113. // if(element.goods.type==1){
  114. // isIns=true;
  115. // }
  116. // })
  117. // if(isIns){
  118. // //是否设置过保险信息
  119. // var petinfo=wx.getStorageSync('petinfo'+that.data.cartId);
  120. // console.info(petinfo)
  121. // if(!petinfo){
  122. // wx.navigateTo({
  123. // url: '/pages/goods/pet/index?id='+that.data.cartId,
  124. // })
  125. // }else{
  126. // that.setData({
  127. // petinfo:petinfo
  128. // })
  129. // }
  130. // }
  131. }
  132. wx.hideLoading();
  133. });
  134. },
  135. checkNurse(){
  136. //是否包含安心包产品 如果含有 需要填写安心包产品内容
  137. let that=this;
  138. let isNurse=false;
  139. var list=that.data.checkedGoodsList;
  140. for(var i=0;i<that.data.checkedGoodsList.length;i++){
  141. // console.log(that.data.checkedGoodsList[i].goods);
  142. // 0 服务类商品 1保险 2中介 3买约分离次卡
  143. // if(that.data.checkedGoodsList[i].goods.categoryId==1036016){
  144. if(that.data.checkedGoodsList[i].goods.type==1){
  145. isNurse=true;
  146. break;
  147. }
  148. }
  149. return isNurse;
  150. },
  151. checkInstance(){//是否为宠物保险
  152. let that=this;
  153. var isIns=false;
  154. var list=that.data.checkedGoodsList;
  155. console.info(that.data.checkedGoodsList);
  156. for(var i=0;i<that.data.checkedGoodsList.length;i++){
  157. if(that.data.checkedGoodsList[i].goods.type==1){
  158. isIns=true;
  159. break;
  160. }
  161. }
  162. return isIns;
  163. },
  164. selectAddress() {
  165. wx.navigateTo({
  166. url: '/pages/ucenter/address/address',
  167. })
  168. },
  169. selectCoupon() {
  170. wx.navigateTo({
  171. url: '/pages/ucenter/couponSelect/couponSelect',
  172. })
  173. },
  174. bindMessageInput: function (e) {
  175. this.setData({
  176. message: e.detail.value
  177. });
  178. },
  179. onReady: function () {
  180. // 页面渲染完成
  181. },
  182. onShow: function () {
  183. // console.log(this.data.dateList);
  184. // 页面显示
  185. user.checkLogin().then(res => {
  186. app.globalData.hasLogin = true;
  187. console.info("session 未过期")
  188. }).catch(() => {
  189. console.info("session 过期")
  190. app.globalData.hasLogin = false;
  191. wx.navigateTo({
  192. url: '/pages/auth/login/login',
  193. })
  194. });
  195. wx.showLoading({
  196. title: '加载中...',
  197. });
  198. try {
  199. var cartId = wx.getStorageSync('cartId');
  200. if (cartId === "") {
  201. cartId = 0;
  202. }
  203. var addressId = wx.getStorageSync('addressId');
  204. if (addressId === "") {
  205. addressId = 0;
  206. }
  207. var couponId = wx.getStorageSync('couponId');
  208. if (couponId === "") {
  209. couponId = 0;
  210. }
  211. var userCouponId = wx.getStorageSync('userCouponId');
  212. if (userCouponId === "") {
  213. userCouponId = 0;
  214. }
  215. var grouponRulesId = wx.getStorageSync('grouponRulesId');
  216. if (grouponRulesId === "") {
  217. grouponRulesId = 0;
  218. }
  219. var grouponLinkId = wx.getStorageSync('grouponLinkId');
  220. if (grouponLinkId === "") {
  221. grouponLinkId = 0;
  222. }
  223. this.setData({
  224. cartId: cartId,
  225. addressId: addressId,
  226. couponId: couponId,
  227. userCouponId: userCouponId,
  228. grouponRulesId: grouponRulesId,
  229. grouponLinkId: grouponLinkId
  230. });
  231. this.getCheckoutInfo();
  232. } catch (e) {
  233. // Do something when catch error
  234. console.log(e);
  235. }
  236. },
  237. onHide: function () {
  238. // 页面隐藏
  239. },
  240. onUnload: function () {
  241. // 页面关闭
  242. //清空宠物保险的缓存数据
  243. console.info('checkout onload')
  244. //wx.setStorageSync('petinfo'+this.data.cartId, null);
  245. },
  246. submitOrder: function () {
  247. let that=this;
  248. if (that.data.addressId <= 0) {
  249. util.showErrorToast('请选择收货地址');
  250. return ;
  251. }
  252. // 检查是否已经预约
  253. if (that.data.isNeedAppoint&&!that.data.isFinishAppoint) {
  254. // util.showErrorToast('请先预约服务时间');
  255. wx.showToast({
  256. title: '请先预约服务时间',
  257. icon: 'none',
  258. duration: 2000
  259. });
  260. return ;
  261. }
  262. //门店和商品是否符合
  263. util.request(api.OrderCheck, {
  264. addressId: that.data.addressId,
  265. shopId: that.data.checkedAddress.shopId,
  266. cart:this.data.cartId
  267. }).then(function(res) {
  268. if (res.errno === 0) {
  269. that.submitInfo();
  270. // if (res.data==false) {
  271. // wx.showModal({
  272. // title: '提醒',
  273. // // content: '收货地址需在'+app.globalData.city+',请修改'
  274. // content: '收货地址需在服务范围内,请修改地址'
  275. // });
  276. // that.submitInfo();
  277. // }else{
  278. // that.submitInfo();
  279. // }
  280. }else{
  281. wx.showModal({
  282. title: '提醒',
  283. // content: '收货地址需在'+app.globalData.city+',请修改'
  284. content: res.errmsg
  285. });
  286. }
  287. }).catch(res=>{
  288. util.showErrorToast(res.errmsg)
  289. });
  290. },
  291. submitInfo(){
  292. //是否含有保姆安心包产品
  293. var isnurse=this.checkNurse();
  294. if(isnurse&&this.data.nurseId==0){//跳转安心包注册页
  295. wx.navigateTo({
  296. url: '/pages/auth/register/register',
  297. })
  298. return;
  299. }
  300. var orderInfo={
  301. cartId: this.data.cartId,
  302. addressId: this.data.addressId,
  303. couponId: this.data.couponId,
  304. userCouponId: this.data.userCouponId,
  305. message: this.data.message,
  306. orderDate: this.data.orderData,
  307. grouponRulesId: this.data.grouponRulesId,
  308. grouponLinkId: this.data.grouponLinkId,
  309. nurseId:this.data.nurseId,
  310. petinfo:this.data.petinfo,
  311. shareId:this.data.shareId,
  312. //预约参数信息
  313. };
  314. //是宠物保险
  315. var isInsure=this.checkInstance();
  316. if(isInsure){
  317. //缓存order数据,在宠物保险页提交
  318. wx.setStorageSync('orderInfo', orderInfo);
  319. wx.navigateTo({
  320. url: '/pages/goods/pet/index?id='+this.data.cartId,
  321. })
  322. return;
  323. }
  324. // 如果是多次卡先预估,单次卡不用预估
  325. if(!this.data.isOneAppoint){
  326. // this.orderAppoint();
  327. let weeks=[];
  328. this.data.selectedDateList.forEach(item=>{
  329. let obj={
  330. dayOfWeek:this.data.weekArrList[item.week].id,
  331. startTime:item.time.split('-')[0],
  332. endTime:item.time.split('-')[1]
  333. };
  334. weeks.push(obj);
  335. });
  336. let tempStartDate=null;
  337. if(this.data.firstAppointList.length!=0&&this.data.firstAppointList.length>=this.data.firstDateIndex){
  338. tempStartDate=this.data.firstAppointList[this.data.firstDateIndex].date;
  339. }
  340. let params={
  341. weeks:weeks,
  342. type:this.data.activeTab,
  343. startDate:tempStartDate,//this.data.firstAppointList[this.data.firstDateIndex].date,
  344. lng:this.data.checkedAddress.lng,
  345. lat:this.data.checkedAddress.lat,
  346. shopId:this.data.checkedAddress.shopId,
  347. goodId:this.data.checkedGoodsList[0].goodsId
  348. };
  349. console.log(params);
  350. this.orderPay(params);
  351. }else{
  352. let weeks=[{
  353. dayOfWeek:(this.data.dateList[this.data.dateIndex]).id,
  354. startTime:(this.data.timeList[this.data.timeIndex].time.split('-'))[0],
  355. endTime:(this.data.timeList[this.data.timeIndex].time.split('-'))[1]
  356. }];
  357. let params={
  358. weeks:weeks,
  359. type:0,
  360. startDate:this.data.dateList[this.data.dateIndex].date,
  361. lng:this.data.checkedAddress.lng,
  362. lat:this.data.checkedAddress.lat,
  363. shopId:this.data.checkedAddress.shopId,
  364. goodId:this.data.checkedGoodsList[0].goodsId
  365. };
  366. console.log(params);
  367. this.orderPay(params);
  368. }
  369. },
  370. orderPay(orderData){
  371. var orderInfo={
  372. cartId: this.data.cartId,
  373. addressId: this.data.addressId,
  374. couponId: this.data.couponId,
  375. userCouponId: this.data.userCouponId,
  376. message: this.data.message,
  377. orderDate: this.data.orderData,
  378. grouponRulesId: this.data.grouponRulesId,
  379. grouponLinkId: this.data.grouponLinkId,
  380. nurseId:this.data.nurseId,
  381. petinfo:this.data.petinfo,
  382. shareId:this.data.shareId,
  383. //预约参数信息
  384. orderDate:orderData
  385. };
  386. util.request(api.OrderSubmit, orderInfo, 'POST').then(res => {
  387. if (res.errno === 0) {
  388. console.log(res.data.isNeedPay);
  389. if(res.data.isNeedPay==false){
  390. console.log("跳过支付");
  391. util.redirect('/pages/ucenter/order/order');
  392. return;
  393. }
  394. // 下单成功,重置couponId
  395. wx.setStorageSync('couponId', 0);
  396. const orderId = res.data.orderId;
  397. this.setData({orderId:orderId});
  398. const grouponLinkId = res.data.grouponLinkId;
  399. util.request(api.OrderPrepay, {
  400. orderId: orderId
  401. }, 'POST').then(res=>{
  402. if (res.errno === 0) {
  403. const payParam = res.data;
  404. console.log("支付过程开始");
  405. wx.requestPayment({
  406. 'timeStamp': payParam.timeStamp,
  407. 'nonceStr': payParam.nonceStr,
  408. 'package': payParam.packageValue,
  409. 'signType': payParam.signType,
  410. 'paySign': payParam.paySign,
  411. 'success': res=> {
  412. console.log("支付过程成功");
  413. if (grouponLinkId) {
  414. setTimeout(() => {
  415. wx.redirectTo({
  416. url: '/pages/groupon/grouponDetail/grouponDetail?id=' + grouponLinkId
  417. })
  418. }, 1000);
  419. } else {
  420. wx.redirectTo({
  421. url: '/pages/checkout/payResult/payResult?status=1&orderId=' + orderId+'&actualPrice='+this.data.actualPrice
  422. });
  423. }
  424. },
  425. 'fail': res=> {
  426. console.log("支付过程失败");
  427. // wx.redirectTo({
  428. // url: '/pages/checkout/payResult/payResult?status=0&orderId=' + orderId
  429. // });
  430. // 弹出支付失败
  431. this.setData({
  432. payFailShow:true
  433. });
  434. },
  435. 'complete': function (res) {
  436. console.log("支付过程结束")
  437. }
  438. });
  439. } else {
  440. // 弹出支付失败
  441. this.setData({
  442. payFailShow:true
  443. });
  444. // wx.redirectTo({
  445. // url: '/pages/checkout/payResult/payResult?status=0&orderId=' + orderId
  446. // });
  447. }
  448. });
  449. } else {
  450. util.showErrorToast(res.errmsg);
  451. }
  452. });
  453. },
  454. surplusMonth: function (year) {
  455. var date = new Date();
  456. var year2 = date.getFullYear()
  457. var month = date.getMonth() + 1
  458. var day = date.getDate()
  459. var hour = date.getHours()
  460. var minute = date.getMinutes()
  461. var second = date.getSeconds()
  462. var monthDatas = [];
  463. if (year == year2) {
  464. var surplusMonth = 12 - month;
  465. monthDatas.push(month + "月")
  466. for (var i = month; i < 12; i++) {
  467. monthDatas.push(i + 1 + "月")
  468. }
  469. } else {
  470. for (var i = 0; i < 12; i++) {
  471. monthDatas.push(i + 1 + "月")
  472. }
  473. }
  474. return monthDatas;
  475. },
  476. //天数计算
  477. surplusDay: function (year, month, day) {
  478. var days = 31;
  479. var dayDatas = [];
  480. var date = new Date();
  481. var year2 = date.getFullYear()
  482. var month2 = date.getMonth() + 1
  483. switch (parseInt(month)) {
  484. case 1:
  485. case 3:
  486. case 5:
  487. case 7:
  488. case 8:
  489. case 10:
  490. case 12:
  491. days = 31;
  492. break;
  493. //对于2月份需要判断是否为闰年
  494. case 2:
  495. if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
  496. days = 29;
  497. break;
  498. } else {
  499. days = 28;
  500. break;
  501. }
  502. case 4:
  503. case 6:
  504. case 9:
  505. case 11:
  506. days = 30;
  507. break;
  508. }
  509. if (year == year2 && month == month2) {
  510. // dayDatas.push(day + "日")
  511. for (var i = day; i < days; i++) {
  512. dayDatas.push(i + 1 + "日")
  513. }
  514. } else {
  515. console.log(month + "月" + days + "天")
  516. for (var i = 0; i < days; i++) {
  517. dayDatas.push(i + 1 + "日")
  518. }
  519. }
  520. return dayDatas;
  521. },
  522. //时间计算
  523. surplusHour: function (year, month, day, hour) {
  524. var date = new Date();
  525. var year2 = date.getFullYear()
  526. var month2 = date.getMonth() + 1
  527. var day2 = date.getDate();
  528. var hourEnd = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21];
  529. var hours = [
  530. ['09时', '10时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时'],
  531. ['10时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时', '21时']
  532. ];
  533. return hours;
  534. },
  535. /**
  536. * 生命周期函数--监听页面加载
  537. */
  538. onLoad: function (options) {
  539. this.setData({
  540. userInfo: app.globalData.userInfo
  541. });
  542. let that=this;
  543. if(options.nurseId){
  544. this.setData({
  545. nurseId:options.nurseId
  546. })
  547. }
  548. if(typeof options.shareId!='undefined'&&options.shareId>0){
  549. that.setData({
  550. shareId:options.shareId
  551. })
  552. }
  553. var date = new Date();
  554. var year = date.getFullYear()
  555. var month = date.getMonth() + 1
  556. var day = date.getDate()
  557. var hour = date.getHours()
  558. var surplusMonth = that.surplusMonth(year);
  559. console.log(surplusMonth)
  560. var surplusDay = this.surplusDay(year, month, day);
  561. console.log(surplusDay)
  562. var surplusHour = this.surplusHour(year, month, day, hour)
  563. console.log(surplusHour)
  564. //初始化picker
  565. that.setData({
  566. multiArray: [
  567. [year + '年', (year + 1) + '年', (year + 2) + '年'],
  568. surplusMonth,
  569. surplusDay,
  570. surplusHour[0],
  571. ['~'],
  572. surplusHour[1]
  573. ],
  574. year: year,
  575. month: month,
  576. day: day,
  577. startHour: surplusHour[0][0],
  578. endHour: surplusHour[1][0],
  579. })
  580. },
  581. varietiesChange: function (e) {
  582. var Varieties = this.data.array[parseInt(e.detail.value)]
  583. console.log(Varieties)
  584. this.setData({
  585. Varieties: Varieties
  586. })
  587. },
  588. warehouseChange: function (e) {
  589. var Warehouse = this.data.array[parseInt(e.detail.value)]
  590. console.log(Warehouse)
  591. this.setData({
  592. Warehouse: Warehouse
  593. })
  594. },
  595. //某一列的值改变时触发
  596. bindMultiPickerColumnChange: function (e) {
  597. var date = new Date();
  598. var year1 = date.getFullYear()
  599. var month1 = date.getMonth() + 1
  600. var day1 = date.getDate()
  601. var hour1 = date.getHours()
  602. console.log("当前月份" + this.data.month + '修改的列为', e.detail.column, ',值为', e.detail.value);
  603. var data = {
  604. multiArray: this.data.multiArray,
  605. multiIndex: this.data.multiIndex,
  606. year: this.data.year,
  607. month: this.data.month,
  608. day: this.data.day,
  609. startHour: this.data.startHour,
  610. endHour: this.data.startHour,
  611. };
  612. data.multiIndex[e.detail.column] = e.detail.value;
  613. switch (e.detail.column) {
  614. case 0:
  615. var yearStr = data.multiArray[e.detail.column][e.detail.value];
  616. var year = yearStr.substring(0, yearStr.length - 1)
  617. data.year = parseInt(year);
  618. var surplusMonth = this.surplusMonth(year);
  619. data.multiArray[1] = surplusMonth;
  620. if (data.year == year1) {
  621. data.month = month1;
  622. } else {
  623. data.month = 1;
  624. }
  625. if (data.year == year1 && month1 == data.month) {
  626. data.day = day1;
  627. } else {
  628. data.day = 1;
  629. }
  630. var surplusDay = this.surplusDay(data.year, data.month, data.day);
  631. data.multiArray[2] = surplusDay;
  632. var surplusHour;
  633. if (data.year == year1 && month1 == data.month && data.day == day1) {
  634. surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
  635. } else {
  636. surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
  637. }
  638. console.log(surplusHour)
  639. data.multiArray[3] = surplusHour[0];
  640. data.multiArray[5] = surplusHour[1];
  641. data.startHour = surplusHour[0];
  642. data.endHour = surplusHour[1];
  643. data.multiIndex[1] = 0;
  644. data.multiIndex[2] = 0;
  645. data.multiIndex[3] = 0;
  646. data.multiIndex[5] = 0;
  647. break;
  648. case 1:
  649. console.log('选择月份' + data.multiArray[e.detail.column][e.detail.value]);
  650. var monthStr = data.multiArray[e.detail.column][e.detail.value];
  651. var month = monthStr.substring(0, monthStr.length - 1);
  652. data.month = month;
  653. data.day = 1;
  654. if (data.year == year1 && month1 == data.month) {
  655. data.day = day1;
  656. } else {
  657. data.day = 1;
  658. }
  659. var surplusDay = this.surplusDay(data.year, data.month, data.day);
  660. data.multiArray[2] = surplusDay;
  661. var surplusHour;
  662. if (data.year == year1 && month1 == data.month && data.day == day1) {
  663. surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
  664. } else {
  665. surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
  666. }
  667. data.multiArray[3] = surplusHour[0];
  668. data.multiArray[5] = surplusHour[1];
  669. data.startHour = surplusHour[0];
  670. data.endHour = surplusHour[1];
  671. data.multiIndex[2] = 0;
  672. data.multiIndex[3] = 0;
  673. data.multiIndex[5] = 0;
  674. break;
  675. case 2:
  676. console.log('选择日' + data.multiArray[e.detail.column][e.detail.value]);
  677. var dayStr = data.multiArray[e.detail.column][e.detail.value];
  678. var day = dayStr.substring(0, dayStr.length - 1);
  679. data.day = day;
  680. var surplusHour;
  681. if (data.year == year1 && month1 == data.month && data.day == day1) {
  682. surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
  683. } else {
  684. surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
  685. }
  686. data.multiArray[3] = surplusHour[0];
  687. data.multiArray[5] = surplusHour[1];
  688. data.startHour = surplusHour[0];
  689. data.endHour = surplusHour[1];
  690. data.multiIndex[3] = 0;
  691. data.multiIndex[5] = 0;
  692. break;
  693. case 3:
  694. console.log('起始时间' + data.multiArray[e.detail.column][e.detail.value]);
  695. var hourStr = data.multiArray[e.detail.column][e.detail.value];
  696. var hour = hourStr.substring(0, hourStr.length - 1);
  697. data.startHour = hour;
  698. console.log('起始时间' + hour + " day1:" + day1);
  699. /*var endhours2 = [];
  700. var end = ['09时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时', '20时'];
  701. for (var i = e.detail.value; i < end.length; i++) {
  702. endhours2.push(end[i]);
  703. }
  704. data.multiArray[5] = endhours2; */
  705. if (e.detail.value > data.multiIndex[5])
  706. data.multiIndex[5] = e.detail.value;
  707. break;
  708. case 5:
  709. var hourStr = data.multiArray[e.detail.column][e.detail.value];
  710. var hour = hourStr.substring(0, hourStr.length - 1);
  711. data.endHour = hour;
  712. if (e.detail.value <data.multiIndex[3])
  713. data.multiIndex[3] = e.detail.value;
  714. //console.log('index:'+data.multiIndex[3]+'value:'+e.detail.value+'结束时间' + data.multiArray[e.detail.column][e.detail.value]);
  715. break;
  716. }
  717. this.setData(data)
  718. },
  719. //value 改变时触发 change 事件
  720. bindMultiPickerChange: function (e) {
  721. console.info(e);
  722. console.info(this.data.multiArray);
  723. console.info(this.data);
  724. console.info(this.data.multiIndex);
  725. var dateStr =
  726. this.data.multiArray[0][this.data.multiIndex[0]] +
  727. this.data.multiArray[1][this.data.multiIndex[1]] +
  728. this.data.multiArray[2][this.data.multiIndex[2]] +
  729. this.data.multiArray[3][this.data.multiIndex[3]] +
  730. this.data.multiArray[4][this.data.multiIndex[4]] +
  731. this.data.multiArray[5][this.data.multiIndex[5]];
  732. console.log('picker发送选择改变,携带值为', dateStr)
  733. this.setData({
  734. orderData: dateStr
  735. })
  736. },
  737. onClose(){
  738. this.setData({
  739. choosePopup:false
  740. });
  741. },
  742. dateCheck(e){
  743. let index=e.currentTarget.dataset.index;
  744. let date=e.currentTarget.dataset.date;
  745. if(index>=2&&date!='2021-08-21'&&date!='2021-08-22'&&date!='2021-08-28'&&date!='2021-08-29'){//前三天不可预约
  746. this.setData({
  747. dateIndex:index
  748. });
  749. }
  750. },
  751. timeCheck(e){
  752. let index=e.currentTarget.dataset.index;
  753. this.setData({
  754. timeIndex:index
  755. });
  756. },
  757. weekCheck(e){
  758. let index=e.currentTarget.dataset.index;
  759. this.setData({
  760. weekIndex:index,
  761. // selectTimeIndex:'null'
  762. });
  763. },
  764. timeSelect(e){
  765. let index=e.currentTarget.dataset.index;
  766. let time=e.currentTarget.dataset.time;
  767. if(this.data.activeTab!=2){
  768. let weekList=this.data.weekArrList;
  769. weekList.forEach(item=>{
  770. item.num=0;
  771. });
  772. this.setData({
  773. weekArrList:weekList,
  774. });
  775. let itemData = "weekArrList[" + this.data.weekIndex + "].num";
  776. let selectedDateList=[];
  777. let dateItem={week:this.data.weekIndex,time:time,weekStr:this.data.weekArrList[this.data.weekIndex].week};
  778. selectedDateList.push(dateItem);
  779. console.log(this.data);
  780. this.setData({
  781. selectTimeIndex:index,
  782. [itemData]:1,
  783. selectedWeekList:[this.data.weekIndex],
  784. selectedDateList:selectedDateList
  785. });
  786. console.log(this.data);
  787. }else{
  788. // 如果选中的时间段小于2个
  789. if(this.data.selectedDateList.length<2){
  790. let itemData = "weekArrList[" + this.data.weekIndex + "].num";
  791. let num=this.data.weekArrList[this.data.weekIndex].num;
  792. let selectedDateList=this.data.selectedDateList;
  793. selectedDateList.push({week:this.data.weekIndex,time:time,weekStr:this.data.weekArrList[this.data.weekIndex].week});
  794. let selectedWeekList=this.data.selectedWeekList;
  795. if(selectedWeekList.indexOf(this.data.weekIndex)==-1){
  796. selectedWeekList.push(this.data.weekIndex);
  797. }
  798. this.setData({
  799. [itemData]:num+1,
  800. selectTimeIndex:index,
  801. // selectedWeekList:selectedWeekList,
  802. selectedWeekList:[this.data.weekIndex],
  803. selectedDateList:selectedDateList
  804. });
  805. }else{
  806. // 删除第一个
  807. let firstTimeSelected=this.data.selectedDateList[0];
  808. let firstWeekSelectedIndex=firstTimeSelected.week;
  809. // let firstWeekSelected=this.data.weekArrList[firstWeekSelectedIndex];
  810. let itemDataDel = "weekArrList[" + firstWeekSelectedIndex + "].num";
  811. let numDel=this.data.weekArrList[firstWeekSelectedIndex].num;
  812. let selectedDateListDel=this.data.selectedDateList;
  813. selectedDateListDel.shift();
  814. this.setData({
  815. [itemDataDel]:numDel-1,
  816. // selectTimeIndex:index,
  817. selectedDateList: selectedDateListDel
  818. });
  819. // 加入新选中的
  820. let itemData = "weekArrList[" + this.data.weekIndex + "].num";
  821. let num=this.data.weekArrList[this.data.weekIndex].num;
  822. let selectedDateList=this.data.selectedDateList;
  823. selectedDateList.push({week:this.data.weekIndex,time:time,weekStr:this.data.weekArrList[this.data.weekIndex].week});
  824. this.setData({
  825. [itemData]:num+1,
  826. // selectTimeIndex:index,
  827. selectedDateList:selectedDateList
  828. });
  829. let weekListNew=[];
  830. this.data.selectedDateList.forEach(item=>{
  831. if(weekListNew.indexOf(item.week)==-1){
  832. weekListNew.push(item.week);
  833. }
  834. });
  835. this.setData({
  836. selectedWeekList:weekListNew,
  837. });
  838. }
  839. console.log(this.data);
  840. }
  841. },
  842. firstDateCheck(e){
  843. let index=e.currentTarget.dataset.index;
  844. this.setData({
  845. firstDateIndex:index
  846. });
  847. },
  848. onTabChange(e){
  849. let weekList=this.data.weekArrList;
  850. weekList.forEach(item=>{
  851. item.num=0;
  852. });
  853. this.setData({
  854. weekArrList:weekList,
  855. activeTab:e.detail.name,
  856. selectTimeIndex:'null',
  857. selectedWeekList:[],
  858. selectedDateList:[]
  859. });
  860. },
  861. showAppoint(){
  862. this.setData({
  863. choosePopup:true,
  864. popupType:(this.data.popupType==3?2:this.data.popupType),
  865. isFinishAppoint:false
  866. });
  867. if(this.data.popupType=='1'){
  868. let index=2;
  869. let length=this.data.dateList.length;
  870. let list=this.data.dateList;
  871. for(let i=0;i<length;i++){
  872. if(i>=2&&list[i].date!='2021-08-21'&&list[i].date!='2021-08-22'&&list[i].date!='2021-08-28'&&list[i].date!='2021-08-29'){
  873. index=i;
  874. break;
  875. }
  876. }
  877. console.log(index);
  878. this.setData({
  879. dateIndex:index
  880. })
  881. }
  882. },
  883. confirmTime(){
  884. console.log(this.data.activeTab);
  885. console.log(this.data);
  886. if(this.data.popupType==1){
  887. let date=this.data.dateList[this.data.dateIndex].date;
  888. let week=this.data.dateList[this.data.dateIndex].week;
  889. let time=this.data.timeList[this.data.timeIndex].time;
  890. console.log(week,time);
  891. this.setData({
  892. oneTimeAppoint:date+' '+week+' '+time,
  893. choosePopup:false,
  894. isFinishAppoint:true
  895. });
  896. }else if(this.data.popupType==2){
  897. if(this.data.activeTab==2){
  898. if(this.data.selectedDateList.length<1){
  899. wx.showToast({
  900. title: '请选择服务时间',
  901. icon: 'none',
  902. duration: 2000
  903. });
  904. }else if(this.data.selectedDateList.length==1){
  905. wx.showToast({
  906. title: '请选择第二次服务时间',
  907. icon: 'none',
  908. duration: 2000
  909. });
  910. }else{
  911. // 选择频次
  912. let futureDateList=util.getDateList(new Date(new Date().getTime()+60*60*1000*24),1);
  913. let minIndex=Math.min.apply(null, this.data.selectedWeekList);
  914. console.log(minIndex);
  915. console.log((this.data.weekArrList[minIndex]).id);
  916. let beginDate=futureDateList.filter(item=>{return (new Date(item.date)).getDay()==(this.data.weekArrList[minIndex]).id});
  917. console.log(beginDate);
  918. let inter=7;
  919. let firstAppointList=util.getDateList(new Date(new Date(beginDate[0].date).getTime()),inter);
  920. this.setData({
  921. popupType:3,
  922. firstAppointList:firstAppointList
  923. })
  924. }
  925. }else{
  926. if(this.data.selectedDateList.length==0){
  927. wx.showToast({
  928. title: '请选择服务时间',
  929. icon: 'none',
  930. duration: 2000
  931. });
  932. }else{
  933. // 选择频次
  934. let futureDateList=util.getDateList(new Date(new Date().getTime()+60*60*1000*24),1);
  935. let minIndex=Math.min.apply(null, this.data.selectedWeekList);
  936. console.log(minIndex);
  937. let beginDate=futureDateList.filter(item=>{return (new Date(item.date)).getDay()==(this.data.weekArrList[minIndex]).id});
  938. console.log(beginDate);
  939. let inter=(this.data.activeTab==3?14:7);
  940. let firstAppointList=util.getDateList(new Date(new Date(beginDate[0].date).getTime()),inter);
  941. this.setData({
  942. popupType:3,
  943. firstAppointList:firstAppointList
  944. })
  945. }
  946. }
  947. }else if(this.data.popupType==3){
  948. let firstTime=this.data.firstAppointList[this.data.firstDateIndex].date;
  949. console.log(firstTime);
  950. console.log(this.data.selectedDateList);
  951. this.orderAppoint();
  952. // this.setData({
  953. // choosePopup:false,
  954. // isFinishAppoint:true
  955. // });
  956. }
  957. },
  958. orderAppoint(){
  959. // 如果是多次卡先预估,单次卡不用预估
  960. let weeks=[];
  961. this.data.selectedDateList.forEach(item=>{
  962. let obj={
  963. dayOfWeek:this.data.weekArrList[item.week].id,
  964. startTime:item.time.split('-')[0],
  965. endTime:item.time.split('-')[1]
  966. };
  967. weeks.push(obj);
  968. });
  969. let params={
  970. weeks:weeks,
  971. type:this.data.activeTab,
  972. startDate:this.data.firstAppointList[this.data.firstDateIndex].date,
  973. lng:this.data.checkedAddress.lng,
  974. lat:this.data.checkedAddress.lat,
  975. shopId:this.data.checkedAddress.shopId,
  976. goodId:this.data.checkedGoodsList[0].goodsId
  977. };
  978. wx.showLoading({
  979. title: '加载中',
  980. });
  981. util.request(api.OrderAppoint, params, "POST")
  982. .then(res=> {
  983. wx.hideLoading();
  984. if (res.errno == 0) {
  985. // this.orderPay(params);
  986. this.setData({
  987. choosePopup:false,
  988. isFinishAppoint:true,
  989. popupType:2,
  990. noSerTimes:res.data,
  991. appointFailTip:(res.data>=1?true:false)
  992. });
  993. } else {
  994. // util.showErrorToast(res.errmsg);
  995. wx.showToast({
  996. title: res.errmsg,
  997. icon: 'none',
  998. duration: 2000
  999. });
  1000. }
  1001. }).catch(function (err) {
  1002. console.log(err);
  1003. wx.hideLoading();
  1004. wx.showToast({
  1005. title: err.errMsg,
  1006. icon: 'none'
  1007. })
  1008. });
  1009. },
  1010. cancelPay(){
  1011. this.setData({
  1012. payFailShow:false
  1013. });
  1014. },
  1015. rePay(){
  1016. util.request(api.OrderPrepay, {
  1017. orderId: this.data.orderId
  1018. }, 'POST').then(res=> {
  1019. if (res.errno === 0) {
  1020. const payParam = res.data;
  1021. console.log("支付过程开始")
  1022. wx.requestPayment({
  1023. 'timeStamp': payParam.timeStamp,
  1024. 'nonceStr': payParam.nonceStr,
  1025. 'package': payParam.packageValue,
  1026. 'signType': payParam.signType,
  1027. 'paySign': payParam.paySign,
  1028. 'success': res=>{
  1029. console.log("支付过程成功");
  1030. this.setData({
  1031. payFailShow:false
  1032. })
  1033. wx.redirectTo({
  1034. url: '/pages/checkout/payResult/payResult?status=1&orderId=' +this.data.orderId+'&actualPrice='+this.data.actualPrice
  1035. });
  1036. },
  1037. 'fail': res=> {
  1038. console.log("支付过程失败")
  1039. this.setData({
  1040. payFailShow:false
  1041. });
  1042. util.showErrorToast('支付失败');
  1043. },
  1044. 'complete': res=> {
  1045. console.log("支付过程结束");
  1046. }
  1047. });
  1048. }
  1049. });
  1050. },
  1051. goBuyMember(){
  1052. wx.navigateTo({
  1053. url: "/pages/member/buyMember/buyMember"
  1054. });
  1055. },
  1056. });