z-date-slide.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view>
  3. <swiper class="swiper shadow-2" :disable-touch="disabletouch" :current="current" circular @change="change" @animationfinish="animationfinish" @transition="transition">
  4. <swiper-item :key='index' v-for="(item,index) in list">
  5. <view class="swiper-item flex-n fja">
  6. <view class="date_content" :key="idx" v-for="(itm,idx) in item" @click="chooseDate(idx)">
  7. <view class="date_content_1" :class="idx==6||idx==5?'date_week_style':''">{{itm.xx}}</view>
  8. <!-- date_select -->
  9. <view class="date_content_2" :class="[{'date_now':$Date.getDayDate().date==itm.date},{'date_select':choose==idx}]">
  10. {{itm.dd}}
  11. <view class="date_imp flex-n fac fjc" v-if="dataList&&dataList[idx]&&dataList[idx].isImportant">
  12. <view class=" iconfont iconxing2" ></view>
  13. <!-- iconxing2 iconxing-->
  14. </view>
  15. </view>
  16. <!-- <view class="flex-n fac" v-if="dataList&&dataList[idx]&&dataList[idx].record">
  17. <view class="date_content_4" ></view>
  18. <view class="date_content_3 mt-8">{{dataList[idx].record}}</view>
  19. </view> -->
  20. <view class="date_content_3 mt-8" v-if="dataList&&dataList[idx]&&dataList[idx].record">{{dataList[idx].record>99?'99+':dataList[idx].record}}</view>
  21. <view class="date_content_4 mt-8" v-else>无</view>
  22. </view>
  23. </view>
  24. </swiper-item>
  25. </swiper>
  26. <view style="height: 230rpx;"></view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. name: 'z-date-slide',
  32. props:{
  33. dataList:Array
  34. },
  35. data() {
  36. return {
  37. list: ['', '', ''],
  38. dx: 0,
  39. current:1,
  40. disabletouch:false,
  41. weekName:['一','二','三','四','五','六','日'],
  42. showday:{},//需要传入的值
  43. choose:0,
  44. // week
  45. }
  46. },
  47. methods: {
  48. getDate(newval){
  49. console.log(newval)
  50. var date=newval.split('-');
  51. var dateInfo=this.$Date.getDayDate({yy:date[0],mm:date[1],dd:date[2]});
  52. console.log(dateInfo)
  53. for(var i=0,len=this.$Date.getWeekDate(dateInfo.yy,dateInfo.mm,dateInfo.dd).length;i<len;i++){
  54. if(this.$Date.getWeekDate(dateInfo.yy,dateInfo.mm,dateInfo.dd)[i].date==newval){
  55. this.choose=i;
  56. }
  57. }
  58. this.getDateList(dateInfo,1,0,2);
  59. },
  60. //获取日期数据 获取上一周 下一周
  61. getDateList(dateInfo,current,x1,x2){
  62. this.current=current;
  63. var dateString='';
  64. //#ifdef APP-PLUS
  65. dateString=dateInfo.yy+'/'+Number(dateInfo.mm)+'/'+Number(dateInfo.dd);
  66. //#endif
  67. //#ifndef APP-PLUS
  68. dateString=dateInfo.date;
  69. //#endif
  70. var before=new Date(new Date(dateString).getTime() - 7 * 24 * 60 * 60 * 1000),
  71. after=new Date(new Date(dateString).getTime() + 7 * 24 * 60 * 60 * 1000);
  72. this.list.splice(x1,1,this.$Date.getWeekDate(before.getFullYear(),before.getMonth()+1,before.getDate()));
  73. this.list.splice(current,1,this.$Date.getWeekDate(dateInfo.yy,dateInfo.mm,dateInfo.dd));
  74. this.list.splice(x2,1,this.$Date.getWeekDate(after.getFullYear(),after.getMonth()+1,after.getDate()));
  75. this.disabletouch=false;
  76. this.$emit('getDateInfo',this.list[current][this.choose]);
  77. this.$emit('getDateRange',this.list[current]);
  78. },
  79. //选择的日期
  80. chooseDate(idx){
  81. this.choose=idx;
  82. console.log('选择的日期',this.current,this.choose)
  83. this.$emit('getDateInfo',this.list[this.current][this.choose]);
  84. this.$emit('getDateRange',this.list[this.current]);
  85. },
  86. change(e){
  87. this.disabletouch=true;
  88. },
  89. animationfinish(e) {
  90. console.log('zz')
  91. var current = e.detail.current;
  92. var left = 0,
  93. right = 0;
  94. if (current - 1 >= 0) {
  95. left = current - 1;
  96. } else {
  97. left = 2;
  98. }
  99. if (current + 1 > 2) {
  100. right = 0;
  101. } else {
  102. right = current + 1;
  103. }
  104. if (this.dx < 0) {
  105. // this.chooseDate(6);
  106. this.getDateList(this.list[current][0],current,left,right);
  107. this.dx=0;
  108. // console.log('左滑:左面是', left, '当前是', current, '右面是', right);
  109. } else if (this.dx > 0) {
  110. // this.chooseDate(0);
  111. this.getDateList(this.list[current][0],current,left,right);
  112. this.dx=0
  113. // console.log('右滑:左面是', left, '当前是', current, '右面是', right);
  114. } else {
  115. // console.log('没有滑动:左面是', left, '当前是', current, '右面是', right);
  116. this.disabletouch=false;
  117. }
  118. },
  119. transition(e) {
  120. this.dx = e.detail.dx;
  121. }
  122. }
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. .swiper{
  127. height: 206rpx;
  128. width: 100vw;
  129. position: fixed;
  130. z-index: 400;
  131. background: white;
  132. .swiper-item{
  133. height: 100%;
  134. .date_content{
  135. text-align: center;
  136. .date_content_1{
  137. color: #333333;
  138. margin-top: 20rpx;
  139. font-size: 28rpx;
  140. }
  141. .date_select{
  142. border:2rpx solid #F7913D!important;
  143. .date_imp{
  144. border:2rpx solid #F7913D!important;
  145. .iconfont{
  146. font-size: 25rpx;
  147. transform: scale(0.8);
  148. }
  149. }
  150. }
  151. .date_now{
  152. background:#F7913D;
  153. color: white!important;
  154. box-shadow:5rpx 5rpx 20rpx 0rpx #f5b47e;
  155. border:2rpx solid #F7913D!important;
  156. .date_imp{
  157. border:2rpx solid #F7913D!important;
  158. box-shadow:-1rpx 0rpx 10rpx 0rpx rgba(247,145,61,0.1);
  159. .iconfont{
  160. font-size: 25rpx;
  161. transform: scale(0.8);
  162. }
  163. }
  164. }
  165. .date_content_2{
  166. margin-top: 10rpx;
  167. color: #333333;
  168. font-size: 42rpx;
  169. width:70rpx;
  170. height:70rpx;
  171. border-radius:50%;
  172. text-align: center;
  173. line-height: 70rpx;
  174. border:2rpx solid white;
  175. position: relative;
  176. .date_imp{
  177. position: absolute;
  178. top:-10rpx;
  179. right: -10rpx;
  180. font-size: 20rpx;
  181. width:32rpx;
  182. height:32rpx;
  183. color: #e64340;
  184. background:white;
  185. border:2rpx solid white;
  186. border-radius:50%;
  187. .iconfont{
  188. font-size: 25rpx;
  189. transform: scale(0.8);
  190. }
  191. }
  192. }
  193. // .date_content_3{
  194. // color: #888888;
  195. // font-size: 24rpx;
  196. // }
  197. .date_content_3{
  198. background: #F7913D;
  199. font-size: 24rpx;
  200. color:white;
  201. }
  202. .date_content_4{
  203. background: #ccc;
  204. font-size: 24rpx;
  205. color:white;
  206. }
  207. .date_week_style{
  208. color: #F7913D!important;
  209. }
  210. // .date_content_4{
  211. // width:12rpx;
  212. // height:12rpx;
  213. // background:#F7913D;
  214. // opacity:0.5;
  215. // border-radius:50%;
  216. // margin-top: 6rpx;
  217. // }
  218. }
  219. }
  220. }
  221. </style>