evaluateItem.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 = opts.item&&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. uni.$emit('selKpItem',this.checkedList)
  69. uni.navigateBack()
  70. }
  71. }
  72. }
  73. </script>
  74. <style lang="scss">
  75. page{
  76. height: 100%;
  77. background: #F8F8F8;
  78. }
  79. .kp-details{
  80. height: 100%;
  81. display: flex;
  82. flex-direction: column;
  83. .kp-tabsBox{
  84. flex-grow: 1;
  85. display: flex;
  86. .kp-tabs{
  87. width: 30%;
  88. text-align: center;
  89. margin: 15upx;
  90. overflow: auto;
  91. > view{
  92. padding: 15upx;
  93. background: #fff;
  94. border-radius: 6upx;
  95. box-shadow: 1px 2px 3px #eee;
  96. border: 1px solid #eee;
  97. margin-bottom: 15upx;
  98. > view{
  99. &:last-child{
  100. color: #666;
  101. }
  102. }
  103. }
  104. > view.active{
  105. background: #00aaff;
  106. color: #fff;
  107. > view{
  108. &:last-child{
  109. color: #fff;
  110. }
  111. }
  112. }
  113. }
  114. .kp-items{
  115. width: 70%;
  116. margin: 15upx 15upx 15upx 6upx;
  117. overflow: auto;
  118. .checkbox-item{
  119. width:100%;
  120. padding: 15upx;
  121. border-radius: 6upx;
  122. border: 1px solid #eee;
  123. box-shadow: 1px 2px 3px #eee;
  124. background: #fff;
  125. display: flex;
  126. justify-content: space-between;
  127. margin-bottom: 15upx;
  128. }
  129. }
  130. }
  131. .kp-ok{
  132. text-align: center;
  133. padding: 26upx;
  134. background: #55aaff;
  135. color: #fff;
  136. font-size: 18px;
  137. }
  138. }
  139. </style>