mindlist.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view class="mind">
  3. <!-- tab栏 切孩子 -->
  4. <view class="top ">
  5. <view class="top_t" @click="getTab(ite.val)" :class="[tabval==ite.val?'act':'',daflag?'top_tda':'']" v-for="(ite,idx) in studentlist" :key="idx">{{ite.tit}}<image :src="tapline" class="line"></image></view>
  6. </view>
  7. <view class="pt12">
  8. <xl-list :datype='datype' :datalist="list" :wtdt="wtdt" @getDel="getDel"></xl-list>
  9. </view>
  10. <view style="height: 100rpx;" v-if="checkPermi(['mind:old:add'])&&!daflag"></view>
  11. <view class="mbtn" @click="getAdd" v-if="checkPermi(['mind:old:add'])&&!daflag">更新心理健康状态</view>
  12. </view>
  13. </template>
  14. <script>
  15. import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
  16. import xlList from "@/mine/components/list/list.vue"
  17. import {getmindListFn,getmindDelFn} from "@/api/mine/files.js"
  18. export default {
  19. components:{
  20. xlList
  21. },
  22. data(){
  23. return{
  24. sucimg:require("@/mine/static/score/ncheck.png"),
  25. tapline:require("@/static/images/hline.png"),
  26. list:[],
  27. datype:5,
  28. pageSize: 10,
  29. pageNum: 1,
  30. reachflag: true,
  31. wtdt: '',
  32. tabval:'',
  33. actidx:-1,
  34. daflag:false,
  35. studentlist:[]
  36. }
  37. },
  38. onUnload() {
  39. uni.$off('refreshmindlist')
  40. },
  41. onReachBottom() {
  42. if (this.reachflag) {
  43. this.pageNum++
  44. this.getDataFn()
  45. }
  46. },
  47. onLoad: function(e) {
  48. uni.$on('refreshmindlist', (e) => {
  49. this.reachflag = true;
  50. this.pageNum = 1;
  51. this.list = [];
  52. this.getDataFn();
  53. })
  54. if(e.type&&e.type=='da'){
  55. this.daflag=true;
  56. this.tabval=e.id
  57. this.studentlist=[{
  58. tit:e.name,
  59. val: e.id,
  60. }]
  61. }else{
  62. var roles=this.$store.state.user.choseroles;
  63. var newArr=this.$store.state.user.student;
  64. this.tabval=newArr[0].id
  65. this.studentlist = newArr.map(v => {
  66. return {
  67. tit:v.studentName,
  68. val: v.id,
  69. }
  70. })
  71. }
  72. this.getDataFn()
  73. },
  74. methods:{
  75. checkPermi,checkRole,
  76. getLook(e) {
  77. if (this.actidx == e) {
  78. this.actidx = -1
  79. } else {
  80. this.actidx = e;
  81. }
  82. },
  83. getAdd(){
  84. this.$tab.navigateTo(`/mine/pages/files/mind`)
  85. },
  86. getTab(idx){
  87. this.tabval=idx;
  88. this.list=[];
  89. this.reachflag=true;
  90. this.pageNum=1;
  91. this.getDataFn();
  92. },
  93. getDel(id){
  94. var that=this;
  95. getmindDelFn(id).then(res=>{
  96. if (res.code == 200) {
  97. that.$toast('删除成功')
  98. setTimeout(function(){
  99. that.reachflag = true;
  100. that.pageNum = 1;
  101. that.list = [];
  102. that.getDataFn();
  103. },1500)
  104. } else {
  105. that.$toast(res.msg)
  106. }
  107. })
  108. },
  109. toTree2(arr){
  110. var list=this.list;
  111. let newA = JSON.parse(JSON.stringify(arr));
  112. if(list&&list.length){
  113. list.forEach(ite=>{
  114. for(var i =0;i<newA.length;i++){
  115. if(ite.ayear === newA[i].ayear&&ite.amonth === newA[i].amonth){
  116. ite.children.push(newA[i])
  117. }else{
  118. var obj={
  119. ayear:newA[i].ayear,
  120. amonth:newA[i].amonth,
  121. check:true,
  122. children:[]
  123. }
  124. obj.children.push(newA[i])
  125. list.push(obj)
  126. }
  127. }
  128. })
  129. return list
  130. }else{
  131. var newArrs = [];
  132. var larr=[]
  133. const map = new Map();
  134. newArrs = newA.filter(v => !map.has(v.ayear)&&!map.has(v.amonth) && map.set(v.ayear, 1)&& map.set(v.amonth, 1));
  135. newArrs.forEach(ite=>{
  136. var obj={
  137. ayear:ite.ayear,
  138. amonth:ite.amonth,
  139. check:true
  140. }
  141. larr.push(obj)
  142. })
  143. larr.forEach(ite=>{
  144. ite.children = newA.filter(e => {
  145. return ite.ayear === e.ayear&&ite.amonth === e.amonth
  146. })
  147. })
  148. return larr
  149. }
  150. },
  151. getDataFn(a) {
  152. var params = {
  153. pageSize: this.pageSize,
  154. pageNum: this.pageNum,
  155. studentId:this.tabval
  156. }
  157. getmindListFn(params).then(res => {
  158. if (res.code == 200) {
  159. this.total = res.total;
  160. if (res.rows.length < this.pageSize) {
  161. this.reachflag = false
  162. this.wtdt = '到底了~';
  163. } else {
  164. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -1)
  165. if (num < res.total) {
  166. this.reachflag = true
  167. this.wtdt = '上拉加载更多'
  168. } else {
  169. this.reachflag = false
  170. this.wtdt = '到底了~';
  171. }
  172. }
  173. // 数据处理
  174. var newArr=res.rows;
  175. if(newArr&&newArr.length){
  176. var timeArr=[];
  177. Object.keys(newArr).some((key) => {
  178. var time=newArr[key].createTime.split(' ');
  179. var a=time[0].split('-')
  180. newArr[key].ayear=a[0];
  181. newArr[key].amonth=a[1];
  182. })
  183. this.list=this.toTree2(newArr)
  184. }else{
  185. this.list=[]
  186. }
  187. } else {
  188. this.$toast(res.msg)
  189. }
  190. })
  191. },
  192. },
  193. }
  194. </script>
  195. <style lang="scss" scoped>
  196. .mind{padding: 100rpx 36rpx 0rpx;min-height: 100vh;background-color: #ffffff;box-sizing: border-box;
  197. .mbtn{position: fixed;left: 0;right: 0;bottom: 0;height: 100rpx;display: flex;align-items: center;justify-content: center;z-index: 2;background: #1f57e6;font-size: 34rpx;font-weight: 500;
  198. color: #FFFFFF;}
  199. .top{height: 96rpx;border-bottom: 2rpx solid #E5E5E5;position: fixed;top: 0;left: 0;right: 0;overflow-x: scroll;display: flex;align-items: center;z-index: 1;background-color: #ffffff;
  200. .top_t{position: relative;font-size: 30rpx;font-weight: 500;color: #AAAAAA;height: 94rpx;line-height: 94rpx;padding:0 20rpx;flex:1 0 auto;text-align: center;
  201. &.act{color: #161616;font-weight: bold;
  202. .line{display: block;}
  203. // &::after{content: '';width: 42rpx;height: 10rpx;background: #1f57e6;border-radius: 6rpx;position: absolute;left: 50%;margin-left: -21rpx;bottom: 12rpx;}
  204. }
  205. &.top_tda{flex: 0 0 auto !important;padding: 0 40rpx;}
  206. .line{width: 40rpx;height: 12rpx;position: absolute;left: 50%;margin-left: -20rpx;bottom: 16rpx;display: none;}
  207. }
  208. }
  209. }
  210. </style>