appointment.js 5.7 KB

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