抖音c端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

559 wiersze
14 KiB

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