index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <u-popup v-model="showPopup" :closeable="false" mode="bottom" border-radius="32" @close="close">
  3. <view class="main">
  4. <view class="cur-date">{{ curMonth }}</view>
  5. <img @tap="close" src="https://qiniu.bms16.com/FhBojI0tUP3dp9gZQ9lNSUNtn8B7" class="close-icon">
  6. <view
  7. class="calendar-wrap"
  8. @touchstart="handleTouchStart"
  9. @touchmove="handleTouchMove"
  10. @touchend="handleTouchEnd"
  11. >
  12. <SecondaryCalendar
  13. ref="uniCalendar"
  14. :style="{ backgroundColor: '#ccc' }"
  15. :show="show"
  16. :date="defaultDate"
  17. :show-month="false"
  18. :toText="$t('取车')"
  19. :show-header="false"
  20. mode="date"
  21. @change="onChange"
  22. />
  23. <view class="director" @tap="nextMonth">
  24. <view :class="['dot_1', extractMonth(curMonth) % 2 !== 0 && 'opc']"/>
  25. <view :class="['dot_2', extractMonth(curMonth) % 2 === 0 && 'opc']"/>
  26. </view>
  27. </view>
  28. <view class="time-wrap">
  29. <view class="picker-text">{{ $t('取车时间') }}</view>
  30. <view class="flex-row flex-between">
  31. <picker-view
  32. :value="[startH,startM]"
  33. style="height: 200rpx; width: 100%;"
  34. @change="pickerChange"
  35. >
  36. <picker-view-column>
  37. <view v-for="(item, index) in hours" :key="index" class="item-picker">
  38. {{ item }}
  39. <text class="unit">{{ $t('时小') }}</text>
  40. </view>
  41. </picker-view-column>
  42. <picker-view-column>
  43. <view v-for="(item, index) in minutes" :key="index" class="item-picker">
  44. {{ item }}
  45. <text class="unit">{{ $t('分') }}</text>
  46. </view>
  47. </picker-view-column>
  48. </picker-view>
  49. </view>
  50. </view>
  51. <view class="bottom-row">
  52. <view class="text">{{ $t('取车小')+':'+startDay }}</view>
  53. <button :loading="isPaickerLoading" class="custom-button" @tap="navToHireCar" >{{ $t('确定') }}</button>
  54. </view>
  55. </view>
  56. </u-popup>
  57. </template>
  58. <script module="tools" lang="wxs" src="@/pages/common/wxs/tools.wxs"></script>
  59. <script module="tools" lang="sjs" src="@/pages/common/wxs/tools.sjs"></script>
  60. <script>
  61. import SecondaryCalendar from './components/uni-calendar'
  62. var common = require('../../common/common.js');
  63. export default {
  64. props: {
  65. showPopup: {
  66. type: Boolean,
  67. default: false
  68. },
  69. },
  70. components: { SecondaryCalendar },
  71. data() {
  72. let _hours=[]
  73. let _minutes=[]
  74. for (let i = 0; i < 24; i++) {
  75. if (i < 10) {
  76. _hours.push('0' + i);
  77. } else {
  78. _hours.push(i);
  79. }
  80. }
  81. for (let i = 0; i < 60; i++) {
  82. if (i < 10) {
  83. _minutes.push('0' + i);
  84. } else {
  85. _minutes.push(i);
  86. }
  87. }
  88. let _isNextDay=(new Date().getMinutes()-0)>30&&((new Date().getHours()-0+1)==0)
  89. let _startH=(new Date().getMinutes()-0)>30?(new Date().getHours()-0+1):(new Date().getHours()-0)
  90. let _startM=(new Date().getMinutes()-0)>30?(new Date().getMinutes()-30):(new Date().getMinutes()-0+30)
  91. return {
  92. defaultDate: null,
  93. show: true,
  94. month: '',
  95. date: '',
  96. startT: 0,
  97. timeValue: [0,0],
  98. startDate: '', // 取车日期
  99. endDate: '', // 还车日期
  100. duration_unit: 0, //周期单位
  101. startH: (new Date().getMinutes()-0)>30?(new Date().getHours()-0+1):(new Date().getHours()-0),
  102. startM: _startM,
  103. startN: 0,
  104. hours: _hours,
  105. minutes: _minutes,
  106. number: [],
  107. startDay: '',
  108. endDay: '',
  109. time: '',
  110. isNextDay:_isNextDay,
  111. isPaickerLoading:false,
  112. startX: '',
  113. startY: '',
  114. moveX: '',
  115. moveY: '',
  116. touchStartTime: 0,
  117. touchEndTime: 0,
  118. curMonth: '',
  119. isClick: true
  120. };
  121. },
  122. mounted() {
  123. this.time = this.isNextDay?common.getToDay(1):common.getToDay()
  124. //#ifdef MP-ALIPAY
  125. let _startH = this.startH< 10&&this.startH!== '00' ? '0' + this.startH : this.startH
  126. const _startM = this.startM< 10&&this.startM!== '00' ? '0' + this.startM : this.startM
  127. //#endif
  128. //#ifdef MP-WEIXIN
  129. let _startH = this.startH< 10&&this.startH!== '00' ? '0' + this.startH : this.startH
  130. const _startM = this.startM< 10&&this.startM!== '00' ? '0' + this.startM : this.startM
  131. //#endif
  132. // #ifdef APP
  133. let _startH = this.startH< 10&&this.startH!== '00' ? '0' + this.startH : this.startH
  134. const _startM = this.startM< 10&&this.startM!== '00' ? '0' + this.startM : this.startM
  135. // #endif
  136. this.startDate = this.time+'T'+_startH+':'+_startM
  137. const DATE = new Date()
  138. this.curMonth = `${DATE.getFullYear()}`+'-'+`${DATE.getMonth()+1}`
  139. this.startDay = common.formatDate(this.time)+' '+_startH+':'+_startM
  140. this.endDate = common.loadAugmentTime(this.duration_unit,this.startDate,this.startN+1)
  141. this.endDay = common.formatTimeDate(this.endDate)
  142. },
  143. /**
  144. * 生命周期函数--监听页面加载
  145. */
  146. onLoad: function(options) {
  147. },
  148. /**
  149. * 生命周期函数--监听页面显示
  150. */
  151. onShow: function() {
  152. },
  153. methods: {
  154. setTakeCarData(result) {
  155. const [date, time] = result.takeCar.split(' ');
  156. const [hour, minute] = time.split(':');
  157. const [year, month] = result.dateText.split('-');
  158. this.startH = +hour;
  159. this.startM = +minute;
  160. this.curMonth = `${year}`+'-'+`${month}`;
  161. this.startDay = result.takeCar;
  162. this.defaultDate = result.dateText;
  163. },
  164. extractMonth(str) {
  165. const match = str.match(/(\d+)月/);
  166. return match ? parseInt(match[1], 10) : null;
  167. },
  168. handleTouchStart(e) {
  169. this.startX = e.touches[0].clientX;
  170. this.startY = e.touches[0].clientY;
  171. this.touchStartTime = Date.now()
  172. this.isClick = true
  173. },
  174. handleTouchMove(e) {
  175. this.moveX = e.touches[0].clientX;
  176. this.moveY = e.touches[0].clientY;
  177. this.isClick = false // 如果有移动,则判定为非点击
  178. },
  179. handleTouchEnd() {
  180. if (this.isClick) return
  181. this.touchEndTime = Date.now();
  182. const diffX = this.moveX - this.startX;
  183. const diffY = this.moveY - this.startY;
  184. const touchDuration = this.touchEndTime - this.touchStartTime
  185. // 判断是否为滑动手势
  186. if (Math.abs(diffX) > 50 && Math.abs(diffY) < 20 && touchDuration < 500) {
  187. if (diffX > 0) {
  188. console.log('向左滑动', this.$refs.uniCalendar);
  189. this.$refs.uniCalendar && this.$refs.uniCalendar.pre()
  190. } else {
  191. console.log('向右滑动');
  192. this.$refs.uniCalendar && this.$refs.uniCalendar.next()
  193. }
  194. const { nowDate } = this.$refs.uniCalendar
  195. this.curMonth = `${nowDate.year}`+'-'+`${nowDate.month}`
  196. }
  197. },
  198. nextMonth() {
  199. this.$refs.uniCalendar && this.$refs.uniCalendar.next()
  200. const { nowDate } = this.$refs.uniCalendar
  201. this.curMonth = `${nowDate.year}`+'-'+`${nowDate.month}`
  202. },
  203. onChange(e) {
  204. this.time = e.fulldate
  205. //#ifdef MP-ALIPAY
  206. const _startH = this.startH< 10&&this.startH!== '00' ? '0' + this.startH : this.startH
  207. const _startM = this.startM< 10&&this.startM!== '00' ? '0' + this.startM : this.startM
  208. //#endif
  209. //#ifdef MP-WEIXIN
  210. const _startH = this.startH< 10&&this.startH!== '00' ? '0' + this.startH : this.startH
  211. const _startM = this.startM< 10&&this.startM!== '00' ? '0' + this.startM : this.startM
  212. //#endif
  213. this.startDate = this.time+'T'+_startH+':'+_startM
  214. this.startDay = common.formatDate(this.time)+' '+_startH+':'+_startM
  215. this.endDate = common.loadAugmentTime(this.duration_unit,this.startDate,this.startN+1)
  216. this.endDay = common.formatTimeDate(this.endDate)
  217. },
  218. pickerChange(e) {
  219. //#ifdef MP-ALIPAY
  220. const val = e.detail.value;
  221. if (val[0] != this.timeValue[0]) {
  222. this.startH = val[0]
  223. this.timeValue[0] = val[0];
  224. }
  225. if (val[1] != this.timeValue[1]) {
  226. this.startM = val[1]
  227. this.timeValue[1] = val[1];
  228. }
  229. //#endif
  230. const val = e.detail.value;
  231. this.startH = val[0]
  232. this.startM = val[1]
  233. this.loadTime()
  234. },
  235. loadTime() {
  236. //#ifdef MP-ALIPAY
  237. const _startH = this.startH< 10&&this.startH!== '00' ? ('0' + this.startH ): this.startH
  238. const _startM = this.startM< 10&&this.startM!== '00' ? ('0' + this.startM) : this.startM
  239. //#endif
  240. const _startH = this.startH< 10&&this.startH!== '00' ? ('0' + this.startH) : this.startH
  241. const _startM = this.startM< 10&&this.startM!== '00' ? ('0' + this.startM) : this.startM
  242. this.startDate =_startH==0?(this.time+'T0'+_startH+':'+_startM):( this.time+'T'+_startH+':'+_startM)
  243. this.startDay = common.formatDate(this.time)+' '+_startH+':'+_startM
  244. this.endDate = common.loadAugmentTime(this.duration_unit,this.startDate,this.startN+1)
  245. this.endDay = common.formatTimeDate(this.endDate)
  246. },
  247. navToHireCar() {
  248. if(this.isPaickerLoading) return
  249. const value = {
  250. takeCar: this.startDay,
  251. returnCar: this.endDay,
  252. leaseTime: this.startN + 1,
  253. startDate: this.startDate,
  254. date: this.time
  255. }
  256. this.$emit('valuesUpdated', value);
  257. },
  258. close() {
  259. this.$emit('close', false)
  260. }
  261. }
  262. };
  263. </script>
  264. <style>
  265. @import './index.css';
  266. </style>