chooseEvaluateItem.vue 3.1 KB

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