checkout.js 44 KB

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