dateSelect.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="select-bg_bx">
  3. <view v-if="isShowTit" @click="switchCut" :class="['select-title',dropdownShow?'select_corlor':'']">
  4. <text>{{defaultDateName}}</text>
  5. <text v-if="placeholder" style="color: #ccc;">{{placeholder}}</text>
  6. <i v-if="isShowMore" class="iconfont iconsanjiao_xia"></i>
  7. </view>
  8. <view v-else @click="switchCut" :class="['select-title',dropdownShow?'select_corlor':'']">
  9. <text v-if="placeholder" style="color: #ccc;">{{placeholder}}</text>
  10. </view>
  11. <view class="select-mark-view" v-show="dropdownShow" @click="switchCut"></view>
  12. <view v-if="dropdownShow" :style="{top}" class="select-fixed_bx">
  13. <slot>
  14. <view class="select-item-box">
  15. <view class="title">时间</view>
  16. <view class="item-child_box">
  17. <button
  18. v-for="(item,index) in getDictionariesInfo.dateDefaultOption"
  19. :key="index"
  20. @click="changeDateOption(item)"
  21. :class="['admin-button-com','mini-btn',selectItemId === item.id?'blue':'default']">
  22. {{item.name}}
  23. </button>
  24. </view>
  25. </view>
  26. <view class="select-item-box">
  27. <view class="title">时间段</view>
  28. <view class="item-child_box" >
  29. <view class="admin-button-com mini-btn default custom" @click="showDatePicker(0)">{{startDate || '选择开始日期'}}</view>
  30. <view class="admin-button-com mini-btn default custom" @click="showDatePicker(1)">{{endDate || '选择结束日期'}}</view>
  31. <view class="admin-button-com mini-btn blue custom" @click="customDateConfirm()">确认</view>
  32. </view>
  33. </view>
  34. </slot>
  35. </view>
  36. <mx-date-picker :show="showPicker" format="yyyy-mm-dd" type="date" :value="defaultPickerDate" :show-tips="true" @confirm="confirmPicker" @cancel="cancelPicker" />
  37. </view>
  38. </template>
  39. <script>
  40. import DropdownList from "@/components/plugin/dropdown-list";
  41. import MxDatePicker from '@/components/mx-datepicker/mx-datepicker.vue';
  42. import {mapGetters} from "vuex";
  43. export default {
  44. name:'dateSelect',
  45. components:{
  46. DropdownList,MxDatePicker
  47. },
  48. props:{
  49. top:{
  50. type: String,
  51. default: 'auto'
  52. },
  53. selectItemId:{
  54. type:[String,Number],
  55. default:''
  56. },
  57. isShowTit:{
  58. type: Boolean,
  59. default: true
  60. },
  61. isShowMore:{
  62. type: Boolean,
  63. default: true
  64. },
  65. placeholder: {
  66. type: String,
  67. default: ''
  68. },
  69. defaultShowName:{
  70. type: String,
  71. default: '今天'
  72. }
  73. },
  74. data(){
  75. return {
  76. defaultPickerDate:'',
  77. showPicker: false,
  78. dropdownShow: false,
  79. selectItem:'',
  80. startDate:'',
  81. endDate:'',
  82. dateIndex:0,
  83. defaultDateName:'今天'
  84. }
  85. },
  86. watch:{
  87. defaultShowName: {
  88. handler(newVal) {
  89. this.defaultDateName = newVal
  90. },
  91. immediate:true
  92. }
  93. },
  94. computed:{
  95. ...mapGetters(["getDictionariesInfo"])
  96. },
  97. mounted(){
  98. let nowDate = new Date();
  99. let currentDate = nowDate.Format("yyyy-MM-dd")
  100. this.defaultPickerDate = currentDate
  101. },
  102. onLoad(){
  103. },
  104. methods:{
  105. showDatePicker(index){//显示
  106. this.showPicker = true;
  107. this.dateIndex = index
  108. },
  109. confirmPicker(e) {//选择
  110. if(this.dateIndex == 0){
  111. this.startDate = e.value
  112. }else{
  113. this.endDate = e.value
  114. }
  115. this.showPicker = false;
  116. },
  117. customDateConfirm() {
  118. if(this.$util.isEmpty(this.startDate)){
  119. this.$msg('请选择开始日期')
  120. return false
  121. }
  122. if(this.$util.isEmpty(this.endDate)){
  123. this.$msg('请选择开始日期')
  124. return false
  125. }
  126. this.dropdownShow = false
  127. this.defaultDateName = '时间段'
  128. this.$emit('selectDateFn',{selectTime:'custom',startTime:this.startDate,endTime:this.endDate})
  129. },
  130. cancelPicker(){
  131. this.showPicker = false;
  132. },
  133. switchCut(){
  134. this.dropdownShow = !this.dropdownShow
  135. },
  136. changeDateOption(val){
  137. this.dropdownShow = false;
  138. this.defaultDateName = val.name;
  139. this.$emit('selectDateFn',{selectTime:val.value})
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .select-bg_bx {
  146. .select-title {
  147. color: #666666;
  148. font-size: 26upx;
  149. & .iconsanjiao_xia {
  150. margin-left: 10upx;
  151. }
  152. &.select_corlor {
  153. color: #3385FF;
  154. & .iconsanjiao_xia {
  155. transform: rotate(180deg);
  156. }
  157. }
  158. }
  159. .select-mark-view {
  160. height: 100vh;
  161. height: 100%;
  162. position: fixed;
  163. width: 100%;
  164. background-color: rgba(0, 0, 0, 0.5);
  165. left: 0;
  166. top: 0upx;
  167. z-index: 20;
  168. }
  169. & .select-fixed_bx {
  170. position: fixed;
  171. width: 100%;
  172. background-color: #FFFFFF;
  173. left: 0;
  174. z-index: 29;
  175. padding:120upx 30upx 40upx;
  176. border-radius: 0upx 0upx 20upx 20upx;
  177. transition: all 0.5s ease-in-out;
  178. & .select-item-box {
  179. & .title {
  180. font-size: 24upx;
  181. color: #333333;
  182. font-weight: 600;
  183. text-align: left;
  184. }
  185. & .item-child_box {
  186. padding: 20upx 0 0;
  187. align-items: center;
  188. & .admin-button-com {
  189. margin-bottom: 20upx;
  190. padding: 18upx 50upx;
  191. margin-right: 20upx;
  192. &.custom {
  193. width: 100%;
  194. }
  195. }
  196. }
  197. }
  198. }
  199. }
  200. </style>