抖音c端
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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