appointment.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. const app = getApp();
  2. import productApi from '../../api/product'
  3. import storeApi from '../../api/store'
  4. import orderApi from '../../api/order'
  5. import until from '../../utils/util'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. peopleNum: 1,
  12. activeTab: 0,
  13. productInfo: {
  14. },
  15. shopInfo: {},
  16. tabs: [],
  17. orderTime: "",
  18. orderTimeHeight: 0
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: async function (options) {
  24. var shopId = options.shopId;
  25. var productId = options.productId
  26. var productInfo = await productApi.getProductById(productId);
  27. var shopInfo = await storeApi.getStoreById(shopId);
  28. this.setData({
  29. productInfo: productInfo.info,
  30. shopInfo:shopInfo.info
  31. })
  32. var tabs = await this.createTimeList(268);
  33. this.setData({
  34. tabs
  35. });
  36. this.getOrderHeight();
  37. this.checkedTime()
  38. },
  39. checkAuth: async function () {
  40. const self = this
  41. const isAuth = await app.isAuth()
  42. if (!isAuth) {
  43. wx.redirectTo({
  44. url: '/pages/prompt/prompt?page=' + this.route,
  45. })
  46. }
  47. console.log(self.productInfo)
  48. let data = {
  49. productId: self.data.productInfo.id,
  50. storeId: self.data.shopInfo.id,
  51. appointmentTime: self.data.orderTime,
  52. num: self.data.peopleNum,
  53. mobile: 15656942279
  54. }
  55. const rs = await orderApi.createOrder(data)
  56. console.log(rs)
  57. },
  58. onSlideChangeEnd: function (e) {
  59. var that = this;
  60. that.setData({
  61. activeTab: e.detail.index
  62. })
  63. },
  64. //动态生成产品的父盒子高度
  65. getOrderHeight: function () {
  66. var activeTab = this.data.activeTab;
  67. var orderTimeHeight = (this.data.tabs[activeTab].list.length) / 5 * 130;
  68. this.setData({
  69. orderTimeHeight
  70. })
  71. },
  72. createTimeList: async function (price) {
  73. var titles = ["今天", "明天", "12-23", "12-24", "12-25", "12-26", "12-27"];
  74. var day = ["12-21", "12-22", "12-23", "12-24", "12-25", "12-26", "12-27"];
  75. const tabs = [];
  76. let list = [{
  77. id: "1",
  78. time: "8:00",
  79. price: price,
  80. },
  81. {
  82. id: "2",
  83. time: "8:30",
  84. price: price,
  85. },
  86. {
  87. id: "3",
  88. time: "9:00",
  89. price: price,
  90. },
  91. {
  92. id: "4",
  93. time: "9:30",
  94. price: price,
  95. },
  96. {
  97. id: "5",
  98. time: "10:00",
  99. price: price,
  100. },
  101. {
  102. id: "6",
  103. time: "10:30",
  104. price: price,
  105. },
  106. {
  107. id: "7",
  108. time: "11:00",
  109. price: price,
  110. },
  111. {
  112. id: "8",
  113. time: "11:30",
  114. price: price,
  115. }, {
  116. id: "9",
  117. time: "12:00",
  118. price: price,
  119. },
  120. {
  121. id: "10",
  122. time: "12:30",
  123. price: price,
  124. },
  125. {
  126. id: "11",
  127. time: "13:00",
  128. price: price,
  129. },
  130. {
  131. id: "12",
  132. time: "13:30",
  133. price: price,
  134. },
  135. {
  136. id: "13",
  137. time: "14:00",
  138. price: price,
  139. },
  140. {
  141. id: "14",
  142. time: "14:30",
  143. price: price,
  144. },
  145. {
  146. id: "15",
  147. time: "15:00",
  148. price: price,
  149. },
  150. {
  151. id: "16",
  152. time: "15:30",
  153. price: price,
  154. }, {
  155. id: "17",
  156. time: "16:00",
  157. price: price,
  158. },
  159. {
  160. id: "18",
  161. time: "16:30",
  162. price: price,
  163. },
  164. {
  165. id: "19",
  166. time: "17:00",
  167. price: price,
  168. },
  169. {
  170. id: "20",
  171. time: "17:30",
  172. price: price,
  173. },
  174. {
  175. id: "21",
  176. time: "18:00",
  177. price: price,
  178. },
  179. {
  180. id: "22",
  181. time: "18:30",
  182. price: price,
  183. },
  184. {
  185. id: "23",
  186. time: "19:00",
  187. price: price,
  188. },
  189. {
  190. id: "24",
  191. time: "19:30",
  192. price: price,
  193. },
  194. {
  195. id: "25",
  196. time: "20:00",
  197. price: price,
  198. }
  199. ];
  200. titles.forEach(function (item, i, array) {
  201. list.forEach(function (item, i, array) {
  202. array[i].timeId = i;
  203. array[i].inTime = true;
  204. array[i].checked = false;
  205. })
  206. tabs.push({
  207. title: titles[i],
  208. day: day[i],
  209. list
  210. })
  211. })
  212. // tabs[2].list.splice(7,7)
  213. return tabs;
  214. },
  215. //判断产品是否过时间
  216. checkedTime: function (e) {
  217. // 设置一小时内订单不能购买
  218. var timeLimit = 1;
  219. var nowTime = new Date(2020, 11, 21, 18, 29, 0);
  220. var hour = nowTime.getHours();
  221. var tabs = this.data.tabs[0];
  222. var list = firstTabs.list;
  223. // console.log(tabs[5].list)
  224. list.forEach(function (item, i, array) {
  225. var orderHour = item.time.split(":")[0];
  226. if (parseInt(orderHour) <= parseInt(hour)) {
  227. item.inTime = false;
  228. }
  229. })
  230. this.setData({
  231. tabs: nowTabs
  232. })
  233. },
  234. getOrderTime: function (e) {
  235. // var date = document.getElementById("orderDate");
  236. // console.log(date.target)
  237. // console.log(e.currentTarget)
  238. //选中日期的下标
  239. var i = this.data.activeTab;
  240. //选中时间的下标
  241. var index = e.currentTarget.dataset.i;
  242. //获取选中的日期
  243. var date = this.data.tabs[i].day;
  244. var time = e.currentTarget.dataset.time;
  245. var year = (new Date()).getFullYear()
  246. var oTime = year +'-'+ date + ' ' + time;
  247. //设置选中的样式
  248. var tabs = this.data.tabs;
  249. var list = tabs[i].list;
  250. //先清空其他选中的样式
  251. list.forEach(function (item, i, array) {
  252. item.checked = false;
  253. })
  254. if (list[index].inTime) {
  255. list[index].checked = true;
  256. this.data.tabs[i].list = list;
  257. }
  258. this.setData({
  259. orderTime: oTime,
  260. tabs
  261. })
  262. },
  263. addPeopleNum: function (e) {
  264. var num = e.currentTarget.dataset.num;
  265. var maxNum = 9;
  266. if (num < maxNum) {
  267. num++;
  268. }
  269. this.setData({
  270. peopleNum: num
  271. })
  272. },
  273. reducePeopleNum: function (e) {
  274. var num = e.currentTarget.dataset.num;
  275. if (num > 1) {
  276. num--;
  277. }
  278. this.setData({
  279. peopleNum: num
  280. })
  281. },
  282. /**
  283. * 生命周期函数--监听页面初次渲染完成
  284. */
  285. onReady: function () {
  286. },
  287. /**
  288. * 生命周期函数--监听页面显示
  289. */
  290. onShow: function () {
  291. },
  292. /**
  293. * 生命周期函数--监听页面隐藏
  294. */
  295. onHide: function () {
  296. },
  297. /**
  298. * 生命周期函数--监听页面卸载
  299. */
  300. onUnload: function () {
  301. },
  302. /**
  303. * 页面相关事件处理函数--监听用户下拉动作
  304. */
  305. onPullDownRefresh: function () {
  306. },
  307. /**
  308. * 页面上拉触底事件的处理函数
  309. */
  310. onReachBottom: function () {
  311. },
  312. /**
  313. * 用户点击右上角分享
  314. */
  315. onShareAppMessage: function () {
  316. }
  317. })