index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <u-popup :show="isShow" @close="close" :closeOnClickOverlay="true">
  3. <view class="container">
  4. <view class="search">
  5. <u-row>
  6. <u-col :span="2" v-if="multiple">
  7. <view class="all-choosed">
  8. <image
  9. @click="handleChooseAll"
  10. :src="allChecked?'/static/icon/choosed.png':'/static/icon/nochoose.png'"
  11. class="choosed-image">
  12. </image>
  13. 全选
  14. </view>
  15. </u-col>
  16. <u-col :span="!multiple?12:10">
  17. <u-search
  18. v-model="search.text"
  19. placeholder="关键字搜索"
  20. @search="handleSearch"
  21. @custom="handleSearch"
  22. >
  23. </u-search>
  24. </u-col>
  25. </u-row>
  26. </view>
  27. <view class="last">
  28. <u-button type="primary" :plain="true" :disabled="page==1" @click="handleLast">
  29. <u-icon name="arrow-up" color="#2979ff" size="28"></u-icon>
  30. </u-button>
  31. </view>
  32. <view class="list">
  33. <template v-for="(item,index) in showList">
  34. <view class="item" :key="index"
  35. @click="handleClick(item)"
  36. >
  37. <image
  38. v-if="multiple"
  39. :src="item.checked?'/static/icon/choosed.png':'/static/icon/nochoose.png'"
  40. class="choosed-image">
  41. </image>
  42. <image
  43. v-if="item.icon"
  44. :src="item.icon"
  45. class="icon-image">
  46. </image>
  47. <view>
  48. <view class="item-value">
  49. {{item.deptName}}
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <view class="empty" v-if="showList.length==0">暂无数据</view>
  55. </view>
  56. <view class="next">
  57. <u-button type="primary" :plain="true" :disabled="page==totalPage" @click="handleNext">
  58. <u-icon name="arrow-down" color="#2979ff" size="28"></u-icon>
  59. </u-button>
  60. </view>
  61. </view>
  62. </u-popup>
  63. </template>
  64. <script>
  65. import {isArray,clone } from 'lodash'
  66. import {commonDeptAll} from '@/api/common/system.js'
  67. import {getImages} from '@/plugins/images'
  68. //资源引入
  69. let shujiegou = getImages('/assetsMobile/images/common/shujiegou.png') //行驶在线
  70. export default {
  71. props: {
  72. //单页展示数据量
  73. size: {
  74. type: Number,
  75. default: 30
  76. },
  77. // 多选
  78. multiple: {
  79. type: Boolean,
  80. default: false
  81. },
  82. },
  83. data() {
  84. return {
  85. allChecked: false,
  86. isShow: false,
  87. loadding: false,
  88. page: 1,
  89. total: 0,
  90. totalPage: 0,
  91. search: {
  92. text: ''
  93. },
  94. orginList: [],
  95. resultList: [], //搜索结果集合
  96. showList: [],
  97. }
  98. },
  99. mounted() {
  100. this.getData()
  101. },
  102. methods: {
  103. show() {
  104. this.isShow= true;
  105. },
  106. handleChooseAll() {
  107. this.allChecked = !this.allChecked
  108. this.resultList.map(e => {
  109. e.checked = this.allChecked
  110. })
  111. },
  112. computeCheckedData() {
  113. let allLength = this.resultList.length
  114. let checedLength = this.resultList.filter((e) => e.checked).length
  115. if(allLength == checedLength) {
  116. this.allChecked = true
  117. } else {
  118. this.allChecked = false
  119. }
  120. },
  121. getChoosed() {
  122. let data = this.orginList.filter((e) => e.checked)
  123. this.$emit('confirm',data)
  124. },
  125. handleClick(e) {
  126. if(this.multiple) {
  127. e.checked=!e.checked
  128. this.computeCheckedData()
  129. } else {
  130. console.log(e,'e')
  131. this.$emit('confirm',e);
  132. this.isShow = false;
  133. }
  134. },
  135. handleSearch() {
  136. this.page = 1
  137. if(this.search.text) {
  138. this.resultList = this.orginList.filter((e) => e.deptName.includes(this.search.text) || e.deptName.includes(this.search.text))
  139. } else {
  140. this.resultList = clone(this.orginList)
  141. }
  142. this.computeCheckedData()
  143. this.totalPage = Math.ceil(this.resultList.length / this.size)
  144. this.handlePageData()
  145. },
  146. //上一页
  147. handleLast() {
  148. if(this.page != 1) this.page -= 1;
  149. this.handlePageData()
  150. },
  151. //下一页
  152. handleNext() {
  153. if(this.page != this.totalPage) this.page += 1;
  154. this.handlePageData()
  155. },
  156. //处理分页数据
  157. handlePageData() {
  158. let index = (this.page - 1) * this.size
  159. this.showList = clone(this.resultList).splice(index,this.size)
  160. },
  161. getData() {
  162. let that = this;
  163. this.loadding = true;
  164. commonDeptAll({
  165. }).then((res) => {
  166. if(isArray(res.data)) {
  167. res.data.forEach((item) => {
  168. let obj = {
  169. ...item,
  170. icon: shujiegou,
  171. checked: false,
  172. }
  173. this.orginList.push(obj);
  174. })
  175. this.$emit('onDataLoad',this.orginList)
  176. this.handleSearch()
  177. } else {
  178. this.orginList = [];
  179. this.showList = [];
  180. this.page = 1
  181. this.totalPage = 0
  182. }
  183. }).finally(() => {
  184. this.loadding = false
  185. })
  186. },
  187. close() {
  188. if(this.multiple) this.getChoosed()
  189. this.isShow = false
  190. },
  191. }
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. /* 内容satrt */
  196. .container {
  197. background: #fff;
  198. .search {
  199. padding: 20rpx 40rpx 20rpx 40rpx;
  200. .all-choosed {
  201. display: flex;
  202. justify-content: flex-start;
  203. align-items: center;
  204. font-size: 24rpx;
  205. }
  206. }
  207. .list {
  208. height: calc(100vh - 400rpx);
  209. padding: 0 20rpx;
  210. overflow-y: auto;
  211. .item {
  212. padding: 16rpx 20rpx;
  213. display: flex;
  214. align-items: center;
  215. .item-value {
  216. font-size: 28rpx;
  217. }
  218. .item-label {
  219. font-size: 28rpx;
  220. }
  221. // border-bottom: 2rpx solid #ddd;
  222. }
  223. .empty {
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. height: calc(100vh - 400rpx);
  228. color: #909193;
  229. min-height: 800rpx;
  230. }
  231. }
  232. .last,.next {
  233. margin: 10rpx 40rpx;
  234. display: flex;
  235. justify-content: center;
  236. align-items: center;
  237. }
  238. }
  239. /* 内容end */
  240. .choosed-image {
  241. width: 40rpx;
  242. height: 40rpx;
  243. margin-right: 10rpx;
  244. }
  245. .icon-image {
  246. width: 30rpx;
  247. height: 30rpx;
  248. margin-right: 10rpx;
  249. }
  250. </style>