FillGatherInfoSelectModal.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1000"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. class="ant-modal2"
  8. :footer="false"
  9. @cancel="handleCancel"
  10. >
  11. <a-card :bordered="false">
  12. <div class="table-page-search-wrapper">
  13. <a-form layout="inline">
  14. <a-row :gutter="48">
  15. <a-col :md="8" :sm="24">
  16. <a-form-item label="关键字">
  17. <a-input v-model.trim="queryParam.keyword" placeholder="请输入名称/类型名称"/>
  18. </a-form-item>
  19. </a-col>
  20. <a-col :md="8 || 24" :sm="24">
  21. <span class="table-page-search-submitButtons">
  22. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  23. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  24. </span>
  25. </a-col>
  26. </a-row>
  27. </a-form>
  28. </div>
  29. <div class="table-operator" style="margin-bottom: 8px;">
  30. <a-button v-if="$auth('fill-gathers-edit')" type="primary" icon="plus" @click="addFillInfos">新增</a-button>
  31. </div>
  32. <s-table
  33. ref="table"
  34. size="default"
  35. rowKey="id"
  36. :columns="columns"
  37. :data="loadData"
  38. :alert="options.alert"
  39. :customRow="options.customRow"
  40. :rowSelection="options.rowSelection"
  41. showPagination="auto"
  42. >
  43. <span slot="action" slot-scope="record">
  44. <template>
  45. <a @click="handleView(record)">查看</a>
  46. <operation-button
  47. v-if="$auth('fill-gathers-edit')"
  48. :type="2"
  49. title="是否要删除该条数据?"
  50. @confirm="batchDelete(record.id)">删除</operation-button>
  51. </template>
  52. </span>
  53. </s-table>
  54. <detail ref="detailModal"/>
  55. <fill-info-select-modal :type="'checkbox'" ref="fillInfoSelectModal" @selected="selectInfoSave" />
  56. </a-card>
  57. <template slot="footer">
  58. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  59. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">确定</a-button>
  60. </template>
  61. </a-modal>
  62. </template>
  63. <script>
  64. import { STable, Ellipsis } from '@/components'
  65. import Detail from './Detail'
  66. import FillInfoSelectModal from '@/views/fill/info/modules/FillInfoSelectModal'
  67. import {
  68. getFillGatherInfoPage,
  69. fetchFillGatherInfo,
  70. addFillGatherInfos,
  71. deleteFillGatherInfos
  72. } from '@/api/fill/gather-info'
  73. export default {
  74. name: 'FillGatherInfoSelectModal',
  75. components: {
  76. STable,
  77. Ellipsis,
  78. FillInfoSelectModal,
  79. Detail
  80. },
  81. props: {
  82. type: {
  83. type: String,
  84. default: 'radio'
  85. }
  86. },
  87. data () {
  88. return {
  89. confirmLoading: false,
  90. mdl: {},
  91. modalTitle: null,
  92. visible: false,
  93. extraModel: {},
  94. // 查询参数
  95. queryParam: {
  96. },
  97. extraQueryParam: {
  98. },
  99. natureMap: {},
  100. typeMap: {},
  101. useTypeMap: {},
  102. // 表头
  103. columns: [
  104. {
  105. title: '序号',
  106. dataIndex: 'index',
  107. customRender: (text, record, index) => {
  108. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  109. }
  110. },
  111. {
  112. title: '名称',
  113. dataIndex: 'infoName'
  114. },
  115. {
  116. title: '字段名称',
  117. dataIndex: 'fieldKey'
  118. },
  119. {
  120. title: '类型',
  121. dataIndex: 'type',
  122. customRender: (text, record, index) => {
  123. return this.BaseTool.Table.getMapText(this.typeMap, text)
  124. }
  125. },
  126. {
  127. title: '性质',
  128. dataIndex: 'nature',
  129. customRender: (text, record, index) => {
  130. return this.BaseTool.Table.getMapText(this.natureMap, text)
  131. }
  132. },
  133. {
  134. title: '操作',
  135. key: 'action',
  136. width: '200px',
  137. align: 'center',
  138. scopedSlots: { customRender: 'action' }
  139. }
  140. ],
  141. // 下拉框map
  142. // 加载数据方法 必须为 Promise 对象
  143. loadData: parameter => {
  144. parameter = {
  145. ...parameter,
  146. ...this.queryParam,
  147. ...this.extraQueryParam,
  148. dataScope: {
  149. sortBy: 'desc',
  150. sortName: 'update_time'
  151. }
  152. }
  153. return getFillGatherInfoPage(parameter)
  154. .then(res => {
  155. return res.data
  156. })
  157. },
  158. selectedRowKeys: [],
  159. selectedRows: [],
  160. options: {
  161. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  162. rowSelection: {
  163. selectedRowKeys: this.selectedRowKeys,
  164. onChange: this.onSelectChange
  165. }
  166. },
  167. optionAlertShow: false,
  168. isCreated: false
  169. }
  170. },
  171. created () {
  172. // 下拉框map
  173. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.FILL_INFO_TYPE)
  174. this.natureMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.FILL_INFO_NATURE)
  175. },
  176. methods: {
  177. tableOption () {
  178. if (!this.optionAlertShow) {
  179. this.options = {
  180. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  181. rowSelection: {
  182. selectedRowKeys: this.selectedRowKeys,
  183. onChange: this.onSelectChange,
  184. type: this.type,
  185. getCheckboxProps: record => ({
  186. props: {
  187. disabled: false,
  188. name: record.id
  189. }
  190. })
  191. },
  192. customRow: (record) => {
  193. return {
  194. on: { // 事件
  195. click: (event) => { // 点击行
  196. // 选择对象
  197. this.mySelect([record.id], [record])
  198. },
  199. dblclick: (event) => {
  200. this.mySelect([record.id], [record])
  201. this.handleSelect()
  202. }
  203. }
  204. }
  205. }
  206. }
  207. this.optionAlertShow = true
  208. } else {
  209. this.options = {
  210. alert: false,
  211. rowSelection: null
  212. }
  213. this.optionAlertShow = false
  214. }
  215. },
  216. addFillInfos () {
  217. this.$refs.fillInfoSelectModal.base({ hideSelectGatherId: this.extraQueryParam.gatherId })
  218. },
  219. handleView (record) {
  220. fetchFillGatherInfo({ id: record.id }).then(res => {
  221. const modal = this.$refs.detailModal
  222. modal.base(res.data)
  223. })
  224. },
  225. handleOk () {
  226. this.$refs.table.refresh()
  227. },
  228. onSelectChange (selectedRowKeys, selectedRows) {
  229. this.selectedRowKeys = selectedRowKeys
  230. this.selectedRows = selectedRows
  231. },
  232. resetSearchForm () {
  233. this.queryParam = {
  234. }
  235. this.$refs.table.refresh(true)
  236. },
  237. base (extraModel, queryParam = {}) {
  238. this.visible = true
  239. this.modalTitle = '配置列表'
  240. this.extraQueryParam = queryParam
  241. this.extraModel = extraModel
  242. if (this.isCreated) {
  243. this.$refs.table.clearSelected()
  244. this.options.rowSelection.type = this.type
  245. this.handleOk()
  246. } else {
  247. this.tableOption()
  248. this.isCreated = true
  249. }
  250. },
  251. batchDelete (id) {
  252. let ids = []
  253. if (this.BaseTool.String.isBlank(id)) {
  254. const length = this.selectedRows.length
  255. if (length === 0) {
  256. this.$message.info('请选择要删除的记录')
  257. return
  258. }
  259. ids = this.selectedRows.map(item => item.id)
  260. } else {
  261. ids = [id]
  262. }
  263. deleteFillGatherInfos(ids).then(res => {
  264. this.$message.info('删除成功')
  265. this.handleOk()
  266. this.$refs.table.clearSelected()
  267. })
  268. },
  269. handleCancel () {
  270. this.visible = false
  271. this.confirmLoading = false
  272. },
  273. handleSelect () {
  274. if (this.selectedRowKeys.length === 0) {
  275. this.$message.warn('请至少选择一项信息')
  276. } else {
  277. this.confirmLoading = true
  278. this.$emit('selected', this.extraModel, this.selectedRowKeys, this.selectedRows)
  279. this.confirmLoading = false
  280. this.visible = false
  281. }
  282. },
  283. mySelect (selectedRowKeys, selectedRows) {
  284. if (this.type === 'radio') {
  285. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  286. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  287. } else {
  288. let mySelectedRowKeys
  289. let mySelectedRows = this.selectedRows.filter(item => item.id !== selectedRowKeys[0])
  290. if (this.selectedRowKeys.includes(selectedRowKeys[0])) {
  291. mySelectedRowKeys = this.selectedRowKeys.filter(item => item !== selectedRowKeys[0])
  292. } else {
  293. mySelectedRowKeys = [...selectedRowKeys, ...this.selectedRowKeys]
  294. mySelectedRows = [...mySelectedRows, ...selectedRows]
  295. }
  296. this.$refs.table.updateSelect(mySelectedRowKeys, mySelectedRows)
  297. this.$refs.table.rowSelection.onChange(mySelectedRowKeys, mySelectedRows)
  298. }
  299. },
  300. selectInfoSave (extraModel, selectedRowKeys, selectedRows) {
  301. console.log(111, extraModel, selectedRowKeys, selectedRows)
  302. const gatherId = this.extraQueryParam.gatherId
  303. addFillGatherInfos({ gatherId: gatherId, infoIds: selectedRowKeys })
  304. .then(() => {
  305. this.$refs.table.refresh(true)
  306. }).catch(() => {
  307. })
  308. }
  309. }
  310. }
  311. </script>