RepairApplicationFormSelectModal.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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="8" :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-col :md="8 || 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. </span>
  24. </a-col>
  25. </a-row>
  26. </a-form>
  27. </div>
  28. <div class="table-operator" style="margin-bottom: 8px;">
  29. </div>
  30. <s-table
  31. ref="table"
  32. size="default"
  33. rowKey="id"
  34. :columns="columns"
  35. :data="loadData"
  36. :alert="options.alert"
  37. :customRow="options.customRow"
  38. :rowSelection="options.rowSelection"
  39. showPagination="auto"
  40. >
  41. <span slot="action" slot-scope="record1">
  42. <template>
  43. <a @click="handleView(record1)">查看</a>
  44. </template>
  45. </span>
  46. <span slot="status" slot-scope="text">
  47. <badge :text="BaseTool.Object.getField(statusMap,text)" :status="DictCache.COLOR.REPAIR_APPLICATION_FORM_STATUS[text]"/>
  48. </span>
  49. <span slot="level" slot-scope="text">
  50. <badge :text="BaseTool.Object.getField(statusMap,text)" :status="DictCache.COLOR.REPAIR_APPLICATION_FORM_LEVEL[text]"/>
  51. </span>
  52. </s-table>
  53. <detail ref="detailModal"/>
  54. </a-card>
  55. <template slot="footer">
  56. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  57. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">选择</a-button>
  58. </template>
  59. </a-modal>
  60. </template>
  61. <script>
  62. import { STable, Ellipsis } from '@/components'
  63. import Detail from './Detail'
  64. import { getRepairApplicationFormPage, fetchRepairApplicationForm } from '@/api/repair/application-form'
  65. export default {
  66. name: 'RepairApplicationFormSelectModal',
  67. components: {
  68. STable,
  69. Ellipsis,
  70. Detail
  71. },
  72. props: {
  73. type: {
  74. type: String,
  75. default: 'radio'
  76. },
  77. selectedRowKey: {
  78. type: Array,
  79. default: () => {
  80. return []
  81. }
  82. },
  83. selectedRow: {
  84. type: Array,
  85. default: () => {
  86. return []
  87. }
  88. }
  89. },
  90. data () {
  91. return {
  92. confirmLoading: false,
  93. mdl: {},
  94. modalTitle: null,
  95. visible: false,
  96. record: null,
  97. // 查询参数
  98. queryParam: {
  99. },
  100. extraQueryParam: {
  101. },
  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: 'sbId',
  114. customRender: (text, record, index) => {
  115. return record.sbName
  116. }
  117. },
  118. // {
  119. // title: '部位名称',
  120. // dataIndex: 'partId',
  121. // customRender: (text, record, index) => {
  122. // return record.partName
  123. // }
  124. //},
  125. {
  126. title: '报修人',
  127. dataIndex: 'repairUserName'
  128. },
  129. {
  130. title: '报修单号',
  131. dataIndex: 'no'
  132. },
  133. {
  134. title: '报修来源',
  135. dataIndex: 'source',
  136. customRender: (text, record, index) => {
  137. return this.BaseTool.Object.getField(this.sourceMap, text)
  138. }
  139. },
  140. {
  141. title: '报修时间',
  142. dataIndex: 'applyTime'
  143. },
  144. {
  145. title: '紧急等级',
  146. dataIndex: 'level',
  147. scopedSlots: { customRender: 'level' }
  148. },
  149. {
  150. title: '问题描述',
  151. dataIndex: 'content'
  152. },
  153. {
  154. title: '报修状态',
  155. dataIndex: 'status',
  156. scopedSlots: { customRender: 'status' }
  157. },
  158. {
  159. title: '备注',
  160. dataIndex: 'remark'
  161. },
  162. {
  163. title: '创建日期',
  164. dataIndex: 'createdTime'
  165. },
  166. {
  167. title: '操作',
  168. key: 'action',
  169. width: '200px',
  170. align: 'center',
  171. scopedSlots: { customRender: 'action' }
  172. }
  173. ],
  174. // 下拉框map
  175. sourceMap: {},
  176. levelMap: {},
  177. statusMap: {},
  178. // 加载数据方法 必须为 Promise 对象
  179. loadData: parameter => {
  180. parameter = {
  181. ...parameter,
  182. ...this.queryParam,
  183. ...this.extraQueryParam,
  184. dataScope: {
  185. sortBy: 'desc',
  186. sortName: 'update_time'
  187. }
  188. }
  189. return getRepairApplicationFormPage(Object.assign(parameter, this.queryParam))
  190. .then(res => {
  191. return res.data
  192. })
  193. },
  194. selectedRowKeys: [],
  195. selectedRows: [],
  196. options: {
  197. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  198. rowSelection: {
  199. selectedRowKeys: this.selectedRowKeys,
  200. onChange: this.onSelectChange
  201. }
  202. },
  203. optionAlertShow: false,
  204. isCreated: false
  205. }
  206. },
  207. created () {
  208. // 下拉框map
  209. this.sourceMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_SOURCE)
  210. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_LEVEL)
  211. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_STATUS)
  212. },
  213. methods: {
  214. tableOption () {
  215. if (!this.optionAlertShow) {
  216. this.options = {
  217. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  218. rowSelection: {
  219. selectedRowKeys: this.selectedRowKeys,
  220. onChange: this.onSelectChange,
  221. type: this.type,
  222. getCheckboxProps: record => ({
  223. props: {
  224. disabled: false,
  225. name: record.id
  226. }
  227. })
  228. },
  229. customRow: (record) => {
  230. return {
  231. on: { // 事件
  232. click: (event) => { // 点击行
  233. // 选择对象
  234. this.mySelect([record.id], [record])
  235. },
  236. dblclick: (event) => {
  237. this.mySelect([record.id], [record])
  238. this.handleSelect()
  239. }
  240. }
  241. }
  242. }
  243. }
  244. this.optionAlertShow = true
  245. } else {
  246. this.options = {
  247. alert: false,
  248. rowSelection: null
  249. }
  250. this.optionAlertShow = false
  251. }
  252. },
  253. handleView (record) {
  254. fetchRepairApplicationForm({ id: record.id }).then(res => {
  255. const modal = this.$refs.detailModal
  256. modal.base(res.data)
  257. })
  258. },
  259. handleOk () {
  260. this.$refs.table.refresh()
  261. },
  262. onSelectChange (selectedRowKeys, selectedRows) {
  263. this.selectedRowKeys = selectedRowKeys
  264. this.selectedRows = selectedRows
  265. },
  266. resetSearchForm () {
  267. this.queryParam = {
  268. }
  269. this.$refs.table.refresh(true)
  270. },
  271. base (record, queryParam = {}) {
  272. this.visible = true
  273. this.modalTitle = '选择信息'
  274. this.extraQueryParam = queryParam
  275. this.record = record
  276. if (this.isCreated) {
  277. this.$refs.table.clearSelected()
  278. this.options.rowSelection.type = this.type
  279. this.handleOk()
  280. } else {
  281. this.tableOption()
  282. this.isCreated = true
  283. }
  284. },
  285. handleCancel () {
  286. this.visible = false
  287. this.confirmLoading = false
  288. },
  289. handleSelect () {
  290. if (this.selectedRowKeys.length === 0) {
  291. this.$message.warn('请至少选择一项信息')
  292. } else {
  293. this.confirmLoading = true
  294. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  295. this.confirmLoading = false
  296. this.visible = false
  297. }
  298. },
  299. mySelect (selectedRowKeys, selectedRows) {
  300. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  301. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  302. }
  303. }
  304. }
  305. </script>