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.
 
 
 
 
 
 

248 lines
6.8 KiB

  1. <template>
  2. <view class="page">
  3. <!-- 主列表页 -->
  4. <view :class="sideOpen ? 'show' : ''" class="mainpage" style="padding-top: 80rpx;">
  5. <!-- 顶部条目/分页信息栏 -->
  6. <l-customlist-banner @buttonClick="sideOpen = true">{{ 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.F_InvoiceId">
  12. <view class="customlist-item-field">
  13. <text class="customlist-item-field-title">客户名称:</text>
  14. {{ displayListItem(item, 'F_CustomerId') }}
  15. </view>
  16. <view class="customlist-item-field">
  17. <text class="customlist-item-field-title">开票信息:</text>
  18. {{ displayListItem(item, 'F_InvoiceContent') }}
  19. </view>
  20. <!-- 操作按钮组 -->
  21. <l-customlist-action @view="action('view', item)" @edit="action('edit', item)" showEdit />
  22. </view>
  23. </l-customlist>
  24. </l-scroll-list>
  25. </view>
  26. <!-- 关闭筛选栏按钮 -->
  27. <view @click="sideOpen = false" :class="sideOpen ? 'show' : ''" class="sideclose">
  28. <l-icon type="pullright" color="blue" />
  29. </view>
  30. <!-- 侧边栏 -->
  31. <scroll-view :class="sideOpen ? 'show' : ''" class="sidepage" scroll-y>
  32. <view v-if="ready" class="padding">
  33. <l-input v-model="queryData.keyword" @change="searchChange()" title="内容" placeholder="按内容筛选" />
  34. <view class="padding-tb">
  35. <l-button @click="reset" line="orange" class="block" block>重置筛选条件</l-button>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. <!-- 添加按钮 -->
  40. <l-customlist-add v-if="!sideOpen" @click="action('create')" />
  41. </view>
  42. </template>
  43. <script>
  44. import moment from 'moment'
  45. import get from 'lodash/get'
  46. import set from 'lodash/set'
  47. import pickBy from 'lodash/pickBy'
  48. import mapValues from 'lodash/mapValues'
  49. export default {
  50. data() {
  51. return {
  52. // 表单结构
  53. scheme: {
  54. F_CustomerId: { type: 'select', dataSource: '1', dataSourceId: 'crmCustomer,f_fullname,f_customerid' },
  55. F_InvoiceContent: { type: 'texteditor' }
  56. },
  57. // 筛选菜单值
  58. searchData: {},
  59. defaultQueryData: {},
  60. queryData: {
  61. keyword: ''
  62. },
  63. // 数据源
  64. dataSource: {
  65. F_CustomerId: []
  66. },
  67. // 页面相关参数
  68. ready: false,
  69. tips: '加载中…',
  70. loadState: '向下翻以加载更多',
  71. sideOpen: false,
  72. // 列表条目与分页信息
  73. page: 1,
  74. total: 2,
  75. list: []
  76. }
  77. },
  78. async onLoad() {
  79. await this.init()
  80. },
  81. onUnload() {
  82. this.OFF('invoice-list-change')
  83. },
  84. methods: {
  85. // 页面初始化
  86. async init() {
  87. this.ON('invoice-list-change', this.refreshList)
  88. await Promise.all([
  89. // 加载 F_CustomerId 字段的数据源:客户信息
  90. this.FETCH_DATASOURCE('crmCustomer').then(result => {
  91. this.dataSource.F_CustomerId = result.data.map(t => ({ text: t.f_fullname, value: t.f_customerid }))
  92. }),
  93. // 拉取列表信息
  94. this.fetchList()
  95. ])
  96. this.defaultQueryData = this.COPY(this.queryData)
  97. this.ready = true
  98. },
  99. // 拉取列表
  100. async fetchList() {
  101. if (this.page > this.total) {
  102. return
  103. }
  104. const result = await this.HTTP_GET(
  105. '/crm/invoice/list',
  106. {
  107. pagination: { rows: 10, page: this.page, sidx: 'F_CreateDate', sord: 'DESC' },
  108. queryJson: JSON.stringify(this.searchData)
  109. },
  110. '加载数据时出错'
  111. )
  112. if (!result) {
  113. return
  114. }
  115. this.total = result.total
  116. this.page = result.page + 1
  117. this.list = this.list.concat(result.rows)
  118. this.tips = `已加载 ${Math.min(result.page, result.total)} / ${result.total} 页,共 ${result.records} 项`
  119. this.loadState = result.page >= result.total ? '已加载所有项目' : '向下翻以加载更多'
  120. },
  121. // 刷新清空列表
  122. async refreshList() {
  123. this.page = 1
  124. this.total = 2
  125. this.list = []
  126. await this.fetchList()
  127. },
  128. // 列表下拉
  129. pullDown() {
  130. this.refreshList().then(() => {
  131. this.$refs.list.stopPullDown()
  132. })
  133. },
  134. // 点击「编辑」、「查看」、「添加」、「删除」按钮
  135. action(type, item) {
  136. switch (type) {
  137. default:
  138. case 'create':
  139. this.NAV_TO('./single?type=create')
  140. return
  141. case 'view':
  142. this.NAV_TO('./single?type=view', item, true)
  143. return
  144. case 'edit':
  145. this.NAV_TO('./single?type=edit', item, true)
  146. return
  147. }
  148. },
  149. // 显示列表中的标题项
  150. displayListItem(item, field) {
  151. const fieldItem = this.scheme[field]
  152. const value = item[field]
  153. switch (fieldItem.type) {
  154. case 'currentInfo':
  155. case 'organize':
  156. switch (fieldItem.dataType) {
  157. case 'user':
  158. return get(this.GET_GLOBAL('user'), `${value}.name`, '')
  159. case 'department':
  160. return get(this.GET_GLOBAL('department'), `${value}.name`, '')
  161. case 'company':
  162. return get(this.GET_GLOBAL('company'), `${value}.name`, '')
  163. default:
  164. return value || ''
  165. }
  166. case 'radio':
  167. case 'select':
  168. const selectItem = this.dataSource[field].find(t => t.value === value)
  169. return get(selectItem, 'text', '')
  170. case 'checkbox':
  171. if (!value || value.split(',').length <= 0) {
  172. return ''
  173. }
  174. const checkboxItems = value.split(',')
  175. return this.dataSource[field]
  176. .filter(t => checkboxItems.includes(t.value))
  177. .map(t => t.text)
  178. .join(',')
  179. case 'datetime':
  180. if (!value) {
  181. return ''
  182. }
  183. return moment(value).format(Number(fieldItem.dateformat) === 0 ? 'YYYY年 M月 D日' : 'YYYY-MM-DD HH:mm')
  184. default:
  185. return value || ''
  186. }
  187. },
  188. // 设置搜索条件
  189. async searchChange() {
  190. const result = {}
  191. const queryObj = pickBy(this.queryData, t => (Array.isArray(t) ? t.length > 0 : t))
  192. Object.assign(result, mapValues(queryObj, t => (Array.isArray(t) ? t.join(',') : t)))
  193. this.searchData = result
  194. await this.refreshList()
  195. },
  196. // 点击「清空搜索条件」按钮
  197. reset() {
  198. this.queryData = this.COPY(this.defaultQueryData)
  199. this.searchChange()
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="less" scoped>
  205. @import '~@/common/css/sidepage.less';
  206. @import '~@/common/css/customlist.less';
  207. </style>