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

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