CustomFieldTemplate.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <a-card :bordered="false">
  3. <div v-show="visible">
  4. <div class="table-page-search-wrapper" @keyup.enter="handleEnter">
  5. <a-form layout="inline">
  6. <a-row :gutter="48" v-show="advanced">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="关键字">
  9. <a-input v-model="queryParam.keyword" placeholder="请输入名称/类型名称"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="类型">
  14. <a-select
  15. v-model="queryParam.type"
  16. placeholder="请选择">
  17. <a-select-option
  18. v-for="(label,value) in typeMap"
  19. :key="value"
  20. :label="label"
  21. :value="parseInt(value)">{{ label }}
  22. </a-select-option>
  23. </a-select>
  24. </a-form-item>
  25. </a-col>
  26. </a-row>
  27. <a-row :gutter="48">
  28. <a-col :md="24 || 24" :sm="24" style="text-align: right">
  29. <span class="table-page-search-submitButtons">
  30. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  31. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  32. <a @click="()=>{ this.advanced = !this.advanced}" style="margin-left: 8px">
  33. {{ advanced ? '收起' : '展开' }}
  34. <a-icon :type="advanced ? 'up' : 'down'"/>
  35. </a>
  36. </span>
  37. </a-col>
  38. </a-row>
  39. </a-form>
  40. </div>
  41. <div class="table-operator" style="margin-bottom: 8px;">
  42. <a-row>
  43. <a-col :md="16">
  44. <a-button v-if="$auth('customize-fieldTemplate-add')" type="primary" icon="plus" @click="handleAdd()">新增</a-button>
  45. <a-button style="margin-left: 8px" v-if="$auth('customize-fieldTemplate-export')" type="primary" icon="download" @click="doExport">导出</a-button>
  46. <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0 && $auth('customize-fieldTemplate-del')">
  47. <a-menu slot="overlay">
  48. <a-popconfirm title="是否要删除所选数据?" @confirm="batchDelete()">
  49. <a-menu-item key="1"><a-icon type="delete" /><a>删除</a></a-menu-item>
  50. </a-popconfirm>
  51. </a-menu>
  52. <a-button style="margin-left: 8px">
  53. 批量操作 <a-icon type="down" />
  54. </a-button>
  55. </a-dropdown>
  56. </a-col>
  57. </a-row>
  58. </div>
  59. <s-table
  60. ref="table"
  61. size="default"
  62. rowKey="id"
  63. :columns="columns"
  64. :data="loadData"
  65. :alert="options.alert"
  66. :rowSelection="options.rowSelection"
  67. showPagination="auto"
  68. >
  69. <span slot="action" slot-scope="record">
  70. <template>
  71. <a @click="handleView(record)">查看</a>
  72. <operation-button
  73. v-if="$auth('customize-fieldTemplate-edit')"
  74. @click="handleEdit(record)"
  75. >修改</operation-button>
  76. <operation-button
  77. v-if="$auth('customize-fieldTemplate-del')"
  78. :type="2"
  79. title="是否要删除该条数据?"
  80. @confirm="batchDelete(record.id)">删除</operation-button>
  81. </template>
  82. </span>
  83. </s-table>
  84. </div>
  85. <base-form ref="baseModal" @ok="handleOk"/>
  86. <detail ref="detailModal" @ok="handleOk"/>
  87. </a-card>
  88. </template>
  89. <script>
  90. import { STable, Ellipsis } from '@/components'
  91. import BaseForm from './modules/BaseForm'
  92. import Detail from './modules/Detail'
  93. import { getCustomFieldTemplatePage, deleteCustomFieldTemplates, fetchCustomFieldTemplate, exportCustomFieldTemplate } from '@/api/customize/fieldTemplate'
  94. export default {
  95. name: 'CustomFieldTemplateList',
  96. components: {
  97. STable,
  98. Ellipsis,
  99. BaseForm,
  100. Detail
  101. },
  102. data () {
  103. return {
  104. advanced: false,
  105. visible: true,
  106. // 查询参数
  107. queryParam: {
  108. },
  109. // 表头
  110. columns: [
  111. {
  112. title: '序号',
  113. dataIndex: 'index',
  114. customRender: (text, record, index) => {
  115. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  116. }
  117. },
  118. /* {
  119. title: '模板内容',
  120. dataIndex: 'content'
  121. },*/
  122. {
  123. title: '类型',
  124. dataIndex: 'type',
  125. customRender: (text, record, index) => {
  126. return this.BaseTool.Table.getMapText(this.typeMap, text)
  127. }
  128. },
  129. {
  130. title: '备注',
  131. dataIndex: 'remark'
  132. },
  133. {
  134. title: '创建日期',
  135. dataIndex: 'createdTime'
  136. },
  137. {
  138. title: '创建人名称',
  139. dataIndex: 'createdUserName'
  140. },
  141. {
  142. title: '二级类别',
  143. dataIndex: 'secondTypeId'
  144. },
  145. {
  146. title: '操作',
  147. key: 'action',
  148. width: '200px',
  149. align: 'center',
  150. scopedSlots: { customRender: 'action' }
  151. }
  152. ],
  153. // 下拉框map
  154. typeMap: {},
  155. // 加载数据方法 必须为 Promise 对象
  156. loadData: parameter => {
  157. parameter = {
  158. ...parameter,
  159. ...this.queryParam,
  160. dataScope: {
  161. sortBy: 'desc',
  162. sortName: 'update_time'
  163. }
  164. }
  165. return getCustomFieldTemplatePage(Object.assign(parameter, this.queryParam))
  166. .then(res => {
  167. return res.data
  168. })
  169. },
  170. selectedRowKeys: [],
  171. selectedRows: [],
  172. options: {
  173. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  174. rowSelection: {
  175. selectedRowKeys: this.selectedRowKeys,
  176. onChange: this.onSelectChange
  177. }
  178. },
  179. optionAlertShow: false
  180. }
  181. },
  182. created () {
  183. // 下拉框map
  184. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CUSTOM_FIELD_TEMPLATE_TYPE)
  185. this.tableOption()
  186. },
  187. methods: {
  188. tableOption () {
  189. if (!this.optionAlertShow) {
  190. this.options = {
  191. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  192. rowSelection: {
  193. selectedRowKeys: this.selectedRowKeys,
  194. onChange: this.onSelectChange,
  195. getCheckboxProps: record => ({
  196. props: {
  197. disabled: false,
  198. name: record.id
  199. }
  200. })
  201. }
  202. }
  203. this.optionAlertShow = true
  204. } else {
  205. this.options = {
  206. alert: false,
  207. rowSelection: null
  208. }
  209. this.optionAlertShow = false
  210. }
  211. },
  212. batchDelete (id) {
  213. let ids = []
  214. if (this.BaseTool.String.isBlank(id)) {
  215. const length = this.selectedRows.length
  216. if (length === 0) {
  217. this.$message.info('请选择要删除的记录')
  218. return
  219. }
  220. ids = this.selectedRows.map(item => item.id)
  221. } else {
  222. ids = [id]
  223. }
  224. deleteCustomFieldTemplates(ids).then(res => {
  225. this.$message.info('删除成功')
  226. this.handleOk()
  227. this.$refs.table.clearSelected()
  228. })
  229. },
  230. handleAdd () {
  231. this.visible = false
  232. const modal = this.$refs.baseModal
  233. modal.base()
  234. },
  235. handleEdit (record) {
  236. this.visible = false
  237. fetchCustomFieldTemplate({ id: record.id }).then(res => {
  238. const modal = this.$refs.baseModal
  239. modal.base(res.data)
  240. })
  241. },
  242. handleView (record) {
  243. this.visible = false
  244. fetchCustomFieldTemplate({ id: record.id }).then(res => {
  245. const modal = this.$refs.detailModal
  246. modal.base(res.data)
  247. })
  248. },
  249. handleOk (values) {
  250. this.visible = true
  251. this.$refs.table.refresh()
  252. },
  253. onSelectChange (selectedRowKeys, selectedRows) {
  254. this.selectedRowKeys = selectedRowKeys
  255. this.selectedRows = selectedRows
  256. },
  257. resetSearchForm () {
  258. this.queryParam = {
  259. }
  260. this.$refs.table.refresh(true)
  261. },
  262. doExport () {
  263. const parameter = {
  264. ...this.queryParam
  265. }
  266. exportCustomFieldTemplate(parameter).then(file => {
  267. this.BaseTool.Util.downLoadExportExcel(file)
  268. })
  269. },
  270. handleEnter () {
  271. this.$refs.table.refresh(true)
  272. }
  273. }
  274. }
  275. </script>