checkout.js 32 KB

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