抖音c端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

284 lines
6.5 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. pickedDate: "请选择日期",
  17. pickedStartTime: "请选择",
  18. pickedEndTime: "请选择",
  19. describeStr: "",
  20. mallList: [],
  21. merchantId: "",
  22. currentIndex: "",
  23. status: "",
  24. isShowBtns: false
  25. },
  26. onLoad(options) {
  27. console.log(options, 'options')
  28. const date = (new Date()).getTime()
  29. const nowDate = util.timestampToTime(date, 'YYYY-MM-DD')
  30. const startTime = util.timestampToTime(options.startTime * 1, 'YYYY-MM-DD')
  31. console.log(nowDate, startTime, 'time');
  32. const finalStartTime = options.startTime * 1 > date * 1 ? startTime : nowDate
  33. console.log(finalStartTime, 'finalStartTime');
  34. this.setData({
  35. id: options.id || '',
  36. orderId: options.orderId || '',
  37. startTime: finalStartTime,
  38. endTime: options.endTime || '',
  39. mallList: JSON.parse(options.mallList)[0].merchantVoList || '',
  40. })
  41. console.log(this.data.mallList, 'mallList');
  42. const mallTenantId = tt.getStorageSync('mallTenantId');
  43. if (mallTenantId) {
  44. this.setData({
  45. mallTenantId
  46. })
  47. }
  48. if (this.data.id) {
  49. this.getDetail(this.data.id)
  50. } else {
  51. this.setData({
  52. isShowBtns: true
  53. })
  54. }
  55. },
  56. setMerchant(e) {
  57. console.log(e.detail.value, 'e');
  58. const index = e.detail.value
  59. this.setData({
  60. currentIndex: index,
  61. merchantId: this.data.mallList[index].id
  62. })
  63. console.log(this.data.currentIndex, this.data.merchantId);
  64. },
  65. chooseAddress() {
  66. if (!this.data.isShowBtns) return
  67. let that = this;
  68. tt.chooseLocation({
  69. success: function (res) {
  70. that.setData({
  71. pickedAddress: res.address,
  72. })
  73. },
  74. fail: function (error) {
  75. console.log(error)
  76. },
  77. complete: function (data) {}
  78. })
  79. },
  80. chooseDate(e) {
  81. console.log(e.detail.value, 'e');
  82. this.setData({
  83. pickedDate: e.detail.value
  84. })
  85. },
  86. chooseStartTime(e) {
  87. console.log(e.detail.value, 'e');
  88. this.setData({
  89. pickedStartTime: e.detail.value
  90. })
  91. },
  92. chooseEndTime(e) {
  93. console.log(e.detail.value, 'e');
  94. this.setData({
  95. pickedEndTime: e.detail.value
  96. })
  97. },
  98. describing(e) {
  99. this.setData({
  100. describeStr: e.detail.value
  101. })
  102. },
  103. confirm() {
  104. const tempData = this.data
  105. if (tempData.pickedAddress == '请选择地址') {
  106. tt.showToast({
  107. title: '请选择地址!',
  108. icon: 'fail'
  109. });
  110. return
  111. }
  112. if (tempData.pickedDate == '请选择日期') {
  113. tt.showToast({
  114. title: '请请选择日期!',
  115. icon: 'fail'
  116. });
  117. return
  118. }
  119. if (tempData.pickedStartTime == '请选择') {
  120. tt.showToast({
  121. title: '请起始时间!',
  122. icon: 'fail'
  123. });
  124. return
  125. }
  126. if (tempData.pickedEndTime == '请选择') {
  127. tt.showToast({
  128. title: '请结束时间!',
  129. icon: 'fail'
  130. });
  131. return
  132. }
  133. const data = {
  134. couponOrderId: tempData.orderId,
  135. userAddress: tempData.pickedAddress,
  136. startDate: tempData.pickedDate + " " + tempData.pickedStartTime + ":00",
  137. endDate: tempData.pickedDate + " " + tempData.pickedEndTime + ":00",
  138. describeStr: tempData.describeStr,
  139. mallTenantId: tempData.mallTenantId || '',
  140. reservationMerchantId: tempData.merchantId
  141. }
  142. if (this.data.id) {
  143. data.id = this.data.id
  144. }
  145. if (this.data.status == 1) {
  146. data.status = 0
  147. }
  148. console.log(data, 'data');
  149. this.saveOrderReservation(data)
  150. },
  151. cancel() {
  152. tt.showModal({
  153. title: "取消预约",
  154. content: "确定要取消预约吗?",
  155. showCancel: true,
  156. success: (res) => {
  157. if (res.confirm) {
  158. this.cancelReservation(this.data.id)
  159. }
  160. if (res.cancel) {
  161. return
  162. }
  163. },
  164. fail: (res) => {
  165. },
  166. });
  167. },
  168. cancelReservation(id) {
  169. const that = this
  170. Http.post({
  171. url: config.api.cancelReservation,
  172. data: {
  173. id,
  174. mallTenantId: this.data.mallTenantId || ''
  175. }
  176. }).then(res => {
  177. console.log(res, 'cancelReservation');
  178. tt.showToast({
  179. title: '取消成功!',
  180. icon: 'success',
  181. duration: 2000,
  182. success: (res) => {
  183. setTimeout(() => {
  184. tt.navigateBack();
  185. }, 1500);
  186. },
  187. fail: (res) => {
  188. },
  189. });
  190. }).catch(err => {
  191. console.log(err, 'cancelReservation');
  192. tt.showToast({
  193. title: err.message,
  194. icon: 'none'
  195. });
  196. })
  197. },
  198. saveOrderReservation(data) {
  199. Http.post({
  200. url: config.api.saveOrderReservation,
  201. data
  202. }).then(res => {
  203. console.log(res, 'saveOrderReservation');
  204. tt.showToast({
  205. title: '预约成功!',
  206. icon: 'success',
  207. duration: 2000,
  208. success: (res) => {
  209. setTimeout(() => {
  210. tt.navigateBack();
  211. }, 1500);
  212. },
  213. fail: (res) => {
  214. },
  215. });
  216. }).catch(err => {
  217. console.log(err, 'saveOrderReservation');
  218. tt.showToast({
  219. title: err.message,
  220. icon: 'none'
  221. });
  222. })
  223. },
  224. getDetail(id) {
  225. const that = this
  226. Http.get({
  227. url: config.api.getOrderReservationDetail,
  228. data: {
  229. id,
  230. mallTenantId: this.data.mallTenantId || ''
  231. }
  232. }).then(res => {
  233. console.log(res, 'getOrderReservationDetail');
  234. const status = res.data.status
  235. that.setData({
  236. pickedAddress: res.data.userAddress || '请选择地址',
  237. pickedDate: util.timestampToTime(res.data.startDate, 'YYYY-MM-DD'),
  238. pickedStartTime: util.timestampToTime(res.data.startDate, 'hh:mm'),
  239. pickedEndTime: util.timestampToTime(res.data.endDate, 'hh:mm'),
  240. describeStr: res.data.describeStr,
  241. status,
  242. appointmentText: res.data.status == 1 ? "重新预约" : "修改预约"
  243. })
  244. if (status == 0 || status == 1 || status == 2 || status == 3) {
  245. that.setData({
  246. isShowBtns: true
  247. })
  248. }
  249. }).catch(err => {
  250. console.log(err, 'getOrderReservationDetail');
  251. })
  252. }
  253. })