z-date-area.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view>
  3. <view class="time-card shadow-2">
  4. <view class="flex-n fac top">
  5. <view class="now_time flex-1" v-if="monthDayList[15]">{{monthDayList[15].yy}}年{{monthDayList[15].mm>9?monthDayList[15].mm:('0'+monthDayList[15].mm)}}月</view>
  6. <view class="time-card-tab iconfont iconfanhui" @click="beforeMonth(monthDayList[15])"></view>
  7. <view class="time-card-tab time-card-tab-trans iconfont iconfanhui ml-100" @click="afterMonth(monthDayList[15])"></view>
  8. </view>
  9. <view class="time-card_container mt-38">
  10. <view class="time-card_week" :class="index>4?'time-card_week_day':''" v-for="(item,index) in weekName" :key="item">{{item}}</view>
  11. <view class="time-card_day" :class="item.mm!=monthDayList[15].mm?'time-card_day_out':''" v-for="(item,index) in monthDayList"
  12. :key="index" @click="chooseDay(item,index)">
  13. <view class="time-card_day_item" :class="[{'date_now':$Date.getDayDate().date==item.date},{'date_select':choose==index}]">
  14. {{item.dd}}
  15. <view class="date_imp flex-n fac fjc" v-if="importantDataList&&importantDataList[index]&&importantDataList[index].importantDates&&importantDataList[index].importantDates.length>0">
  16. <view class=" iconfont iconxing2"></view>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. const app = getApp({
  26. allowDefault: true
  27. });
  28. export default {
  29. props:{
  30. value:String
  31. },
  32. model: {
  33. prop: 'value',
  34. },
  35. data() {
  36. return {
  37. weekName: ['一', '二', '三', '四', '五', '六', '日'],
  38. monthDayList: [],
  39. importantDataList: [],
  40. choose: 20,
  41. };
  42. },
  43. mounted() {
  44. //获取当前时间的信息
  45. var date = this.$Date.getDayDate();
  46. // this.day = date;
  47. this.monthDayList = this.$Date.getMonthDate({
  48. yy: date.yy,
  49. mm: date.mm,
  50. dd: date.dd
  51. });
  52. for (var i in this.monthDayList) {
  53. if (this.monthDayList[i].dd == date.dd && this.monthDayList[i].mm == date.mm) {
  54. this.choose = i;
  55. break;
  56. }
  57. }
  58. },
  59. watch: {
  60. value(newval, oldval) {
  61. console.log('反显日期',newval)
  62. if (newval) {
  63. var date = newval.split('-');
  64. this.monthDayList = this.$Date.getMonthDate({
  65. yy: date[0],
  66. mm: date[1],
  67. dd: date[2]
  68. });
  69. for (var i in this.monthDayList) {
  70. if (this.monthDayList[i].dd == date[2] && this.monthDayList[i].mm == date[1]) {
  71. this.choose = i;
  72. break;
  73. }
  74. }
  75. }
  76. },
  77. },
  78. methods:{
  79. //获取重点日期
  80. getImportantDate(startTime, endTime) {
  81. this.$axios.post('app/order/orderImportantDate', {
  82. "startTime": startTime,
  83. "endTime": endTime,
  84. "storeId": uni.getStorageSync('storeId')
  85. }).then(res => {
  86. console.log('重点日期', res.data)
  87. this.importantDataList = res.data.list;
  88. }).catch(err => {
  89. // this.$message.error(err.msg);
  90. })
  91. },
  92. //前一个月
  93. beforeMonth(date) {
  94. console.log(date, this.choose)
  95. this.monthDayList = this.$Date.getMonthDate({
  96. yy: date.mm - 1 > 0 ? date.yy : (date.yy - 1),
  97. mm: date.mm - 1 > 0 ? date.mm - 1 : 12,
  98. dd: date.dd
  99. });
  100. for(var i in this.monthDayList){
  101. if(this.monthDayList[i].dd==1){
  102. this.choose=i;
  103. break;
  104. }
  105. }
  106. this.chooseDay(this.monthDayList[this.choose], this.choose);
  107. this.getImportantDate(this.monthDayList[0].date, this.monthDayList[this.monthDayList.length - 1].date);
  108. },
  109. //后一个月
  110. afterMonth(date) {
  111. this.monthDayList = this.$Date.getMonthDate({
  112. yy: date.mm + 1 > 12 ? (date.yy + 1) : date.yy,
  113. mm: date.mm + 1 > 12 ? 1 : date.mm + 1,
  114. dd: date.dd
  115. });
  116. for(var i in this.monthDayList){
  117. if(this.monthDayList[i].dd==1){
  118. this.choose=i;
  119. break;
  120. }
  121. }
  122. this.chooseDay(this.monthDayList[this.choose], this.choose);
  123. this.getImportantDate(this.monthDayList[0].date, this.monthDayList[this.monthDayList.length - 1].date);
  124. },
  125. chooseDay(item, index) {
  126. console.log(item)
  127. this.choose = index;
  128. this.$emit('input',item.date)
  129. this.$emit('change',item);
  130. },
  131. }
  132. }
  133. </script>
  134. <style scoped lang="scss">
  135. .time-card {
  136. padding: 46rpx 4rpx;
  137. .top {
  138. padding: 0 40rpx;
  139. }
  140. .now_time {
  141. font-weight: bold;
  142. color: #333333;
  143. font-size: 32rpx;
  144. }
  145. .time-card-tab {
  146. width: 18rpx;
  147. height: 34rpx;
  148. color: #2481EE;
  149. }
  150. .time-card-tab-trans {
  151. transform: rotateZ(180deg);
  152. }
  153. .time-card_container {
  154. display: grid;
  155. grid-template-columns: repeat(7, calc(100% / 7));
  156. color: #333333;
  157. text-align: center;
  158. .time-card_week {
  159. font-size: 28rpx;
  160. line-height: 50rpx;
  161. margin: 10rpx;
  162. }
  163. .time-card_week_day {
  164. color: #F7913D !important;
  165. }
  166. .time-card_day {
  167. font-size: 24rpx;
  168. justify-self: center;
  169. height: 70rpx;
  170. .time-card_day_item {
  171. width: 50rpx;
  172. height: 50rpx;
  173. line-height: 50rpx;
  174. margin: 10rpx;
  175. position: relative;
  176. // background:rgba(247,145,61,1);
  177. border-radius: 50%;
  178. .date_imp {
  179. position: absolute;
  180. top: -10rpx;
  181. right: -10rpx;
  182. font-size: 20rpx;
  183. line-height: 24rpx;
  184. width: 24rpx;
  185. height: 24rpx;
  186. color: #e64340;
  187. background: white;
  188. border: 2rpx solid white;
  189. border-radius: 50%;
  190. .iconfont {
  191. font-size: 25rpx;
  192. transform: scale(0.8);
  193. }
  194. }
  195. }
  196. .date_select {
  197. border: 2rpx solid #F7913D !important;
  198. .date_imp {
  199. border: 2rpx solid #F7913D !important;
  200. .iconfont {
  201. font-size: 25rpx;
  202. transform: scale(0.8);
  203. }
  204. }
  205. }
  206. .date_now {
  207. background: #F7913D;
  208. color: white !important;
  209. box-shadow: 5rpx 5rpx 20rpx 0rpx #f5b47e;
  210. border: 2rpx solid #F7913D !important;
  211. .date_imp {
  212. border: 2rpx solid #F7913D !important;
  213. box-shadow: -1rpx 0rpx 10rpx 0rpx rgba(247, 145, 61, 0.1);
  214. .iconfont {
  215. font-size: 25rpx;
  216. transform: scale(0.8);
  217. }
  218. }
  219. }
  220. }
  221. .time-card_day_out {
  222. color: #999999 !important;
  223. }
  224. }
  225. }
  226. </style>