checkout.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  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. traceId: '', //视频号的traceid
  9. requireOrder: 0, //视频号 是否需要推单,1:需要,0:不需要
  10. increaseSumPrice: 0,
  11. isRecommend: false,
  12. isNoMatch: true,
  13. codeShow: false,
  14. recCode: '',
  15. recommendTips: '',
  16. memberDiscount: '',
  17. isMember: false,
  18. orderId: '',
  19. payFailShow: false,
  20. choosePopup: false,
  21. noSerTimes: '',
  22. popupType: 1, //1单次预约 2 选择服务频次 3选择首次预约时间
  23. // timeList: check.getTimeList(1),
  24. timeList: [],
  25. // dateList: util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24 * 0), 1, 21),
  26. dateList: [],
  27. // firstAppointList:util.getDateList(new Date(new Date().getTime()+60*60*1000*24),7),
  28. firstAppointList: [],
  29. timeIndex: '', //选中的时间段
  30. dateIndex: 0, //单次预约选中的日期
  31. firstDateIndex: 0, //首次预约时间
  32. activeTab: 1, //频次
  33. weekIndex: 0, //选中的周几
  34. weekArrList: [{
  35. id: 1,
  36. week: '周一',
  37. num: 0
  38. },
  39. {
  40. id: 2,
  41. week: '周二',
  42. num: 0
  43. },
  44. {
  45. id: 3,
  46. week: '周三',
  47. num: 0
  48. },
  49. {
  50. id: 4,
  51. week: '周四',
  52. num: 0
  53. },
  54. {
  55. id: 5,
  56. week: '周五',
  57. num: 0
  58. },
  59. {
  60. id: 6,
  61. week: '周六',
  62. num: 0
  63. },
  64. {
  65. id: 0,
  66. week: '周日',
  67. num: 0
  68. },
  69. ],
  70. selectedWeekList: [],
  71. selectedDateList: [],
  72. selectTimeIndex: 'null', //选中的时间段
  73. oneTimeAppoint: '2021-04-22 周一 13:00-14:00',
  74. isNeedAppoint: false, //是否需要预约
  75. isFinishAppoint: false, //已选择预约
  76. isOneAppoint: true, //单次卡
  77. appointFailTip: false, //预约失败提示
  78. bookStartDate: '', //可预约时间段
  79. bookEndDate: '',
  80. multiIndex: [0, 0, 0, 0, 0, 0],
  81. multiArray: [],
  82. array: [],
  83. year: "",
  84. month: "",
  85. day: "",
  86. startHour: "",
  87. endHour: "",
  88. orderData: "", //此时间为预计上门时间
  89. checkedGoodsList: [],
  90. checkedAddress: {},
  91. availableCouponLength: 0, // 可用的优惠券数量
  92. goodsTotalPrice: 0.00, //商品总价
  93. freightPrice: 0.00, //快递费
  94. couponPrice: 0.00, //优惠券的价格
  95. grouponPrice: 0.00, //团购优惠价格
  96. orderTotalPrice: 0.00, //订单总价
  97. actualPrice: 0.00, //实际需要支付的总价
  98. cartId: 0,
  99. addressId: 0,
  100. addressMsg: '',
  101. couponId: 0,
  102. userCouponId: 0,
  103. message: '',
  104. grouponLinkId: 0, //参与的团购
  105. grouponRulesId: 0, //团购规则ID
  106. nurseId: 0, //安心包认证id
  107. petinfo: null, //宠物保险内容
  108. shareId: 0,
  109. userInfo: {},
  110. remarkDisable: false,
  111. fraId: '', //加盟商id
  112. rId: '', //阿姨推荐码
  113. channelId: 5, //渠道id
  114. goodsType: 1, //商品类型 如果是6 可以不填写预约时间,
  115. serviceDuration: '',
  116. noonType: 1,
  117. selectTimeValue: '',
  118. date: '',
  119. week: '',
  120. time: '',
  121. selectweek: '一周一次',
  122. weekday: '周一',
  123. selecttime: ''
  124. },
  125. //获取checkou信息
  126. getCheckoutInfo: function (appType) {
  127. let that = this;
  128. util.request(api.CartCheckout, {
  129. cartId: that.data.cartId,
  130. addressId: that.data.addressId,
  131. couponId: that.data.couponId,
  132. userCouponId: that.data.userCouponId,
  133. grouponRulesId: that.data.grouponRulesId,
  134. shareId: that.data.shareId,
  135. }).then(function (res) {
  136. if (res.errno === 0) {
  137. that.setData({
  138. isRecommend: res.data.checkedGoodsList[0].goods.attribute != 1,
  139. isMember: res.data.isMember,
  140. memberDiscount: res.data.memberDiscount,
  141. checkedGoodsList: res.data.checkedGoodsList,
  142. checkedAddress: res.data.checkedAddress,
  143. availableCouponLength: res.data.availableCouponLength,
  144. actualPrice: res.data.actualPrice,
  145. couponPrice: res.data.couponPrice,
  146. grouponPrice: res.data.grouponPrice,
  147. freightPrice: res.data.freightPrice,
  148. goodsTotalPrice: res.data.goodsTotalPrice,
  149. orderTotalPrice: res.data.orderTotalPrice,
  150. addressId: res.data.addressId,
  151. addressMsg: res.data.addressMsg,
  152. couponId: res.data.couponId,
  153. userCouponId: res.data.userCouponId,
  154. grouponRulesId: res.data.grouponRulesId,
  155. isNeedAppoint: appType == "1" ? true : false, //0需要预约 服务类商品,1保险 2中介 3买约分离次卡res.data.checkedGoodsList[0].goods.type === 0 ||
  156. isOneAppoint: res.data.checkedGoodsList[0].product.serviceTimes == 1 ? true : false, //1为单次,其余为多次
  157. popupType: res.data.checkedGoodsList[0].product.serviceTimes == 1 ? 1 : 2,
  158. bookStartDate: res.data.bookStartDate,
  159. bookEndDate: res.data.bookEndDate,
  160. goodsType: res.data.goodsType,
  161. increaseSumPrice: res.data.increaseSumPrice,
  162. serviceDuration: res.data.serviceDuration
  163. });
  164. let serviceDuration = res.data.checkedGoodsList[0].product.serviceDuration;
  165. if (that.data.popupType == 2) {
  166. let timeList = [];
  167. if (res.data.timeRange != null && res.data.timeRange.length > 0) {
  168. res.data.timeRange.forEach((time, index) => {
  169. timeList.push({
  170. id: index + 1,
  171. time: time
  172. })
  173. })
  174. } else
  175. timeList = check.getTimeList(serviceDuration);
  176. that.setData({
  177. timeList: timeList
  178. });
  179. }
  180. if (res.data.addressId == null && res.data.addressMsg != null) {
  181. wx.showToast({
  182. title: res.data.addressMsg,
  183. icon: 'none'
  184. })
  185. }
  186. // that.LimitCanAppointmentDate();
  187. }
  188. wx.hideLoading();
  189. });
  190. },
  191. LimitCanAppointmentDate() { //特殊商品 如果需要限制可预约的时间范围 在次方法中实现
  192. if (this.data.checkedGoodsList[0].goodsId == 1190332) {
  193. let dates = [];
  194. this.data.dateList.forEach(item => {
  195. if (item.date < '2022-04-01')
  196. dates.push(item);
  197. })
  198. this.setData({
  199. dateList: dates
  200. })
  201. }
  202. //控制可预约时间范围
  203. let that = this;
  204. if (that.data.bookStartDate) {
  205. let dates = [];
  206. let dateIndex = -1;
  207. that.data.dateList.forEach((item, index) => {
  208. if (item.date < that.data.bookStartDate || item.date > that.data.bookEndDate) {
  209. item.isBook = false;
  210. item.mark = "不可约";
  211. } else {
  212. //设置第一个可预约的时间index
  213. if (dateIndex < 0) dateIndex = index;
  214. }
  215. dates.push(item);
  216. })
  217. that.setData({
  218. dateList: dates,
  219. dateIndex: dateIndex
  220. })
  221. }
  222. console.info(that.data.dateList)
  223. console.info(that.data.dateIndex)
  224. //设置默认起始可预约 index:dateIndex 近7天如果有周六 周日 不允许预约
  225. //存在一种情况 如果今天是周四,如果起始index=2 则周日允许预约 虽然页面显示为”约满"
  226. // if(this.data.dateList[3].id==0) {
  227. // console.info(" dateIndex:4")
  228. // this.setData({
  229. // dateIndex:4
  230. // })
  231. // }else{
  232. // if(this.data.dateList[2].id==0) {
  233. // console.info(" dateIndex:3")
  234. // this.setData({
  235. // dateIndex:3
  236. // })
  237. // }
  238. // }
  239. },
  240. selectAddress() {
  241. wx.navigateTo({
  242. url: '/pages/ucenter/address/address',
  243. })
  244. },
  245. selectCoupon() {
  246. wx.navigateTo({
  247. url: '/pages/ucenter/couponSelect/couponSelect',
  248. })
  249. },
  250. bindMessageInput: function (e) {
  251. this.setData({
  252. message: e.detail.value
  253. });
  254. },
  255. bindCodeInput: function (e) {
  256. this.setData({
  257. recCode: e.detail.value
  258. });
  259. if (e.detail.value.length == 5) {
  260. // 校验服务者真实性
  261. this.recCodeCheck();
  262. // this.setData({
  263. // codeShow:true
  264. // })
  265. } else {
  266. this.setData({
  267. codeShow: false
  268. });
  269. }
  270. },
  271. recCodeCheck() {
  272. wx.showLoading({
  273. title: '加载中',
  274. });
  275. util.request(api.checkRecommend, {
  276. recCode: this.data.recCode
  277. }, "GET")
  278. .then(res => {
  279. wx.hideLoading();
  280. if (res.errno == 0) {
  281. if (res.data) {
  282. this.setData({
  283. codeShow: true,
  284. isNoMatch: false,
  285. recommendTips: '推荐人:' + res.data
  286. });
  287. } else {
  288. this.setData({
  289. codeShow: true,
  290. isNoMatch: true,
  291. recommendTips: '未匹配到推荐者,请您和推荐人核对'
  292. });
  293. }
  294. } else {
  295. this.setData({
  296. codeShow: false,
  297. });
  298. wx.showToast({
  299. title: res.errmsg,
  300. icon: 'none',
  301. duration: 2000
  302. });
  303. }
  304. }).catch(function (err) {
  305. wx.hideLoading();
  306. this.setData({
  307. codeShow: false,
  308. });
  309. wx.showToast({
  310. title: err.errMsg,
  311. icon: 'none'
  312. })
  313. });
  314. },
  315. onReady: function () {
  316. // 页面渲染完成
  317. },
  318. onShow: function () {
  319. // console.log(this.data.dateList);
  320. // 页面显示
  321. user.checkLogin().then(res => {
  322. app.globalData.hasLogin = true;
  323. console.info("session 未过期")
  324. }).catch(() => {
  325. console.info("session 过期")
  326. app.globalData.hasLogin = false;
  327. wx.navigateTo({
  328. url: '/pages/auth/login/login',
  329. })
  330. });
  331. wx.showLoading({
  332. title: '加载中...',
  333. });
  334. try {
  335. var cartId = wx.getStorageSync('cartId');
  336. if (cartId === "") {
  337. cartId = 0;
  338. }
  339. var addressId = wx.getStorageSync('addressId');
  340. if (addressId === "") {
  341. addressId = 0;
  342. } else if (typeof addressId === 'number') {} else if ((typeof addressId === 'string' && addressId.indexOf("{") !== -1) || addressId.length > 20) {
  343. addressId = JSON.parse(addressId).id;
  344. }
  345. var couponId = wx.getStorageSync('couponId');
  346. if (couponId === "") {
  347. couponId = 0;
  348. }
  349. var userCouponId = wx.getStorageSync('userCouponId');
  350. if (userCouponId === "") {
  351. userCouponId = 0;
  352. }
  353. var grouponRulesId = wx.getStorageSync('grouponRulesId');
  354. if (grouponRulesId === "") {
  355. grouponRulesId = 0;
  356. }
  357. var grouponLinkId = wx.getStorageSync('grouponLinkId');
  358. if (grouponLinkId === "") {
  359. grouponLinkId = 0;
  360. }
  361. //客户点选的预约动作
  362. var appType = wx.getStorageSync('appType');
  363. console.info(appType)
  364. this.setData({
  365. cartId: cartId,
  366. addressId: addressId,
  367. couponId: couponId,
  368. userCouponId: userCouponId,
  369. grouponRulesId: grouponRulesId,
  370. grouponLinkId: grouponLinkId
  371. });
  372. this.getCheckoutInfo(appType);
  373. } catch (e) {
  374. // Do something when catch error
  375. console.log(e);
  376. }
  377. },
  378. onHide: function () {
  379. // 页面隐藏
  380. },
  381. onUnload: function () {
  382. // 页面关闭
  383. //清空宠物保险的缓存数据
  384. console.info('checkout onload')
  385. //wx.setStorageSync('petinfo'+this.data.cartId, null);
  386. },
  387. submitOrder: function () {
  388. let that = this;
  389. if (that.data.addressId <= 0) {
  390. //所选地址无服务门店,或选择其他地址
  391. let errmsg = that.data.addressMsg == '' ? '请选择收货地址' : that.data.addressMsg;
  392. //util.showErrorToast(errmsg);
  393. wx.showModal({
  394. title: '提示',
  395. content: errmsg,
  396. showCancel: false,
  397. });
  398. return;
  399. }
  400. // 检查是否已经预约
  401. if (that.data.goodsType != 6 && that.data.goodsType != 4 && that.data.isNeedAppoint && !that.data.isFinishAppoint) {
  402. // util.showErrorToast('请先预约服务时间');
  403. wx.showToast({
  404. title: '请先预约服务时间',
  405. icon: 'none',
  406. duration: 2000
  407. });
  408. return;
  409. }
  410. wx.showLoading({
  411. title: '检测中',
  412. });
  413. that.submitInfo();
  414. },
  415. submitInfo() {
  416. // 如果是多次卡先预估,单次卡不用预估
  417. if (!this.data.isOneAppoint) {
  418. let weeks = [];
  419. this.data.selectedDateList.forEach(item => {
  420. let obj = {
  421. dayOfWeek: this.data.weekArrList[item.week].id,
  422. startTime: item.time.split('-')[0],
  423. endTime: item.time.split('-')[1]
  424. };
  425. weeks.push(obj);
  426. });
  427. let tempStartDate = null;
  428. if (this.data.firstAppointList.length != 0 && this.data.firstAppointList.length >= this.data.firstDateIndex) {
  429. tempStartDate = this.data.firstAppointList[this.data.firstDateIndex].date;
  430. }
  431. let params = {
  432. weeks: weeks,
  433. type: this.data.activeTab,
  434. startDate: tempStartDate, //this.data.firstAppointList[this.data.firstDateIndex].date,
  435. lng: this.data.checkedAddress.lng,
  436. lat: this.data.checkedAddress.lat,
  437. shopId: this.data.checkedAddress.shopId,
  438. goodId: this.data.checkedGoodsList[0].goodsId
  439. };
  440. console.log(params);
  441. this.orderPay(params);
  442. } else {
  443. let weeks = [];
  444. if (this.data.isNeedAppoint && this.data.goodsType != 6 && this.data.goodsType != 4) {
  445. weeks = [{
  446. dayOfWeek: (new Date(this.data.dateList[this.data.dateIndex].bookdate)).getDay(),
  447. startTime: this.data.timeList[this.data.timeIndex].begin,
  448. endTime: this.data.timeList[this.data.timeIndex].end
  449. }];
  450. }
  451. let params = {
  452. weeks: weeks,
  453. type: 0,
  454. startDate: this.data.isNeedAppoint ? this.data.dateList[this.data.dateIndex].bookdate : null,
  455. lng: this.data.checkedAddress.lng,
  456. lat: this.data.checkedAddress.lat,
  457. shopId: this.data.checkedAddress.shopId,
  458. goodId: this.data.checkedGoodsList[0].goodsId
  459. };
  460. console.log(params);
  461. this.orderPay(params);
  462. }
  463. },
  464. orderPay(orderData) {
  465. let that = this;
  466. var orderInfo = {
  467. cartId: this.data.cartId,
  468. addressId: this.data.addressId,
  469. couponId: this.data.couponId,
  470. userCouponId: this.data.userCouponId,
  471. message: this.data.message,
  472. orderDate: this.data.orderData,
  473. grouponRulesId: this.data.grouponRulesId,
  474. grouponLinkId: this.data.grouponLinkId,
  475. nurseId: this.data.nurseId,
  476. petinfo: this.data.petinfo,
  477. shareId: this.data.shareId,
  478. recCode: this.data.recCode ? this.data.recCode : this.data.rId, //服务者推荐id(如果填写推荐码 以填写为准)
  479. fraId: this.data.fraId, //加盟商id
  480. channelId: this.data.channelId, //渠道码
  481. //预约参数信息
  482. orderDate: orderData,
  483. requireOrder: this.data.requireOrder,
  484. traceId: this.data.traceId //视频号
  485. };
  486. if (this.data.codeShow && !this.data.isNoMatch) {
  487. orderInfo.recCode = this.data.recCode;
  488. }
  489. console.log(orderInfo);
  490. util.request(api.OrderSubmit, orderInfo, 'POST').then(res => {
  491. //视频号,校验 wx.checkBeforeAddOrder
  492. wx.checkBeforeAddOrder({
  493. success(res) {
  494. console.log("checkBeforeAddOrder-success:", res);
  495. if (res.data.errcode == 0) {
  496. that.setData({
  497. traceId: res.data.traceId,
  498. requireOrder: res.data.requireOrder
  499. })
  500. }
  501. },
  502. fail(res) {
  503. console.log("checkBeforeAddOrder-fail:", res);
  504. }
  505. })
  506. if (res.errno === 0) {
  507. console.log(res.data.isNeedPay);
  508. if (res.data.isNeedPay == false) {
  509. console.log("跳过支付");
  510. util.redirect('/pages/ucenter/order/order');
  511. return;
  512. }
  513. // 下单成功,重置couponId
  514. wx.setStorageSync('couponId', 0);
  515. const orderId = res.data.orderId;
  516. this.setData({
  517. orderId: orderId
  518. });
  519. const grouponLinkId = res.data.grouponLinkId;
  520. util.request(api.OrderPrepay, {
  521. orderId: orderId
  522. }, 'POST').then(res => {
  523. if (res.errno === 0) {
  524. const payParam = res.data;
  525. console.log("支付过程开始");
  526. if (this.data.requireOrder == 1) {
  527. //视频号支付
  528. wx.requestOrderPayment({
  529. 'timeStamp': payParam.timeStamp,
  530. 'nonceStr': payParam.nonceStr,
  531. 'package': payParam.packageValue,
  532. 'signType': payParam.signType,
  533. 'paySign': payParam.paySign,
  534. 'success': res => {
  535. console.log("支付过程成功");
  536. if (grouponLinkId) {
  537. setTimeout(() => {
  538. wx.redirectTo({
  539. url: '/pages/groupon/grouponDetail/grouponDetail?id=' + grouponLinkId
  540. })
  541. }, 1000);
  542. } else {
  543. wx.redirectTo({
  544. url: '/pages/checkout/payResult/payResult?status=1&orderId=' + orderId + '&actualPrice=' + this.data.actualPrice
  545. });
  546. }
  547. },
  548. 'fail': res => {
  549. console.log("支付过程失败");
  550. // wx.redirectTo({
  551. // url: '/pages/checkout/payResult/payResult?status=0&orderId=' + orderId
  552. // });
  553. // 弹出支付失败
  554. this.setData({
  555. payFailShow: true,
  556. remarkDisable: true
  557. });
  558. },
  559. 'complete': function (res) {
  560. console.log("支付过程结束")
  561. }
  562. });
  563. } else {
  564. wx.requestPayment({
  565. 'timeStamp': payParam.timeStamp,
  566. 'nonceStr': payParam.nonceStr,
  567. 'package': payParam.packageValue,
  568. 'signType': payParam.signType,
  569. 'paySign': payParam.paySign,
  570. 'success': res => {
  571. console.log("支付过程成功");
  572. if (grouponLinkId) {
  573. setTimeout(() => {
  574. wx.redirectTo({
  575. url: '/pages/groupon/grouponDetail/grouponDetail?id=' + grouponLinkId
  576. })
  577. }, 1000);
  578. } else {
  579. wx.redirectTo({
  580. url: '/pages/checkout/payResult/payResult?status=1&orderId=' + orderId + '&actualPrice=' + this.data.actualPrice
  581. });
  582. }
  583. },
  584. 'fail': res => {
  585. console.log("支付过程失败");
  586. // 弹出支付失败
  587. this.setData({
  588. payFailShow: true,
  589. remarkDisable: true
  590. });
  591. },
  592. 'complete': function (res) {
  593. console.log("支付过程结束")
  594. }
  595. });
  596. }
  597. } else {
  598. // 弹出支付失败
  599. this.setData({
  600. payFailShow: true,
  601. remarkDisable: true
  602. });
  603. }
  604. });
  605. } else {
  606. wx.showToast({
  607. title: res.errmsg,
  608. icon: 'none'
  609. })
  610. }
  611. });
  612. },
  613. surplusMonth: function (year) {
  614. var date = new Date();
  615. var year2 = date.getFullYear()
  616. var month = date.getMonth() + 1
  617. var day = date.getDate()
  618. var hour = date.getHours()
  619. var minute = date.getMinutes()
  620. var second = date.getSeconds()
  621. var monthDatas = [];
  622. if (year == year2) {
  623. var surplusMonth = 12 - month;
  624. monthDatas.push(month + "月")
  625. for (var i = month; i < 12; i++) {
  626. monthDatas.push(i + 1 + "月")
  627. }
  628. } else {
  629. for (var i = 0; i < 12; i++) {
  630. monthDatas.push(i + 1 + "月")
  631. }
  632. }
  633. return monthDatas;
  634. },
  635. //天数计算
  636. surplusDay: function (year, month, day) {
  637. var days = 31;
  638. var dayDatas = [];
  639. var date = new Date();
  640. var year2 = date.getFullYear()
  641. var month2 = date.getMonth() + 1
  642. switch (parseInt(month)) {
  643. case 1:
  644. case 3:
  645. case 5:
  646. case 7:
  647. case 8:
  648. case 10:
  649. case 12:
  650. days = 31;
  651. break;
  652. //对于2月份需要判断是否为闰年
  653. case 2:
  654. if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
  655. days = 29;
  656. break;
  657. } else {
  658. days = 28;
  659. break;
  660. }
  661. case 4:
  662. case 6:
  663. case 9:
  664. case 11:
  665. days = 30;
  666. break;
  667. }
  668. if (year == year2 && month == month2) {
  669. // dayDatas.push(day + "日")
  670. for (var i = day; i < days; i++) {
  671. dayDatas.push(i + 1 + "日")
  672. }
  673. } else {
  674. console.log(month + "月" + days + "天")
  675. for (var i = 0; i < days; i++) {
  676. dayDatas.push(i + 1 + "日")
  677. }
  678. }
  679. return dayDatas;
  680. },
  681. //时间计算
  682. surplusHour: function (year, month, day, hour) {
  683. var date = new Date();
  684. var year2 = date.getFullYear()
  685. var month2 = date.getMonth() + 1
  686. var day2 = date.getDate();
  687. var hourEnd = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21];
  688. var hours = [
  689. ['09时', '10时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时'],
  690. ['10时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时', '21时']
  691. ];
  692. return hours;
  693. },
  694. /**
  695. * 生命周期函数--监听页面加载
  696. */
  697. onLoad: function (options) {
  698. this.setData({
  699. userInfo: app.globalData.userInfo
  700. });
  701. let that = this;
  702. if (options.nurseId) {
  703. this.setData({
  704. nurseId: options.nurseId
  705. })
  706. }
  707. var rId = wx.getStorageSync('rId');
  708. if (rId) {
  709. this.setData({
  710. rId: rId,
  711. recCode: rId
  712. })
  713. }
  714. var fraId = wx.getStorageSync('fraId');
  715. if (fraId) {
  716. this.setData({
  717. fraId: fraId
  718. })
  719. }
  720. var channelId = wx.getStorageSync('channelId');
  721. if (channelId) {
  722. this.setData({
  723. channelId: parseInt(channelId)
  724. })
  725. }
  726. if (typeof options.shareId != 'undefined' && options.shareId > 0) {
  727. that.setData({
  728. shareId: options.shareId
  729. })
  730. }
  731. //视频号,校验 wx.checkBeforeAddOrder
  732. wx.checkBeforeAddOrder({
  733. success(res) {
  734. console.log("checkBeforeAddOrder-success:", res);
  735. if (res.data.errcode == 0) {
  736. that.setData({
  737. traceId: res.data.traceId,
  738. requireOrder: res.data.requireOrder
  739. })
  740. }
  741. },
  742. fail(res) {
  743. console.log("checkBeforeAddOrder-fail:", res);
  744. }
  745. })
  746. var date = new Date();
  747. var year = date.getFullYear()
  748. var month = date.getMonth() + 1
  749. var day = date.getDate()
  750. var hour = date.getHours()
  751. var surplusMonth = that.surplusMonth(year);
  752. console.log(surplusMonth)
  753. var surplusDay = this.surplusDay(year, month, day);
  754. console.log(surplusDay)
  755. var surplusHour = this.surplusHour(year, month, day, hour)
  756. console.log(surplusHour)
  757. //初始化picker
  758. that.setData({
  759. multiArray: [
  760. [year + '年', (year + 1) + '年', (year + 2) + '年'],
  761. surplusMonth,
  762. surplusDay,
  763. surplusHour[0],
  764. ['~'],
  765. surplusHour[1]
  766. ],
  767. year: year,
  768. month: month,
  769. day: day,
  770. startHour: surplusHour[0][0],
  771. endHour: surplusHour[1][0],
  772. })
  773. },
  774. varietiesChange: function (e) {
  775. var Varieties = this.data.array[parseInt(e.detail.value)]
  776. console.log(Varieties)
  777. this.setData({
  778. Varieties: Varieties
  779. })
  780. },
  781. warehouseChange: function (e) {
  782. var Warehouse = this.data.array[parseInt(e.detail.value)]
  783. console.log(Warehouse)
  784. this.setData({
  785. Warehouse: Warehouse
  786. })
  787. },
  788. //某一列的值改变时触发
  789. bindMultiPickerColumnChange: function (e) {
  790. var date = new Date();
  791. var year1 = date.getFullYear()
  792. var month1 = date.getMonth() + 1
  793. var day1 = date.getDate()
  794. var hour1 = date.getHours()
  795. console.log("当前月份" + this.data.month + '修改的列为', e.detail.column, ',值为', e.detail.value);
  796. var data = {
  797. multiArray: this.data.multiArray,
  798. multiIndex: this.data.multiIndex,
  799. year: this.data.year,
  800. month: this.data.month,
  801. day: this.data.day,
  802. startHour: this.data.startHour,
  803. endHour: this.data.startHour,
  804. };
  805. data.multiIndex[e.detail.column] = e.detail.value;
  806. switch (e.detail.column) {
  807. case 0:
  808. var yearStr = data.multiArray[e.detail.column][e.detail.value];
  809. var year = yearStr.substring(0, yearStr.length - 1)
  810. data.year = parseInt(year);
  811. var surplusMonth = this.surplusMonth(year);
  812. data.multiArray[1] = surplusMonth;
  813. if (data.year == year1) {
  814. data.month = month1;
  815. } else {
  816. data.month = 1;
  817. }
  818. if (data.year == year1 && month1 == data.month) {
  819. data.day = day1;
  820. } else {
  821. data.day = 1;
  822. }
  823. var surplusDay = this.surplusDay(data.year, data.month, data.day);
  824. data.multiArray[2] = surplusDay;
  825. var surplusHour;
  826. if (data.year == year1 && month1 == data.month && data.day == day1) {
  827. surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
  828. } else {
  829. surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
  830. }
  831. console.log(surplusHour)
  832. data.multiArray[3] = surplusHour[0];
  833. data.multiArray[5] = surplusHour[1];
  834. data.startHour = surplusHour[0];
  835. data.endHour = surplusHour[1];
  836. data.multiIndex[1] = 0;
  837. data.multiIndex[2] = 0;
  838. data.multiIndex[3] = 0;
  839. data.multiIndex[5] = 0;
  840. break;
  841. case 1:
  842. console.log('选择月份' + data.multiArray[e.detail.column][e.detail.value]);
  843. var monthStr = data.multiArray[e.detail.column][e.detail.value];
  844. var month = monthStr.substring(0, monthStr.length - 1);
  845. data.month = month;
  846. data.day = 1;
  847. if (data.year == year1 && month1 == data.month) {
  848. data.day = day1;
  849. } else {
  850. data.day = 1;
  851. }
  852. var surplusDay = this.surplusDay(data.year, data.month, data.day);
  853. data.multiArray[2] = surplusDay;
  854. var surplusHour;
  855. if (data.year == year1 && month1 == data.month && data.day == day1) {
  856. surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
  857. } else {
  858. surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
  859. }
  860. data.multiArray[3] = surplusHour[0];
  861. data.multiArray[5] = surplusHour[1];
  862. data.startHour = surplusHour[0];
  863. data.endHour = surplusHour[1];
  864. data.multiIndex[2] = 0;
  865. data.multiIndex[3] = 0;
  866. data.multiIndex[5] = 0;
  867. break;
  868. case 2:
  869. console.log('选择日' + data.multiArray[e.detail.column][e.detail.value]);
  870. var dayStr = data.multiArray[e.detail.column][e.detail.value];
  871. var day = dayStr.substring(0, dayStr.length - 1);
  872. data.day = day;
  873. var surplusHour;
  874. if (data.year == year1 && month1 == data.month && data.day == day1) {
  875. surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
  876. } else {
  877. surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
  878. }
  879. data.multiArray[3] = surplusHour[0];
  880. data.multiArray[5] = surplusHour[1];
  881. data.startHour = surplusHour[0];
  882. data.endHour = surplusHour[1];
  883. data.multiIndex[3] = 0;
  884. data.multiIndex[5] = 0;
  885. break;
  886. case 3:
  887. console.log('起始时间' + data.multiArray[e.detail.column][e.detail.value]);
  888. var hourStr = data.multiArray[e.detail.column][e.detail.value];
  889. var hour = hourStr.substring(0, hourStr.length - 1);
  890. data.startHour = hour;
  891. console.log('起始时间' + hour + " day1:" + day1);
  892. /*var endhours2 = [];
  893. var end = ['09时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时', '20时'];
  894. for (var i = e.detail.value; i < end.length; i++) {
  895. endhours2.push(end[i]);
  896. }
  897. data.multiArray[5] = endhours2; */
  898. if (e.detail.value > data.multiIndex[5])
  899. data.multiIndex[5] = e.detail.value;
  900. break;
  901. case 5:
  902. var hourStr = data.multiArray[e.detail.column][e.detail.value];
  903. var hour = hourStr.substring(0, hourStr.length - 1);
  904. data.endHour = hour;
  905. if (e.detail.value < data.multiIndex[3])
  906. data.multiIndex[3] = e.detail.value;
  907. //console.log('index:'+data.multiIndex[3]+'value:'+e.detail.value+'结束时间' + data.multiArray[e.detail.column][e.detail.value]);
  908. break;
  909. }
  910. this.setData(data)
  911. },
  912. //value 改变时触发 change 事件
  913. bindMultiPickerChange: function (e) {
  914. console.info(e);
  915. console.info(this.data.multiArray);
  916. console.info(this.data);
  917. console.info(this.data.multiIndex);
  918. var dateStr =
  919. this.data.multiArray[0][this.data.multiIndex[0]] +
  920. this.data.multiArray[1][this.data.multiIndex[1]] +
  921. this.data.multiArray[2][this.data.multiIndex[2]] +
  922. this.data.multiArray[3][this.data.multiIndex[3]] +
  923. this.data.multiArray[4][this.data.multiIndex[4]] +
  924. this.data.multiArray[5][this.data.multiIndex[5]];
  925. console.log('picker发送选择改变,携带值为', dateStr)
  926. this.setData({
  927. orderData: dateStr
  928. })
  929. },
  930. onClose() {
  931. this.setData({
  932. choosePopup: false,
  933. remarkDisable: false,
  934. });
  935. },
  936. dateCheck(e) {
  937. let index = e.currentTarget.dataset.index;
  938. let date = e.currentTarget.dataset.date;
  939. let week = e.currentTarget.dataset.week;
  940. let isbook = e.currentTarget.dataset.isbook;
  941. console.info("dateCheck:" + index);
  942. this.setData({
  943. dateIndex: index
  944. });
  945. let period = this.data.dateList[this.data.dateIndex].period;
  946. let current = (this.data.noonType == 1 ? '上午' : '下午');
  947. let list = period.filter(item => {
  948. return item.ofTime == current;
  949. });
  950. let bookdate = this.data.dateList[this.data.dateIndex].bookdate
  951. let weekOfDay = this.data.dateList[this.data.dateIndex].weekOfDay
  952. this.setData({
  953. timeList: list,
  954. date: bookdate,
  955. week: weekOfDay
  956. });
  957. let isNoTime = list.every(item => {
  958. return item.timeMsg && item.timeMsg != null;
  959. });
  960. if (isNoTime) {
  961. this.setData({
  962. timeIndex: -1,
  963. selectTimeValue: ''
  964. });
  965. }
  966. },
  967. noonTab(e) {
  968. let noon = e.currentTarget.dataset.noon;
  969. this.setData({
  970. timeIndex: -1,
  971. noonType: noon,
  972. selectTimeValue: '',
  973. });
  974. let period = this.data.dateList[this.data.dateIndex].period;
  975. let current = (this.data.noonType == 1 ? '上午' : '下午');
  976. let list = period.filter(item => {
  977. return item.ofTime == current;
  978. });
  979. this.setData({
  980. timeList: list
  981. });
  982. },
  983. timeCheck(e) {
  984. let index = e.currentTarget.dataset.index;
  985. let toastMsg = e.currentTarget.dataset.toastmsg;
  986. let msg = e.currentTarget.dataset.msg;
  987. if (msg == null || msg == '') {
  988. let time = (this.data.timeList[index].begin).split(':')[0];
  989. let bookTime = this.data.timeList[index].begin + '-' + this.data.timeList[index].end
  990. this.setData({
  991. timeIndex: index,
  992. selectTimeValue: Number(time),
  993. time: bookTime
  994. });
  995. } else {
  996. wx.showToast({
  997. title: toastMsg,
  998. icon: 'none'
  999. })
  1000. }
  1001. },
  1002. weekCheck(e) {
  1003. let index = e.currentTarget.dataset.index;
  1004. let weekday = e.currentTarget.dataset.weekday;
  1005. console.log("weekday", weekday);
  1006. this.setData({
  1007. weekIndex: index,
  1008. weekday: weekday
  1009. });
  1010. },
  1011. timeSelect(e) {
  1012. let index = e.currentTarget.dataset.index;
  1013. let time = e.currentTarget.dataset.time;
  1014. if (this.data.activeTab != 2) {
  1015. let weekList = this.data.weekArrList;
  1016. weekList.forEach(item => {
  1017. item.num = 0;
  1018. });
  1019. this.setData({
  1020. weekArrList: weekList,
  1021. selecttime: time
  1022. });
  1023. let itemData = "weekArrList[" + this.data.weekIndex + "].num";
  1024. let selectedDateList = [];
  1025. let dateItem = {
  1026. week: this.data.weekIndex,
  1027. time: time,
  1028. weekStr: this.data.weekArrList[this.data.weekIndex].week
  1029. };
  1030. selectedDateList.push(dateItem);
  1031. // console.log(this.data);
  1032. this.setData({
  1033. selectTimeIndex: index,
  1034. [itemData]: 1,
  1035. selectedWeekList: [this.data.weekIndex],
  1036. selectedDateList: selectedDateList
  1037. });
  1038. console.log("111",this.data.selectedDateList);
  1039. } else {
  1040. // 如果选中的时间段小于2个
  1041. if (this.data.selectedDateList.length < 2) {
  1042. let itemData = "weekArrList[" + this.data.weekIndex + "].num";
  1043. let num = this.data.weekArrList[this.data.weekIndex].num;
  1044. let selectedDateList = this.data.selectedDateList;
  1045. selectedDateList.push({
  1046. week: this.data.weekIndex,
  1047. time: time,
  1048. weekStr: this.data.weekArrList[this.data.weekIndex].week
  1049. });
  1050. let selectedWeekList = this.data.selectedWeekList;
  1051. if (selectedWeekList.indexOf(this.data.weekIndex) == -1) {
  1052. selectedWeekList.push(this.data.weekIndex);
  1053. }
  1054. this.setData({
  1055. selecttime: time,
  1056. [itemData]: num + 1,
  1057. selectTimeIndex: index,
  1058. // selectedWeekList:selectedWeekList,
  1059. selectedWeekList: [this.data.weekIndex],
  1060. selectedDateList: selectedDateList
  1061. });
  1062. console.log("222",this.data.selectedDateList);
  1063. } else {
  1064. // 删除第一个
  1065. let firstTimeSelected = this.data.selectedDateList[0];
  1066. let firstWeekSelectedIndex = firstTimeSelected.week;
  1067. // let firstWeekSelected=this.data.weekArrList[firstWeekSelectedIndex];
  1068. let itemDataDel = "weekArrList[" + firstWeekSelectedIndex + "].num";
  1069. let numDel = this.data.weekArrList[firstWeekSelectedIndex].num;
  1070. let selectedDateListDel = this.data.selectedDateList;
  1071. selectedDateListDel.shift();
  1072. this.setData({
  1073. selecttime: time,
  1074. [itemDataDel]: numDel - 1,
  1075. // selectTimeIndex:index,
  1076. selectedDateList: selectedDateListDel
  1077. });
  1078. // 加入新选中的
  1079. let itemData = "weekArrList[" + this.data.weekIndex + "].num";
  1080. let num = this.data.weekArrList[this.data.weekIndex].num;
  1081. let selectedDateList = this.data.selectedDateList;
  1082. selectedDateList.push({
  1083. week: this.data.weekIndex,
  1084. time: time,
  1085. weekStr: this.data.weekArrList[this.data.weekIndex].week
  1086. });
  1087. this.setData({
  1088. [itemData]: num + 1,
  1089. // selectTimeIndex:index,
  1090. selectedDateList: selectedDateList
  1091. });
  1092. let weekListNew = [];
  1093. this.data.selectedDateList.forEach(item => {
  1094. if (weekListNew.indexOf(item.week) == -1) {
  1095. weekListNew.push(item.week);
  1096. }
  1097. });
  1098. this.setData({
  1099. selectedWeekList: weekListNew,
  1100. });
  1101. console.log("333",this.data.selectedDateList);
  1102. }
  1103. // console.log(this.data);
  1104. }
  1105. },
  1106. firstDateCheck(e) {
  1107. let index = e.currentTarget.dataset.index;
  1108. this.setData({
  1109. firstDateIndex: index
  1110. });
  1111. },
  1112. onTabChange(e) {
  1113. let weekList = this.data.weekArrList;
  1114. weekList.forEach(item => {
  1115. item.num = 0;
  1116. });
  1117. if (e.detail.name == '1') {
  1118. this.setData({
  1119. selectweek: '一周1次'
  1120. })
  1121. } else if (e.detail.name == '2') {
  1122. this.setData({
  1123. selectweek: '一周2次'
  1124. })
  1125. } else {
  1126. this.setData({
  1127. selectweek: '两周1次'
  1128. })
  1129. }
  1130. console.log("selectweek", this.data.selectweek);
  1131. this.setData({
  1132. weekArrList: weekList,
  1133. activeTab: e.detail.name,
  1134. selectTimeIndex: 'null',
  1135. selectedWeekList: [],
  1136. selectedDateList: []
  1137. });
  1138. },
  1139. showAppoint() {
  1140. if (this.data.addressId == 0) {
  1141. util.showErrorToast("请选择服务地址");
  1142. return;
  1143. }
  1144. this.setData({
  1145. choosePopup: true,
  1146. remarkDisable: true,
  1147. popupType: (this.data.popupType == 3 ? 2 : this.data.popupType),
  1148. isFinishAppoint: false
  1149. });
  1150. if (this.data.popupType == '1') {
  1151. this.getDayTime();
  1152. }
  1153. },
  1154. confirmTime() {
  1155. console.log(this.data.activeTab);
  1156. console.log(this.data);
  1157. if (this.data.popupType == 1) {
  1158. if (this.data.timeIndex === '' || this.data.timeIndex < 0) {
  1159. wx.showToast({
  1160. title: '请选择服务时间',
  1161. icon: 'none',
  1162. duration: 2000
  1163. });
  1164. return false;
  1165. }
  1166. let date = this.data.dateList[this.data.dateIndex].bookdate;
  1167. let week = this.data.dateList[this.data.dateIndex].weekOfDay;
  1168. let time = this.data.timeList[this.data.timeIndex].begin + '-' + this.data.timeList[this.data.timeIndex].end;
  1169. console.log(week, time);
  1170. this.setData({
  1171. oneTimeAppoint: date + ' ' + week + ' ' + time,
  1172. choosePopup: false,
  1173. remarkDisable: false,
  1174. isFinishAppoint: true
  1175. });
  1176. } else if (this.data.popupType == 2) {
  1177. if (this.data.activeTab == 2) {
  1178. if (this.data.selectedDateList.length < 1) {
  1179. wx.showToast({
  1180. title: '请选择服务时间',
  1181. icon: 'none',
  1182. duration: 2000
  1183. });
  1184. } else if (this.data.selectedDateList.length == 1) {
  1185. wx.showToast({
  1186. title: '请选择第二次服务时间',
  1187. icon: 'none',
  1188. duration: 2000
  1189. });
  1190. } else {
  1191. // 选择频次
  1192. let futureDateList = util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24), 1);
  1193. let minIndex = Math.min.apply(null, this.data.selectedWeekList);
  1194. console.log(minIndex);
  1195. console.log((this.data.weekArrList[minIndex]).id);
  1196. let beginDate = futureDateList.filter(item => {
  1197. return (new Date(item.date)).getDay() == (this.data.weekArrList[minIndex]).id
  1198. });
  1199. console.log(beginDate);
  1200. let inter = 7;
  1201. let firstAppointList = util.getDateList(new Date(new Date(beginDate[0].date).getTime()), inter);
  1202. this.setData({
  1203. popupType: 3,
  1204. firstAppointList: firstAppointList
  1205. })
  1206. }
  1207. } else {
  1208. if (this.data.selectedDateList.length == 0) {
  1209. wx.showToast({
  1210. title: '请选择服务时间',
  1211. icon: 'none',
  1212. duration: 2000
  1213. });
  1214. } else {
  1215. // 选择频次
  1216. let futureDateList = util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24), 1);
  1217. let minIndex = Math.min.apply(null, this.data.selectedWeekList);
  1218. console.log(minIndex);
  1219. let beginDate = futureDateList.filter(item => {
  1220. return (new Date(item.date)).getDay() == (this.data.weekArrList[minIndex]).id
  1221. });
  1222. console.log(beginDate);
  1223. let inter = (this.data.activeTab == 3 ? 14 : 7);
  1224. let firstAppointList = util.getDateList(new Date(new Date(beginDate[0].date).getTime()), inter);
  1225. this.setData({
  1226. popupType: 3,
  1227. firstAppointList: firstAppointList
  1228. })
  1229. }
  1230. }
  1231. } else if (this.data.popupType == 3) {
  1232. let firstTime = this.data.firstAppointList[this.data.firstDateIndex].date;
  1233. console.log(firstTime);
  1234. console.log(this.data.selectedDateList);
  1235. // this.orderAppoint();
  1236. this.setData({
  1237. choosePopup: false,
  1238. remarkDisable: false,
  1239. isFinishAppoint: true,
  1240. popupType: 2,
  1241. });
  1242. }
  1243. },
  1244. orderAppoint() {
  1245. // 如果是多次卡先预估,单次卡不用预估
  1246. let weeks = [];
  1247. this.data.selectedDateList.forEach(item => {
  1248. let obj = {
  1249. dayOfWeek: this.data.weekArrList[item.week].id,
  1250. startTime: item.time.split('-')[0],
  1251. endTime: item.time.split('-')[1]
  1252. };
  1253. weeks.push(obj);
  1254. });
  1255. let params = {
  1256. weeks: weeks,
  1257. type: this.data.activeTab,
  1258. startDate: this.data.firstAppointList[this.data.firstDateIndex].date,
  1259. lng: this.data.checkedAddress.lng,
  1260. lat: this.data.checkedAddress.lat,
  1261. shopId: this.data.checkedAddress.shopId,
  1262. goodId: this.data.checkedGoodsList[0].goodsId
  1263. };
  1264. wx.showLoading({
  1265. title: '加载中',
  1266. });
  1267. util.request(api.OrderAppoint, params, "POST")
  1268. .then(res => {
  1269. wx.hideLoading();
  1270. if (res.errno == 0) {
  1271. // this.orderPay(params);
  1272. this.setData({
  1273. choosePopup: false,
  1274. remarkDisable: false,
  1275. isFinishAppoint: true,
  1276. popupType: 2,
  1277. });
  1278. } else {
  1279. // util.showErrorToast(res.errmsg);
  1280. wx.showToast({
  1281. title: res.errmsg,
  1282. icon: 'none',
  1283. duration: 2000
  1284. });
  1285. }
  1286. }).catch(function (err) {
  1287. console.log(err);
  1288. wx.hideLoading();
  1289. wx.showToast({
  1290. title: err.errMsg,
  1291. icon: 'none'
  1292. })
  1293. });
  1294. },
  1295. cancelPay() {
  1296. this.setData({
  1297. payFailShow: false,
  1298. remarkDisable: false
  1299. });
  1300. wx.navigateBack({
  1301. delta: 1,
  1302. })
  1303. },
  1304. rePay() {
  1305. wx.showLoading({
  1306. title: '支付中',
  1307. })
  1308. this.setData({
  1309. payFailShow: false,
  1310. remarkDisable: false
  1311. });
  1312. util.request(api.OrderPrepay, {
  1313. orderId: this.data.orderId
  1314. }, 'POST').then(res => {
  1315. if (res.errno === 0) {
  1316. const payParam = res.data;
  1317. console.log("支付过程开始")
  1318. wx.requestPayment({
  1319. 'timeStamp': payParam.timeStamp,
  1320. 'nonceStr': payParam.nonceStr,
  1321. 'package': payParam.packageValue,
  1322. 'signType': payParam.signType,
  1323. 'paySign': payParam.paySign,
  1324. 'success': res => {
  1325. console.log("支付过程成功");
  1326. wx.redirectTo({
  1327. url: '/pages/checkout/payResult/payResult?status=1&orderId=' + this.data.orderId + '&actualPrice=' + this.data.actualPrice
  1328. });
  1329. },
  1330. 'fail': res => {
  1331. console.log("支付过程失败")
  1332. util.showErrorToast('支付失败');
  1333. },
  1334. 'complete': res => {
  1335. wx.hideLoading();
  1336. console.log("支付过程结束");
  1337. }
  1338. })
  1339. } else {
  1340. wx.hideLoading();
  1341. };
  1342. }).catch(res => {
  1343. wx.hideLoading();
  1344. });
  1345. },
  1346. goBuyMember() {
  1347. wx.navigateTo({
  1348. url: "/pages/member/buyMember/buyMember"
  1349. });
  1350. },
  1351. getDayStock() {
  1352. if (this.data.dateIndex < 0) {
  1353. return false;
  1354. }
  1355. let params = {
  1356. day: this.data.dateList[this.data.dateIndex].date,
  1357. goodsId: this.data.checkedGoodsList[0].goodsId,
  1358. lng: this.data.checkedAddress.lng,
  1359. lat: this.data.checkedAddress.lat,
  1360. productId: this.data.checkedGoodsList[0].product.id,
  1361. serviceDuration: this.data.serviceDuration
  1362. }
  1363. wx.showLoading({
  1364. title: '加载中',
  1365. });
  1366. util.request(api.EveryDayStock, params, "GET")
  1367. .then(res => {
  1368. wx.hideLoading();
  1369. if (res.errno == 0) {
  1370. this.setData({
  1371. timeList: res.data,
  1372. timeIndex: 0
  1373. });
  1374. } else {
  1375. wx.showToast({
  1376. title: res.errmsg,
  1377. icon: 'none',
  1378. duration: 2000
  1379. });
  1380. this.setData({
  1381. timeList: [],
  1382. timeIndex: ''
  1383. });
  1384. }
  1385. }).catch(function (err) {
  1386. console.log(err);
  1387. wx.hideLoading();
  1388. wx.showToast({
  1389. title: err.errMsg,
  1390. icon: 'none'
  1391. });
  1392. this.setData({
  1393. timeList: [],
  1394. timeIndex: ''
  1395. });
  1396. });
  1397. },
  1398. getDayTime() {
  1399. let params = {
  1400. days: 30,
  1401. productId: this.data.checkedGoodsList[0].productId,
  1402. serviceDuration: this.data.serviceDuration
  1403. }
  1404. wx.showLoading({
  1405. title: '加载中',
  1406. });
  1407. util.request(api.everyDayTime, params, "GET")
  1408. .then(res => {
  1409. wx.hideLoading();
  1410. if (res.errno == 0) {
  1411. this.setData({
  1412. dateList: res.data,
  1413. dateIndex: 0,
  1414. timeIndex: -1,
  1415. noonType: 1
  1416. });
  1417. let period = res.data[0].period;
  1418. let list = period.filter(item => {
  1419. return item.ofTime == '上午';
  1420. });
  1421. this.setData({
  1422. timeList: list
  1423. });
  1424. } else {
  1425. wx.showToast({
  1426. title: res.errmsg,
  1427. icon: 'none',
  1428. duration: 2000
  1429. });
  1430. this.setData({
  1431. timeList: [],
  1432. timeIndex: ''
  1433. });
  1434. }
  1435. }).catch(function (err) {
  1436. console.log(err);
  1437. wx.hideLoading();
  1438. wx.showToast({
  1439. title: err.errMsg,
  1440. icon: 'none'
  1441. });
  1442. this.setData({
  1443. timeList: [],
  1444. timeIndex: ''
  1445. });
  1446. });
  1447. },
  1448. });