抖音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.

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