checkout.js 34 KB

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