index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view class="">
  3. <view class="classWeeks">
  4. <view class="weeks" v-for="(itemList, index) in check" :key="index" @click="chooseDatas(itemList,index)"
  5. :style="chooseData==index?'background: linear-gradient(-35deg, #005AFF 0%, #0078FF 100%);box-shadow: 0px 5rpx 8rpx 0px rgba(0, 92, 255, 0.25);':'background: #FFFFFF;'">
  6. <view class="week" :style="chooseData==index?'color: #FFFFFF;':'color: #333333;'">
  7. {{itemList.week}}
  8. </view>
  9. <view class="weekData" :style="chooseData==index?'color: #FFFFFF;':'color: #333333;'">
  10. {{itemList.date}}
  11. </view>
  12. </view>
  13. </view>
  14. <view class="classChooseTime">
  15. <view v-for="(item, index) in dataTimeList" :key="index" :class="[item.prohibit?'timeBody':'timeBodyNo']"
  16. :style="sectionTime == item.time?'border: 1px solid #005AFF;color: #005AFF;':item.type?'background: #FFFFFF;color: #C3C3C3;border: 1px solid #EEEEEE;':''"
  17. @click="chooseTimes(item)" style="text-align: center;position: relative;margin-left: 20rpx;">
  18. <span
  19. :style="sectionTime == item.time || item.type?'position: relative;z-index: 1;':''">{{item.time}}</span>
  20. <image v-if="sectionTime == item.time" class="chooseImg" :src="require('../../../static/select.png')">
  21. <image v-if="item.type" class="chooseImg" :src="require('../../../static/mang.png')">
  22. </view>
  23. </view>
  24. <view class="classBottom">
  25. <view class="dataView">
  26. {{chooseWeeks}} {{sectionTime}}
  27. </view>
  28. <view @tap="goBack()" class="classbtn">确定预约</view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. getTimeList
  35. } from "@/api/shop.js"
  36. export default {
  37. data: function() {
  38. return {
  39. shopId: "",
  40. chooseWeeks: "今天",
  41. chooseData: null,
  42. sectionTime: "",
  43. dataTimeList: [],
  44. list: [],
  45. check: [],
  46. startTime:""
  47. }
  48. },
  49. watch: {
  50. chooseData(val) {
  51. this.dataTimeList = []
  52. for (let subIndex in this.list[this.check[val].intTime]) {
  53. let startTime = this.dataTime(this.list[this.check[val].intTime][subIndex].startTime);
  54. let endTime = this.dataTime(this.list[this.check[val].intTime][subIndex].endTime);
  55. console.log(this.list[this.check[val].intTime][subIndex].prohibit,'prohibit');
  56. this.dataTimeList.push({
  57. time: startTime + "-" + endTime,
  58. startTime:this.list[this.check[val].intTime][subIndex].startTime,
  59. type: this.list[this.check[val].intTime][subIndex].isBusy,
  60. prohibit:this.list[this.check[val].intTime][subIndex].prohibit
  61. })
  62. }
  63. }
  64. },
  65. onLoad: function(option) { //option为object类型,会序列化上个页面传递的参数
  66. this.shopId = option.shopId;
  67. let i = 0;
  68. this.list = JSON.parse(option.dataTimeList);
  69. for (let index in this.list) {
  70. i = i + 1;
  71. let date = new Date(parseInt(index));
  72. let year = date.getFullYear();
  73. let month = date.getMonth() + 1;
  74. let day = date.getDate();
  75. let dt2 = new Date(parseInt(index));
  76. let weekDay = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
  77. let weekDays = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
  78. if (month < 10) {
  79. month = "0" + month;
  80. }
  81. if (day < 10) {
  82. day = "0" + day;
  83. }
  84. // console.log(duty);
  85. //把七天的时间和星期添加到数组中
  86. this.check.push({
  87. intTime: index,
  88. date: month + "." + day,
  89. day: day,
  90. weekday: weekDays[dt2.getDay()],
  91. week: i === 1 ? "今天" : weekDay[dt2.getDay()],
  92. sectionTime: "",
  93. });
  94. }
  95. this.chooseData = 0;
  96. let listKey = Object.keys(this.list);
  97. this.check.forEach((res,index)=>{
  98. if(res.date == option.dataTime.substring(0, option.dataTime.lastIndexOf("日")).replace(/月/g, ".")){
  99. this.chooseData = index;
  100. }
  101. })
  102. this.sectionTime = option.dataTime.substring(option.dataTime.lastIndexOf(" ") + 1, option.dataTime.length);
  103. console.log(option.dataTime); //打印出上个页面传递的参数。
  104. // this.chooseTime(option)
  105. },
  106. methods: {
  107. dataTime(val) {
  108. let date = new Date(parseInt(val));
  109. let h = date.getHours();
  110. h = h < 10 ? ('0' + h) : h; //小时补0
  111. let m = date.getMinutes();
  112. m = m < 10 ? ('0' + m) : m; //分钟补0
  113. return h + ":" + m
  114. },
  115. goBack() {
  116. uni.$emit('chooseData', {data:this.check[this.chooseData].date.replace(".", "月") + "日 " + this.sectionTime,startTime:this.startTime})
  117. uni.navigateBack({
  118. delta: 1
  119. })
  120. },
  121. chooseTimes(data) {
  122. if (data.type) return;
  123. if(!data.prohibit) return;
  124. this.startTime = data.startTime;
  125. this.sectionTime = data.time;
  126. },
  127. chooseDatas(data, index) {
  128. this.chooseData = index;
  129. this.sectionTime = data.sectionTime;
  130. this.chooseWeeks = data.week;
  131. },
  132. // chooseTime(option) {
  133. // this.check = [];
  134. // for (let i = 0; i < 5; i++) {
  135. // //24 * 3600 * 1000 就是计算一天的时间
  136. // var date = new Date(new Date().getTime() + i * 24 * 3600 * 1000);
  137. // var year = date.getFullYear();
  138. // var month = date.getMonth() + 1;
  139. // var day = date.getDate();
  140. // var dt2 = new Date(new Date().getTime() + i * 24 * 3600 * 1000);
  141. // var weekDay = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
  142. // var weekDays = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
  143. // if (month < 10) {
  144. // month = "0" + month;
  145. // }
  146. // if (day < 10) {
  147. // day = "0" + day;
  148. // }
  149. // // console.log(duty);
  150. // //把七天的时间和星期添加到数组中
  151. // this.check.push({
  152. // date: month + "." + day,
  153. // day: day,
  154. // weekday: weekDays[dt2.getDay()],
  155. // week: i === 0 ? "今天" : weekDay[dt2.getDay()],
  156. // sectionTime: "",
  157. // });
  158. // for (let item in this.check) {
  159. // if (this.check[item].date == option.dataTime.substring(0, option.dataTime.lastIndexOf("日"))
  160. // .replace(/月/g, ".")) {
  161. // this.check[item].sectionTime = option.dataTime.substring(option.dataTime.lastIndexOf(" ") + 1,
  162. // option.dataTime.length);
  163. // this.chooseWeeks = this.check[item].week;
  164. // }
  165. // }
  166. // }
  167. // }
  168. }
  169. }
  170. </script>
  171. <style>
  172. page {
  173. background: #F5F5F5;
  174. }
  175. .classWeeks {
  176. display: flex;
  177. height: 130rpx;
  178. background: #FFFFFF;
  179. border-radius: 0px 0px 16rpx 16rpx;
  180. justify-content: space-around;
  181. align-items: center;
  182. padding: 8rpx 14rpx;
  183. }
  184. .weeks {
  185. width: 100rpx;
  186. height: 99rpx;
  187. border-radius: 6rpx;
  188. }
  189. .week {
  190. height: 26rpx;
  191. font-size: 28rpx;
  192. font-family: PingFang SC;
  193. font-weight: bold;
  194. line-height: 40rpx;
  195. text-align: center;
  196. padding-top: 24rpx;
  197. }
  198. .weekData {
  199. height: 19rpx;
  200. font-size: 24rpx;
  201. font-family: PingFang SC;
  202. font-weight: 500;
  203. color: #FFFFFF;
  204. line-height: 41rpx;
  205. text-align: center;
  206. padding-top: 12rpx;
  207. }
  208. .timeBody {
  209. width: 216rpx;
  210. height: 90rpx;
  211. background: #FFFFFF;
  212. border: 1px solid #EEEEEE;
  213. box-shadow: 0px 7rpx 12rpx 0px rgba(167, 167, 167, 0.1);
  214. border-radius: 8rpx;
  215. font-size: 28rpx;
  216. font-family: PingFang SC;
  217. font-weight: bold;
  218. color: #333333;
  219. line-height: 90rpx;
  220. margin-top: 10rpx;
  221. text-align: center;
  222. }
  223. .timeBodyNo {
  224. width: 216rpx;
  225. height: 90rpx;
  226. background: #999999;
  227. border: 1px solid #EEEEEE;
  228. box-shadow: 0px 7rpx 12rpx 0px rgba(167, 167, 167, 0.1);
  229. border-radius: 8rpx;
  230. font-size: 28rpx;
  231. font-family: PingFang SC;
  232. font-weight: bold;
  233. color: #eeeeee;
  234. line-height: 90rpx;
  235. margin-top: 10rpx;
  236. text-align: center;
  237. }
  238. .classChooseTime {
  239. display: flex;
  240. flex-wrap: wrap;
  241. justify-content: start;
  242. padding: 0 13rpx;
  243. }
  244. .chooseImg {
  245. width: 47rpx;
  246. height: 47rpx;
  247. /* position: relative;
  248. top: 36rpx;
  249. left: 10rpx; */
  250. position: absolute;
  251. bottom: 0;
  252. right: 0;
  253. z-index: 2;
  254. }
  255. .classBottom {
  256. width: 690rpx;
  257. height: 110rpx;
  258. background: #FFFFFF;
  259. border: 1px solid #EEEEEE;
  260. box-shadow: 0px 8rpx 17rpx 0px rgba(168, 165, 165, 0.09);
  261. border-radius: 55rpx;
  262. margin-left: 28rpx;
  263. position: absolute;
  264. bottom: 77rpx;
  265. }
  266. .dataView {
  267. font-size: 40rpx;
  268. font-family: PingFang SC;
  269. font-weight: bold;
  270. color: #005DFF;
  271. line-height: 110rpx;
  272. float: left;
  273. padding-left: 28rpx;
  274. }
  275. .classbtn {
  276. width: 240rpx;
  277. height: 110rpx;
  278. background: linear-gradient(0deg, #005AFF 0%, #0078FF 100%);
  279. border-radius: 0 55rpx 55rpx 0;
  280. font-size: 34rpx;
  281. font-family: PingFang SC;
  282. font-weight: 500;
  283. color: #FEFEFE;
  284. text-align: center;
  285. line-height: 110rpx;
  286. float: right;
  287. }
  288. </style>