appointment.js 6.2 KB

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