index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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" :show-action="false" @change="search"
  7. 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-checkbox-group wrap @change="checkboxGroupChange(item,index)">
  13. <u-checkbox v-model="item.checked">
  14. <view class="u-flex-col fieldContent u-m-l-10">
  15. <view class="fieldList u-line-1 u-flex" v-for="(column,c) in realColumnOptions"
  16. :key="c">
  17. <view class="val">{{column.label+':'}} {{item[column.value]}}</view>
  18. </view>
  19. </view>
  20. </u-checkbox>
  21. </u-checkbox-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. getPopSelect,
  35. getRelationSelect
  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. pageSize: 20
  70. },
  71. cur: null,
  72. firstVal: '',
  73. firstId: 0,
  74. selectId: "",
  75. publicField: '',
  76. selectItem: [],
  77. actionConfig: {},
  78. formData: {},
  79. userInfo: {},
  80. subVal: [],
  81. columnOptions: [],
  82. realColumnOptions: [],
  83. isDynamic: true,
  84. }
  85. },
  86. onLoad(e) {
  87. this.userInfo = uni.getStorageSync('userInfo') || {}
  88. this.onLoadData = JSON.parse(e.data);
  89. this.actionConfig = this.onLoadData.actionConfig
  90. this.isDynamic = this.actionConfig.dataSource == 'dynamic'
  91. this.realColumnOptions = this.actionConfig.columnOptions.filter(o => o.ifShow || o.ifShow === undefined)
  92. this.columnOptions = this.actionConfig.columnOptions.map(o => o.value)
  93. uni.setNavigationBarTitle({
  94. title: this.actionConfig.popupTitle || '选择数据'
  95. })
  96. this.formData = this.onLoadData.formData
  97. this.listQuery.pageSize = this.actionConfig.hasPage && this.isDynamic ? this.actionConfig.pageSize : 10000
  98. uni.$on('refresh', () => {
  99. this.list = [];
  100. this.mescroll.resetUpScroll();
  101. })
  102. },
  103. computed: {
  104. paramList() {
  105. return this.getParamList
  106. }
  107. },
  108. methods: {
  109. upCallback(page) {
  110. const interfaceId = this.actionConfig.interfaceId
  111. const modelId = this.actionConfig.modelId
  112. if (this.isDynamic && !interfaceId) return this.handleEmpty()
  113. if (!this.isDynamic && !modelId) return this.handleEmpty()
  114. let query = {
  115. ...this.listQuery,
  116. currentPage: page.num,
  117. keyword: this.keyword,
  118. columnOptions: this.columnOptions.join(',')
  119. }
  120. if (this.isDynamic) {
  121. query.interfaceId = interfaceId
  122. query.paramList = this.paramList()
  123. } else {
  124. query.modelId = this.actionConfig.modelId
  125. query.relationField = this.actionConfig.relationField
  126. }
  127. const id = this.isDynamic ? interfaceId : modelId
  128. const method = this.isDynamic ? getPopSelect : getRelationSelect
  129. method(id, query, {
  130. load: page.num == 1
  131. }).then(res => {
  132. this.mescroll.endSuccess(res.data.list.length);
  133. if (page.num == 1) this.list = [];
  134. this.list = this.list.concat(res.data.list);
  135. this.list = this.list.map((o, i) => ({
  136. ...o,
  137. checked: false
  138. }))
  139. }).catch(() => {
  140. this.mescroll.endErr();
  141. })
  142. },
  143. handleEmpty() {
  144. this.mescroll.endSuccess(0);
  145. this.mescroll.endErr()
  146. },
  147. getParamList() {
  148. let templateJson = this.actionConfig.templateJson
  149. for (let i = 0; i < templateJson.length; i++) {
  150. templateJson[i].defaultValue = this.formData[templateJson[i].relationField] || ''
  151. if (templateJson[i].jnpfKey === 'createUser') {
  152. templateJson[i].defaultValue = this.userInfo.userId
  153. }
  154. if (templateJson[i].jnpfKey === 'createTime') {
  155. templateJson[i].defaultValue = new Date().getTime()
  156. }
  157. if (templateJson[i].jnpfKey === 'currOrganize') {
  158. templateJson[i].defaultValue = this.userInfo.organizeId
  159. }
  160. if (templateJson[i].jnpfKey === 'currPosition') {
  161. templateJson[i].defaultValue = this.userInfo.positionIds && this.userInfo.positionIds.length ? this
  162. .userInfo.positionIds[0] : ''
  163. }
  164. }
  165. return templateJson
  166. },
  167. checkboxGroupChange(e, index) {
  168. this.selectItem = this.list.filter(o => o.checked)
  169. let subVal = []
  170. for (let i = 0; i < this.selectItem.length; i++) {
  171. const e = this.selectItem[i]
  172. let item = {}
  173. for (let j = 0; j < this.actionConfig.relationOptions.length; j++) {
  174. let row = this.actionConfig.relationOptions[j]
  175. item[row.field] = row.type == 1 ? e[!this.isDynamic ? row.value + '_jnpfId' : row.value] : row
  176. .value
  177. }
  178. subVal.push(item)
  179. }
  180. this.subVal = subVal
  181. },
  182. interfaceDataHandler(data) {
  183. if (!data.dataProcessing) return data.list
  184. const dataHandler = this.jnpf.getScriptFunc(data.dataProcessing)
  185. if (!dataHandler) return data.list
  186. return dataHandler(data.list)
  187. },
  188. radioChange(item) {
  189. this.selectId = item[this.publicField];
  190. this.innerValue = item[this.onLoadData.relationField];
  191. },
  192. handleConfirm() {
  193. uni.$emit('linkPageConfirm', this.subVal, this.onLoadData.tableVmodel)
  194. this.handleClose()
  195. },
  196. handleClose() {
  197. uni.navigateBack();
  198. },
  199. search() {
  200. this.searchTimer && clearTimeout(this.searchTimer)
  201. this.searchTimer = setTimeout(() => {
  202. this.list = [];
  203. this.listQuery.keyword = this.keyword
  204. this.listQuery.currentPage = 1
  205. this.listQuery.pageSize = this.hasPage ? this.pageSize : 10000
  206. this.mescroll.resetUpScroll();
  207. }, 300)
  208. },
  209. }
  210. }
  211. </script>
  212. <style scoped lang="scss">
  213. page {
  214. background-color: #f0f2f6;
  215. }
  216. .jnpf-pop-select {
  217. background-color: #f0f2f6;
  218. width: 100%;
  219. padding-bottom: 90rpx;
  220. .tableList {
  221. overflow: hidden auto;
  222. padding: 0 20rpx;
  223. .list-card {
  224. background-color: #fff;
  225. width: 100%;
  226. border-radius: 8rpx;
  227. margin-top: 20rpx;
  228. padding: 20rpx 20rpx;
  229. align-items: flex-start;
  230. .u-checkbox-group {
  231. width: 100%;
  232. .u-checkbox__label {
  233. .fieldContent {
  234. width: 100%;
  235. .fieldList {
  236. width: 752rpx;
  237. .key {
  238. width: 136rpx;
  239. margin-right: 10rpx;
  240. text-align: right;
  241. overflow: hidden;
  242. white-space: nowrap;
  243. text-overflow: ellipsis;
  244. }
  245. .val {
  246. flex: 0.85;
  247. overflow: hidden;
  248. white-space: nowrap;
  249. text-overflow: ellipsis;
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }
  257. }
  258. </style>