index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 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. //确认
  114. confirm(){
  115. this.$emit('change')
  116. if(this.modalTimeType){
  117. this.value.type = 6
  118. }
  119. this.$refs.popup.close()
  120. },
  121. //外部选择时间
  122. changeTypeFn(_type){
  123. this.value.type = _type
  124. this.value.beginTime = null
  125. this.value.endTime = null
  126. this.value.time = []
  127. this.$emit('change')
  128. },
  129. modalTimeSelect(_type){
  130. const v = this
  131. v.modalTimeType = _type
  132. const todayNum = new Date(new Date().toLocaleDateString()).getTime()
  133. const today = new Date()
  134. //年
  135. var year = today.getFullYear();
  136. //月
  137. const month = today.getMonth() + 1
  138. //周
  139. const nows = today.getDay() || 7
  140. //天
  141. const day = today.getDate()
  142. if(_type == 1){
  143. v.value.beginTime = format(todayNum - 86400000)
  144. v.value.endTime = format(todayNum)
  145. }
  146. if(_type == 2){
  147. v.value.beginTime = format(todayNum - (86400000 * 2))
  148. v.value.endTime = format(todayNum - 86400000)
  149. }
  150. if(_type == 3){
  151. v.value.beginTime = format(todayNum - (86400000 * (nows + 6)))
  152. v.value.endTime = format(todayNum - 86400000 * (nows - 1))
  153. }
  154. if(_type == 4){
  155. if(month == 1){
  156. v.value.beginTime = (year - 1) + '-' + 12 + '-' + '1 00:00:00'
  157. v.value.endTime = year + '-' + 1 + '-' + '1 00:00:00'
  158. }else{
  159. v.value.beginTime = year + '-' + (month - 1) + '-' + '1 00:00:00'
  160. v.value.endTime = year + '-' + month + '-' + '1 00:00:00'
  161. }
  162. }
  163. if(_type == 5){
  164. if(month < 4){
  165. v.value.beginTime = (year - 1) + '-' + (12 - 3 + month) + '-' + day + ' 00:00:00'
  166. v.value.endTime = format(today.getTime())
  167. }else{
  168. v.value.beginTime = year + '-' + (month - 3) + '-' + day + ' 00:00:00'
  169. v.value.endTime = format(today.getTime())
  170. }
  171. }
  172. if(_type == 6){
  173. if(month < 7){
  174. v.value.beginTime = (year - 1) + '-' + (12 - 6 + month) + '-' + day + ' 00:00:00'
  175. v.value.endTime = format(today.getTime())
  176. }else{
  177. v.value.beginTime = year + '-' + (month - 6) + '-' + day + ' 00:00:00'
  178. v.value.endTime = format(today.getTime())
  179. }
  180. }
  181. v.value.time = [v.value.beginTime,v.value.endTime]
  182. console.log(v.value)
  183. },
  184. openBotomModal(){
  185. console.log(this.value)
  186. this.$refs.popup.open('bottom')
  187. },
  188. },
  189. created() {
  190. },
  191. }
  192. </script>
  193. <style lang="less">
  194. .btn-box{
  195. display: flex;
  196. justify-content: space-between;
  197. font-size: 30rpx;
  198. height: 80rpx;
  199. line-height: 80rpx;
  200. padding: 0 40rpx;
  201. font-weight: 600;
  202. }
  203. .commons-time-box {
  204. display: flex;
  205. height: 50rpx;
  206. line-height: 50rpx;
  207. font-size: 24rpx;
  208. margin: 30rpx 30rpx;
  209. border: 1px solid #dcdcdc;
  210. border-radius: 8rpx;
  211. .modal-select-box{
  212. width:16.66%;
  213. text-align: center;
  214. }
  215. .time-box {
  216. width: 15%;
  217. text-align: center;
  218. }
  219. .time-box-icon {
  220. width: 10%;
  221. }
  222. .time-box.active {
  223. background-color: #487CFF;
  224. color: #fff;
  225. }
  226. .active {
  227. background-color: #487CFF;
  228. color: #fff;
  229. text{
  230. color: #fff!important;
  231. }
  232. }
  233. }
  234. </style>