index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view>
  3. <view class="" style="height:1rpx">
  4. </view>
  5. <view class="commons-time-box">
  6. <view
  7. class="time-box"
  8. :class="value.type == i.type ? 'active' : ''"
  9. v-for="i in typeList"
  10. :key="i.type"
  11. @click="changeTypeFn(i.type)">
  12. {{i.name}}
  13. </view>
  14. <view :class="value.type == 6 ? 'active' : ''" class="time-box time-box-icon" @click="openBotomModal">
  15. <uni-icons type="calendar" size="20"></uni-icons>
  16. </view>
  17. <uni-popup ref="popup" type="bottom" background-color="#fff">
  18. <view class="btn-box">
  19. <view class="" style="color:red">
  20. 取消
  21. </view>
  22. <view class="" style="color:#007AFF" @click="confirm">
  23. 确认
  24. </view>
  25. </view>
  26. <view class="commons-time-box">
  27. <view
  28. class="modal-select-box"
  29. :class="modalTimeType == i.type ? 'active' : ''"
  30. v-for="i in modalTimeList"
  31. @click="modalTimeSelect(i.type)"
  32. :key="i.type">
  33. {{i.name}}
  34. </view>
  35. </view>
  36. <view>
  37. <view class="color-bl text-center" style="margin:30rpx">
  38. 选择时间区间
  39. </view>
  40. <view class="">
  41. <uni-datetime-picker @change="selectPicker" v-model="value.time" type="daterange" rangeSeparator="至" />
  42. </view>
  43. <view style="height:200rpx">
  44. </view>
  45. </view>
  46. </uni-popup>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import {format} from '../../util/uitl.js'
  52. export default {
  53. props: {
  54. value: {
  55. type: Object,
  56. }
  57. },
  58. watch: {
  59. value: {
  60. handler() {
  61. this.$emit("input", this.value)
  62. },
  63. deep: true,
  64. immediate: true,
  65. },
  66. },
  67. data() {
  68. return {
  69. typeList:[{
  70. name:"本日",
  71. type:0,
  72. },{
  73. name:"昨日",
  74. type:1,
  75. },{
  76. name:"本周",
  77. type:2,
  78. },{
  79. name:"上周",
  80. type:3,
  81. },{
  82. name:"本月",
  83. type:4,
  84. },{
  85. name:"上月",
  86. type:5,
  87. }],
  88. modalTimeList:[
  89. {
  90. name:"昨日",
  91. type:1,
  92. },{
  93. name:"前日",
  94. type:2,
  95. },{
  96. name:"上周",
  97. type:3,
  98. },{
  99. name:"上月",
  100. type:4,
  101. },{
  102. name:"近三个月",
  103. type:5,
  104. },{
  105. name:"近半年",
  106. type:6,
  107. }
  108. ],
  109. modalTimeType:null,
  110. }
  111. },
  112. methods:{
  113. selectPicker(){
  114. },
  115. //确认
  116. confirm(){
  117. if(this.modalTimeType || this.value.time.length != 0){
  118. this.value.type = 6
  119. this.$emit('change')
  120. }
  121. this.$refs.popup.close()
  122. },
  123. //外部选择时间
  124. changeTypeFn(_type){
  125. this.value.type = _type
  126. this.value.beginTime = null
  127. this.value.endTime = null
  128. this.value.time = []
  129. this.$emit('change')
  130. },
  131. modalTimeSelect(_type){
  132. const v = this
  133. v.modalTimeType = _type
  134. const todayNum = new Date(new Date().toLocaleDateString()).getTime()
  135. const today = new Date()
  136. //年
  137. var year = today.getFullYear();
  138. //月
  139. const month = today.getMonth() + 1
  140. //周
  141. const nows = today.getDay() || 7
  142. //天
  143. const day = today.getDate()
  144. if(_type == 1){
  145. v.value.beginTime = format(todayNum - 86400000)
  146. v.value.endTime = format(todayNum)
  147. }
  148. if(_type == 2){
  149. v.value.beginTime = format(todayNum - (86400000 * 2))
  150. v.value.endTime = format(todayNum - 86400000)
  151. }
  152. if(_type == 3){
  153. v.value.beginTime = format(todayNum - (86400000 * (nows + 6)))
  154. v.value.endTime = format(todayNum - 86400000 * (nows - 1))
  155. }
  156. if(_type == 4){
  157. if(month == 1){
  158. v.value.beginTime = (year - 1) + '-' + 12 + '-' + '1 00:00:00'
  159. v.value.endTime = year + '-' + 1 + '-' + '1 00:00:00'
  160. }else{
  161. v.value.beginTime = year + '-' + (month - 1) + '-' + '1 00:00:00'
  162. v.value.endTime = year + '-' + month + '-' + '1 00:00:00'
  163. }
  164. }
  165. if(_type == 5){
  166. if(month < 4){
  167. v.value.beginTime = (year - 1) + '-' + (12 - 3 + month) + '-' + day + ' 00:00:00'
  168. v.value.endTime = format(today.getTime())
  169. }else{
  170. v.value.beginTime = year + '-' + (month - 3) + '-' + day + ' 00:00:00'
  171. v.value.endTime = format(today.getTime())
  172. }
  173. }
  174. if(_type == 6){
  175. if(month < 7){
  176. v.value.beginTime = (year - 1) + '-' + (12 - 6 + month) + '-' + day + ' 00:00:00'
  177. v.value.endTime = format(today.getTime())
  178. }else{
  179. v.value.beginTime = year + '-' + (month - 6) + '-' + day + ' 00:00:00'
  180. v.value.endTime = format(today.getTime())
  181. }
  182. }
  183. v.value.time = [v.value.beginTime,v.value.endTime]
  184. console.log(v.value)
  185. },
  186. openBotomModal(){
  187. console.log(this.value)
  188. this.$refs.popup.open('bottom')
  189. },
  190. },
  191. created() {
  192. },
  193. }
  194. </script>
  195. <style lang="less">
  196. .btn-box{
  197. display: flex;
  198. justify-content: space-between;
  199. font-size: 30rpx;
  200. height: 80rpx;
  201. line-height: 80rpx;
  202. padding: 0 40rpx;
  203. font-weight: 600;
  204. }
  205. .commons-time-box {
  206. display: flex;
  207. height: 50rpx;
  208. line-height: 50rpx;
  209. font-size: 24rpx;
  210. margin: 30rpx 30rpx;
  211. border: 1px solid #dcdcdc;
  212. border-radius: 8rpx;
  213. .modal-select-box{
  214. width:16.66%;
  215. text-align: center;
  216. }
  217. .time-box {
  218. width: 15%;
  219. text-align: center;
  220. }
  221. .time-box-icon {
  222. width: 10%;
  223. }
  224. .time-box.active {
  225. background-color: #487CFF;
  226. color: #fff;
  227. }
  228. .active {
  229. background-color: #487CFF;
  230. color: #fff;
  231. text{
  232. color: #fff!important;
  233. }
  234. }
  235. }
  236. </style>