yuyuetime.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <view class="content">
  3. <tui-tabs :top="0" :tabs="tabs" :currentTab="timestype" itemWidth="50%" @change="change"></tui-tabs>
  4. <view class="container">
  5. <view v-if="timestype==0" class="panel">
  6. <view class="panel-weeks">
  7. <button v-for="(item,index) in weeks" :key="index"
  8. :type="pickerWeeks == index ? 'primary':'default'" size="mini" :data-item="item"
  9. :data-index="index" @tap="onSelectWeeks">{{item}}</button>
  10. </view>
  11. </view>
  12. <view v-if="timestype==1" class="panel">
  13. <view class="panel-body">
  14. <button v-for="(item,index) in 29" :key="index" :type="pickerMonth == item+1 ? 'primary':'default'"
  15. size="mini" :data-item="item+1" @tap="onSelectMonth">{{item+1}}</button>
  16. </view>
  17. </view>
  18. <!-- 时间选项 -->
  19. <view class="time-box">
  20. <block v-for="(item,_index) in timeArr" :key="_index">
  21. <view class="item">
  22. <view class="item-box" :class="{'disable':item.disable,
  23. 'active':isMultiple?item.isActive:_index==timeActive}" :style="{color:isMultiple?item.isActive? selectedItemColor:'#333'
  24. :_index==timeActive?selectedItemColor:'#333'}" @click="selectTimeEvent(_index,item)">
  25. <text>{{item.seltime}}</text>
  26. <text class="all">{{item.disable?disableText:undisableText}}</text>
  27. </view>
  28. </view>
  29. </block>
  30. </view>
  31. </view>
  32. <view class="bottom">
  33. <view class="show-time">
  34. 预约时间:{{orderDateTime}}
  35. </view>
  36. <button form-type="submit" type="default" size="mini" class="submit-btn" @click="handleSubmit">
  37. 确认
  38. </button>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. props: {
  45. disableText: { //禁用显示的文本
  46. type: String,
  47. default: "已约满"
  48. },
  49. undisableText: { //未禁用显示的文本
  50. type: String,
  51. default: "可预约"
  52. },
  53. selectedItemColor: { // 时间选中的颜色
  54. type: String,
  55. default: "rgba(255, 69, 0, 1)"
  56. },
  57. },
  58. watch: {},
  59. data() {
  60. return {
  61. id: 0,
  62. timestype: 0,
  63. tabs: [{
  64. name: "按周约"
  65. }, {
  66. name: "按月约"
  67. }],
  68. pickerMonth: '',
  69. pickerWeeks: '',
  70. weeks: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
  71. isMultiple: false, //多选
  72. orderDateTime: '暂无选择', // 选中时间
  73. orderTimeArr: {}, //多选的时间
  74. timeArr: [], //时间数据
  75. nowDate: "", // 当前日期
  76. dateActive: 0, //选中的日期索引
  77. timeActive: 0, //选中的时间索引
  78. timeQuanBeginIndex: 0, //时间段开始的下标
  79. selectDate: "", //选择的日期
  80. selectTime: "", //选择的时间
  81. timeQuanBegin: "", //时间段开始时间
  82. timeQuanEnd: "", //时间段结束时间
  83. }
  84. },
  85. onLoad: function(e) {
  86. this.id = e.id;
  87. },
  88. created(props) {
  89. this.selectDate = this.nowDate;
  90. this.initOnload();
  91. },
  92. methods: {
  93. initOnload() {
  94. var _this = this;
  95. _this.$request.post('Servicetime.index', {
  96. samkey: (new Date()).valueOf()
  97. }).then(res => {
  98. if (res.errno == 0) {
  99. _this.timeArr = res.data;
  100. _this.timeQuanBegin = _this.timeQuanEnd = ""
  101. let isFullTime = true
  102. _this.timeArr.forEach((item, index) => {
  103. // 判断是否当前日期时间都被预约
  104. if (!item.disable) {
  105. isFullTime = false
  106. }
  107. })
  108. _this.orderDateTime = isFullTime ? "暂无选择" : _this.selectDate
  109. _this.timeActive = -1
  110. for (let i = 0, len = _this.timeArr.length; i < len; i++) {
  111. if (!_this.timeArr[i].disable) {
  112. _this.orderDateTime = `${_this.selectDate} ${_this.timeArr[i].seltime}`
  113. _this.timeActive = i
  114. return
  115. }
  116. }
  117. }
  118. })
  119. },
  120. change(e) {
  121. this.timestype = e.index;
  122. },
  123. onSelectWeeks(e) {
  124. this.pickerWeeks = e.currentTarget.dataset.index;
  125. },
  126. onSelectMonth(e) {
  127. this.pickerMonth = e.currentTarget.dataset.item;
  128. },
  129. // 日期选择事件
  130. selectDateEvent(index, item) {
  131. this.dateActive = index
  132. this.selectDate = item.date
  133. this.initOnload()
  134. },
  135. // 时间选择事件
  136. selectTimeEvent(index, item) {
  137. if (item.disable) {
  138. return
  139. }
  140. this.timeActive = index
  141. this.selectTime = item.seltime
  142. this.orderDateTime = `${this.selectDate} ${item.seltime}`
  143. },
  144. // 选择时间段
  145. handleSelectQuantum(index, item) {
  146. if (item.disable) {
  147. return
  148. }
  149. function clearTime() {
  150. this.timeQuanBeginIndex = index
  151. this.timeQuanBegin = item.time
  152. this.timeQuanEnd = ""
  153. }
  154. if (!this.timeQuanBegin) {
  155. clearTime.call(this)
  156. return
  157. }
  158. if (!this.timeQuanEnd && this.timeQuanBegin) {
  159. let isDisble = false
  160. let start = this.timeQuanBeginIndex
  161. let end = index
  162. start > end && ([start, end] = [end, start])
  163. for (let i = start + 1; i < end; i++) {
  164. if (this.timeArr[i].disable) {
  165. isDisble = true
  166. clearTime.call(this)
  167. return
  168. }
  169. }
  170. if (!isDisble) {
  171. for (let i = start + 1; i < end; i++) {
  172. this.timeArr[i].isInclude = true
  173. }
  174. }
  175. this.timeQuanEnd = item.time
  176. return
  177. }
  178. if (this.timeQuanBegin && this.timeQuanEnd) {
  179. this.timeArr.forEach(t => {
  180. t.isInclude = false
  181. })
  182. clearTime.call(this)
  183. }
  184. },
  185. handleChange() {
  186. this.timeQuanBegin > this.timeQuanEnd && ([this.timeQuanBegin, this.timeQuanEnd] = [this.timeQuanEnd, this
  187. .timeQuanBegin
  188. ])
  189. },
  190. handleSubmit() {
  191. var _this = this;
  192. var yue_date;
  193. if (_this.timestype == 1) {
  194. yue_date = _this.pickerMonth;
  195. } else {
  196. yue_date = _this.pickerWeeks + 1;
  197. }
  198. _this.$request.post('order.yuyuetime', {
  199. id: _this.id,
  200. timestype: _this.timestype,
  201. yue_date: yue_date,
  202. servicetime: _this.orderDateTime
  203. }).then(res => {
  204. if (res.errno == 0) {
  205. uni.showModal({
  206. title: '提示',
  207. content: '提交成功!',
  208. showCancel: false,
  209. //是否显示取消按钮
  210. success: function(res) {
  211. if (res.cancel) { //点击取消,默认隐藏弹框
  212. } else {
  213. _this.tui.href('/pagesA/my/myOrder/myTimes');
  214. }
  215. }
  216. });
  217. }
  218. })
  219. }
  220. },
  221. /**
  222. * 页面相关事件处理函数--监听用户下拉动作
  223. */
  224. onPullDownRefresh: function() {
  225. setTimeout(() => {
  226. uni.stopPullDownRefresh()
  227. }, 200);
  228. },
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. .panel {
  233. background-color: #fff;
  234. margin-bottom: 20rpx;
  235. padding-left: 10rpx;
  236. padding-right: 10rpx;
  237. &-body {
  238. padding: 10rpx 0 20rpx 0;
  239. overflow: hidden;
  240. >button {
  241. width: 12%;
  242. display: block;
  243. float: left;
  244. margin-top: 10rpx;
  245. margin-left: 1%;
  246. margin-right: 1%;
  247. margin-bottom: 10rpx;
  248. padding: 0 20rpx;
  249. border-radius: 0;
  250. &:after {
  251. display: none;
  252. }
  253. }
  254. }
  255. &-weeks {
  256. padding: 10rpx 0 10rpx 0;
  257. overflow: hidden;
  258. >button {
  259. width: 12%;
  260. display: block;
  261. float: left;
  262. margin-top: 10rpx;
  263. margin-bottom: 10rpx;
  264. margin-left: 1%;
  265. margin-right: 1%;
  266. padding: 0 10rpx;
  267. border-radius: 0;
  268. &:after {
  269. display: none;
  270. }
  271. }
  272. }
  273. }
  274. .container {
  275. view,
  276. text,
  277. image {
  278. box-sizing: border-box;
  279. }
  280. scroll-view {
  281. width: 100%;
  282. white-space: nowrap;
  283. height: 75px;
  284. background-color: #fff;
  285. position: relative;
  286. padding-top: 10px;
  287. // margin-top:10px;
  288. &::after {
  289. background: #e5e5e5;
  290. content: '';
  291. display: block;
  292. width: 100%;
  293. height: 1px;
  294. position: absolute;
  295. bottom: 0;
  296. left: 0;
  297. transform: scaleY(0.5);
  298. }
  299. .flex-box {
  300. display: inline-block;
  301. height: 60px;
  302. width: 25%;
  303. margin: 0 7rpx 0 7rpx;
  304. box-sizing: border-box;
  305. &.active {
  306. .date-box {
  307. border: none;
  308. .days {
  309. font-weight: bold;
  310. color: #818181;
  311. }
  312. .date {
  313. font-weight: bold;
  314. color: #818181;
  315. }
  316. }
  317. }
  318. .date-box {
  319. border: none;
  320. display: flex;
  321. height: 50px;
  322. flex-direction: column;
  323. align-items: center;
  324. justify-content: space-around;
  325. font-size: 30upx;
  326. color: rgba(129, 129, 129, 1);
  327. .date {
  328. font-weight: bold;
  329. color: #818181;
  330. font-size: 30upx;
  331. }
  332. }
  333. }
  334. }
  335. .weeks-box {
  336. padding-left: 20upx;
  337. padding-right: 20upx;
  338. padding-top: 60upx;
  339. background-color: #fff;
  340. }
  341. .time-box {
  342. padding-top: 28upx;
  343. padding-left: 14upx;
  344. padding-right: 10upx;
  345. padding-bottom: 200upx;
  346. display: flex;
  347. flex-wrap: wrap;
  348. // margin-top:10px;
  349. background-color: #fff;
  350. .item {
  351. width: 33%;
  352. padding: 9upx;
  353. &-box {
  354. width: 100%;
  355. height: 154upx;
  356. padding: 0 10upx;
  357. background: #fff;
  358. color: #333;
  359. border: 1px solid #EEEEEE;
  360. font-size: 28upx;
  361. border-radius: 10upx;
  362. display: flex;
  363. flex-direction: column;
  364. align-items: center;
  365. justify-content: center;
  366. &.disable {
  367. background: #F1F3F6 !important;
  368. color: #999 !important;
  369. // border: 1px solid #EEEEEE;
  370. }
  371. &.active {
  372. // background: #0094D7;
  373. border: 1px solid rgba(255, 69, 0, 1);
  374. font-weight: bold;
  375. }
  376. .all {
  377. font-size: 22upx;
  378. padding-top: 5px;
  379. }
  380. }
  381. }
  382. }
  383. }
  384. page {
  385. height: 100%;
  386. }
  387. .content {
  388. text-align: center;
  389. height: 100%;
  390. }
  391. /* 两个按钮 */
  392. .bottom {
  393. display: flex;
  394. flex-direction: row;
  395. position: fixed;
  396. bottom: 0;
  397. padding-top: 20rpx;
  398. padding-bottom: env(safe-area-inset-bottom);
  399. top: auto;
  400. left: 0px;
  401. width: 100%;
  402. background-color: #fff;
  403. }
  404. .show-time {
  405. width: 70%;
  406. height: 47px;
  407. color: #505050;
  408. background-color: rgba(255, 255, 255, 1);
  409. font-size: 15px;
  410. line-height: 47px;
  411. text-align: center;
  412. }
  413. .submit-btn {
  414. width: 200rpx;
  415. height: 70rpx;
  416. line-height: 70rpx;
  417. font-size: 28rpx;
  418. border-radius: 50rpx;
  419. color: #ffffff;
  420. align-items: center;
  421. background-color: rgba(255, 69, 0, 1);
  422. }
  423. .fontw {
  424. font-weight: bold;
  425. }
  426. .borderb {
  427. border-bottom: 2px solid rgba(255, 69, 0, 1);
  428. }
  429. button[type=primary] {
  430. background-color: rgba(255, 69, 0, 1);
  431. color: #fff;
  432. }
  433. </style>