checkout.js 44 KB

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