checkout.js 41 KB

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