addCheck.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="addCheck">
  3. <van-nav-bar
  4. title="添加检查手册"
  5. left-arrow
  6. @click-left="onClickLeft"
  7. />
  8. <div class="addCheck-container">
  9. <div class="search-flex">
  10. <van-search v-model="query.key" placeholder="请输入检查内容" @change="refreshData"/>
  11. <select-cell title="选择检查内容库" is-all v-model="query.ruleId" :dataList="ruleList" :prop="prop" @change="refreshData"/>
  12. </div>
  13. <div class="card-list">
  14. <Scroll
  15. ref="Scroll"
  16. @refresh="refreshData"
  17. @loadMore="getDataList"
  18. :pullup="pullup">
  19. <empty v-if="!dataList || dataList.length === 0" />
  20. <div v-else class="list-item">
  21. <van-cell
  22. :class="{'active':item.checked}"
  23. v-for="(item, index) in dataList"
  24. clickable
  25. :key="item.id"
  26. :title="item.itemName"
  27. :label="item.pointName"
  28. @click="click(item,index)">
  29. <template #right-icon>
  30. <van-checkbox v-model="item.checked"/>
  31. </template>
  32. </van-cell>
  33. </div>
  34. </Scroll>
  35. </div>
  36. <div>
  37. <van-button type="info" size="large" @click="addItem">确认选中</van-button>
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. import NavBar from '@/components/NavBar'
  44. import SelectCell from '@/components/selectCell'
  45. import Scroll from '@/components/scroll/scroll'
  46. import {checkItemList,checkList} from './api'
  47. export default {
  48. name: "addCheck",
  49. components: {
  50. NavBar,
  51. Scroll,
  52. SelectCell,
  53. },
  54. props:["orgType"],
  55. data(){
  56. return {
  57. id:null,
  58. query:{
  59. key:'',
  60. ruleId:null,
  61. pageNum:1,
  62. pageSize:10,
  63. },
  64. dataList:[],
  65. ruleList:[],
  66. selected:[],
  67. //获取到所有的ruleId集合
  68. ruleIdList:[],
  69. prop:{
  70. label:'name',
  71. value:'id'
  72. },
  73. pullup:false,
  74. }
  75. },
  76. mounted(){
  77. this.id = this.$route.query.id;
  78. this.getCheckItem();
  79. },
  80. methods:{
  81. onClickLeft(){
  82. this.$emit('goBack')
  83. },
  84. refreshData(){
  85. this.pullup = true;
  86. this.query.pageNum = 1;
  87. this.total = 0;
  88. this.dataList = [];
  89. this.getDataList();
  90. },
  91. click(v,i){
  92. this.$set(this.dataList[i],'checked',!this.dataList[i].checked);
  93. },
  94. addItem(){
  95. this.selected = this.dataList.filter(v=>v.checked);
  96. if(this.selected.length === 0) return this.$toast('请选择检查项');
  97. this.$emit('addItem',this.selected);
  98. },
  99. getCheckItem(){
  100. let data = {orgType:this.orgType};
  101. checkItemList(data).then(res=>{
  102. this.ruleList = res.data;
  103. this.ruleIdList = res.data.map(v=>{return v.id});
  104. this.getDataList()
  105. })
  106. },
  107. getDataList(){
  108. if( this.dataList.length !== 0 && this.dataList.length >= this.total) {
  109. this.pullup = false;
  110. this.$toast('已加载完毕');
  111. return;
  112. }
  113. let data = JSON.parse(JSON.stringify(this.query));
  114. data.ruleId = this.query.ruleId || this.ruleIdList;
  115. checkList(data).then(res=>{
  116. if(res.total === '0'){
  117. this.pullup = false;
  118. this.$toast('已加载完毕');
  119. return
  120. }
  121. res.rows.forEach(v=>{
  122. v.isAdd = 1;
  123. v.checked = false;
  124. v.pointId = v.id;
  125. v.status = 0;
  126. if(!v.nfcList) v.nfcList = [];
  127. });
  128. this.total = res.total;
  129. if(this.dataList.length < res.total) {
  130. this.dataList = [...this.dataList,...res.rows] ;
  131. this.pullup = true;
  132. this.query.pageNum++;
  133. this.$refs.Scroll.refresh();
  134. }
  135. })
  136. },
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .addCheck{
  142. .card-list{
  143. padding: 20px 0;
  144. height: calc(100vh - 424px);
  145. overflow: auto;
  146. }
  147. .active{
  148. color:#1989fa;
  149. }
  150. }
  151. </style>