checkout.js 34 KB

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