time-select.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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" >确定</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. onShow() {
  94. },
  95. filters: {
  96. formatDate: function(value, format) {
  97. // 这里可以根据format来格式化日期
  98. if (value) {
  99. return value.substring(0, 10).split('-').slice(1).join('-');
  100. }
  101. }
  102. },
  103. data() {
  104. return {
  105. noonType: 1,
  106. selectTimeValue: '',
  107. timeList: [],
  108. dateList: [],
  109. timeIndex: '',
  110. //选中的时间段
  111. dateIndex: 0,
  112. //选中的日期
  113. appointDate: '',
  114. futureDays: '',
  115. time: '',
  116. week: '',
  117. date: ''
  118. };
  119. },
  120. methods: {
  121. getDayTime(params) {
  122. uni.showLoading({
  123. title: '加载中'
  124. });
  125. util.request(api.everyDayTime, params, 'GET')
  126. .then((res) => {
  127. uni.hideLoading();
  128. if (res.errno == 0) {
  129. console.log("时间", res.data);
  130. this.setData({
  131. dateList: res.data,
  132. dateIndex: 0,
  133. timeIndex: -1,
  134. noonType: 1
  135. });
  136. let period = res.data[0].period;
  137. let list = period.filter((item) => {
  138. return item.ofTime == '上午';
  139. });
  140. this.setData({
  141. timeList: list
  142. });
  143. } else {
  144. uni.showToast({
  145. title: res.errmsg,
  146. icon: 'none',
  147. duration: 2000
  148. });
  149. this.setData({
  150. timeList: [],
  151. timeIndex: ''
  152. });
  153. }
  154. })
  155. .catch((err) => {
  156. console.log(err);
  157. uni.hideLoading();
  158. uni.showToast({
  159. title: err.errMsg,
  160. icon: 'none'
  161. });
  162. this.setData({
  163. timeList: [],
  164. timeIndex: ''
  165. });
  166. });
  167. },
  168. noonTab(e) {
  169. let noon = e.currentTarget.dataset.noon;
  170. console.log("noon", noon);
  171. this.setData({
  172. timeIndex: -1,
  173. noonType: noon,
  174. selectTimeValue: ''
  175. });
  176. console.log("noon1", noon);
  177. let period = this.dateList[this.dateIndex].period;
  178. let current = this.noonType == 1 ? '上午' : '下午';
  179. let list = period.filter((item) => {
  180. return item.ofTime == current;
  181. });
  182. this.setData({
  183. timeList: list
  184. });
  185. },
  186. dateCheck(e) {
  187. let index = e.currentTarget.dataset.index;
  188. let date = e.currentTarget.dataset.date;
  189. let week = e.currentTarget.dataset.week;
  190. let isbook = e.currentTarget.dataset.isbook;
  191. this.setData({
  192. dateIndex: index
  193. });
  194. let period = this.dateList[this.dateIndex].period;
  195. let current = this.noonType == 1 ? '上午' : '下午';
  196. let list = period.filter((item) => {
  197. return item.ofTime == current;
  198. });
  199. let bookdate = this.dateList[this.dateIndex].bookdate
  200. let weekOfDay = this.dateList[this.dateIndex].weekOfDay
  201. this.setData({
  202. timeList: list,
  203. date: bookdate,
  204. week: weekOfDay
  205. });
  206. let isNoTime = list.every((item) => {
  207. return item.timeMsg && item.timeMsg != null;
  208. });
  209. if (isNoTime) {
  210. this.setData({
  211. timeIndex: -1,
  212. selectTimeValue: ''
  213. });
  214. }
  215. },
  216. timeCheck(e) {
  217. console.log( e.currentTarget);
  218. let index = e.currentTarget.dataset.index;
  219. let msg = e.currentTarget.dataset.msg;
  220. let toastMsg= e.currentTarget.dataset.toastmsg;
  221. if (msg == null || msg == '') {
  222. let time = this.timeList[index].begin.split(':')[0];
  223. let bookTime = this.timeList[index].begin + '-' + this.timeList[index].end
  224. this.setData({
  225. timeIndex: index,
  226. selectTimeValue: Number(time),
  227. time: bookTime
  228. });
  229. }else{
  230. uni.showToast({
  231. title:toastMsg,
  232. icon:'none'
  233. })
  234. }
  235. },
  236. confirmTime() {
  237. if (this.timeIndex === '' || this.timeIndex < 0) {
  238. util.showErrorToast('请选择服务时间');
  239. return false;
  240. }
  241. let date = this.dateList[this.dateIndex].bookdate;
  242. let week = this.dateList[this.dateIndex].weekOfDay;
  243. let time = this.timeList[this.timeIndex].begin + '-' + this.timeList[this.timeIndex].end;
  244. let futureDays = (((new Date(date)).getTime() - (new Date()).getTime()) / (1000 * 24 * 3600));
  245. futureDays = Math.ceil(futureDays);
  246. this.setData({
  247. choosePopup: false,
  248. appointDate: date + ' ' + week + ' ' + time,
  249. futureDays: futureDays,
  250. });
  251. this.$emit('timeShow', {
  252. appointDate: this.appointDate,
  253. futureDays: this.futureDays,
  254. Time: {
  255. date,
  256. week,
  257. time
  258. }
  259. });
  260. },
  261. getDayTime(params) {
  262. uni.showLoading({
  263. title: '加载中'
  264. });
  265. util.request(api.everyDayTime, params, 'GET')
  266. .then((res) => {
  267. uni.hideLoading();
  268. if (res.errno == 0) {
  269. console.log("时间", res.data);
  270. this.setData({
  271. dateList: res.data,
  272. dateIndex: 0,
  273. timeIndex: -1,
  274. noonType: 1
  275. });
  276. let period = res.data[0].period;
  277. let list = period.filter((item) => {
  278. return item.ofTime == '上午';
  279. });
  280. this.setData({
  281. timeList: list
  282. });
  283. } else {
  284. uni.showToast({
  285. title: res.errmsg,
  286. icon: 'none',
  287. duration: 2000
  288. });
  289. this.setData({
  290. timeList: [],
  291. timeIndex: ''
  292. });
  293. }
  294. })
  295. .catch((err) => {
  296. console.log(err);
  297. uni.hideLoading();
  298. uni.showToast({
  299. title: err.errMsg,
  300. icon: 'none'
  301. });
  302. this.setData({
  303. timeList: [],
  304. timeIndex: ''
  305. });
  306. });
  307. },
  308. },
  309. }
  310. </script>
  311. <style>
  312. .popup-wrapper view {
  313. color: #888;
  314. font-size: 30rpx;
  315. }
  316. .popup-content {
  317. flex: 1;
  318. }
  319. .appointment-tips {
  320. display: flex;
  321. justify-content: space-between;
  322. width: 178px;
  323. /* margin: 170px auto 10px; */
  324. position: absolute;
  325. bottom: 72rpx;
  326. left: calc(50% - 89px);
  327. }
  328. .appointment-tips view span {
  329. width: 20rpx;
  330. height: 20rpx;
  331. border-radius: 20rpx;
  332. background-color: #feebd7;
  333. display: inline-block;
  334. margin-right: 10rpx;
  335. }
  336. .appointment-tips view .selected {
  337. background-color: #d77958;
  338. }
  339. .appointment-tips view .no-appointment {
  340. background-color: #ccc;
  341. }
  342. .appointment-tips view text {
  343. color: #d77958;
  344. font-size: 24rpx;
  345. }
  346. .time-select-bottom {
  347. width: 100vw;
  348. background-color: #feebd7;
  349. height: 54rpx;
  350. font-size: 22rpx !important;
  351. /* color: #00b4fe !important; */
  352. line-height: 54rpx;
  353. padding-left: 30rpx;
  354. position: absolute;
  355. bottom: 0;
  356. }
  357. .time-select-left {
  358. /* flex: 2; */
  359. border-right: 1rpx solid #ddd;
  360. padding: 0 8rpx 0 20rpx;
  361. width: 370rpx;
  362. }
  363. .time-select-right {
  364. flex: 1;
  365. /* padding: 0 8rpx; */
  366. height: 900rpx;
  367. overflow-y: hidden;
  368. }
  369. .scroll-view_H {
  370. white-space: nowrap;
  371. /* 确保子元素在同一行内显示 */
  372. overflow-x: scroll;
  373. /* 允许横向滚动 */
  374. }
  375. .time-select-left-item {
  376. height: 108rpx;
  377. display: flex;
  378. flex-direction: column;
  379. padding: 4rpx 0;
  380. width: 20vw;
  381. }
  382. .date-line-wrapper {
  383. display: flex;
  384. flex-direction: column;
  385. align-items: center;
  386. }
  387. .time-select-left-item .date-msg {
  388. height: 36rpx;
  389. line-height: 36rpx;
  390. color: #292929;
  391. font-size: 36rpx;
  392. font-weight: bold;
  393. }
  394. .time-select-left-item .date-msg1 {
  395. height: 36rpx;
  396. line-height: 36rpx;
  397. color: #292929;
  398. font-size: 22rpx;
  399. margin-top: 10rpx;
  400. }
  401. .time-select-left-item .date-msg.avail-date {
  402. color: #999 !important;
  403. font-weight: bold;
  404. }
  405. .time-select-left-item .date-msg1.avail-date {
  406. color: #999 !important;
  407. font-weight: bold;
  408. }
  409. .popup-wrapper .popup-content .current-date {
  410. color: #d77958;
  411. font-weight: bold;
  412. }
  413. view.popup-btn-wrapper {
  414. margin: 10rpx auto;
  415. padding: 24rpx;
  416. background-color: #d77958;
  417. text-align: center;
  418. width: 682rpx;
  419. border-radius: 16rpx;
  420. }
  421. view.popup-btn-wrapper view {
  422. color: #fff;
  423. }
  424. .time-select-middle {
  425. background-color: #FCFCFC;
  426. padding: 10rpx 0rpx;
  427. height: 800rpx;
  428. position: relative;
  429. }
  430. .noon-select {
  431. width: 100%;
  432. display: flex;
  433. justify-content: center;
  434. margin: 30rpx auto;
  435. }
  436. .noon-select .divider {
  437. height: 40rpx;
  438. width: 2rpx;
  439. background-color: #e5e5e5;
  440. }
  441. .noon-select .noon-item {
  442. text-align: center;
  443. color: #979797;
  444. font-size: 36rpx;
  445. width: 49%;
  446. }
  447. .noon-itemactive-noon {
  448. text-align: center;
  449. color: #d77958!important;
  450. font-size: 36rpx !important;
  451. width: 49%;
  452. }
  453. .popup-title-new.popup-title {
  454. display: flex;
  455. flex-direction: column;
  456. font-size: 20px;
  457. font-weight: bold;
  458. text-align: left;
  459. padding: 30rpx;
  460. }
  461. .popup-title-new view {
  462. color: #000;
  463. font-size: 40rpx;
  464. font-weight: bold;
  465. }
  466. .popup-title-new view.fee-tips {
  467. color: #d77958;
  468. font-size: 22rpx;
  469. }
  470. .current-line {
  471. width: 38rpx;
  472. height: 6rpx;
  473. background: #d77958;
  474. border-radius: 3rpx;
  475. margin: auto;
  476. opacity: 1;
  477. }
  478. .current-line0 {
  479. opacity: 0;
  480. }
  481. .current-time {
  482. color: #fff !important;
  483. font-family: AlibabaPuHuiTi_2_65_Medium;
  484. line-height: 70rpx;
  485. height: 70rpx;
  486. background-color: #d77958;
  487. border-radius: 8px;
  488. font-size: 36rpx;
  489. }
  490. .time-item-wrapper {
  491. display: flex;
  492. width: 90vw;
  493. justify-content: flex-start;
  494. flex-wrap: wrap;
  495. text-align: center;
  496. gap: 20px;
  497. margin: 10px auto;
  498. }
  499. .time-item-wrapper .time-msg {
  500. width: 20%;
  501. line-height: 70rpx;
  502. height: 70rpx;
  503. background-color: #feebd7;
  504. border-radius: 8px;
  505. font-size: 36rpx;
  506. font-weight: bold;
  507. }
  508. .time-item-wrapper .avail-time {
  509. width: 20%;
  510. line-height: 70rpx;
  511. height: 70rpx;
  512. background-color: #CCCCCC;
  513. border-radius: 8px;
  514. font-size: 36rpx;
  515. font-weight: bold;
  516. }
  517. </style>