CustomFormSelectModal.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1000"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. class="ant-modal2"
  8. @cancel="handleCancel"
  9. >
  10. <a-card :bordered="false">
  11. <div class="table-page-search-wrapper">
  12. <a-form layout="inline">
  13. <a-row :gutter="48">
  14. <a-col :md="6" :sm="24">
  15. <a-form-item label="关键字">
  16. <a-input v-model="queryParam.keyword" placeholder="请输入名称/类型名称"/>
  17. </a-form-item>
  18. </a-col>
  19. <a-col :md="6 || 24" :sm="24">
  20. <span class="table-page-search-submitButtons">
  21. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  22. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  23. <a @click="()=>{ this.advanced = !this.advanced}" style="margin-left: 8px">
  24. {{ advanced ? '收起' : '展开' }}
  25. <a-icon :type="advanced ? 'up' : 'down'"/>
  26. </a>
  27. </span>
  28. </a-col>
  29. </a-row>
  30. </a-form>
  31. </div>
  32. <div class="table-operator">
  33. </div>
  34. <s-table
  35. ref="table"
  36. size="default"
  37. rowKey="id"
  38. :columns="columns"
  39. :data="loadData"
  40. :alert="options.alert"
  41. :customRow="options.customRow"
  42. :rowSelection="options.rowSelection"
  43. showPagination="auto"
  44. >
  45. <span slot="action" slot-scope="record1">
  46. <template>
  47. <a @click="handleView(record1)">查看</a>
  48. </template>
  49. </span>
  50. </s-table>
  51. <detail ref="detailModal"/>
  52. </a-card>
  53. <template slot="footer">
  54. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  55. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">确定</a-button>
  56. </template>
  57. </a-modal>
  58. </template>
  59. <script>
  60. import { STable, Ellipsis } from '@/components'
  61. import Detail from './Detail'
  62. import { getCustomFormPage, fetchCustomForm } from '@/api/custom/form'
  63. export default {
  64. name: 'CustomFormSelectModal',
  65. components: {
  66. STable,
  67. Ellipsis,
  68. Detail
  69. },
  70. props: {
  71. type: {
  72. type: String,
  73. default: 'radio'
  74. },
  75. selectedRowKey: {
  76. type: Array,
  77. default: () => {
  78. return []
  79. }
  80. },
  81. selectedRow: {
  82. type: Array,
  83. default: () => {
  84. return []
  85. }
  86. }
  87. },
  88. data () {
  89. return {
  90. advanced: false,
  91. confirmLoading: false,
  92. mdl: {},
  93. modalTitle: null,
  94. visible: false,
  95. record: null,
  96. // 查询参数
  97. queryParam: {
  98. },
  99. extraQueryParam: {
  100. },
  101. // 表头
  102. columns: [
  103. {
  104. title: '序号',
  105. dataIndex: 'index',
  106. customRender: (text, record, index) => {
  107. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  108. }
  109. },
  110. {
  111. title: '报废单 调拨单。。。',
  112. dataIndex: 'type',
  113. customRender: (text, record, index) => {
  114. return this.BaseTool.Amount.formatter(text)
  115. } ,
  116. },
  117. {
  118. title: '表单json',
  119. dataIndex: 'jsonString'
  120. },
  121. {
  122. title: '流程ID',
  123. dataIndex: 'flowId'
  124. },
  125. {
  126. title: '备注',
  127. dataIndex: 'remark'
  128. },
  129. {
  130. title: '创建人',
  131. dataIndex: 'createdUserName'
  132. },
  133. {
  134. title: '创建时间',
  135. dataIndex: 'createdTime'
  136. },
  137. {
  138. title: '操作',
  139. key: 'action',
  140. width: '200px',
  141. align: 'center',
  142. scopedSlots: { customRender: 'action' }
  143. }
  144. ],
  145. // 下拉框map
  146. // 加载数据方法 必须为 Promise 对象
  147. loadData: parameter => {
  148. parameter = {
  149. ...parameter,
  150. ...this.queryParam,
  151. ...this.extraQueryParam,
  152. dataScope: {
  153. sortBy: 'desc',
  154. sortName: 'update_time'
  155. }
  156. }
  157. return getCustomFormPage(Object.assign(parameter, this.queryParam))
  158. .then(res => {
  159. return res.data
  160. })
  161. },
  162. selectedRowKeys: [],
  163. selectedRows: [],
  164. options: {
  165. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  166. rowSelection: {
  167. selectedRowKeys: this.selectedRowKeys,
  168. onChange: this.onSelectChange
  169. }
  170. },
  171. optionAlertShow: false,
  172. isCreated: false
  173. }
  174. },
  175. created () {
  176. // 下拉框map
  177. },
  178. methods: {
  179. tableOption () {
  180. if (!this.optionAlertShow) {
  181. this.options = {
  182. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  183. rowSelection: {
  184. selectedRowKeys: this.selectedRowKeys,
  185. onChange: this.onSelectChange,
  186. type: this.type,
  187. getCheckboxProps: record => ({
  188. props: {
  189. disabled: false,
  190. name: record.id
  191. }
  192. })
  193. },
  194. customRow: (record) => {
  195. return {
  196. on: { // 事件
  197. click: (event) => { // 点击行
  198. // 选择对象
  199. this.mySelect([record.id], [record])
  200. },
  201. dblclick: (event) => {
  202. this.mySelect([record.id], [record])
  203. this.handleSelect()
  204. }
  205. }
  206. }
  207. }
  208. }
  209. this.optionAlertShow = true
  210. } else {
  211. this.options = {
  212. alert: false,
  213. rowSelection: null
  214. }
  215. this.optionAlertShow = false
  216. }
  217. },
  218. handleView (record) {
  219. fetchCustomForm({ id: record.id }).then(res => {
  220. const modal = this.$refs.detailModal
  221. modal.base(res.data)
  222. })
  223. },
  224. handleOk () {
  225. this.$refs.table.refresh()
  226. },
  227. onSelectChange (selectedRowKeys, selectedRows) {
  228. this.selectedRowKeys = selectedRowKeys
  229. this.selectedRows = selectedRows
  230. },
  231. resetSearchForm () {
  232. this.queryParam = {
  233. }
  234. this.$refs.table.refresh(true)
  235. },
  236. base (record, queryParam = {}) {
  237. this.visible = true
  238. this.modalTitle = '选择信息'
  239. this.extraQueryParam = queryParam
  240. this.record = record
  241. if (this.isCreated) {
  242. this.$refs.table.clearSelected()
  243. this.options.rowSelection.type = this.type
  244. this.handleOk()
  245. } else {
  246. this.tableOption()
  247. this.isCreated = true
  248. }
  249. },
  250. handleCancel () {
  251. this.visible = false
  252. this.confirmLoading = false
  253. },
  254. handleSelect () {
  255. if (this.selectedRowKeys.length === 0) {
  256. this.$message.warn('请至少选择一项信息')
  257. } else {
  258. this.confirmLoading = true
  259. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  260. this.confirmLoading = false
  261. this.visible = false
  262. }
  263. },
  264. mySelect(selectedRowKeys, selectedRows) {
  265. if (this.type === 'radio') {
  266. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  267. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  268. } else {
  269. let mySelectedRowKeys
  270. let mySelectedRows = this.selectedRows.filter(item => item.id !== selectedRowKeys[0])
  271. if (this.selectedRowKeys.includes(selectedRowKeys[0])) {
  272. mySelectedRowKeys = this.selectedRowKeys.filter(item => item !== selectedRowKeys[0])
  273. } else {
  274. mySelectedRowKeys = [...selectedRowKeys, ...this.selectedRowKeys]
  275. mySelectedRows = [...mySelectedRows, ...selectedRows]
  276. }
  277. this.$refs.table.updateSelect(mySelectedRowKeys, mySelectedRows)
  278. this.$refs.table.rowSelection.onChange(mySelectedRowKeys, mySelectedRows)
  279. }
  280. }
  281. }
  282. }
  283. </script>