xm-search-form.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <sd-advance-search v-if="initValues.length" @search="search" @reset="reset" @close="close">
  3. <component :is="sdform" ref="form" :init-values="initValues" :class="$style.form">
  4. <template v-slot="{ model }">
  5. <table>
  6. <sd-form-colgroup :columns="6" />
  7. <tr v-for="(row, index) in tableInfo" :key="index">
  8. <sd-form-item-td v-for="item in row" :key="item.name" v-bind="item">
  9. <sdRangeInput
  10. v-if="item.dataType === 'number'"
  11. :max.sync="model[item.name + 'max']"
  12. :min.sync="model[item.name + 'min']"
  13. />
  14. <template v-if="item.attr.selectionType === 'GROUP'">
  15. <sd-group-picker
  16. v-model="model[item.name]"
  17. single
  18. :class="item.attr.includeSub ? $style.dep : ''"
  19. />
  20. <a-checkbox v-if="item.attr.includeSub" v-model="model[item.name + 'includeSub']">
  21. 含子部门
  22. </a-checkbox>
  23. </template>
  24. </sd-form-item-td>
  25. </tr>
  26. </table>
  27. </template>
  28. </component>
  29. </sd-advance-search>
  30. </template>
  31. <script>
  32. import sdAdvanceSearch from '@/application-manage/sd-advance-search.vue'
  33. import sdRangeInput from '@/form-designer/sd-range-input'
  34. import asyncComponent from '@/common/services/async-component'
  35. import runtimeUtil from '@/form-designer/runtime-util'
  36. import components from './_import-components/xm-search-form-import'
  37. export default {
  38. name: 'XmSearchForm',
  39. components: { sdRangeInput, sdAdvanceSearch, ...components },
  40. props: {
  41. onlListColumnDefs: {
  42. type: Array,
  43. default: undefined,
  44. },
  45. },
  46. data() {
  47. return {
  48. sdform: asyncComponent(() =>
  49. import(/* webpackChunkName: "sd-form" */ '@/common/components/sd-form.vue')
  50. ),
  51. customFilterExpressions: [],
  52. }
  53. },
  54. computed: {
  55. initValues() {
  56. return this.onlListColumnDefs
  57. .filter((item) => {
  58. return item.search
  59. })
  60. .map((item) => {
  61. let dataType = item.fieldType.replace(/selectgroup|selectuser/, 'selectperson')
  62. let selectionType = item.fieldAttr?.selectionType || ''
  63. if (item.fieldId === 'CREATOR_NAME') {
  64. // 内置字段创建人创建部门特殊处理下,改成选者器
  65. dataType = 'selectperson'
  66. selectionType = 'User'
  67. }
  68. if (item.fieldId === 'CREATE_DEPT_NAME') {
  69. dataType = 'selectperson'
  70. selectionType = 'Group'
  71. }
  72. let component = runtimeUtil.getRender(item.fieldAttrFD?.cid)
  73. if (dataType === 'date') {
  74. component = 'ARangePicker'
  75. }
  76. if (component === 'a-checkbox-group') {
  77. // 不支持多选,弄成单选
  78. component = 'ARadioGroup'
  79. }
  80. if (component === 'a-textarea') {
  81. component = 'AInput'
  82. }
  83. return {
  84. name: item.fieldId,
  85. attr: {
  86. selectionType,
  87. selectListItem: item.fieldAttr?.selectListItem,
  88. selectTreeItem: item.fieldAttr?.selectTreeItem,
  89. showLevel: item.fieldAttr?.showLevel,
  90. includeSub: item.attrFD.includeSub,
  91. },
  92. caption: item.fieldName,
  93. dataType,
  94. inputProps: { allowClear: true, single: true },
  95. component,
  96. }
  97. })
  98. },
  99. tableInfo() {
  100. const rows = []
  101. this.initValues.forEach((item, index) => {
  102. // 整理成每行三列显示
  103. if (index % 3 === 0) {
  104. rows.push([item])
  105. } else {
  106. rows[rows.length - 1].push(item)
  107. }
  108. })
  109. return rows
  110. },
  111. },
  112. methods: {
  113. search() {
  114. const t = []
  115. const fieldsValue = this.$refs.form.getFieldsValue()
  116. this.initValues.forEach((item) => {
  117. if (fieldsValue[item.name]) {
  118. if (item.dataType === 'string' || item.dataType === 'title') {
  119. t.push({
  120. dataType: 'str',
  121. name: item.name,
  122. op: 'like',
  123. stringValue: '%' + fieldsValue[item.name] + '%',
  124. })
  125. }
  126. if (item.dataType === 'selectlist') {
  127. t.push({
  128. dataType: 'str',
  129. name: item.name,
  130. op: 'eq',
  131. stringValue: fieldsValue[item.name],
  132. })
  133. }
  134. if (item.dataType === 'selecttree' && fieldsValue[item.name].length) {
  135. t.push({
  136. dataType: 'str',
  137. name: item.name,
  138. op: 'eq',
  139. stringValue: fieldsValue[item.name].join(','),
  140. })
  141. }
  142. if (item.dataType === 'selectperson' && fieldsValue[item.name].length) {
  143. let stringValue = fieldsValue[item.name]?.[0]['code']
  144. if (['CREATE_DEPT_NAME', 'CREATOR_NAME'].includes(item.name)) {
  145. // 创建人创建部门存的是就是名称字符串,这里特殊处理下
  146. stringValue = fieldsValue[item.name]?.[0]['name']
  147. } else {
  148. if (item.name.toLowerCase().indexOf('name') > -1) {
  149. // 创建人创建部门存的是就是名称字符串,这里特殊处理下
  150. stringValue = fieldsValue[item.name]?.[0]['name']
  151. } else if (item.name === 'startDept') {
  152. stringValue = fieldsValue[item.name]?.[0]['name']
  153. }
  154. }
  155. t.push({
  156. dataType: 'str',
  157. name: item.name,
  158. op: 'eq',
  159. stringValue: `${
  160. fieldsValue[item.name + 'includeSub'] && item.attr.selectionType === 'GROUP'
  161. ? '@includeSub@'
  162. : ''
  163. }${stringValue}`,
  164. })
  165. }
  166. if (item.dataType === 'date' && fieldsValue[item.name].length) {
  167. t.push({
  168. dataType: 'long',
  169. name: item.name,
  170. op: 'ge',
  171. longValue: new Date(
  172. fieldsValue[item.name][0].format('YYYY-MM-DD') + ' 00:00:00'
  173. ).valueOf(),
  174. })
  175. t.push({
  176. dataType: 'long',
  177. name: item.name,
  178. op: 'le',
  179. longValue: new Date(
  180. fieldsValue[item.name][1].format('YYYY-MM-DD') + ' 23:59:59'
  181. ).valueOf(),
  182. })
  183. }
  184. }
  185. if (item.dataType === 'number') {
  186. if (fieldsValue[item.name + 'min']) {
  187. t.push({
  188. dataType: 'long',
  189. name: item.name,
  190. op: 'ge',
  191. longValue: Number(fieldsValue[item.name + 'min']),
  192. })
  193. }
  194. if (fieldsValue[item.name + 'max']) {
  195. t.push({
  196. dataType: 'long',
  197. name: item.name,
  198. op: 'le',
  199. longValue: Number(fieldsValue[item.name + 'max']),
  200. })
  201. }
  202. }
  203. })
  204. this.$emit('search', t)
  205. },
  206. reset() {
  207. for (const x in this.$refs.form.getFieldsValue()) {
  208. this.$refs.form.setFieldValue(x, undefined)
  209. }
  210. this.search()
  211. },
  212. close() {
  213. this.reset()
  214. this.$emit('close')
  215. },
  216. },
  217. }
  218. </script>
  219. <style module lang="scss">
  220. @use '@/common/design' as *;
  221. .form table {
  222. table-layout: fixed;
  223. }
  224. .dep {
  225. width: calc(100% - 130px);
  226. margin-right: 10px;
  227. }
  228. </style>