evaluateItem.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. if(res.status == 200){
  47. this.items = res.data
  48. this.onTab(0)
  49. }
  50. })
  51. },
  52. methods:{
  53. onTab(index){
  54. this.activeIndex = index
  55. this.childItems = this.items[index].assessTargetList
  56. this.childItems.map(item=>{
  57. let hasItemIndex = this.checkedList.findIndex(o=>o.id==item.id)
  58. item.checked = hasItemIndex>=0
  59. })
  60. },
  61. chooseItem(item,index){
  62. console.log(item,index)
  63. let hasItemIndex = this.checkedList.findIndex(o=>o.id==item.id)
  64. // 已存在
  65. if(hasItemIndex>=0){
  66. this.checkedList.splice(hasItemIndex,1)
  67. }else{
  68. this.checkedList.push(item)
  69. }
  70. this.childItems[index].checked = !(hasItemIndex>=0)
  71. this.childItems.splice()
  72. },
  73. kpOk(){
  74. uni.$emit('selKpItem',this.checkedList)
  75. uni.navigateBack()
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss">
  81. page{
  82. height: 100%;
  83. background: #F8F8F8;
  84. }
  85. .kp-details{
  86. height: 100%;
  87. display: flex;
  88. flex-direction: column;
  89. .kp-tabsBox{
  90. flex-grow: 1;
  91. display: flex;
  92. .kp-tabs{
  93. width: 30%;
  94. text-align: center;
  95. margin: 15upx;
  96. overflow: auto;
  97. > view{
  98. padding: 15upx;
  99. background: #fff;
  100. border-radius: 6upx;
  101. box-shadow: 1px 2px 3px #eee;
  102. border: 1px solid #eee;
  103. margin-bottom: 15upx;
  104. > view{
  105. &:last-child{
  106. color: #666;
  107. }
  108. }
  109. }
  110. > view.active{
  111. background: #00aaff;
  112. color: #fff;
  113. > view{
  114. &:last-child{
  115. color: #fff;
  116. }
  117. }
  118. }
  119. }
  120. .kp-items{
  121. width: 70%;
  122. margin: 15upx 15upx 15upx 6upx;
  123. overflow: auto;
  124. .checkbox-item{
  125. width:100%;
  126. padding: 15upx;
  127. border-radius: 6upx;
  128. border: 1px solid #eee;
  129. box-shadow: 1px 2px 3px #eee;
  130. background: #fff;
  131. display: flex;
  132. justify-content: space-between;
  133. margin-bottom: 15upx;
  134. }
  135. }
  136. }
  137. .kp-ok{
  138. text-align: center;
  139. padding: 26upx;
  140. background: #55aaff;
  141. color: #fff;
  142. font-size: 18px;
  143. }
  144. }
  145. </style>