trainModel.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="trainModel">
  3. <div class="visit-tips" v-show="activeType == 'visited'">
  4. <span>上周训练时长不足80分钟或训练次数小于4次的学员<br />
  5. 需在每周三24:00前完成回访</span>
  6. </div>
  7. <search @onSearch="onSearch" placeholder="学生姓名或手机号">
  8. <template #left>
  9. <van-dropdown-menu style="padding-right: .1rem" :close-on-click-outside="false" active-color="#01C1B5">
  10. <van-dropdown-item title="筛选" ref="item" class="visitTime">
  11. <van-cell title="日期" is-link @click="showCalendar = true" title-style="font-size: .14rem;" :value="calendarValue" value-class="calendarColor"></van-cell>
  12. </van-dropdown-item>
  13. </van-dropdown-menu>
  14. </template>
  15. </search>
  16. <van-row class="searchArray">
  17. <van-col span="6" class="title-style" @click="onSort(0)">
  18. 训练时长
  19. <div>
  20. <i class="box box-up" :class="{'active': searchArray[0] == 'ASC'}" style="margin-bottom: .03rem;"></i>
  21. <i class="box box-down" :class="{'active': searchArray[0] == 'DESC'}"></i>
  22. </div>
  23. </van-col>
  24. <van-col span="6" class="title-style" @click="onSort(1)">
  25. 训练次数
  26. <div>
  27. <i class="box box-up" :class="{'active': searchArray[1] == 'ASC'}" style="margin-bottom: .03rem;"></i>
  28. <i class="box box-down" :class="{'active': searchArray[1] == 'DESC'}"></i>
  29. </div>
  30. </van-col>
  31. <van-col span="6" class="title-style" @click="onSort(2)">
  32. 训练天数
  33. <div>
  34. <i class="box box-up" :class="{'active': searchArray[2] == 'ASC'}" style="margin-bottom: .03rem;"></i>
  35. <i class="box box-down" :class="{'active': searchArray[2] == 'DESC'}"></i>
  36. </div>
  37. </van-col>
  38. <van-col span="6" class="title-style" @click="onSort(3)">
  39. 评测次数
  40. <div>
  41. <i class="box box-up" :class="{'active': searchArray[3] == 'ASC'}" style="margin-bottom: .03rem;"></i>
  42. <i class="box box-down" :class="{'active': searchArray[3] == 'DESC'}"></i>
  43. </div>
  44. </van-col>
  45. </van-row>
  46. <van-calendar
  47. v-model="showCalendar"
  48. :minDate="minDate"
  49. :default-date="defaultDate"
  50. :first-day-of-week="1"
  51. :formatter="formatterDay"
  52. color="#01C1B5"
  53. type="range"
  54. get-container="body"
  55. @select="selectDate"
  56. @confirm="onConfirm"
  57. @close="onClose"
  58. />
  59. </div>
  60. </template>
  61. <script>
  62. import Search from '@/components/Search';
  63. import dayjs from "dayjs";
  64. import { getNowDateAndMonday, getNowDateAndSunday } from '@/common/common'
  65. export default {
  66. props: {
  67. active: {
  68. type: String,
  69. default: 'all'
  70. },
  71. defaultTime: {
  72. type: Number,
  73. default: 0
  74. }
  75. },
  76. components: { Search },
  77. data() {
  78. return {
  79. showCalendar: false,
  80. minDate: new Date(2000, 0, 1),
  81. defaultDate:[],
  82. // 类型为全部时
  83. startDay: null,
  84. endDay: null,
  85. search: null,
  86. searchArray: [null, null, null, null],
  87. searchType: {
  88. // ASC DESC
  89. totalPlayTime: null,
  90. trainNum: null,
  91. trainDay: null,
  92. recordNum: null,
  93. },
  94. }
  95. },
  96. async mounted() {
  97. let defaultTime = this.defaultTime
  98. let day = defaultTime * 7
  99. let startTime = new Date(), endTime = new Date()
  100. if(day > 0) {
  101. startTime = getNowDateAndMonday(dayjs().add(day, 'day').format("YYYY-MM-DD"))
  102. endTime = getNowDateAndSunday(dayjs().add(day, 'day').format("YYYY-MM-DD"))
  103. } else {
  104. startTime = getNowDateAndMonday(dayjs().subtract(Math.abs(day), 'day').format("YYYY-MM-DD"))
  105. endTime = getNowDateAndSunday(dayjs().subtract(Math.abs(day), 'day').format("YYYY-MM-DD"))
  106. }
  107. this.defaultDate = [new Date(startTime), new Date(endTime)]
  108. this.startDay = startTime
  109. this.endDay = endTime
  110. this.onSort()
  111. },
  112. computed: {
  113. calendarValue() {
  114. return `${dayjs(this.startDay).format("YYYY/MM/DD")} - ${dayjs(this.endDay).format("YYYY/MM/DD")}`;
  115. },
  116. activeType() {
  117. return this.active
  118. }
  119. },
  120. methods: {
  121. onSort(type) {
  122. let searchArray = this.searchArray
  123. searchArray.forEach((item, index) => {
  124. if(index != type) {
  125. searchArray[index] = null
  126. }
  127. });
  128. if(searchArray[type] == 'ASC') {
  129. searchArray[type] = 'DESC'
  130. } else if(searchArray[type] == 'DESC') {
  131. searchArray[type] = null
  132. } else {
  133. searchArray[type] = 'ASC'
  134. }
  135. this.$forceUpdate()
  136. // console.log(searchArray)
  137. this.onAllFilter()
  138. },
  139. onSearch(val) {
  140. this.search = val
  141. this.onAllFilter()
  142. },
  143. onAllFilter() {
  144. const searchArray = this.searchArray
  145. let currentIndex = null
  146. let currentType = null
  147. searchArray.forEach((item, index) => {
  148. if(item) {
  149. currentIndex = index
  150. currentType = item
  151. }
  152. })
  153. const searchType = ['totalPlayTime', 'trainNum', 'trainDay', 'recordNum']
  154. let params = {
  155. search: this.search,
  156. startTime: this.startDay,
  157. endTime: this.endDay,
  158. page: 1,
  159. sort: searchType[currentIndex],
  160. order: currentType
  161. }
  162. this.$listeners.onLoad(params)
  163. },
  164. changeDropDownItemStatus() {
  165. this.$refs.item.toggle(false)
  166. },
  167. selectDate(date) {
  168. let [start, end] = date;
  169. if (start) {
  170. const num = dayjs(start).get("day");
  171. if (num === 0) {
  172. start = dayjs(start).subtract(6, "day");
  173. } else {
  174. start = dayjs(start).subtract(num - 1, "day");
  175. }
  176. }
  177. if (start) {
  178. const num = 7 - dayjs(start).get("day");
  179. if (num < 7) {
  180. end = dayjs(start).add(num, "day");
  181. }
  182. }
  183. this.defaultDate = [new Date(start.valueOf()),new Date(end.valueOf())]
  184. },
  185. onConfirm(date) {
  186. let [start, end] = date;
  187. this.showCalendar = false;
  188. if (start) {
  189. const num = dayjs(start).get("day");
  190. if (num === 0) {
  191. start = dayjs(start).subtract(6, "day");
  192. } else {
  193. start = dayjs(start).subtract(num - 1, "day");
  194. }
  195. }
  196. if (end) {
  197. const num = 7 - dayjs(end).get("day");
  198. if (num < 7) {
  199. end = dayjs(end).add(num, "day");
  200. }
  201. }
  202. this.startDay = dayjs(start).format("YYYY-MM-DD");
  203. this.endDay = dayjs(end).format("YYYY-MM-DD");
  204. //
  205. this.changeDropDownItemStatus()
  206. this.onAllFilter()
  207. },
  208. onClose() {
  209. // 关闭弹窗时初始化默认日期
  210. this.defaultDate = [new Date(this.startDay), new Date(this.endDay)]
  211. },
  212. formatterDay(day) {
  213. const month = day.date.getMonth() + 1;
  214. const date = day.date.getDate();
  215. let nowDate = new Date()
  216. if(month == nowDate.getMonth() + 1 && date == nowDate.getDate()){
  217. day.text = '今天'
  218. }
  219. return day
  220. }
  221. }
  222. }
  223. </script>
  224. <style lang="less" scoped>
  225. /deep/.van-dropdown-menu__title::after {
  226. border-color: transparent transparent #01C1B5 #01C1B5;
  227. }
  228. .calendarColor {
  229. color: #333;
  230. font-size: .14rem;
  231. }
  232. .visit-tips {
  233. background-color: #fff;
  234. // padding: 10px 10px 0;
  235. padding: 10px 12px 0;
  236. text-align: center;
  237. span {
  238. display: block;
  239. padding: 6px 12px;
  240. background-color: #FFF6DE;
  241. font-size: 12px;
  242. color: #FF802C;
  243. text-align: left;
  244. }
  245. }
  246. .searchArray {
  247. font-size: .14rem;
  248. padding-top: .15rem;
  249. padding-bottom: .12rem;
  250. color: #1A1A1A;
  251. background-color: #f5f5f5;
  252. }
  253. .title-style {
  254. display: flex;
  255. align-items: center;
  256. justify-content: center;
  257. }
  258. .box {
  259. display: flex;
  260. flex-direction: row;
  261. align-items: center;
  262. margin-left: .02rem;
  263. }
  264. .box-up {
  265. width: 0;
  266. height: 0;
  267. border-left: 4px solid transparent;
  268. border-right: 4px solid transparent;
  269. border-bottom: 5px solid #ccc;
  270. &.active {
  271. border-bottom-color: #01C1B5;
  272. }
  273. }
  274. .box-down {
  275. width: 0;
  276. height: 0;
  277. border-left: 4px solid transparent;
  278. border-right: 4px solid transparent;
  279. border-top: 5px solid #ccc;
  280. &.active {
  281. border-top-color: #01C1B5;
  282. }
  283. }
  284. </style>