consult.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. var app = getApp();
  2. var util = require("../../utils/util.js");
  3. let pageid = "";
  4. let timer = null;
  5. let endTotal = 0
  6. let num = 0
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. appAssetsUrl2: app.appAssetsUrl2,
  13. // 行家id
  14. id: null,
  15. // 主题id
  16. topicId: null,
  17. topicList: [],
  18. content: null,
  19. price: null,
  20. groupList: [],
  21. groupList3: [],
  22. bottomLeft: app.bottomLeft,
  23. onePer: true, // 单人请教
  24. addressIndex: 0,
  25. addressArray: [],
  26. tuanList: [
  27. {
  28. endtime: "2022-10-12 21:25:06",
  29. },
  30. {
  31. endtime: "2022-10-15 21:25:06",
  32. },
  33. {
  34. endtime: "2022-10-15 21:25:06",
  35. },
  36. {
  37. endtime: "2022-10-13 21:25:06",
  38. },
  39. ],
  40. time: "07:00",
  41. timelist: [
  42. [
  43. "07",
  44. "08",
  45. "09",
  46. "10",
  47. "11",
  48. "12",
  49. "13",
  50. "14",
  51. "15",
  52. "16",
  53. "17",
  54. "18",
  55. "19",
  56. "20",
  57. "21",
  58. "22",
  59. "23",
  60. ],
  61. ["00", "15", "30", "45"],
  62. ],
  63. hourIndex: 0,
  64. minuteIndex: 0,
  65. date: "",
  66. startDate: "",
  67. addressPopup: false,
  68. pickMove: false,
  69. groupWay: 0, // 拼团方式
  70. groupNumberPeople: 0, //拼团人数
  71. storeId: null, // 门店id
  72. contents: "", //预约内容
  73. topicPrice: 0,
  74. payPrice: 0,
  75. timeList: [], //空余时间
  76. isGroup: false, // 是否有拼团
  77. aa: [],
  78. },
  79. showTime() {
  80. this.popup.showPopup();
  81. },
  82. // 场地
  83. showAddress() {
  84. this.setData({
  85. addressPopup: true,
  86. });
  87. },
  88. //场地change
  89. bindChange(e) {
  90. console.log(e);
  91. this.setData({
  92. addressIndex: e.detail.value,
  93. });
  94. },
  95. pickstart() {
  96. this.setData({
  97. pickMove: true,
  98. });
  99. },
  100. pickend() {
  101. this.setData({
  102. pickMove: false,
  103. });
  104. },
  105. confirmAddress() {
  106. if (this.data.pickMove) {
  107. return;
  108. }
  109. this.setData({
  110. addressPopup: false,
  111. storeId: this.data.addressArray[this.data.addressIndex].id,
  112. });
  113. },
  114. toStoreDetail(e) {
  115. console.log(e, 111);
  116. wx.navigateTo({
  117. url: "/expert/storedetail/storedetail?id=" + e.currentTarget.dataset.id,
  118. });
  119. },
  120. putblur(e) {
  121. this.setData({
  122. contents: e.detail.value,
  123. });
  124. },
  125. submit() {
  126. if (this.data.topicId === null) {
  127. return app.showError("请选择话题!");
  128. }
  129. if (this.data.groupNumberPeople == 0 && !this.data.onePer) {
  130. return app.showError("请选择拼团人数!");
  131. }
  132. if (this.data.contents == "") {
  133. return app.showError("请输入预约内容!");
  134. }
  135. if (!util.getUserId()) {
  136. wx.reLaunch({
  137. url: "/pages/login",
  138. });
  139. return;
  140. }
  141. wx.requestSubscribeMessage({
  142. tmplIds: [
  143. "7W7QGAJiJ5xzYZtzzG3vaiVrGGtUYklkqKGCFpMP2wU",
  144. "LyWMllU4dWpy1Y8tS39EhOBLUSQWmUb_yDFKoJojKq8",
  145. ],
  146. success: (success) => {},
  147. fail: (fail) => {},
  148. complete: (complete) => {
  149. app._post_form(
  150. "meet/consult",
  151. "",
  152. {
  153. content: this.data.contents,
  154. expertId: this.data.id,
  155. groupNumberPeople: this.data.groupNumberPeople,
  156. groupWay: this.data.groupWay,
  157. meetPrice: this.data.payPrice,
  158. meetTime: this.data.date + " " + this.data.time + ":00",
  159. storeId: this.data.storeId,
  160. topicId: this.data.topicId,
  161. type: 0,
  162. id: util.getUserId(),
  163. },
  164. (res) => {
  165. if (res.code == 0) {
  166. wx.showActionSheet({
  167. itemList: ["微信支付"],
  168. success: (response) => {
  169. if (response.tapIndex === 0) {
  170. wx.showLoading({
  171. title: "正在处理...",
  172. mask: true,
  173. });
  174. wx.requestPayment({
  175. timeStamp: res.map.timestamp,
  176. nonceStr: res.map.nonce_str,
  177. package: "prepay_id=" + res.map.prepay_id,
  178. signType: "MD5",
  179. paySign: res.map.sign,
  180. success: (result) => {
  181. if (result.errMsg == "requestPayment:ok") {
  182. wx.showLoading({
  183. title: "正在处理...",
  184. mask: true,
  185. });
  186. console.log(result, 11111111);
  187. wx.hideLoading();
  188. // wx.showModal({
  189. // title: "温馨提示",
  190. // content: "支付成功!",
  191. // showCancel: false,
  192. // });
  193. wx.showToast({
  194. title: "支付成功!",
  195. icon: "none",
  196. duration: 1500,
  197. });
  198. setTimeout(() => {
  199. wx.navigateTo({
  200. url:
  201. "/expert/success/success?expertId=" +
  202. this.data.id +
  203. "&meetId=" +
  204. res.map.businessId +
  205. "&onePer=" +
  206. this.data.onePer,
  207. });
  208. },2000)
  209. } else {
  210. wx.hideLoading();
  211. wx.showToast({
  212. title: "支付失败!",
  213. icon: "none",
  214. duration: 1500,
  215. });
  216. }
  217. },
  218. fail: (error) => {
  219. wx.hideLoading();
  220. wx.showToast({
  221. title: "支付失败!",
  222. icon: "none",
  223. duration: 1500,
  224. });
  225. },
  226. });
  227. }
  228. },
  229. fail(errors) {},
  230. });
  231. } else {
  232. wx.showModal({
  233. title: "温馨提示",
  234. content: res.msg,
  235. showCancel: false,
  236. });
  237. }
  238. },
  239. function (res) {}
  240. );
  241. },
  242. });
  243. console.log(util.getUserId());
  244. // wx.navigateTo({
  245. // url: '/expert/success/success'
  246. // })
  247. },
  248. hiddenAddress() {
  249. this.setData({
  250. addressPopup: false,
  251. });
  252. },
  253. know() {
  254. this.popup.hidePopup();
  255. },
  256. //话题选择change
  257. msgChange(e) {
  258. let that = this;
  259. let temp;
  260. if (e && e.hasOwnProperty("detail")) {
  261. temp = e.detail.value;
  262. } else {
  263. temp = e;
  264. }
  265. console.log(e,'20')
  266. for (let item of this.data.topicList) {
  267. if (item.id == temp) {
  268. this.setData({
  269. topicId: temp,
  270. content: item.topicDescribe,
  271. price: item.topicPrice,
  272. payPrice: that.data.onePer
  273. ? item.topicPrice
  274. : that.data.groupNumberPeople == 0
  275. ? item.topicPrice
  276. : item.topicPrice / that.data.groupNumberPeople,
  277. });
  278. this.getGroupList();
  279. }
  280. }
  281. },
  282. //日期change
  283. bindDateChange(e) {
  284. this.setData({
  285. date: e.detail.value,
  286. });
  287. },
  288. //时间change
  289. timeChange(e) {
  290. this.setData({
  291. time: e.detail.value,
  292. });
  293. },
  294. bindMultiPickerChange(e) {
  295. console.log(e, 11111111);
  296. let hourIndex = e.detail.value[0];
  297. let minuteIndex = e.detail.value[1];
  298. this.setData({
  299. hourIndex: hourIndex,
  300. minuteIndex: minuteIndex,
  301. time:
  302. this.data.timelist[0][[hourIndex]] +
  303. ":" +
  304. this.data.timelist[1][minuteIndex],
  305. });
  306. },
  307. //拼团方式change
  308. pinChange(e) {
  309. let that = this;
  310. if (e.detail.value == "1") {
  311. this.setData({
  312. onePer: false,
  313. payPrice: that.data.price,
  314. });
  315. } else {
  316. this.setData({
  317. onePer: true,
  318. payPrice: that.data.price,
  319. groupNumberPeople: 0,
  320. });
  321. }
  322. this.setData({
  323. groupWay: e.detail.value,
  324. });
  325. },
  326. //拼团人数
  327. perChange(e) {
  328. let that = this;
  329. this.setData({
  330. groupNumberPeople: e.detail.value,
  331. payPrice: that.data.price / e.detail.value,
  332. });
  333. },
  334. //更多拼团
  335. more() {
  336. this.getGroupList();
  337. this.popup1.showPopup();
  338. },
  339. // 参与拼团
  340. joinGroup(e) {
  341. // console.log(e.currentTarget.dataset.meetid);
  342. // console.log(e.currentTarget.dataset.expertId);
  343. if (!util.getUserId()) {
  344. wx.reLaunch({
  345. url: "/pages/login",
  346. });
  347. return;
  348. }
  349. wx.navigateTo({
  350. url:
  351. "/meet/meet/addmeet?expertId=" +
  352. e.currentTarget.dataset.expertid +
  353. "&meetId=" +
  354. e.currentTarget.dataset.meetid +
  355. "&memberId=" +
  356. e.currentTarget.dataset.memberid
  357. });
  358. // console.log('expertId',e.currentTarget.dataset.expertid)
  359. // console.log('expertId1',this.data.id)
  360. // console.log(e)
  361. // console.log(this.data.onePer,'111222')
  362. // app._put_form(
  363. // "meet/joinTheGroup",
  364. // "",
  365. // {
  366. // id: util.getUserId(),
  367. // meetId: e.currentTarget.dataset.meetid,
  368. // },
  369. // (res) => {
  370. // if (res.code === 0) {
  371. // wx.showActionSheet({
  372. // itemList: ["微信支付"],
  373. // success: (response) => {
  374. // if (response.tapIndex === 0) {
  375. // wx.showLoading({
  376. // title: "正在处理...",
  377. // mask: true,
  378. // });
  379. // wx.requestPayment({
  380. // timeStamp: res.map.timestamp,
  381. // nonceStr: res.map.nonce_str,
  382. // package: "prepay_id=" + res.map.prepay_id,
  383. // signType: "MD5",
  384. // paySign: res.map.sign,
  385. // success: (result) => {
  386. // if (result.errMsg == "requestPayment:ok") {
  387. // wx.showLoading({
  388. // title: "正在处理...",
  389. // mask: true,
  390. // });
  391. // console.log(result, 11111111);
  392. // wx.hideLoading();
  393. // wx.showToast({
  394. // title: "拼团成功",
  395. // icon: "success",
  396. // });
  397. // wx.navigateTo({
  398. // url:
  399. // "/expert/success/success?expertId=" +
  400. // this.data.id +
  401. // "&meetId=" +
  402. // res.map.businessId +
  403. // "&onePer=" +
  404. // false,
  405. // });
  406. // } else {
  407. // wx.hideLoading();
  408. // wx.showToast({
  409. // title: "支付失败!",
  410. // icon: "none",
  411. // duration: 1500,
  412. // });
  413. // }
  414. // },
  415. // fail: (error) => {
  416. // wx.hideLoading();
  417. // wx.showToast({
  418. // title: "支付失败!",
  419. // icon: "none",
  420. // duration: 1500,
  421. // });
  422. // },
  423. // });
  424. // }
  425. // },
  426. // });
  427. // // this.getGroupList();
  428. // }
  429. // }
  430. // );
  431. },
  432. freeTime(id) {
  433. app._get(`expert/info/${id}`, {}, (res) => {
  434. if (res.code === 0) {
  435. this.setData({
  436. timeList: res.expert.periodBOList,
  437. });
  438. }
  439. });
  440. },
  441. //场地change
  442. // addressChange(e) {
  443. // this.setData({
  444. // addressIndex: e.detail.value,
  445. // })
  446. // },
  447. //取消事件
  448. _error(e) {
  449. this[e.currentTarget.dataset.name].hidePopup();
  450. clearInterval(timer);
  451. endTotal = 0
  452. num = 0
  453. // this.setData({
  454. // maskShow: false,
  455. // isDjs: false,
  456. // time: 5
  457. // })
  458. },
  459. //倒计时
  460. nowTime(res) {
  461. //时间函数
  462. num++
  463. let that = this;
  464. // var endTotal = 0
  465. let len = res.length; //时间数据长度
  466. if(endTotal == len) {
  467. clearInterval(timer);
  468. return;
  469. }
  470. for (let i = 0; i < len; i++) {
  471. if(res[i].difftime == '已结束!') {
  472. continue
  473. }
  474. let localDate = new Date();
  475. var intDiff = res[i].groupWayEndTime; //获取数据中的时间
  476. let endTime = new Date(intDiff);
  477. let stratTime = (new Date(res[i].currentTime)).getTime() + num*1000
  478. // console.log(endTime.getTime(),localDate.getTime(),'ooooooooooppppp111')
  479. //计算秒数,取数据只取当月的,所以从天开始
  480. // let s = (endTime.getTime() - localDate.getTime()) / 1000;
  481. let s = (endTime.getTime() - stratTime) / 1000;
  482. // let s = (endTime.getTime() - stratTime.getTime()) / 1000;
  483. // console.log(intDiff)
  484. var day = 0,
  485. hour = 0,
  486. minute = 0,
  487. second = 0,
  488. msg = "";
  489. if (s > 0) {
  490. //转换时间
  491. day = Math.floor(s / 86400);
  492. // hour =
  493. // Math.floor((s % 86400) / 3600) < 10
  494. // ? "0" + Math.floor((s % 86400) / 3600)
  495. // : Math.floor((s % 86400) / 3600);
  496. hour =Math.floor(s / 60 / 60) < 10 ? '0' + Math.floor(s / 60 / 60) : Math.floor(s / 60 / 60);
  497. minute =
  498. Math.floor((s % 3600) / 60) < 10
  499. ? "0" + Math.floor((s % 3600) / 60)
  500. : Math.floor((s % 3600) / 60);
  501. second =
  502. Math.floor(s % 60) < 10
  503. ? "0" + Math.floor(s % 60)
  504. : Math.floor(s % 60);
  505. msg = hour + ":" + minute + ":" + second;
  506. } else {
  507. msg = "已结束!";
  508. endTotal++
  509. // res[i].difftime = msg;
  510. // clearInterval(timer);
  511. }
  512. // console.log(str);
  513. res[i].difftime = msg; //在数据中添加difftime参数名,把时间放进去
  514. }
  515. that.setData({
  516. // wearList: res
  517. groupList: res.slice(0, 10),
  518. groupList3: res.slice(0, 3),
  519. });
  520. // this.setData({
  521. // groupList: res.list.slice(0, 10),
  522. // groupList3: res.list.slice(0, 3),
  523. // });
  524. // console.log(that.data.groupList3)
  525. },
  526. /**
  527. * 生命周期函数--监听页面加载
  528. */
  529. onLoad: function (options) {
  530. console.log(options);
  531. if (options.topicId) {
  532. this.setData({
  533. topicId: options.topicId,
  534. });
  535. }
  536. console.log(options,'options.topicId')
  537. this.setData({
  538. id: options.id,
  539. topicPrice: options.price,
  540. payPrice: options.price,
  541. });
  542. this.getTopic(options.id);
  543. this.getMeetAddressList(options.id);
  544. this.freeTime(options.id);
  545. var currentDate = new Date()
  546. var preDate = new Date(currentDate.getTime() + (2*24*3600*1000))
  547. let year = preDate.getFullYear()
  548. let mon = preDate.getMonth() + 1
  549. let day = preDate.getDate()
  550. let s = year + '-' + (mon<10?('0'+mon):mon) + '-' + (day<10?('0'+day):day)
  551. this.setData({
  552. date: s,
  553. startDate: s
  554. });
  555. },
  556. /**
  557. * 生命周期函数--监听页面初次渲染完成
  558. */
  559. onReady: function () {
  560. //获得popup组件
  561. this.popup = this.selectComponent("#popup");
  562. this.popup1 = this.selectComponent("#popup1");
  563. },
  564. /**
  565. * 生命周期函数--监听页面显示
  566. */
  567. onShow: function () {},
  568. // 获取擅长话题
  569. getTopic(id) {
  570. let that = this
  571. app._get(
  572. "experttopic/list",
  573. {
  574. expertId: id,
  575. },
  576. (res) => {
  577. if (res.code === 0) {
  578. this.setData({
  579. topicList: res.list,
  580. });
  581. if (this.data.topicId) {
  582. this.data.topicList.forEach((v, i) => {
  583. if (v.id == this.data.topicId) {
  584. v.checked = true;
  585. } else {
  586. v.checked = false;
  587. }
  588. });
  589. this.setData({
  590. topicList: this.data.topicList,
  591. });
  592. this.msgChange(this.data.topicId);
  593. }else {
  594. this.setData({
  595. topicId: res.list[0].id,
  596. 'topicList[0].checked': true,
  597. content: res.list[0].topicDescribe,
  598. price: res.list[0].topicPrice,
  599. payPrice: that.data.onePer
  600. ? res.list[0].topicPrice
  601. : that.data.groupNumberPeople == 0
  602. ? res.list[0].topicPrice
  603. : res.list[0].topicPrice / that.data.groupNumberPeople,
  604. });
  605. // this.setData({
  606. // topicId: temp,
  607. // content: item.topicDescribe,
  608. // price: item.topicPrice,
  609. // payPrice: that.data.onePer
  610. // ? item.topicPrice
  611. // : that.data.groupNumberPeople == 0
  612. // ? item.topicPrice
  613. // : item.topicPrice / that.data.groupNumberPeople,
  614. // });
  615. }
  616. this.getGroupList()
  617. console.log(this.data.topicId,'topicId2222')
  618. }
  619. }
  620. );
  621. },
  622. // 拼团列表
  623. getGroupList() {
  624. clearInterval(timer);
  625. this.setData({
  626. groupList: [],
  627. groupList3: [],
  628. });
  629. app._get(
  630. "meet/groupList",
  631. {
  632. expertId: this.data.id,
  633. topicId: this.data.topicId,
  634. },
  635. (res) => {
  636. if (res.code === 0) {
  637. // this.setData({
  638. // groupList: res.list.slice(0, 10), res.list
  639. // groupList3: res.list.slice(0, 3),
  640. // });
  641. // this.nowTime(this.data.tuanList);
  642. if (res.list.length > 0) {
  643. timer = setInterval(this.nowTime, 990, res.list);
  644. }
  645. }
  646. }
  647. );
  648. },
  649. // 约见场地列表
  650. getMeetAddressList(expertId) {
  651. let that = this;
  652. app._get(`expert/meetingVenueList/${expertId}`, {}, (res) => {
  653. if (res.code === 0) {
  654. this.setData({
  655. addressArray: res.list,
  656. storeId: res.list[0].id,
  657. });
  658. }
  659. });
  660. },
  661. /**
  662. * 生命周期函数--监听页面隐藏
  663. */
  664. onHide: function () {},
  665. onUnload: function () {
  666. clearInterval(timer);
  667. endTotal = 0
  668. num = 0
  669. // this.data.groupList.forEach((v, k) => {
  670. // clearInterval(v.timer);
  671. // });
  672. // this.data.groupList.forEach((v, k) => {
  673. // clearInterval(v.timer);
  674. // // clearTimeout(v.timer)
  675. // // var index = "groupList[" + k + "].timer"; //这里必须这样拼接
  676. // // this.setData({
  677. // // [index]: null,
  678. // // });
  679. // console.log(this.data.aa)
  680. // });
  681. },
  682. /**
  683. * 页面相关事件处理函数--监听用户下拉动作
  684. */
  685. onPullDownRefresh: function () {},
  686. /**
  687. * 页面上拉触底事件的处理函数
  688. */
  689. onReachBottom: function () {},
  690. showShareMenu: function () {
  691. wx.showShareMenu();
  692. },
  693. hideShareMenu() {
  694. wx.hideShareMenu();
  695. },
  696. });