checkout.js 36 KB

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