selectTime.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view>
  3. <lxCalendar @change="changeTime" :dot_lists="list" :value="dateValue"></lxCalendar>
  4. <view class="hours-box">
  5. <view class="hours-title">可选时间段</view>
  6. <view class="hours-content">
  7. <view v-for="(hour,index) in hourList" :key="index"
  8. :class="hourListSelceted[index] ? 'selected' : 'default'"
  9. v-show="hour.enable" @click="selectHour(index,hour.hour)">{{hour.show}}</button>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="share-box">
  14. <view class="button">
  15. <button @click="goSubmit()" class="start" >
  16. 提交资料
  17. </button>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import md5 from "@/common/md5.js";
  24. import lxCalendar from '@/components/lx-calendar/lx-calendar.vue'
  25. export default {
  26. components:{
  27. lxCalendar,
  28. },
  29. data() {
  30. return {
  31. fieldList: [],
  32. shareUrl:getApp().globalData.shareUrl,
  33. areaId:'',
  34. list: [],
  35. dateValue:'',
  36. hourList:[],
  37. hourListSelceted:[],
  38. selectDate:getApp().globalData.nowTime,
  39. selectedHour:[],
  40. };
  41. },
  42. onLoad(option) {
  43. this.areaId = option.id || '4'
  44. this.getDaysTime(option.id);
  45. },
  46. methods: {
  47. changeTime(e){
  48. this.selectDate = e.fulldate;
  49. this.getHoursTime(this.areaId,this.selectDate)
  50. },
  51. selectHour(index,param){
  52. this.hourListSelceted.splice(index,1,!this.hourListSelceted[index])
  53. },
  54. goSubmit(){
  55. if(!this.hourListSelceted.includes(true)) {
  56. uni.showToast({
  57. title:'请选择时间段',
  58. icon:'none'
  59. })
  60. }else {
  61. let filterArr = []
  62. this.hourListSelceted.forEach((item,index)=>{
  63. if(item){
  64. filterArr.push(this.hourList[index].hour)
  65. }
  66. })
  67. filterArr.join(',')
  68. uni.navigateTo({
  69. url: "/pages/makeField/fieldForm?id=" + this.areaId +'&day=' + this.selectDate +'&hour=' + filterArr,
  70. });
  71. }
  72. },
  73. getDaysTime(id) {
  74. let md5Sign = md5(
  75. "method=" +
  76. "area" +
  77. "&timestamp=" +
  78. getApp().globalData.globalTimestamp +
  79. "&secret=" +
  80. getApp().globalData.secret
  81. );
  82. let url =
  83. getApp().globalData.shareUrl +
  84. "api/api.php" +
  85. "?method=area&source=area&action=get_days&timestamp=" +
  86. getApp().globalData.globalTimestamp +
  87. "&sign=" +
  88. md5Sign;
  89. uni.request({
  90. url: url,
  91. method: "POST",
  92. header: {
  93. "content-type": "application/x-www-form-urlencoded",
  94. },
  95. data: {
  96. area_id :id,
  97. days:'30'
  98. },
  99. success: (res) => {
  100. if (res.data.code === 200) {
  101. let dayList = res.data.data;
  102. if(dayList.length){
  103. this.dateValue = dayList[0]
  104. }
  105. this.list = dayList;
  106. this.getHoursTime(id,this.selectDate)
  107. }
  108. },
  109. fail: () => {
  110. console.log("连接失败");
  111. },
  112. });
  113. },
  114. getHoursTime(id,time) {
  115. let md5Sign = md5(
  116. "method=" +
  117. "area" +
  118. "&timestamp=" +
  119. getApp().globalData.globalTimestamp +
  120. "&secret=" +
  121. getApp().globalData.secret
  122. );
  123. let url =
  124. getApp().globalData.shareUrl +
  125. "api/api.php" +
  126. "?method=area&source=area&action=get_hours&timestamp=" +
  127. getApp().globalData.globalTimestamp +
  128. "&sign=" +
  129. md5Sign;
  130. uni.request({
  131. url: url,
  132. method: "POST",
  133. header: {
  134. "content-type": "application/x-www-form-urlencoded",
  135. },
  136. data: {
  137. area_id :id,
  138. date :time,
  139. //order_id : 2 //如果是自己修改自己的预定,传入预定ID,否则可不传
  140. },
  141. success: (res) => {
  142. if (res.data.code === 200) {
  143. let hourArr = res.data.data;
  144. let hourCss = [];
  145. hourArr.forEach((item,index)=>{
  146. hourCss.push(false)
  147. })
  148. this.hourListSelceted = hourCss;
  149. this.hourList = res.data.data
  150. }
  151. },
  152. fail: () => {
  153. console.log("连接失败");
  154. },
  155. });
  156. },
  157. },
  158. };
  159. </script>
  160. <style lang="scss" scope>
  161. .calendar-box {
  162. display: flex;
  163. justify-content: center;
  164. }
  165. .hours-box {
  166. margin-top: 30rpx;
  167. min-height: 500rpx;
  168. overflow-x: scroll;
  169. .hours-title {
  170. padding-left: 20rpx;
  171. font-weight: 600;
  172. font-size: 26rpx;
  173. }
  174. .hours-content {
  175. display: flex;
  176. flex-wrap: wrap;
  177. justify-content: space-around;
  178. align-items: center;
  179. margin-top: 20rpx;
  180. view {
  181. width: 45%;
  182. height: 80rpx;
  183. background: #f4f4f4;
  184. text-align: center;
  185. line-height: 80rpx;
  186. margin-bottom: 20rpx;
  187. border-radius: 10rpx;
  188. font-size: 24rpx;
  189. }
  190. }
  191. .selected {
  192. background: #5398ff!important;
  193. color:#fff;
  194. }
  195. .default{
  196. background: #f4f4f4!important;
  197. color:#000
  198. }
  199. }
  200. .share-box {
  201. box-sizing: border-box;
  202. height: 150rpx;
  203. width: 100%;
  204. align-items: center;
  205. justify-content: space-evenly;
  206. position: fixed;
  207. bottom: 0;
  208. display: flex;
  209. background: #ffffff;
  210. .share {
  211. display: flex;
  212. justify-content: center;
  213. align-items: center;
  214. width: 60rpx;
  215. height: 60rpx;
  216. position: relative;
  217. button::after {
  218. border: none;
  219. }
  220. image {
  221. width: 100%;
  222. height: 100%;
  223. position: absolute;
  224. }
  225. .shareCount {
  226. display: flex;
  227. justify-content: center;
  228. align-items: center;
  229. position: absolute;
  230. top: -20%;
  231. right: -25%;
  232. color: #ffffff;
  233. height: 30rpx;
  234. width: 30rpx;
  235. padding: 3rpx;
  236. font-size: 16rpx;
  237. border-radius: 50%;
  238. background: #fe3637;
  239. }
  240. }
  241. .button {
  242. height: 100rpx;
  243. width: 75%;
  244. display: flex;
  245. justify-content: center;
  246. button {
  247. width: 80%;
  248. height: 80%;
  249. border: 1px solid;
  250. outline: none;
  251. background: none;
  252. font-size: 30rpx;
  253. background-color: transparent;
  254. border-color: none;
  255. color: #00a8ea;
  256. }
  257. }
  258. }
  259. </style>