You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 4 години
преди 2 години
преди 4 години
преди 2 години
преди 4 години
преди 2 години
преди 4 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="page">
  3. <!-- 主列表页 -->
  4. <view class="mainpage" style="padding-top: 80rpx; height: calc(100vh - var(--window-top));">
  5. <!-- 顶部条目/分页信息栏 -->
  6. <l-customlist-banner :buttonShow="false">{{ tips }}</l-customlist-banner>
  7. <!-- 滚动列表,跨端支持上拉/下拉 -->
  8. <l-scroll-list v-if="ready" @pullDown="pullDown" @toBottom="fetchList()" ref="list">
  9. <l-customlist :tips="loadState" showTips>
  10. <!-- 单条记录 -->
  11. <view class="customlist-item" v-for="item of list" :key="item[primaryKey]">
  12. <!-- 主字段 -->
  13. <view v-for="scheme of mainSchemes" :key="scheme" class="customlist-item-field margin-bottom-sm">
  14. <text class="customlist-item-field-title">{{ scheme.title }}:</text>
  15. {{ displayListItem(item, scheme) }}
  16. </view>
  17. <!-- 副字段 -->
  18. <view v-for="scheme of subSchemes" :key="scheme" class="customlist-item-field" style="font-size: 0.9em;">
  19. <text class="customlist-item-field-title">{{ scheme.title }}:</text>
  20. {{ displayListItem(item, scheme) }}
  21. </view>
  22. <!-- 操作区 -->
  23. <l-customlist-action
  24. @view="action('view', item[primaryKey])"
  25. @edit="action('edit', item[primaryKey])"
  26. @delete="action('delete', item[primaryKey])"
  27. showEdit
  28. showDelete
  29. />
  30. </view>
  31. </l-customlist>
  32. </l-scroll-list>
  33. </view>
  34. <l-customlist-add @click="action('create')" />
  35. </view>
  36. </template>
  37. <script>
  38. import get from 'lodash/get'
  39. import moment from 'moment'
  40. import customFormMixins from '@/common/customform.js'
  41. export default {
  42. mixins: [customFormMixins],
  43. data() {
  44. return {
  45. formId: '',
  46. formScheme: {},
  47. dataSource: {},
  48. // 主键
  49. primaryKey: '',
  50. // 主副字段
  51. mainSchemes: [],
  52. subSchemes: [],
  53. // 分页
  54. page: 1,
  55. total: 2,
  56. list: [],
  57. // 页面相关参数
  58. ready: false,
  59. tips: '加载中…',
  60. loadState: '向下翻以加载更多'
  61. }
  62. },
  63. async onLoad({ formId }) {
  64. await this.init(formId)
  65. },
  66. onUnload() {
  67. this.OFF('custom-list-change')
  68. },
  69. methods: {
  70. // 初始化页面
  71. async init(formId) {
  72. this.ON('custom-list-change', this.refreshList)
  73. // 加载页面参数(列表 scheme)
  74. this.formId = formId
  75. const pageInfo = this.GET_PARAM()
  76. const listScheme = JSON.parse(pageInfo.F_Scheme)
  77. this.SET_TITLE(pageInfo.F_Name)
  78. // 拉取表单结构(表单 scheme),提取出主、副字段
  79. const formScheme = await this.fetchFormScheme()
  80. const scheme = formScheme.F_Scheme
  81. const mainTitleIds = listScheme.title.split(',')
  82. const subTitleIds = listScheme.content.filter(Boolean)
  83. // 提取主表、主键信息
  84. const mainTable = scheme.dbTable.find(t => !t.relationName)
  85. const tableName = mainTable.name
  86. this.primaryKey = `${mainTable.field.toLowerCase()}${scheme.dbTable.findIndex(t => !t.relationName)}`
  87. this.formScheme = formScheme
  88. // 依次提取主副显示字段的 scheme,并生成它们的 dataSource
  89. const mainSchemes = []
  90. const subSchemes = []
  91. for (let tableIndex = 0; tableIndex < scheme.data.length; ++tableIndex) {
  92. const { componts } = scheme.data[tableIndex]
  93. componts.forEach(t => {
  94. if (t.table === tableName) {
  95. if (mainTitleIds.includes(t.id)) {
  96. mainSchemes.push({ ...t, __path__: `${t.field.toLowerCase()}${tableIndex}` })
  97. } else if (subTitleIds.includes(t.id)) {
  98. subSchemes.push({ ...t, __path__: `${t.field.toLowerCase()}${tableIndex}` })
  99. }
  100. }
  101. })
  102. }
  103. this.mainSchemes = mainSchemes
  104. this.subSchemes = subSchemes
  105. this.dataSource = await this.fetchDataSource([...mainSchemes, ...subSchemes])
  106. this.ready = true
  107. await this.fetchList()
  108. },
  109. // 拉取列表
  110. async fetchList() {
  111. if (this.page > this.total) {
  112. return
  113. }
  114. const result = await this.HTTP_GET(
  115. 'learun/adms/custmer/pagelist',
  116. {
  117. pagination: { rows: 10, page: this.page, sidx: this.primaryKey, sord: 'ASC' },
  118. queryJson: JSON.stringify({}),
  119. formId: this.formId
  120. },
  121. '加载数据时出错'
  122. )
  123. if (!result) {
  124. return
  125. }
  126. this.total = result.total
  127. this.page = result.page + 1
  128. this.list = this.list.concat(result.rows)
  129. this.tips = `已加载 ${Math.min(result.page, result.total)} / ${result.total} 页,共 ${result.records} 项`
  130. this.loadState = result.page >= result.total ? '已加载所有项目' : '向下翻以加载更多'
  131. },
  132. // 刷新清空列表
  133. async refreshList() {
  134. this.page = 1
  135. this.total = 2
  136. this.list = []
  137. await this.fetchList()
  138. },
  139. // 拉取自定义应用的定义 JSON
  140. async fetchFormScheme() {
  141. const result = await this.HTTP_GET('learun/adms/form/scheme', [{ id: this.formId, ver: '' }])
  142. const scheme = result[this.formId]
  143. scheme.F_Scheme = JSON.parse(scheme.F_Scheme)
  144. return scheme
  145. },
  146. // 拉取自定义应用需要数据源的字段的数据源
  147. async fetchDataSource(schemes) {
  148. const dsObj = {}
  149. for (const scheme of schemes) {
  150. const dsItem = await this.getSourceData(scheme)
  151. if (dsItem) {
  152. dsObj[scheme.field] = dsItem
  153. }
  154. }
  155. return dsObj
  156. },
  157. // 点击打开/编辑按钮
  158. async action(type = 'create', id = 'no') {
  159. switch (type) {
  160. default:
  161. case 'create':
  162. case 'view':
  163. case 'edit':
  164. this.NAV_TO(`./single?type=${type}&id=${id}`, this.formScheme, true)
  165. break
  166. case 'delete':
  167. if (!(await this.CONFIRM('删除项目', '确定要删除该项吗?', true))) {
  168. return
  169. }
  170. this.LOADING('提交删除中…')
  171. this.HTTP_POST('learun/adms/form/delete', { schemeInfoId: this.formId, keyValue: id }, '删除失败').then(success => {
  172. this.HIDE_LOADING()
  173. if (!success) {
  174. return
  175. }
  176. this.TOAST('删除成功', 'success')
  177. this.refreshList()
  178. })
  179. break
  180. }
  181. },
  182. // 列表下拉
  183. pullDown() {
  184. this.refreshList().then(() => {
  185. this.$refs.list.stopPullDown()
  186. })
  187. },
  188. // 获取自定义应用表单项的值
  189. displayListItem(item, scheme) {
  190. const value = item[scheme.__path__]
  191. const field = scheme.field
  192. switch (scheme.type) {
  193. case 'currentInfo':
  194. case 'organize':
  195. switch (scheme.dataType) {
  196. case 'user':
  197. return get(this.GET_GLOBAL('user'), `${value}.name`, '')
  198. case 'department':
  199. return get(this.GET_GLOBAL('department'), `${value}.name`, '')
  200. case 'company':
  201. return get(this.GET_GLOBAL('company'), `${value}.name`, '')
  202. default:
  203. return value || ''
  204. }
  205. case 'radio':
  206. case 'select':
  207. const selectItem = this.dataSource[field].find(t => t.value === value)
  208. return get(selectItem, 'text', '')
  209. case 'checkbox':
  210. if (!value || value.split(',').length <= 0) {
  211. return ''
  212. }
  213. const checkboxItems = value.split(',')
  214. return this.dataSource[field]
  215. .filter(t => checkboxItems.includes(t.value))
  216. .map(t => t.text)
  217. .join(',')
  218. case 'datetime':
  219. if (!value) {
  220. return ''
  221. }
  222. return moment(value).format(Number(scheme.dateformat) === 0 ? 'YYYY年 M月 D日' : 'YYYY-MM-DD HH:mm')
  223. default:
  224. return value || ''
  225. }
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang="less" scoped>
  231. @import '~@/common/css/customlist.less';
  232. </style>