CustomFieldTemplateSelectModal.vue 8.4 KB

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