selectTime.vue 5.8 KB

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