evaluateItem.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="kp-details">
  3. <!-- 考评项 -->
  4. <view class="kp-tabsBox">
  5. <view class="kp-tabs">
  6. <view @click="onTab(index)" :class="activeIndex == index ? 'active':''" v-for="(item,index) in items" :key="item.id">
  7. <view>{{item.name}}</view>
  8. <view>({{item.assessTargetNum}}项)</view>
  9. </view>
  10. </view>
  11. <view class="kp-items">
  12. <view v-for="(item,index) in childItems" :key="item.id" @click="chooseItem(item,index)" class="checkbox-item">
  13. <view class="item-name">{{item.name}}</view>
  14. <view>
  15. <checkbox :value="item.id" :checked="item.checked" />
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 选择按钮 -->
  21. <view class="kp-ok" @click="kpOk">
  22. 确定选择
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import {findAllItem} from '@/api/assess'
  28. export default{
  29. data(){
  30. return{
  31. items: [],
  32. activeIndex:0,
  33. childItems:[],
  34. checkedList:[]
  35. }
  36. },
  37. onLoad(opts) {
  38. this.checkedList = JSON.parse(opts.item) || []
  39. findAllItem().then(res=>{
  40. if(res.status == 200){
  41. this.items = res.data
  42. this.onTab(0)
  43. }
  44. })
  45. },
  46. methods:{
  47. onTab(index){
  48. this.activeIndex = index
  49. this.childItems = this.items[index].assessTargetList
  50. this.childItems.map(item=>{
  51. let hasItemIndex = this.checkedList.findIndex(o=>o.id==item.id)
  52. item.checked = hasItemIndex>=0
  53. })
  54. },
  55. chooseItem(item,index){
  56. console.log(item,index)
  57. let hasItemIndex = this.checkedList.findIndex(o=>o.id==item.id)
  58. // 已存在
  59. if(hasItemIndex>=0){
  60. this.checkedList.splice(hasItemIndex,1)
  61. }else{
  62. this.checkedList.push(item)
  63. }
  64. this.childItems[index].checked = !(hasItemIndex>=0)
  65. this.childItems.splice()
  66. },
  67. kpOk(){
  68. console.log(this.checkedList)
  69. uni.$emit('selKpItem',{msg:this.checkedList})
  70. uni.navigateBack()
  71. }
  72. }
  73. }
  74. </script>
  75. <style lang="scss">
  76. page{
  77. height: 100%;
  78. background: #F8F8F8;
  79. }
  80. .kp-details{
  81. height: 100%;
  82. display: flex;
  83. flex-direction: column;
  84. .kp-tabsBox{
  85. flex-grow: 1;
  86. display: flex;
  87. .kp-tabs{
  88. width: 30%;
  89. text-align: center;
  90. margin: 15upx;
  91. overflow: auto;
  92. > view{
  93. padding: 15upx;
  94. background: #fff;
  95. border-radius: 6upx;
  96. box-shadow: 1px 2px 3px #eee;
  97. border: 1px solid #eee;
  98. margin-bottom: 15upx;
  99. > view{
  100. &:last-child{
  101. color: #666;
  102. }
  103. }
  104. }
  105. > view.active{
  106. background: #00aaff;
  107. color: #fff;
  108. > view{
  109. &:last-child{
  110. color: #fff;
  111. }
  112. }
  113. }
  114. }
  115. .kp-items{
  116. width: 70%;
  117. margin: 15upx 15upx 15upx 6upx;
  118. overflow: auto;
  119. .checkbox-item{
  120. width:100%;
  121. padding: 15upx;
  122. border-radius: 6upx;
  123. border: 1px solid #eee;
  124. box-shadow: 1px 2px 3px #eee;
  125. background: #fff;
  126. display: flex;
  127. justify-content: space-between;
  128. margin-bottom: 15upx;
  129. }
  130. }
  131. }
  132. .kp-ok{
  133. text-align: center;
  134. padding: 26upx;
  135. background: #55aaff;
  136. color: #fff;
  137. font-size: 18px;
  138. }
  139. }
  140. </style>