time-select.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <view>
  3. <view class="popup-wrapper popup-wrapper-special">
  4. <!-- 标题 -->
  5. <view class="popup-title popup-title-special popup-title-new">
  6. <view>请选择服务开始时间</view>
  7. <view v-if="selectTimeValue >= 17" class="fee-tips">您选的时间段可能会加收夜间服务费,具体以与商家的沟通为准</view>
  8. <!-- 选择服务者上门时段(具体服务时长以实际服务为准) -->
  9. </view>
  10. <block>
  11. <view class="popup-content popup-content-special">
  12. <view class="time-select-top" style="display: flex;">
  13. <scroll-view class="scroll-view_H" scroll-x="true" scroll-left="0">
  14. <view class="time-select-left-item" @tap="dateCheck" :data-index="index"
  15. :data-week="item.week" :data-date="item.date" :data-isbook="item.isBook"
  16. v-for="(item, index) in dateList" :key="index" style="display: inline-block;">
  17. <view class="date-line-wrapper">
  18. <view :class="[
  19. 'date-msg',
  20. dateIndex == index ? 'current-date' : '',
  21. item.dateMsg == '不可约' ? 'avail-date' : ''
  22. ]">
  23. {{item.weekOfDay}}
  24. </view>
  25. <view :class="[
  26. 'date-msg1',
  27. dateIndex == index ? 'current-date' : '',
  28. item.dateMsg == '不可约' ? 'avail-date' : ''
  29. ]"> {{ item.bookdate | formatDate }}</view>
  30. <view :class="[
  31. dateIndex == index ? 'current-line' : '',
  32. item.dateMsg == '不可约' ? 'current-line0' : ''
  33. ]"></view>
  34. </view>
  35. </view>
  36. </scroll-view>
  37. </view>
  38. <view class="time-select-middle">
  39. <view class="noon-select">
  40. <view :class="'noon-item' + (noonType == '1' ? 'active-noon' : '')" data-noon="1"
  41. @tap="noonTab">上午</view>
  42. <view class="divider"></view>
  43. <view :class="'noon-item' + (noonType == '2' ? 'active-noon' : '')" data-noon="2"
  44. @tap="noonTab">下午</view>
  45. </view>
  46. <view class="time-item-wrapper">
  47. <view @tap="timeCheck" :data-stock="item.stock" :data-index="index" :data-msg="item.timeMsg" :data-toastmsg="item.toastMsg"
  48. :class="[
  49. 'time-msg',
  50. timeIndex == index ? 'current-time' : '',
  51. item.timeMsg == '不可约' ? 'avail-time' : ''
  52. ]" v-for="(item, index) in timeList" :key="index">
  53. <view :class="timeIndex === index ? 'current-time' : ''">{{ item.begin }}</view>
  54. </view>
  55. </view>
  56. <view class="appointment-tips" >
  57. <view> <span></span>
  58. <text>可预约</text>
  59. </view>
  60. <view> <span class="selected"></span>
  61. <text>已选择</text>
  62. </view>
  63. <view> <span class="no-appointment"></span>
  64. <text>不可约</text>
  65. </view>
  66. </view>
  67. <view class="time-select-bottom" v-if="date!==''&week!==''&time!==''">
  68. <span>当前选择:</span>{{date}}({{week}}){{time}}
  69. </view>
  70. </view>
  71. </view>
  72. </block>
  73. <!-- 确认按钮 -->
  74. <view class="popup-btn-wrapper">
  75. <view @tap="confirmTime" class="confirm-btn" style="border-radius: 16rpx;">确定</view>
  76. </view>
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. var util = require('@/utils/util.js');
  82. var api = require('@/config/api.js');
  83. var check = require('@/utils/check.js');
  84. export default {
  85. name: "time-select",
  86. props: {
  87. timeParams: Object
  88. },
  89. created() {
  90. console.log("传过来的参数", this.timeParams);
  91. this.getDayTime(this.timeParams)
  92. },
  93. filters: {
  94. formatDate: function(value, format) {
  95. // 这里可以根据format来格式化日期
  96. if (value) {
  97. return value.substring(0, 10).split('-').slice(1).join('-');
  98. }
  99. }
  100. },
  101. data() {
  102. return {
  103. noonType: 1,
  104. selectTimeValue: '',
  105. timeList: [],
  106. dateList: [],
  107. timeIndex: '',
  108. //选中的时间段
  109. dateIndex: 0,
  110. //选中的日期
  111. appointDate: '',
  112. futureDays: '',
  113. time: '',
  114. week: '',
  115. date: ''
  116. };
  117. },
  118. methods: {
  119. getDayTime(params) {
  120. uni.showLoading({
  121. title: '加载中'
  122. });
  123. util.request(api.everyDayTime, params, 'GET')
  124. .then((res) => {
  125. uni.hideLoading();
  126. if (res.errno == 0) {
  127. console.log("时间", res.data);
  128. this.setData({
  129. dateList: res.data,
  130. dateIndex: 0,
  131. timeIndex: -1,
  132. noonType: 1
  133. });
  134. let period = res.data[0].period;
  135. let list = period.filter((item) => {
  136. return item.ofTime == '上午';
  137. });
  138. this.setData({
  139. timeList: list
  140. });
  141. } else {
  142. uni.showToast({
  143. title: res.errmsg,
  144. icon: 'none',
  145. duration: 2000
  146. });
  147. this.setData({
  148. timeList: [],
  149. timeIndex: ''
  150. });
  151. }
  152. })
  153. .catch((err) => {
  154. console.log(err);
  155. uni.hideLoading();
  156. uni.showToast({
  157. title: err.errMsg,
  158. icon: 'none'
  159. });
  160. this.setData({
  161. timeList: [],
  162. timeIndex: ''
  163. });
  164. });
  165. },
  166. noonTab(e) {
  167. let noon = e.currentTarget.dataset.noon;
  168. console.log("noon", noon);
  169. this.setData({
  170. timeIndex: -1,
  171. noonType: noon,
  172. selectTimeValue: ''
  173. });
  174. console.log("noon1", noon);
  175. let period = this.dateList[this.dateIndex].period;
  176. let current = this.noonType == 1 ? '上午' : '下午';
  177. let list = period.filter((item) => {
  178. return item.ofTime == current;
  179. });
  180. this.setData({
  181. timeList: list
  182. });
  183. },
  184. dateCheck(e) {
  185. let index = e.currentTarget.dataset.index;
  186. let date = e.currentTarget.dataset.date;
  187. let week = e.currentTarget.dataset.week;
  188. let isbook = e.currentTarget.dataset.isbook;
  189. this.setData({
  190. dateIndex: index
  191. });
  192. let period = this.dateList[this.dateIndex].period;
  193. let current = this.noonType == 1 ? '上午' : '下午';
  194. let list = period.filter((item) => {
  195. return item.ofTime == current;
  196. });
  197. let bookdate = this.dateList[this.dateIndex].bookdate
  198. let weekOfDay = this.dateList[this.dateIndex].weekOfDay
  199. this.setData({
  200. timeList: list,
  201. date: bookdate,
  202. week: weekOfDay
  203. });
  204. let isNoTime = list.every((item) => {
  205. return item.timeMsg && item.timeMsg != null;
  206. });
  207. if (isNoTime) {
  208. this.setData({
  209. timeIndex: -1,
  210. selectTimeValue: ''
  211. });
  212. }
  213. },
  214. timeCheck(e) {
  215. console.log( e.currentTarget);
  216. let index = e.currentTarget.dataset.index;
  217. let msg = e.currentTarget.dataset.msg;
  218. let toastMsg= e.currentTarget.dataset.toastmsg;
  219. if (msg == null || msg == '') {
  220. let time = this.timeList[index].begin.split(':')[0];
  221. let bookTime = this.timeList[index].begin + '-' + this.timeList[index].end
  222. this.setData({
  223. timeIndex: index,
  224. selectTimeValue: Number(time),
  225. time: bookTime
  226. });
  227. }else{
  228. uni.showToast({
  229. title:toastMsg,
  230. icon:'none'
  231. })
  232. }
  233. },
  234. confirmTime() {
  235. if (this.timeIndex === '' || this.timeIndex < 0) {
  236. util.showErrorToast('请选择服务时间');
  237. return false;
  238. }
  239. let date = this.dateList[this.dateIndex].bookdate;
  240. let week = this.dateList[this.dateIndex].weekOfDay;
  241. let time = this.timeList[this.timeIndex].begin + '-' + this.timeList[this.timeIndex].end;
  242. let futureDays = (((new Date(date)).getTime() - (new Date()).getTime()) / (1000 * 24 * 3600));
  243. futureDays = Math.ceil(futureDays);
  244. this.setData({
  245. choosePopup: false,
  246. appointDate: date + ' ' + week + ' ' + time,
  247. futureDays: futureDays,
  248. });
  249. util.addLog(1, 6, 19, {
  250. orderId: this.orderId
  251. });
  252. this.$emit('timeShow', {
  253. appointDate: this.appointDate,
  254. futureDays: this.futureDays,
  255. Time: {
  256. date,
  257. week,
  258. time
  259. }
  260. });
  261. },
  262. },
  263. }
  264. </script>
  265. <style>
  266. .popup-wrapper view {
  267. color: #888;
  268. font-size: 30rpx;
  269. }
  270. .popup-content {
  271. flex: 1;
  272. }
  273. .appointment-tips {
  274. display: flex;
  275. justify-content: space-between;
  276. width: 178px;
  277. /* margin: 170px auto 10px; */
  278. position: absolute;
  279. bottom: 40px;
  280. left: calc(50% - 89px);
  281. }
  282. .appointment-tips view span {
  283. width: 20rpx;
  284. height: 20rpx;
  285. border-radius: 20rpx;
  286. background-color: #EDF8FD;
  287. display: inline-block;
  288. margin-right: 10rpx;
  289. }
  290. .appointment-tips view .selected {
  291. background-color: #00B4FE;
  292. }
  293. .appointment-tips view .no-appointment {
  294. background-color: #ccc;
  295. }
  296. .appointment-tips view text {
  297. color: #00B4FE;
  298. font-size: 24rpx;
  299. }
  300. .time-select-bottom {
  301. width: 100vw;
  302. background-color: #EDF8FD;
  303. height: 54rpx;
  304. font-size: 22rpx !important;
  305. color: #00b4fe !important;
  306. line-height: 54rpx;
  307. padding-left: 30rpx;
  308. position: absolute;
  309. bottom: 0;
  310. }
  311. .time-select-left {
  312. /* flex: 2; */
  313. border-right: 1rpx solid #ddd;
  314. padding: 0 8rpx 0 20rpx;
  315. width: 370rpx;
  316. }
  317. .time-select-right {
  318. flex: 1;
  319. /* padding: 0 8rpx; */
  320. height: 900rpx;
  321. overflow-y: hidden;
  322. }
  323. .scroll-view_H {
  324. white-space: nowrap;
  325. /* 确保子元素在同一行内显示 */
  326. overflow-x: scroll;
  327. /* 允许横向滚动 */
  328. }
  329. .time-select-left-item {
  330. height: 108rpx;
  331. display: flex;
  332. flex-direction: column;
  333. padding: 4rpx 0;
  334. width: 20vw;
  335. }
  336. .date-line-wrapper {
  337. display: flex;
  338. flex-direction: column;
  339. align-items: center;
  340. }
  341. .time-select-left-item .date-msg {
  342. height: 36rpx;
  343. line-height: 36rpx;
  344. color: #292929;
  345. font-size: 36rpx;
  346. font-weight: bold;
  347. }
  348. .time-select-left-item .date-msg1 {
  349. height: 36rpx;
  350. line-height: 36rpx;
  351. color: #292929;
  352. font-size: 22rpx;
  353. margin-top: 10rpx;
  354. }
  355. .time-select-left-item .date-msg.avail-date {
  356. color: #999 !important;
  357. font-weight: bold;
  358. }
  359. .time-select-left-item .date-msg1.avail-date {
  360. color: #999 !important;
  361. font-weight: bold;
  362. }
  363. .popup-wrapper .popup-content .current-date {
  364. color: #09afff;
  365. font-weight: bold;
  366. }
  367. .current-time {
  368. color: #fff !important;
  369. font-size: 36rpx;
  370. font-family: AlibabaPuHuiTi_2_65_Medium;
  371. }
  372. view.popup-btn-wrapper {
  373. margin: 20rpx 0 0;
  374. padding: 0 24rpx 20rpx;
  375. }
  376. view.popup-btn-wrapper button>view {
  377. color: #fff;
  378. }
  379. .time-select-middle {
  380. background-color: #FCFCFC;
  381. padding: 10rpx 0rpx;
  382. height: 700rpx;
  383. position: relative;
  384. }
  385. .noon-select {
  386. width: 100%;
  387. display: flex;
  388. justify-content: center;
  389. margin: 30rpx auto;
  390. }
  391. .noon-select .divider {
  392. height: 40rpx;
  393. width: 2rpx;
  394. background-color: #e5e5e5;
  395. }
  396. .noon-select .noon-item {
  397. text-align: center;
  398. color: #979797;
  399. font-size: 36rpx;
  400. width: 49%;
  401. }
  402. .noon-itemactive-noon {
  403. text-align: center;
  404. color: #09afff !important;
  405. font-size: 36rpx !important;
  406. width: 49%;
  407. }
  408. .popup-title-new.popup-title {
  409. display: flex;
  410. flex-direction: column;
  411. font-size: 20px;
  412. font-weight: bold;
  413. text-align: left;
  414. padding-top: 40rpx;
  415. /* line-height: normal; */
  416. }
  417. .popup-title-new view {
  418. color: #000;
  419. font-size: 40rpx;
  420. font-weight: bold;
  421. }
  422. .popup-title-new view.fee-tips {
  423. color: #ff5735;
  424. font-size: 22rpx;
  425. }
  426. .current-line {
  427. width: 38rpx;
  428. height: 6rpx;
  429. background: #09AFFF;
  430. border-radius: 3rpx;
  431. margin: auto;
  432. opacity: 1;
  433. }
  434. .current-line0 {
  435. opacity: 0;
  436. }
  437. .current-time {
  438. color: #fff !important;
  439. font-family: AlibabaPuHuiTi_2_65_Medium;
  440. line-height: 70rpx;
  441. height: 70rpx;
  442. background-color: #00B4FE;
  443. border-radius: 8px;
  444. font-size: 36rpx;
  445. }
  446. .time-item-wrapper {
  447. display: flex;
  448. width: 90vw;
  449. justify-content: flex-start;
  450. flex-wrap: wrap;
  451. text-align: center;
  452. gap: 20px;
  453. margin: 10px auto;
  454. }
  455. .time-item-wrapper .time-msg {
  456. width: 20%;
  457. line-height: 70rpx;
  458. height: 70rpx;
  459. background-color: #EDF8FD;
  460. border-radius: 8px;
  461. font-size: 36rpx;
  462. font-weight: bold;
  463. }
  464. .time-item-wrapper .avail-time {
  465. width: 20%;
  466. line-height: 70rpx;
  467. height: 70rpx;
  468. background-color: #CCCCCC;
  469. border-radius: 8px;
  470. font-size: 36rpx;
  471. font-weight: bold;
  472. }
  473. </style>