抖音c端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

appointment.js 13 KiB

1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. // c:\Users\Holy-Knight-IX\Desktop\Working Space\4.TikTok-MiniPro\ttc\package2\pages\appointment\appointment.js
  2. let config = require("../../config/config.js");
  3. let util = require("../../utils/util");
  4. let Http = require("../../utils/HttpBasics");
  5. let app = getApp();
  6. const imgurl = require("../../utils/imgurl");
  7. Page({
  8. data: {
  9. appointmentText: "确认预约",
  10. id: "",
  11. orderId: "",
  12. merOrderId: "",
  13. startTime: '',
  14. endTime: "",
  15. mallTenantId: "",
  16. pickedAddress: "请选择地址",
  17. pickedAddressDetail: "",
  18. pickedDate: "请选择日期",
  19. pickedStartTime: "请选择",
  20. pickedEndTime: "请选择",
  21. reservationMerchantName: "",
  22. describeStr: "",
  23. mallList: [],
  24. merchantId: "",
  25. currentIndex: "",
  26. status: "",
  27. isShowBtns: false,
  28. latitude: "",
  29. longitude: "",
  30. shopItem: null
  31. },
  32. onLoad(options) {
  33. console.log(options, 'options')
  34. const mallTenantId = tt.getStorageSync('mallTenantId');
  35. if (mallTenantId) {
  36. this.setData({
  37. mallTenantId
  38. })
  39. }
  40. const date = (new Date()).getTime()
  41. const nowDate = util.timestampToTime(date, 'YYYY-MM-DD')
  42. const startTime = util.timestampToTime(options.startTime * 1, 'YYYY-MM-DD')
  43. console.log(nowDate, startTime, 'time');
  44. const finalStartTime = options.startTime * 1 > date * 1 ? startTime : nowDate
  45. console.log(finalStartTime, 'finalStartTime');
  46. // const mallList = [{
  47. // merchantName: "1家帮汇家政保洁(河池市庆远镇)",
  48. // latitude: 50.277748,
  49. // longitude: 119.996078,
  50. // id: 1
  51. // }, {
  52. // merchantName: "2家帮汇家政保洁(河池市庆远镇)",
  53. // latitude: 35.277748,
  54. // longitude: 119.996078,
  55. // id: 2
  56. // }, {
  57. // merchantName: "3家帮汇家政保洁(河池市庆远镇)",
  58. // id: 3
  59. // }, {
  60. // merchantName: "4家帮汇家政保洁(河池市庆远镇)",
  61. // latitude: 45.277748,
  62. // longitude: 119.996078,
  63. // id: 4
  64. // }]
  65. this.setData({
  66. id: options.id || '',
  67. orderId: options.orderId || '',
  68. merOrderId: options.merOrderId || '',
  69. startTime: finalStartTime,
  70. endTime: options.endTime || '',
  71. })
  72. // this.getCouponMerchant()
  73. if (this.data.id) {
  74. this.getDetail(this.data.id)
  75. } else {
  76. this.setData({
  77. isShowBtns: true
  78. })
  79. }
  80. },
  81. goSelectShop() {
  82. const data = this.data
  83. const id = data.id
  84. const orderId = data.orderId
  85. const merOrderId = data.merOrderId
  86. const startTime = data.startTime
  87. const endTime = data.endTime
  88. tt.navigateTo({
  89. url: `/pages2/shopSelect/shopSelect?id=${id}&orderId=${orderId}&merOrderId=${merOrderId}&startTime=${startTime}&endTime=${endTime}`,
  90. });
  91. },
  92. setMerchant(e) {
  93. console.log(e.detail.value, 'e');
  94. const index = e.detail.value
  95. this.setData({
  96. currentIndex: index,
  97. merchantId: this.data.mallList[index].id,
  98. reservationMerchantName: ''
  99. })
  100. console.log(this.data.currentIndex, this.data.merchantId);
  101. },
  102. /**
  103. * 获得经纬度
  104. */
  105. getLocation() {
  106. console.log('getLocation');
  107. let that = this;
  108. tt.getLocation({
  109. type: "wgs84",
  110. // isHighAccuracy: true,
  111. success: function (res) {
  112. console.log(res, 'getLocation')
  113. that.setData({
  114. latitude: res.latitude,
  115. longitude: res.longitude,
  116. })
  117. const latitudeNow = res.latitude
  118. const longitudeNow = res.longitude
  119. const mallLocationArr = []
  120. const mallList = that.data.mallList
  121. mallList.forEach((item, index) => {
  122. const obj = {
  123. latitude: item.latitude || false,
  124. longitude: item.longitude || false,
  125. id: item.id,
  126. index: index
  127. }
  128. mallLocationArr.push(obj)
  129. })
  130. console.log(mallLocationArr, 'mallLocationArr');
  131. const tempArr = mallList
  132. const bloobArr = []
  133. mallLocationArr.forEach((item, index) => {
  134. const distanceData = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude)
  135. tempArr[index].distance_str = distanceData.distance_str
  136. tempArr[index].distanceName = tempArr[index].merchantName + ' ' + distanceData.distance_str
  137. tempArr[index].distance = distanceData.distance
  138. bloobArr.push(tempArr[index])
  139. })
  140. const finalSortMallList = that.bloob(bloobArr)
  141. console.log(finalSortMallList, 'finalSortMallList');
  142. that.setData({
  143. mallList: finalSortMallList
  144. })
  145. },
  146. // 拒绝提供定位权限
  147. fail: error => {
  148. console.log(error, 'error');
  149. const mallList = that.data.mallList
  150. mallList.forEach(item => {
  151. item.distanceName = item.merchantName
  152. })
  153. that.setData({
  154. mallList
  155. })
  156. },
  157. complete: finish => {
  158. let isSuccess = 0
  159. const mallList = that.data.mallList
  160. mallList.forEach(item => {
  161. if (item.distance_str) {
  162. isSuccess = 1
  163. }
  164. })
  165. if (!isSuccess) {
  166. tt.showToast({
  167. title: '定位失败!',
  168. icon: "fail"
  169. });
  170. }
  171. }
  172. })
  173. },
  174. getCouponMerchant() { //获取适用门店
  175. const that = this
  176. Http.get({
  177. url: config.api.orderDetail,
  178. data: {
  179. orderId: that.data.merOrderId,
  180. mallTenantId: that.data.mallTenantId || ''
  181. }
  182. }).then(res => {
  183. const couponChannelId = res.data.orders[0].couponChannelId
  184. Http.get({
  185. url: config.api.couponMerchant,
  186. data: {
  187. couponChannelId,
  188. mallTenantId: that.data.mallTenantId || ''
  189. }
  190. }).then(res => {
  191. const keys = Object.keys(res.data)
  192. const mallList = []
  193. let i = 0
  194. keys.forEach(item => {
  195. const arr = item.split('|')
  196. const obj = {
  197. tenantId: arr[0],
  198. mallName: arr[1],
  199. merchantVoList: res.data[item],
  200. expand: false
  201. }
  202. if (i == 0) {
  203. obj.expand = true
  204. }
  205. mallList.push(obj)
  206. i++
  207. })
  208. that.setData({
  209. mallList: mallList[0].merchantVoList
  210. })
  211. console.log(that.data.mallList, 'mallList');
  212. that.getLocation()
  213. })
  214. }).catch(err => {
  215. })
  216. },
  217. chooseAddress() {
  218. if (!this.data.isShowBtns) return
  219. let that = this;
  220. tt.chooseLocation({
  221. success: function (res) {
  222. that.setData({
  223. pickedAddress: res.address,
  224. })
  225. },
  226. fail: function (error) {
  227. console.log(error)
  228. },
  229. complete: function (data) {}
  230. })
  231. },
  232. chooseAddressDetail() {
  233. this.setData({
  234. pickedAddressDetailFlag: false
  235. })
  236. },
  237. chooseDate(e) {
  238. console.log(e.detail.value, 'e');
  239. this.setData({
  240. pickedDate: e.detail.value
  241. })
  242. },
  243. chooseStartTime(e) {
  244. console.log(e.detail.value, 'e');
  245. this.setData({
  246. pickedStartTime: e.detail.value
  247. })
  248. },
  249. chooseEndTime(e) {
  250. console.log(e.detail.value, 'e');
  251. this.setData({
  252. pickedEndTime: e.detail.value
  253. })
  254. },
  255. inputAddressDetail(e) {
  256. this.setData({
  257. pickedAddressDetail: e.detail.value
  258. })
  259. },
  260. describing(e) {
  261. this.setData({
  262. describeStr: e.detail.value
  263. })
  264. },
  265. confirm() {
  266. const tempData = this.data
  267. if (tempData.pickedAddress == '请选择地址') {
  268. tt.showToast({
  269. title: '请选择地址!',
  270. icon: 'fail'
  271. });
  272. return
  273. }
  274. if (tempData.pickedDate == '请选择日期') {
  275. tt.showToast({
  276. title: '请请选择日期!',
  277. icon: 'fail'
  278. });
  279. return
  280. }
  281. if (tempData.pickedStartTime == '请选择') {
  282. tt.showToast({
  283. title: '请起始时间!',
  284. icon: 'fail'
  285. });
  286. return
  287. }
  288. if (tempData.pickedEndTime == '请选择') {
  289. tt.showToast({
  290. title: '请结束时间!',
  291. icon: 'fail'
  292. });
  293. return
  294. }
  295. const data = {
  296. couponOrderId: tempData.orderId,
  297. userAddress: tempData.pickedAddress,
  298. detailedAddress: tempData.pickedAddressDetail,
  299. startDate: tempData.pickedDate + " " + tempData.pickedStartTime + ":00",
  300. endDate: tempData.pickedDate + " " + tempData.pickedEndTime + ":00",
  301. describeStr: tempData.describeStr,
  302. mallTenantId: tempData.mallTenantId || '',
  303. reservationMerchantId: tempData.merchantId
  304. }
  305. if (this.data.id) {
  306. data.id = this.data.id
  307. }
  308. if (this.data.status == 1 || this.data.status == '-1') {
  309. data.status = 0
  310. }
  311. console.log(data, 'data');
  312. this.saveOrderReservation(data)
  313. },
  314. cancel() {
  315. tt.showModal({
  316. title: "取消预约",
  317. content: "确定要取消预约吗?",
  318. showCancel: true,
  319. success: (res) => {
  320. if (res.confirm) {
  321. this.cancelReservation(this.data.id)
  322. }
  323. if (res.cancel) {
  324. return
  325. }
  326. },
  327. fail: (res) => {
  328. },
  329. });
  330. },
  331. cancelReservation(id) {
  332. const that = this
  333. Http.post({
  334. url: config.api.cancelReservation,
  335. data: {
  336. id,
  337. mallTenantId: this.data.mallTenantId || ''
  338. }
  339. }).then(res => {
  340. console.log(res, 'cancelReservation');
  341. tt.showToast({
  342. title: '取消成功!',
  343. icon: 'success',
  344. duration: 2000,
  345. success: (res) => {
  346. setTimeout(() => {
  347. tt.navigateBack();
  348. }, 1500);
  349. },
  350. fail: (res) => {
  351. },
  352. });
  353. }).catch(err => {
  354. console.log(err, 'cancelReservation');
  355. tt.showToast({
  356. title: err.message,
  357. icon: 'none'
  358. });
  359. })
  360. },
  361. saveOrderReservation(data) {
  362. Http.post({
  363. url: config.api.saveOrderReservation,
  364. data
  365. }).then(res => {
  366. console.log(res, 'saveOrderReservation');
  367. tt.showToast({
  368. title: '预约成功!',
  369. icon: 'success',
  370. duration: 2000,
  371. success: (res) => {
  372. setTimeout(() => {
  373. tt.navigateBack();
  374. }, 1500);
  375. },
  376. fail: (res) => {
  377. },
  378. });
  379. }).catch(err => {
  380. console.log(err, 'saveOrderReservation');
  381. tt.showToast({
  382. title: err.message,
  383. icon: 'none'
  384. });
  385. })
  386. },
  387. getDetail(id) {
  388. const that = this
  389. Http.get({
  390. url: config.api.getOrderReservationDetail,
  391. data: {
  392. id,
  393. mallTenantId: this.data.mallTenantId || ''
  394. }
  395. }).then(res => {
  396. console.log(res, 'getOrderReservationDetail');
  397. const status = res.data.status
  398. that.setData({
  399. pickedAddress: res.data.userAddress || '请选择地址',
  400. pickedAddressDetail: res.data.detailedAddress,
  401. pickedDate: util.timestampToTime(res.data.startDate, 'YYYY-MM-DD') || '请选择日期',
  402. pickedStartTime: util.timestampToTime(res.data.startDate, 'hh:mm') || '请选择',
  403. pickedEndTime: util.timestampToTime(res.data.endDate, 'hh:mm') || '请选择',
  404. describeStr: res.data.describeStr,
  405. status,
  406. appointmentText: res.data.status == 1 ? "重新预约" : "修改预约",
  407. merchantId: res.data.reservationMerchantId,
  408. reservationMerchantName: res.data.reservationMerchantName
  409. })
  410. if (status == 0 || status == 1 || status == 2 || status == 3 || status == '-1') {
  411. that.setData({
  412. isShowBtns: true
  413. })
  414. }
  415. }).catch(err => {
  416. console.log(err, 'getOrderReservationDetail');
  417. })
  418. },
  419. /**
  420. * @description:根据经纬度计算距离
  421. * @param {*} locationInfo (lat1, lng1, lat2, lng2)
  422. * @return: distanceObj: { distance , distance_str }
  423. */
  424. getDistances(lat1, lng1, lat2, lng2) {
  425. if (lat2 || lng2) {
  426. function rad(num) {
  427. return num * Math.PI / 180.0;
  428. }
  429. var radLat1 = rad(lat1);
  430. var radLat2 = rad(lat2);
  431. var a = radLat1 - radLat2;
  432. var b = rad(lng1) - rad(lng2);
  433. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  434. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  435. s = s * 6378.137;
  436. s = Math.round(s * 10000) / 10000;
  437. var distance = s;
  438. var distance_str = "";
  439. if (parseInt(distance) >= 1) {
  440. distance_str = distance.toFixed(2) + "km";
  441. } else if (!arseInt(distance)) {
  442. return false
  443. } else {
  444. distance_str = (distance * 1000).toFixed(2) + "m";
  445. }
  446. let objData = {
  447. distance: distance,
  448. distance_str: distance_str
  449. }
  450. return objData
  451. } else {
  452. let objData = {
  453. distance: Infinity,
  454. distance_str: ''
  455. }
  456. return objData
  457. }
  458. },
  459. bloob(arr) {
  460. const tempArr = arr
  461. for (let i = 0; i < tempArr.length - 1; i++) {
  462. for (let j = 0; j < tempArr.length - 1 - i; j++) {
  463. if (tempArr[j].distance > tempArr[j + 1].distance) {
  464. let temp = tempArr[j];
  465. tempArr[j] = tempArr[j + 1];
  466. tempArr[j + 1] = temp;
  467. }
  468. }
  469. }
  470. return tempArr
  471. },
  472. onShow() {
  473. const shopItem = app.globalData.shopItem
  474. if (shopItem) {
  475. this.setData({
  476. shopItem,
  477. merchantId: shopItem.id,
  478. reservationMerchantName: ""
  479. })
  480. console.log(this.data.shopItem, 'shopItem');
  481. app.globalData.shopItem = null
  482. }
  483. }
  484. })