evaluateItem.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. <!-- 选择按钮 -->
  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. if(this.checkedList.length){
  69. uni.$emit('selKpItem',this.checkedList)
  70. uni.navigateBack()
  71. }else{
  72. uni.showToast({
  73. icon:'none',
  74. title:'请选择考评指标'
  75. })
  76. }
  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>