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].goods.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. this.setData({
  356. cartId: cartId,
  357. addressId: addressId,
  358. couponId: couponId,
  359. userCouponId: userCouponId,
  360. grouponRulesId: grouponRulesId,
  361. grouponLinkId: grouponLinkId
  362. });
  363. this.getCheckoutInfo(appType);
  364. } catch (e) {
  365. // Do something when catch error
  366. console.log(e);
  367. }
  368. },
  369. onHide: function () {
  370. // 页面隐藏
  371. },
  372. onUnload: function () {
  373. // 页面关闭
  374. //清空宠物保险的缓存数据
  375. console.info('checkout onload')
  376. //wx.setStorageSync('petinfo'+this.data.cartId, null);
  377. },
  378. submitOrder: function () {
  379. let that = this;
  380. if (that.data.addressId <= 0) {
  381. //所选地址无服务门店,或选择其他地址
  382. let errmsg=that.data.addressMsg==''?'请选择收货地址':that.data.addressMsg;
  383. //util.showErrorToast(errmsg);
  384. wx.showModal({
  385. title: '提示',
  386. content: errmsg,
  387. showCancel:false,
  388. });
  389. return;
  390. }
  391. // 检查是否已经预约
  392. if (that.data.goodsType != 6&&that.data.goodsType != 4 && that.data.isNeedAppoint && !that.data.isFinishAppoint) {
  393. // util.showErrorToast('请先预约服务时间');
  394. wx.showToast({
  395. title: '请先预约服务时间',
  396. icon: 'none',
  397. duration: 2000
  398. });
  399. return;
  400. }
  401. wx.showLoading({
  402. title: '检测中',
  403. });
  404. that.submitInfo();
  405. },
  406. submitInfo() {
  407. // 如果是多次卡先预估,单次卡不用预估
  408. if (!this.data.isOneAppoint) {
  409. let weeks = [];
  410. this.data.selectedDateList.forEach(item => {
  411. let obj = {
  412. dayOfWeek: this.data.weekArrList[item.week].id,
  413. startTime: item.time.split('-')[0],
  414. endTime: item.time.split('-')[1]
  415. };
  416. weeks.push(obj);
  417. });
  418. let tempStartDate = null;
  419. if (this.data.firstAppointList.length != 0 && this.data.firstAppointList.length >= this.data.firstDateIndex) {
  420. tempStartDate = this.data.firstAppointList[this.data.firstDateIndex].date;
  421. }
  422. let params = {
  423. weeks: weeks,
  424. type: this.data.activeTab,
  425. startDate: tempStartDate, //this.data.firstAppointList[this.data.firstDateIndex].date,
  426. lng: this.data.checkedAddress.lng,
  427. lat: this.data.checkedAddress.lat,
  428. shopId: this.data.checkedAddress.shopId,
  429. goodId: this.data.checkedGoodsList[0].goodsId
  430. };
  431. console.log(params);
  432. this.orderPay(params);
  433. } else {
  434. let weeks = [];
  435. if (this.data.isNeedAppoint && this.data.goodsType != 6 && this.data.goodsType != 4) {
  436. weeks = [{
  437. dayOfWeek: (new Date(this.data.dateList[this.data.dateIndex].bookdate)).getDay(),
  438. startTime: this.data.timeList[this.data.timeIndex].begin,
  439. endTime: this.data.timeList[this.data.timeIndex].end
  440. }];
  441. }
  442. let params = {
  443. weeks: weeks,
  444. type: 0,
  445. startDate: this.data.isNeedAppoint?this.data.dateList[this.data.dateIndex].bookdate:null,
  446. lng: this.data.checkedAddress.lng,
  447. lat: this.data.checkedAddress.lat,
  448. shopId: this.data.checkedAddress.shopId,
  449. goodId: this.data.checkedGoodsList[0].goodsId
  450. };
  451. console.log(params);
  452. this.orderPay(params);
  453. }
  454. },
  455. orderPay(orderData) {
  456. let that=this;
  457. var orderInfo = {
  458. cartId: this.data.cartId,
  459. addressId: this.data.addressId,
  460. couponId: this.data.couponId,
  461. userCouponId: this.data.userCouponId,
  462. message: this.data.message,
  463. orderDate: this.data.orderData,
  464. grouponRulesId: this.data.grouponRulesId,
  465. grouponLinkId: this.data.grouponLinkId,
  466. nurseId: this.data.nurseId,
  467. petinfo: this.data.petinfo,
  468. shareId: this.data.shareId,
  469. recCode: this.data.recCode ? this.data.recCode : this.data.rId, //服务者推荐id(如果填写推荐码 以填写为准)
  470. fraId: this.data.fraId, //加盟商id
  471. channelId: this.data.channelId, //渠道码
  472. //预约参数信息
  473. orderDate: orderData,
  474. requireOrder:this.data.requireOrder,
  475. traceId:this.data.traceId//视频号
  476. };
  477. if (this.data.codeShow && !this.data.isNoMatch) {
  478. orderInfo.recCode = this.data.recCode;
  479. }
  480. console.log(orderInfo);
  481. util.request(api.OrderSubmit, orderInfo, 'POST').then(res => {
  482. //视频号,校验 wx.checkBeforeAddOrder
  483. wx.checkBeforeAddOrder({
  484. success (res) {
  485. console.log("checkBeforeAddOrder-success:",res);
  486. if(res.data.errcode==0){
  487. that.setData({
  488. traceId:res.data.traceId,
  489. requireOrder:res.data.requireOrder
  490. })
  491. }
  492. },
  493. fail (res) {
  494. console.log("checkBeforeAddOrder-fail:",res);
  495. }
  496. })
  497. if (res.errno === 0) {
  498. console.log(res.data.isNeedPay);
  499. if (res.data.isNeedPay == false) {
  500. console.log("跳过支付");
  501. util.redirect('/pages/ucenter/order/order');
  502. return;
  503. }
  504. // 下单成功,重置couponId
  505. wx.setStorageSync('couponId', 0);
  506. const orderId = res.data.orderId;
  507. this.setData({
  508. orderId: orderId
  509. });
  510. const grouponLinkId = res.data.grouponLinkId;
  511. util.request(api.OrderPrepay, {
  512. orderId: orderId
  513. }, 'POST').then(res => {
  514. if (res.errno === 0) {
  515. const payParam = res.data;
  516. console.log("支付过程开始");
  517. if(this.data.requireOrder==1){
  518. //视频号支付
  519. wx.requestOrderPayment({
  520. 'timeStamp': payParam.timeStamp,
  521. 'nonceStr': payParam.nonceStr,
  522. 'package': payParam.packageValue,
  523. 'signType': payParam.signType,
  524. 'paySign': payParam.paySign,
  525. 'success': res => {
  526. console.log("支付过程成功");
  527. if (grouponLinkId) {
  528. setTimeout(() => {
  529. wx.redirectTo({
  530. url: '/pages/groupon/grouponDetail/grouponDetail?id=' + grouponLinkId
  531. })
  532. }, 1000);
  533. } else {
  534. wx.redirectTo({
  535. url: '/pages/checkout/payResult/payResult?status=1&orderId=' + orderId + '&actualPrice=' + this.data.actualPrice
  536. });
  537. }
  538. },
  539. 'fail': res => {
  540. console.log("支付过程失败");
  541. // wx.redirectTo({
  542. // url: '/pages/checkout/payResult/payResult?status=0&orderId=' + orderId
  543. // });
  544. // 弹出支付失败
  545. this.setData({
  546. payFailShow: true,
  547. remarkDisable: true
  548. });
  549. },
  550. 'complete': function (res) {
  551. console.log("支付过程结束")
  552. }
  553. });
  554. }else{
  555. wx.requestPayment({
  556. 'timeStamp': payParam.timeStamp,
  557. 'nonceStr': payParam.nonceStr,
  558. 'package': payParam.packageValue,
  559. 'signType': payParam.signType,
  560. 'paySign': payParam.paySign,
  561. 'success': res => {
  562. console.log("支付过程成功");
  563. if (grouponLinkId) {
  564. setTimeout(() => {
  565. wx.redirectTo({
  566. url: '/pages/groupon/grouponDetail/grouponDetail?id=' + grouponLinkId
  567. })
  568. }, 1000);
  569. } else {
  570. wx.redirectTo({
  571. url: '/pages/checkout/payResult/payResult?status=1&orderId=' + orderId + '&actualPrice=' + this.data.actualPrice
  572. });
  573. }
  574. },
  575. 'fail': res => {
  576. console.log("支付过程失败");
  577. // wx.redirectTo({
  578. // url: '/pages/checkout/payResult/payResult?status=0&orderId=' + orderId
  579. // });
  580. // 弹出支付失败
  581. this.setData({
  582. payFailShow: true,
  583. remarkDisable: true
  584. });
  585. },
  586. 'complete': function (res) {
  587. console.log("支付过程结束")
  588. }
  589. });
  590. }
  591. } else {
  592. // 弹出支付失败
  593. this.setData({
  594. payFailShow: true,
  595. remarkDisable: true
  596. });
  597. // wx.redirectTo({
  598. // url: '/pages/checkout/payResult/payResult?status=0&orderId=' + orderId
  599. // });
  600. }
  601. });
  602. } else {
  603. wx.showToast({
  604. title: res.errmsg,
  605. icon:'none'
  606. })
  607. // util.showErrorToast(res.errmsg);
  608. }
  609. });
  610. },
  611. surplusMonth: function (year) {
  612. var date = new Date();
  613. var year2 = date.getFullYear()
  614. var month = date.getMonth() + 1
  615. var day = date.getDate()
  616. var hour = date.getHours()
  617. var minute = date.getMinutes()
  618. var second = date.getSeconds()
  619. var monthDatas = [];
  620. if (year == year2) {
  621. var surplusMonth = 12 - month;
  622. monthDatas.push(month + "月")
  623. for (var i = month; i < 12; i++) {
  624. monthDatas.push(i + 1 + "月")
  625. }
  626. } else {
  627. for (var i = 0; i < 12; i++) {
  628. monthDatas.push(i + 1 + "月")
  629. }
  630. }
  631. return monthDatas;
  632. },
  633. //天数计算
  634. surplusDay: function (year, month, day) {
  635. var days = 31;
  636. var dayDatas = [];
  637. var date = new Date();
  638. var year2 = date.getFullYear()
  639. var month2 = date.getMonth() + 1
  640. switch (parseInt(month)) {
  641. case 1:
  642. case 3:
  643. case 5:
  644. case 7:
  645. case 8:
  646. case 10:
  647. case 12:
  648. days = 31;
  649. break;
  650. //对于2月份需要判断是否为闰年
  651. case 2:
  652. if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
  653. days = 29;
  654. break;
  655. } else {
  656. days = 28;
  657. break;
  658. }
  659. case 4:
  660. case 6:
  661. case 9:
  662. case 11:
  663. days = 30;
  664. break;
  665. }
  666. if (year == year2 && month == month2) {
  667. // dayDatas.push(day + "日")
  668. for (var i = day; i < days; i++) {
  669. dayDatas.push(i + 1 + "日")
  670. }
  671. } else {
  672. console.log(month + "月" + days + "天")
  673. for (var i = 0; i < days; i++) {
  674. dayDatas.push(i + 1 + "日")
  675. }
  676. }
  677. return dayDatas;
  678. },
  679. //时间计算
  680. surplusHour: function (year, month, day, hour) {
  681. var date = new Date();
  682. var year2 = date.getFullYear()
  683. var month2 = date.getMonth() + 1
  684. var day2 = date.getDate();
  685. var hourEnd = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21];
  686. var hours = [
  687. ['09时', '10时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时'],
  688. ['10时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时', '21时']
  689. ];
  690. return hours;
  691. },
  692. /**
  693. * 生命周期函数--监听页面加载
  694. */
  695. onLoad: function (options) {
  696. this.setData({
  697. userInfo: app.globalData.userInfo
  698. });
  699. let that = this;
  700. if (options.nurseId) {
  701. this.setData({
  702. nurseId: options.nurseId
  703. })
  704. }
  705. var rId = wx.getStorageSync('rId');
  706. if (rId) {
  707. this.setData({
  708. rId: rId,
  709. recCode: rId
  710. })
  711. }
  712. var fraId = wx.getStorageSync('fraId');
  713. if (fraId) {
  714. this.setData({
  715. fraId: fraId
  716. })
  717. }
  718. var channelId = wx.getStorageSync('channelId');
  719. if (channelId) {
  720. this.setData({
  721. channelId: parseInt(channelId)
  722. })
  723. }
  724. if (typeof options.shareId != 'undefined' && options.shareId > 0) {
  725. that.setData({
  726. shareId: options.shareId
  727. })
  728. }
  729. //视频号,校验 wx.checkBeforeAddOrder
  730. wx.checkBeforeAddOrder({
  731. success (res) {
  732. console.log("checkBeforeAddOrder-success:",res);
  733. if(res.data.errcode==0){
  734. that.setData({
  735. traceId:res.data.traceId,
  736. requireOrder:res.data.requireOrder
  737. })
  738. }
  739. },
  740. fail (res) {
  741. console.log("checkBeforeAddOrder-fail:",res);
  742. }
  743. })
  744. var date = new Date();
  745. var year = date.getFullYear()
  746. var month = date.getMonth() + 1
  747. var day = date.getDate()
  748. var hour = date.getHours()
  749. var surplusMonth = that.surplusMonth(year);
  750. console.log(surplusMonth)
  751. var surplusDay = this.surplusDay(year, month, day);
  752. console.log(surplusDay)
  753. var surplusHour = this.surplusHour(year, month, day, hour)
  754. console.log(surplusHour)
  755. //初始化picker
  756. that.setData({
  757. multiArray: [
  758. [year + '年', (year + 1) + '年', (year + 2) + '年'],
  759. surplusMonth,
  760. surplusDay,
  761. surplusHour[0],
  762. ['~'],
  763. surplusHour[1]
  764. ],
  765. year: year,
  766. month: month,
  767. day: day,
  768. startHour: surplusHour[0][0],
  769. endHour: surplusHour[1][0],
  770. })
  771. },
  772. varietiesChange: function (e) {
  773. var Varieties = this.data.array[parseInt(e.detail.value)]
  774. console.log(Varieties)
  775. this.setData({
  776. Varieties: Varieties
  777. })
  778. },
  779. warehouseChange: function (e) {
  780. var Warehouse = this.data.array[parseInt(e.detail.value)]
  781. console.log(Warehouse)
  782. this.setData({
  783. Warehouse: Warehouse
  784. })
  785. },
  786. //某一列的值改变时触发
  787. bindMultiPickerColumnChange: function (e) {
  788. var date = new Date();
  789. var year1 = date.getFullYear()
  790. var month1 = date.getMonth() + 1
  791. var day1 = date.getDate()
  792. var hour1 = date.getHours()
  793. console.log("当前月份" + this.data.month + '修改的列为', e.detail.column, ',值为', e.detail.value);
  794. var data = {
  795. multiArray: this.data.multiArray,
  796. multiIndex: this.data.multiIndex,
  797. year: this.data.year,
  798. month: this.data.month,
  799. day: this.data.day,
  800. startHour: this.data.startHour,
  801. endHour: this.data.startHour,
  802. };
  803. data.multiIndex[e.detail.column] = e.detail.value;
  804. switch (e.detail.column) {
  805. case 0:
  806. var yearStr = data.multiArray[e.detail.column][e.detail.value];
  807. var year = yearStr.substring(0, yearStr.length - 1)
  808. data.year = parseInt(year);
  809. var surplusMonth = this.surplusMonth(year);
  810. data.multiArray[1] = surplusMonth;
  811. if (data.year == year1) {
  812. data.month = month1;
  813. } else {
  814. data.month = 1;
  815. }
  816. if (data.year == year1 && month1 == data.month) {
  817. data.day = day1;
  818. } else {
  819. data.day = 1;
  820. }
  821. var surplusDay = this.surplusDay(data.year, data.month, data.day);
  822. data.multiArray[2] = surplusDay;
  823. var surplusHour;
  824. if (data.year == year1 && month1 == data.month && data.day == day1) {
  825. surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
  826. } else {
  827. surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
  828. }
  829. console.log(surplusHour)
  830. data.multiArray[3] = surplusHour[0];
  831. data.multiArray[5] = surplusHour[1];
  832. data.startHour = surplusHour[0];
  833. data.endHour = surplusHour[1];
  834. data.multiIndex[1] = 0;
  835. data.multiIndex[2] = 0;
  836. data.multiIndex[3] = 0;
  837. data.multiIndex[5] = 0;
  838. break;
  839. case 1:
  840. console.log('选择月份' + data.multiArray[e.detail.column][e.detail.value]);
  841. var monthStr = data.multiArray[e.detail.column][e.detail.value];
  842. var month = monthStr.substring(0, monthStr.length - 1);
  843. data.month = month;
  844. data.day = 1;
  845. if (data.year == year1 && month1 == data.month) {
  846. data.day = day1;
  847. } else {
  848. data.day = 1;
  849. }
  850. var surplusDay = this.surplusDay(data.year, data.month, data.day);
  851. data.multiArray[2] = surplusDay;
  852. var surplusHour;
  853. if (data.year == year1 && month1 == data.month && data.day == day1) {
  854. surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
  855. } else {
  856. surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
  857. }
  858. data.multiArray[3] = surplusHour[0];
  859. data.multiArray[5] = surplusHour[1];
  860. data.startHour = surplusHour[0];
  861. data.endHour = surplusHour[1];
  862. data.multiIndex[2] = 0;
  863. data.multiIndex[3] = 0;
  864. data.multiIndex[5] = 0;
  865. break;
  866. case 2:
  867. console.log('选择日' + data.multiArray[e.detail.column][e.detail.value]);
  868. var dayStr = data.multiArray[e.detail.column][e.detail.value];
  869. var day = dayStr.substring(0, dayStr.length - 1);
  870. data.day = day;
  871. var surplusHour;
  872. if (data.year == year1 && month1 == data.month && data.day == day1) {
  873. surplusHour = this.surplusHour(data.year, data.month, data.day, hour1)
  874. } else {
  875. surplusHour = this.surplusHour(data.year, data.month, data.day, 1)
  876. }
  877. data.multiArray[3] = surplusHour[0];
  878. data.multiArray[5] = surplusHour[1];
  879. data.startHour = surplusHour[0];
  880. data.endHour = surplusHour[1];
  881. data.multiIndex[3] = 0;
  882. data.multiIndex[5] = 0;
  883. break;
  884. case 3:
  885. console.log('起始时间' + data.multiArray[e.detail.column][e.detail.value]);
  886. var hourStr = data.multiArray[e.detail.column][e.detail.value];
  887. var hour = hourStr.substring(0, hourStr.length - 1);
  888. data.startHour = hour;
  889. console.log('起始时间' + hour + " day1:" + day1);
  890. /*var endhours2 = [];
  891. var end = ['09时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时', '20时'];
  892. for (var i = e.detail.value; i < end.length; i++) {
  893. endhours2.push(end[i]);
  894. }
  895. data.multiArray[5] = endhours2; */
  896. if (e.detail.value > data.multiIndex[5])
  897. data.multiIndex[5] = e.detail.value;
  898. break;
  899. case 5:
  900. var hourStr = data.multiArray[e.detail.column][e.detail.value];
  901. var hour = hourStr.substring(0, hourStr.length - 1);
  902. data.endHour = hour;
  903. if (e.detail.value < data.multiIndex[3])
  904. data.multiIndex[3] = e.detail.value;
  905. //console.log('index:'+data.multiIndex[3]+'value:'+e.detail.value+'结束时间' + data.multiArray[e.detail.column][e.detail.value]);
  906. break;
  907. }
  908. this.setData(data)
  909. },
  910. //value 改变时触发 change 事件
  911. bindMultiPickerChange: function (e) {
  912. console.info(e);
  913. console.info(this.data.multiArray);
  914. console.info(this.data);
  915. console.info(this.data.multiIndex);
  916. var dateStr =
  917. this.data.multiArray[0][this.data.multiIndex[0]] +
  918. this.data.multiArray[1][this.data.multiIndex[1]] +
  919. this.data.multiArray[2][this.data.multiIndex[2]] +
  920. this.data.multiArray[3][this.data.multiIndex[3]] +
  921. this.data.multiArray[4][this.data.multiIndex[4]] +
  922. this.data.multiArray[5][this.data.multiIndex[5]];
  923. console.log('picker发送选择改变,携带值为', dateStr)
  924. this.setData({
  925. orderData: dateStr
  926. })
  927. },
  928. onClose() {
  929. this.setData({
  930. choosePopup: false,
  931. remarkDisable: false,
  932. });
  933. },
  934. dateCheck(e) {
  935. let index = e.currentTarget.dataset.index;
  936. let date = e.currentTarget.dataset.date;
  937. let week = e.currentTarget.dataset.week;
  938. let isbook = e.currentTarget.dataset.isbook;
  939. console.info("dateCheck:" + index);
  940. this.setData({
  941. dateIndex: index
  942. });
  943. let period=this.data.dateList[this.data.dateIndex].period;
  944. let current=(this.data.noonType==1?'上午':'下午');
  945. let list=period.filter(item=>{
  946. return item.ofTime==current;
  947. });
  948. this.setData({
  949. timeList:list
  950. });
  951. let isNoTime=list.every(item=>{
  952. return item.timeMsg&&item.timeMsg!=null;
  953. });
  954. if(isNoTime){
  955. this.setData({
  956. timeIndex:-1,
  957. selectTimeValue:''
  958. });
  959. }
  960. // if (this.data.checkedGoodsList[0].goodsId == 1190332) {
  961. // this.setData({
  962. // dateIndex: index
  963. // });
  964. // } else if (isbook) { //前三天不可预约
  965. // this.setData({
  966. // dateIndex: index
  967. // });
  968. // this.getDayStock();
  969. // }
  970. },
  971. noonTab(e) {
  972. let noon = e.currentTarget.dataset.noon;
  973. this.setData({
  974. timeIndex: -1,
  975. noonType: noon,
  976. selectTimeValue:'',
  977. });
  978. let period=this.data.dateList[this.data.dateIndex].period;
  979. let current=(this.data.noonType==1?'上午':'下午');
  980. let list=period.filter(item=>{
  981. return item.ofTime==current;
  982. });
  983. this.setData({
  984. timeList:list
  985. });
  986. },
  987. timeCheck(e) {
  988. let index = e.currentTarget.dataset.index;
  989. // let stock = e.currentTarget.dataset.stock;
  990. let msg=e.currentTarget.dataset.msg;
  991. if (msg==null||msg=='') {
  992. let time= (this.data.timeList[index].begin).split(':')[0];
  993. this.setData({
  994. timeIndex: index,
  995. selectTimeValue: Number(time)
  996. });
  997. }
  998. },
  999. weekCheck(e) {
  1000. let index = e.currentTarget.dataset.index;
  1001. this.setData({
  1002. weekIndex: index,
  1003. // selectTimeIndex:'null'
  1004. });
  1005. },
  1006. timeSelect(e) {
  1007. let index = e.currentTarget.dataset.index;
  1008. let time = e.currentTarget.dataset.time;
  1009. if (this.data.activeTab != 2) {
  1010. let weekList = this.data.weekArrList;
  1011. weekList.forEach(item => {
  1012. item.num = 0;
  1013. });
  1014. this.setData({
  1015. weekArrList: weekList,
  1016. });
  1017. let itemData = "weekArrList[" + this.data.weekIndex + "].num";
  1018. let selectedDateList = [];
  1019. let dateItem = {
  1020. week: this.data.weekIndex,
  1021. time: time,
  1022. weekStr: this.data.weekArrList[this.data.weekIndex].week
  1023. };
  1024. selectedDateList.push(dateItem);
  1025. console.log(this.data);
  1026. this.setData({
  1027. selectTimeIndex: index,
  1028. [itemData]: 1,
  1029. selectedWeekList: [this.data.weekIndex],
  1030. selectedDateList: selectedDateList
  1031. });
  1032. console.log(this.data);
  1033. } else {
  1034. // 如果选中的时间段小于2个
  1035. if (this.data.selectedDateList.length < 2) {
  1036. let itemData = "weekArrList[" + this.data.weekIndex + "].num";
  1037. let num = this.data.weekArrList[this.data.weekIndex].num;
  1038. let selectedDateList = this.data.selectedDateList;
  1039. selectedDateList.push({
  1040. week: this.data.weekIndex,
  1041. time: time,
  1042. weekStr: this.data.weekArrList[this.data.weekIndex].week
  1043. });
  1044. let selectedWeekList = this.data.selectedWeekList;
  1045. if (selectedWeekList.indexOf(this.data.weekIndex) == -1) {
  1046. selectedWeekList.push(this.data.weekIndex);
  1047. }
  1048. this.setData({
  1049. [itemData]: num + 1,
  1050. selectTimeIndex: index,
  1051. // selectedWeekList:selectedWeekList,
  1052. selectedWeekList: [this.data.weekIndex],
  1053. selectedDateList: selectedDateList
  1054. });
  1055. } else {
  1056. // 删除第一个
  1057. let firstTimeSelected = this.data.selectedDateList[0];
  1058. let firstWeekSelectedIndex = firstTimeSelected.week;
  1059. // let firstWeekSelected=this.data.weekArrList[firstWeekSelectedIndex];
  1060. let itemDataDel = "weekArrList[" + firstWeekSelectedIndex + "].num";
  1061. let numDel = this.data.weekArrList[firstWeekSelectedIndex].num;
  1062. let selectedDateListDel = this.data.selectedDateList;
  1063. selectedDateListDel.shift();
  1064. this.setData({
  1065. [itemDataDel]: numDel - 1,
  1066. // selectTimeIndex:index,
  1067. selectedDateList: selectedDateListDel
  1068. });
  1069. // 加入新选中的
  1070. let itemData = "weekArrList[" + this.data.weekIndex + "].num";
  1071. let num = this.data.weekArrList[this.data.weekIndex].num;
  1072. let selectedDateList = this.data.selectedDateList;
  1073. selectedDateList.push({
  1074. week: this.data.weekIndex,
  1075. time: time,
  1076. weekStr: this.data.weekArrList[this.data.weekIndex].week
  1077. });
  1078. this.setData({
  1079. [itemData]: num + 1,
  1080. // selectTimeIndex:index,
  1081. selectedDateList: selectedDateList
  1082. });
  1083. let weekListNew = [];
  1084. this.data.selectedDateList.forEach(item => {
  1085. if (weekListNew.indexOf(item.week) == -1) {
  1086. weekListNew.push(item.week);
  1087. }
  1088. });
  1089. this.setData({
  1090. selectedWeekList: weekListNew,
  1091. });
  1092. }
  1093. console.log(this.data);
  1094. }
  1095. },
  1096. firstDateCheck(e) {
  1097. let index = e.currentTarget.dataset.index;
  1098. this.setData({
  1099. firstDateIndex: index
  1100. });
  1101. },
  1102. onTabChange(e) {
  1103. let weekList = this.data.weekArrList;
  1104. weekList.forEach(item => {
  1105. item.num = 0;
  1106. });
  1107. this.setData({
  1108. weekArrList: weekList,
  1109. activeTab: e.detail.name,
  1110. selectTimeIndex: 'null',
  1111. selectedWeekList: [],
  1112. selectedDateList: []
  1113. });
  1114. },
  1115. showAppoint() {
  1116. if (this.data.addressId == 0) {
  1117. util.showErrorToast("请选择服务地址");
  1118. return;
  1119. }
  1120. this.setData({
  1121. choosePopup: true,
  1122. remarkDisable: true,
  1123. popupType: (this.data.popupType == 3 ? 2 : this.data.popupType),
  1124. isFinishAppoint: false
  1125. });
  1126. if (this.data.popupType == '1') {
  1127. // let index = 2;
  1128. // let length = this.data.dateList.length;
  1129. // let list = this.data.dateList;
  1130. // for (let i = 0; i < length; i++) {
  1131. // if (i < 7 && i >= 2 && list[i].week != '周六' && list[i].week != '周日') {
  1132. // index = i;
  1133. // break;
  1134. // }
  1135. // }
  1136. // console.log(index);
  1137. // this.setData({
  1138. // dateIndex: index
  1139. // })
  1140. // 获取时间段
  1141. // this.getDayStock();
  1142. this.getDayTime();
  1143. }
  1144. },
  1145. confirmTime() {
  1146. console.log(this.data.activeTab);
  1147. console.log(this.data);
  1148. if (this.data.popupType == 1) {
  1149. if (this.data.timeIndex === ''||this.data.timeIndex<0) {
  1150. wx.showToast({
  1151. title: '请选择服务时间',
  1152. icon: 'none',
  1153. duration: 2000
  1154. });
  1155. return false;
  1156. }
  1157. let date = this.data.dateList[this.data.dateIndex].bookdate;
  1158. let week = this.data.dateList[this.data.dateIndex].weekOfDay;
  1159. let time = this.data.timeList[this.data.timeIndex].begin+'-'+this.data.timeList[this.data.timeIndex].end;
  1160. console.log(week, time);
  1161. this.setData({
  1162. oneTimeAppoint: date + ' ' + week + ' ' + time,
  1163. choosePopup: false,
  1164. remarkDisable: false,
  1165. isFinishAppoint: true
  1166. });
  1167. } else if (this.data.popupType == 2) {
  1168. if (this.data.activeTab == 2) {
  1169. if (this.data.selectedDateList.length < 1) {
  1170. wx.showToast({
  1171. title: '请选择服务时间',
  1172. icon: 'none',
  1173. duration: 2000
  1174. });
  1175. } else if (this.data.selectedDateList.length == 1) {
  1176. wx.showToast({
  1177. title: '请选择第二次服务时间',
  1178. icon: 'none',
  1179. duration: 2000
  1180. });
  1181. } else {
  1182. // 选择频次
  1183. let futureDateList = util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24), 1);
  1184. let minIndex = Math.min.apply(null, this.data.selectedWeekList);
  1185. console.log(minIndex);
  1186. console.log((this.data.weekArrList[minIndex]).id);
  1187. let beginDate = futureDateList.filter(item => {
  1188. return (new Date(item.date)).getDay() == (this.data.weekArrList[minIndex]).id
  1189. });
  1190. console.log(beginDate);
  1191. let inter = 7;
  1192. let firstAppointList = util.getDateList(new Date(new Date(beginDate[0].date).getTime()), inter);
  1193. this.setData({
  1194. popupType: 3,
  1195. firstAppointList: firstAppointList
  1196. })
  1197. }
  1198. } else {
  1199. if (this.data.selectedDateList.length == 0) {
  1200. wx.showToast({
  1201. title: '请选择服务时间',
  1202. icon: 'none',
  1203. duration: 2000
  1204. });
  1205. } else {
  1206. // 选择频次
  1207. let futureDateList = util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24), 1);
  1208. let minIndex = Math.min.apply(null, this.data.selectedWeekList);
  1209. console.log(minIndex);
  1210. let beginDate = futureDateList.filter(item => {
  1211. return (new Date(item.date)).getDay() == (this.data.weekArrList[minIndex]).id
  1212. });
  1213. console.log(beginDate);
  1214. let inter = (this.data.activeTab == 3 ? 14 : 7);
  1215. let firstAppointList = util.getDateList(new Date(new Date(beginDate[0].date).getTime()), inter);
  1216. this.setData({
  1217. popupType: 3,
  1218. firstAppointList: firstAppointList
  1219. })
  1220. }
  1221. }
  1222. } else if (this.data.popupType == 3) {
  1223. let firstTime = this.data.firstAppointList[this.data.firstDateIndex].date;
  1224. console.log(firstTime);
  1225. console.log(this.data.selectedDateList);
  1226. // this.orderAppoint();
  1227. this.setData({
  1228. choosePopup: false,
  1229. remarkDisable: false,
  1230. isFinishAppoint: true,
  1231. popupType: 2,
  1232. // noSerTimes: res.data,
  1233. // appointFailTip: (res.data >= 1 ? true : false)
  1234. });
  1235. // this.setData({
  1236. // choosePopup:false,
  1237. // isFinishAppoint:true
  1238. // });
  1239. }
  1240. },
  1241. orderAppoint() {
  1242. // 如果是多次卡先预估,单次卡不用预估
  1243. let weeks = [];
  1244. this.data.selectedDateList.forEach(item => {
  1245. let obj = {
  1246. dayOfWeek: this.data.weekArrList[item.week].id,
  1247. startTime: item.time.split('-')[0],
  1248. endTime: item.time.split('-')[1]
  1249. };
  1250. weeks.push(obj);
  1251. });
  1252. let params = {
  1253. weeks: weeks,
  1254. type: this.data.activeTab,
  1255. startDate: this.data.firstAppointList[this.data.firstDateIndex].date,
  1256. lng: this.data.checkedAddress.lng,
  1257. lat: this.data.checkedAddress.lat,
  1258. shopId: this.data.checkedAddress.shopId,
  1259. goodId: this.data.checkedGoodsList[0].goodsId
  1260. };
  1261. wx.showLoading({
  1262. title: '加载中',
  1263. });
  1264. util.request(api.OrderAppoint, params, "POST")
  1265. .then(res => {
  1266. wx.hideLoading();
  1267. if (res.errno == 0) {
  1268. // this.orderPay(params);
  1269. this.setData({
  1270. choosePopup: false,
  1271. remarkDisable: false,
  1272. isFinishAppoint: true,
  1273. popupType: 2,
  1274. // noSerTimes: res.data,
  1275. // appointFailTip: (res.data >= 1 ? true : false)
  1276. });
  1277. } else {
  1278. // util.showErrorToast(res.errmsg);
  1279. wx.showToast({
  1280. title: res.errmsg,
  1281. icon: 'none',
  1282. duration: 2000
  1283. });
  1284. }
  1285. }).catch(function (err) {
  1286. console.log(err);
  1287. wx.hideLoading();
  1288. wx.showToast({
  1289. title: err.errMsg,
  1290. icon: 'none'
  1291. })
  1292. });
  1293. },
  1294. cancelPay() {
  1295. this.setData({
  1296. payFailShow: false,
  1297. remarkDisable: false
  1298. });
  1299. wx.navigateBack({
  1300. delta: 1,
  1301. })
  1302. },
  1303. rePay() {
  1304. wx.showLoading({
  1305. title: '支付中',
  1306. })
  1307. this.setData({
  1308. payFailShow: false,
  1309. remarkDisable: false
  1310. });
  1311. util.request(api.OrderPrepay, {
  1312. orderId: this.data.orderId
  1313. }, 'POST').then(res => {
  1314. if (res.errno === 0) {
  1315. const payParam = res.data;
  1316. console.log("支付过程开始")
  1317. wx.requestPayment({
  1318. 'timeStamp': payParam.timeStamp,
  1319. 'nonceStr': payParam.nonceStr,
  1320. 'package': payParam.packageValue,
  1321. 'signType': payParam.signType,
  1322. 'paySign': payParam.paySign,
  1323. 'success': res => {
  1324. console.log("支付过程成功");
  1325. wx.redirectTo({
  1326. url: '/pages/checkout/payResult/payResult?status=1&orderId=' + this.data.orderId + '&actualPrice=' + this.data.actualPrice
  1327. });
  1328. },
  1329. 'fail': res => {
  1330. console.log("支付过程失败")
  1331. util.showErrorToast('支付失败');
  1332. },
  1333. 'complete': res => {
  1334. wx.hideLoading();
  1335. console.log("支付过程结束");
  1336. }
  1337. })
  1338. } else {
  1339. wx.hideLoading();
  1340. };
  1341. }).catch(res => {
  1342. wx.hideLoading();
  1343. });
  1344. },
  1345. goBuyMember() {
  1346. wx.navigateTo({
  1347. url: "/pages/member/buyMember/buyMember"
  1348. });
  1349. },
  1350. getDayStock() {
  1351. if (this.data.dateIndex < 0) {
  1352. return false;
  1353. }
  1354. let params = {
  1355. day: this.data.dateList[this.data.dateIndex].date,
  1356. goodsId: this.data.checkedGoodsList[0].goodsId,
  1357. lng: this.data.checkedAddress.lng,
  1358. lat: this.data.checkedAddress.lat,
  1359. productId:this.data.checkedGoodsList[0].product.id,
  1360. serviceDuration:this.data.serviceDuration
  1361. }
  1362. wx.showLoading({
  1363. title: '加载中',
  1364. });
  1365. util.request(api.EveryDayStock, params, "GET")
  1366. .then(res => {
  1367. wx.hideLoading();
  1368. if (res.errno == 0) {
  1369. this.setData({
  1370. timeList: res.data,
  1371. timeIndex: 0
  1372. });
  1373. // let validList = this.data.timeList.filter(item => {
  1374. // return item.stock > 0
  1375. // });
  1376. // if (validList.length > 0) {
  1377. // this.setData({
  1378. // timeIndex: validList[0].id - 1
  1379. // });
  1380. // } else {
  1381. // this.setData({
  1382. // timeIndex: ''
  1383. // });
  1384. // }
  1385. } else {
  1386. wx.showToast({
  1387. title: res.errmsg,
  1388. icon: 'none',
  1389. duration: 2000
  1390. });
  1391. this.setData({
  1392. timeList: [],
  1393. timeIndex: ''
  1394. });
  1395. }
  1396. }).catch(function (err) {
  1397. console.log(err);
  1398. wx.hideLoading();
  1399. wx.showToast({
  1400. title: err.errMsg,
  1401. icon: 'none'
  1402. });
  1403. this.setData({
  1404. timeList: [],
  1405. timeIndex: ''
  1406. });
  1407. });
  1408. },
  1409. getDayTime() {
  1410. let params = {
  1411. days:30,
  1412. goodsId: this.data.checkedGoodsList[0].goodsId,
  1413. serviceDuration:this.data.serviceDuration
  1414. }
  1415. wx.showLoading({
  1416. title: '加载中',
  1417. });
  1418. util.request(api.everyDayTime, params, "GET")
  1419. .then(res => {
  1420. wx.hideLoading();
  1421. if (res.errno == 0) {
  1422. this.setData({
  1423. dateList: res.data,
  1424. dateIndex:0,
  1425. timeIndex: -1,
  1426. noonType:1
  1427. });
  1428. let period=res.data[0].period;
  1429. let list=period.filter(item=>{
  1430. return item.ofTime=='上午';
  1431. });
  1432. this.setData({
  1433. timeList:list
  1434. });
  1435. } else {
  1436. wx.showToast({
  1437. title: res.errmsg,
  1438. icon: 'none',
  1439. duration: 2000
  1440. });
  1441. this.setData({
  1442. timeList: [],
  1443. timeIndex: ''
  1444. });
  1445. }
  1446. }).catch(function (err) {
  1447. console.log(err);
  1448. wx.hideLoading();
  1449. wx.showToast({
  1450. title: err.errMsg,
  1451. icon: 'none'
  1452. });
  1453. this.setData({
  1454. timeList: [],
  1455. timeIndex: ''
  1456. });
  1457. });
  1458. },
  1459. });