WorkOverChoose.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <view style="width: 100%;">
  3. <u-action-sheet :show="show" @close="onClose">
  4. <view class="cu-bar bg-white">
  5. <view class="action text-blue" @tap="onClose">取消</view>
  6. <view class="action text-green" @tap="selectUsers">确定</view>
  7. </view>
  8. <view style="max-height: 300px; overflow-y: auto;">
  9. <view v-for="item in data" :key="item.id" style="padding: 10px;">
  10. <view @tap="onItemClick(item)" style="display: flex; align-items: center;">
  11. <view style="flex: 1;text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">{{ item.no }}</view>
  12. <view v-if="item.checked" style="color: #409eff;">已选择</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view v-if="!allDataLoaded && !loading" style="text-align: center; padding: 10px;">
  17. <button class="load-more-button" @tap="loadMore">加载更多</button>
  18. </view>
  19. <view v-if="loading" style="text-align: center; padding: 10px;">
  20. Loading...
  21. </view>
  22. </u-action-sheet>
  23. </view>
  24. </template>
  25. <script>
  26. import overService from '@/api/garbageClearance/overService'
  27. export default {
  28. data() {
  29. return {
  30. checkType: '1',
  31. show: false,
  32. labels:'',
  33. index:'',
  34. type:'',
  35. data: [],
  36. localMode: '', // 声明一个本地数据属性
  37. allDataLoaded: false, // 跟踪是否所有数据都已加载
  38. loading: false, // 跟踪加载状态
  39. pageSize: 10, // 每页获取的项目数
  40. currentPage: 1 // 当前页数
  41. };
  42. },
  43. props: {
  44. value: String,
  45. placeholder: {
  46. type: String,
  47. default: '请选择项目'
  48. },
  49. readonly: {
  50. type: Boolean,
  51. default: false
  52. },
  53. disabled: {
  54. type: Boolean,
  55. default: false
  56. },
  57. },
  58. mounted() {
  59. // this.loadData();
  60. },
  61. methods: {
  62. init(index) {
  63. this.pageSize = 10
  64. this.currentPage = 1
  65. this.show = true;
  66. this.index = index;
  67. this.localMode = 'multiple'
  68. this.loadData();
  69. },
  70. onItemClick(item) {
  71. if (this.localMode === 'single') {
  72. this.data.forEach(node => {
  73. node.checked = node === item;
  74. });
  75. } else {
  76. item.checked = !item.checked;
  77. }
  78. },
  79. selectUsers() {
  80. if (this.data.some(item => item.checked)) {
  81. let checkedItems = this.data.filter(item => item.checked).map(item => {
  82. return {
  83. id: item.id,
  84. projectName: item.projectName,
  85. contractName: item.contractName,
  86. projectNumber: item.projectNumber,
  87. contractId: item.contractId,
  88. reportNo: item.reportNo,
  89. isPreInvoice: item.isPreInvoice,
  90. };
  91. });
  92. this.$emit('input', checkedItems, this.index);
  93. this.onClose()
  94. } else {
  95. uni.showToast({
  96. title: '请至少选择一条数据',
  97. icon: 'none',
  98. duration: 2000
  99. });
  100. }
  101. },
  102. loadData() {
  103. this.loading = true; // 开始加载数据,显示loading状态
  104. console.log(3213123)
  105. overService.getNotDisposeList({ status: 1, current: this.currentPage, pageSize: this.pageSize })
  106. .then(data => {
  107. this.loading = false; // 数据加载完成,隐藏loading状态
  108. // 检查新返回的数据是否已经存在,如果存在,则不添加到原始数据数组中
  109. let newData = data.records.filter(record => !this.data.some(item => item.id === record.id));
  110. console.log(newData)
  111. if (this.currentPage === 1) {
  112. // 如果是加载第一页,则直接赋值给 data
  113. this.data = newData.map(item => ({ ...item, checked: false }));
  114. } else {
  115. // 如果不是第一页,则追加到原始数据数组后面
  116. this.data = [...this.data, ...newData.map(item => ({ ...item, checked: false }))];
  117. }
  118. if (data.records.length < this.pageSize) {
  119. this.allDataLoaded = true; // 如果返回的数据少于每页数量,则表示所有数据都已加载
  120. }
  121. if (this.value) {
  122. let keys = this.value.split(',');
  123. this.data.forEach(node => {
  124. if (keys.includes(node.id)) {
  125. node.checked = true;
  126. }
  127. });
  128. this.labels = this.data.filter(node => node.checked).map(node => node.label).join(',');
  129. }
  130. })
  131. .catch(e => {
  132. this.loading = false; // 数据加载失败,隐藏loading状态
  133. throw e;
  134. });
  135. },
  136. loadMore() {
  137. this.currentPage++; // 增加当前页数
  138. this.loadData(); // 加载更多数据
  139. },
  140. onClose() {
  141. // 在关闭操作中清除已选择标记
  142. this.data.forEach(item => {
  143. item.checked = false;
  144. });
  145. this.labels = ''; // 清空标签
  146. this.show = false;
  147. this.data = []; // 清空原始数据
  148. },
  149. checkTypeChange(value){
  150. this.pageSize = 10
  151. this.currentPage = 1
  152. this.data = []; // 清空原始数据
  153. this.loadData(); // 加载更多数据
  154. },
  155. isEmpty(value) {
  156. let result = false;
  157. if (value == null || value == undefined) {
  158. result = true;
  159. }
  160. if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
  161. result = true;
  162. }
  163. if (typeof value == "object" && value instanceof Array && value.length === 0) {
  164. result = true;
  165. }
  166. return result;
  167. },
  168. isNotEmpty (value) {
  169. return !this.isEmpty(value)
  170. },
  171. }
  172. };
  173. </script>
  174. <style scoped>
  175. .load-more-button {
  176. background-color: #409eff;
  177. color: #fff;
  178. border: none;
  179. padding: 10px 20px;
  180. border-radius: 4px;
  181. cursor: pointer;
  182. }
  183. </style>