Select.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <u-popup class="jnpf-tree-select-popup" :maskCloseAble="maskCloseAble" mode="right" v-model="showPopup"
  3. :safeAreaInsetBottom="safeAreaInsetBottom" @close="close" :z-index="uZIndex" width="100%">
  4. <view class="jnpf-tree-select-body">
  5. <view class="jnpf-tree-select-title">
  6. <view class="icon-ym icon-ym-report-icon-preview-pagePre u-font-40 backIcon" @tap="close()"></view>
  7. <view class="title">选择提醒</view>
  8. </view>
  9. <view class="jnpf-tree-select-search">
  10. <u-search :placeholder="$t('app.apply.pleaseKeyword')" v-model="keyword" height="72"
  11. :show-action="false" @change="search()" bg-color="#f0f2f6" shape="square">
  12. </u-search>
  13. </view>
  14. <view class="jnpf-tree-select-tree">
  15. <scroll-view style="height: 100%" :refresher-enabled="false" :refresher-threshold="100"
  16. :scroll-with-animation='true' :refresher-triggered="triggered" @scrolltolower="handleScrollToLower"
  17. :scroll-y="true">
  18. <view class="list-box" v-if="list.length">
  19. <radio-group class="list-item" :value="innerValue" v-for="(item,index) in list" :key="index"
  20. @change="radioChange(item)">
  21. <label class="radio-label">
  22. <radio class="u-radio" :value="item.id" :checked="item.id === selectId" />
  23. <view class="list-item-content u-line-1">{{item.fullName}}</view>
  24. </label>
  25. </radio-group>
  26. </view>
  27. <JnpfEmpty v-else></JnpfEmpty>
  28. </scroll-view>
  29. </view>
  30. <!-- 底部按钮 -->
  31. <view class="jnpf-bottom-actions">
  32. <u-button class="buttom-btn" @click="close()">取消</u-button>
  33. <u-button class="buttom-btn" type="primary" @click.stop="handleConfirm()">确定</u-button>
  34. </view>
  35. </view>
  36. </u-popup>
  37. </template>
  38. <script>
  39. const defaultProps = {
  40. label: 'fullName',
  41. value: 'id',
  42. }
  43. import {
  44. getMsgTemplate
  45. } from '@/api/portal/portal.js'
  46. export default {
  47. props: {
  48. selectType: {
  49. type: String,
  50. default: 'all'
  51. },
  52. clearable: {
  53. type: Boolean,
  54. default: false
  55. },
  56. query: {
  57. type: Object,
  58. default: () => ({})
  59. },
  60. // 是否显示边框
  61. border: {
  62. type: Boolean,
  63. default: true
  64. },
  65. // 通过双向绑定控制组件的弹出与收起
  66. modelValue: {
  67. type: Boolean,
  68. default: false
  69. },
  70. // "取消"按钮的颜色
  71. cancelColor: {
  72. type: String,
  73. default: '#606266'
  74. },
  75. // "确定"按钮的颜色
  76. confirmColor: {
  77. type: String,
  78. default: '#2979ff'
  79. },
  80. // 弹出的z-index值
  81. zIndex: {
  82. type: [String, Number],
  83. default: 99999
  84. },
  85. safeAreaInsetBottom: {
  86. type: Boolean,
  87. default: false
  88. },
  89. // 是否允许通过点击遮罩关闭Picker
  90. maskCloseAble: {
  91. type: Boolean,
  92. default: true
  93. },
  94. //多选
  95. multiple: {
  96. type: Boolean,
  97. default: false
  98. },
  99. // 顶部标题
  100. title: {
  101. type: String,
  102. default: ''
  103. },
  104. // 取消按钮的文字
  105. cancelText: {
  106. type: String,
  107. default: '取消'
  108. },
  109. // 确认按钮的文字
  110. confirmText: {
  111. type: String,
  112. default: '确认'
  113. },
  114. selectedId: {
  115. type: String,
  116. default: ''
  117. },
  118. },
  119. data() {
  120. return {
  121. keyword: '',
  122. selectList: [],
  123. list: [],
  124. pagination: {
  125. currentPage: 1,
  126. pageSize: 20,
  127. messageSource: 4
  128. },
  129. total: 0,
  130. triggered: false,
  131. innerValue: '',
  132. selectId: this.selectedId,
  133. showPopup: false
  134. };
  135. },
  136. watch: {
  137. modelValue: {
  138. immediate: true,
  139. handler(val) {
  140. this.showPopup = val
  141. }
  142. },
  143. },
  144. computed: {
  145. uZIndex() {
  146. // 如果用户有传递z-index值,优先使用
  147. return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
  148. },
  149. realProps() {
  150. return {
  151. ...defaultProps,
  152. }
  153. }
  154. },
  155. methods: {
  156. cleanAll() {
  157. this.selectList = [];
  158. },
  159. radioChange(item) {
  160. this.selectId = item.id;
  161. this.innerValue = item.id;
  162. this.selectList = item
  163. },
  164. search() {
  165. this.searchTimer && clearTimeout(this.searchTimer)
  166. this.searchTimer = setTimeout(() => {
  167. this.resetData()
  168. }, 300)
  169. },
  170. resetData() {
  171. this.list = []
  172. this.pagination = {
  173. currentPage: 1,
  174. pageSize: 20,
  175. messageSource: 4
  176. }
  177. this.upCallback()
  178. },
  179. handleScrollToLower() {
  180. if (this.pagination.pageSize * this.pagination.currentPage < this.total) {
  181. this.pagination.currentPage = this.pagination.currentPage + 1;
  182. this.upCallback()
  183. } else {
  184. uni.showToast({
  185. title: '没有更多信息啦!',
  186. icon: 'none'
  187. });
  188. }
  189. },
  190. upCallback() {
  191. let query = {
  192. currentPage: this.pagination.currentPage,
  193. pageSize: this.pagination.pageSize,
  194. keyword: this.keyword,
  195. messageSource: this.pagination.messageSource
  196. }
  197. this.loading = false
  198. getMsgTemplate(query).then(res => {
  199. const list = res.data.list;
  200. this.list = this.list.concat(list);
  201. this.pagination = res.data.pagination
  202. this.total = this.pagination.total
  203. let item = this.list.filter(o => o.id == this.selectId)[0]
  204. if (item) this.selectList = item
  205. })
  206. },
  207. handleConfirm() {
  208. this.keyword = '';
  209. this.$emit('confirm', this.selectList);
  210. this.close();
  211. },
  212. close() {
  213. this.$emit('close', false);
  214. },
  215. }
  216. };
  217. </script>