index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view class="jnpf-pop-select">
  3. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :sticky="true"
  4. :down="downOption" :up="upOption">
  5. <view class="search-box search-box_sticky">
  6. <u-search :placeholder="$t('app.apply.pleaseKeyword')" v-model="keyword" height="72"
  7. :show-action="false" @change="search" bg-color="#f0f2f6" shape="square">
  8. </u-search>
  9. </view>
  10. <view class="u-flex-col tableList">
  11. <view class="u-flex list-card" v-for="(item,index) in list" :key="index">
  12. <u-radio-group v-model="selectId[0]" v-if="!onLoadData.multiple">
  13. <u-radio :name="item[publicField]" @change="radioChange(item)">
  14. <view class="u-flex-col fieldContent u-m-l-10">
  15. <view v-for="(column,c) in onLoadData.columnOptions" :key="c"
  16. class="fieldList u-line-1 u-flex">
  17. <view class="val">{{column.label+':'}} {{item[column.value]}}</view>
  18. </view>
  19. </view>
  20. </u-radio>
  21. </u-radio-group>
  22. </view>
  23. </view>
  24. </mescroll-body>
  25. <!-- 底部按钮 -->
  26. <view class="flowBefore-actions">
  27. <u-button class="buttom-btn" @click.stop="handleClose()">{{$t('common.cancelText')}}</u-button>
  28. <u-button class="buttom-btn" type="primary" @click.stop="handleConfirm()">{{$t('common.okText')}}</u-button>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. getRelationSelect,
  35. getPopSelect
  36. } from '@/api/common.js'
  37. import resources from '@/libs/resources.js'
  38. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  39. export default {
  40. mixins: [MescrollMixin],
  41. data() {
  42. return {
  43. downOption: {
  44. use: true,
  45. auto: true
  46. },
  47. upOption: {
  48. page: {
  49. num: 0,
  50. size: 20,
  51. time: null
  52. },
  53. empty: {
  54. use: true,
  55. icon: resources.message.nodata,
  56. tip: this.$t('common.noData'),
  57. fixed: true,
  58. top: "300rpx",
  59. },
  60. textNoMore: this.$t('app.apply.noMoreData'),
  61. },
  62. list: [],
  63. type: '',
  64. onLoadData: {},
  65. keyword: '',
  66. innerValue: '',
  67. listQuery: {
  68. keyword: ''
  69. },
  70. modelId: '',
  71. cur: null,
  72. firstId: 0,
  73. selectId: [],
  74. publicField: '',
  75. selectRow: [],
  76. columnOptions: []
  77. }
  78. },
  79. onLoad(e) {
  80. try {
  81. this.onLoadData = JSON.parse(decodeURIComponent(e.data));
  82. this.columnOptions = this.onLoadData.columnOptions.map(option => option.value);
  83. this.innerValue = this.onLoadData.innerValue;
  84. this.type = this.onLoadData.type;
  85. this.publicField = this.onLoadData.propsValue;
  86. this.selectId = [this.onLoadData?.id] || []
  87. this.modelId = this.onLoadData.modelId;
  88. // 更新导航栏标题
  89. uni.setNavigationBarTitle({
  90. title: this.onLoadData.popupTitle
  91. });
  92. } catch (error) {
  93. console.error('Error processing data:', error);
  94. }
  95. },
  96. methods: {
  97. upCallback(page) {
  98. const method = this.type === 'popup' ? getPopSelect : getRelationSelect
  99. const paramList = this.onLoadData.paramList
  100. let query = {
  101. ...this.listQuery,
  102. currentPage: page.num,
  103. pageSize: this.onLoadData.hasPage ? this.onLoadData.pageSize : 10000,
  104. interfaceId: this.onLoadData.modelId,
  105. propsValue: this.onLoadData.propsValue,
  106. relationField: this.onLoadData.relationField,
  107. columnOptions: this.columnOptions.join(','),
  108. paramList
  109. }
  110. if (this.type === 'relation') query = {
  111. ...query,
  112. queryType: this.onLoadData.queryType
  113. }
  114. method(this.modelId, query, {
  115. load: page.num == 1
  116. }).then(res => {
  117. if (!this.onLoadData.hasPage) {
  118. this.mescroll.endBySize(res.data.list.length, res.data.pagination.total)
  119. } else {
  120. this.mescroll.endSuccess(res.data.list.length);
  121. }
  122. if (page.num == 1) this.list = [];
  123. this.list = this.list.concat(res.data.list);
  124. if (this.onLoadData.multiple) {
  125. this.list = this.list.map((o, i) => ({
  126. ...o,
  127. checked: false
  128. }))
  129. if (this.selectId.length) this.setSelectValue()
  130. } else {
  131. var index = this.list.findIndex((item) => {
  132. return item[this.publicField] == this.selectId
  133. })
  134. if (index >= 0) this.selectRow = [this.list[index]]
  135. }
  136. }).catch(() => {
  137. this.mescroll.endErr();
  138. })
  139. },
  140. setSelectValue() {
  141. outer: for (let i = 0; i < this.selectId.length; i++) {
  142. inner: for (let j = 0; j < this.list.length; j++) {
  143. if (this.selectId[i] === this.list[j][this.publicField]) {
  144. this.list[j].checked = true
  145. break inner
  146. }
  147. }
  148. }
  149. },
  150. radioChange(item) {
  151. this.selectId = []
  152. this.selectRow = []
  153. this.selectId.push(item[this.publicField]);
  154. this.selectRow.push(item)
  155. },
  156. handleConfirm() {
  157. this.list.map((o, i) => {
  158. if (this.selectId == o[this.publicField]) {
  159. this.firstId = o[this.publicField];
  160. const val = this.type == 'popup' ? o[this.onLoadData.propsValue] : o[this.publicField];
  161. const emit = this.type == 'popup' ? 'popConfirm' : 'relationConfirm'
  162. uni.$emit(emit, val, this.innerValue, this.onLoadData.vModel, this.selectRow[0])
  163. }
  164. })
  165. uni.navigateBack();
  166. },
  167. handleClose() {
  168. this.selectId = ""
  169. uni.navigateBack();
  170. },
  171. search() {
  172. // 节流,避免输入过快多次请求
  173. this.searchTimer && clearTimeout(this.searchTimer)
  174. this.searchTimer = setTimeout(() => {
  175. this.list = [];
  176. this.listQuery.keyword = this.keyword
  177. this.listQuery.currentPage = 1
  178. this.mescroll.resetUpScroll();
  179. }, 300)
  180. },
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. page {
  186. background-color: #f0f2f6;
  187. }
  188. .jnpf-pop-select {
  189. width: 100%;
  190. height: 100%;
  191. padding-bottom: 106rpx;
  192. .tableList {
  193. overflow: hidden auto;
  194. padding: 0 20rpx;
  195. .list-card {
  196. display: flex;
  197. flex-direction: row;
  198. align-items: center;
  199. background-color: #fff;
  200. width: 100%;
  201. border-radius: 8rpx;
  202. margin-top: 20rpx;
  203. padding: 0rpx 20rpx;
  204. min-height: 88rpx;
  205. .fieldContent {
  206. width: 100%;
  207. .fieldList {
  208. width: 752rpx;
  209. .key {
  210. width: 136rpx;
  211. margin-right: 10rpx;
  212. text-align: right;
  213. overflow: hidden;
  214. white-space: nowrap;
  215. text-overflow: ellipsis;
  216. line-height: 60rpx;
  217. }
  218. .val {
  219. flex: 0.85;
  220. overflow: hidden;
  221. white-space: nowrap;
  222. text-overflow: ellipsis;
  223. }
  224. }
  225. }
  226. }
  227. }
  228. .nodata {
  229. margin-top: 258rpx;
  230. justify-content: center;
  231. align-items: center;
  232. image {
  233. width: 280rpx;
  234. height: 215rpx;
  235. }
  236. }
  237. }
  238. </style>