CheckJobSelectModal.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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="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">
  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. </s-table>
  47. <detail ref="detailModal"/>
  48. </a-card>
  49. <template slot="footer">
  50. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  51. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">选择</a-button>
  52. </template>
  53. </a-modal>
  54. </template>
  55. <script>
  56. import { STable, Ellipsis } from '@/components'
  57. import Detail from './Detail'
  58. import { getCheckJobPage, fetchCheckJob } from '@/api/check/checkjob'
  59. export default {
  60. name: 'CheckJobSelectModal',
  61. components: {
  62. STable,
  63. Ellipsis,
  64. Detail
  65. },
  66. props: {
  67. type: {
  68. type: String,
  69. default: 'radio'
  70. },
  71. selectedRowKey: {
  72. type: Array,
  73. default: () => {
  74. return []
  75. }
  76. },
  77. selectedRow: {
  78. type: Array,
  79. default: () => {
  80. return []
  81. }
  82. }
  83. },
  84. data () {
  85. return {
  86. confirmLoading: false,
  87. mdl: {},
  88. modalTitle: null,
  89. visible: false,
  90. record: null,
  91. // 查询参数
  92. queryParam: {
  93. },
  94. extraQueryParam: {
  95. },
  96. // 表头
  97. columns: [
  98. {
  99. title: '序号',
  100. dataIndex: 'index',
  101. customRender: (text, record, index) => {
  102. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  103. }
  104. },
  105. {
  106. title: '计划id',
  107. dataIndex: 'planId'
  108. },
  109. {
  110. title: '执行日期',
  111. dataIndex: 'startTime'
  112. },
  113. {
  114. title: '截至日期',
  115. dataIndex: 'endTime'
  116. },
  117. {
  118. title: '实际开始时间',
  119. dataIndex: 'actualStartTime'
  120. },
  121. {
  122. title: '实际结束时间',
  123. dataIndex: 'actualEndTime'
  124. },
  125. {
  126. title: '已检设备数',
  127. dataIndex: 'checkedNum'
  128. },
  129. {
  130. title: '异常设备数',
  131. dataIndex: 'abnormalNum'
  132. },
  133. {
  134. title: '应检设备数',
  135. dataIndex: 'checkNum'
  136. },
  137. {
  138. title: '任务状态',
  139. dataIndex: 'status',
  140. customRender: (text, record, index) => {
  141. return this.BaseTool.Object.getField(this.statusMap, text)
  142. }
  143. },
  144. {
  145. title: '创建人名称',
  146. dataIndex: 'createdUserName'
  147. },
  148. {
  149. title: '创建时间',
  150. dataIndex: 'createdTime'
  151. },
  152. {
  153. title: '操作',
  154. key: 'action',
  155. width: '200px',
  156. align: 'center',
  157. scopedSlots: { customRender: 'action' }
  158. }
  159. ],
  160. // 下拉框map
  161. statusMap: {},
  162. // 加载数据方法 必须为 Promise 对象
  163. loadData: parameter => {
  164. parameter = {
  165. ...parameter,
  166. ...this.queryParam,
  167. ...this.extraQueryParam,
  168. dataScope: {
  169. }
  170. }
  171. return getCheckJobPage(Object.assign(parameter, this.queryParam))
  172. .then(res => {
  173. return res.data
  174. })
  175. },
  176. selectedRowKeys: [],
  177. selectedRows: [],
  178. options: {
  179. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  180. rowSelection: {
  181. selectedRowKeys: this.selectedRowKeys,
  182. onChange: this.onSelectChange
  183. }
  184. },
  185. optionAlertShow: false,
  186. isCreated: false
  187. }
  188. },
  189. created () {
  190. // 下拉框map
  191. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_JOB_STATUS)
  192. },
  193. methods: {
  194. tableOption () {
  195. if (!this.optionAlertShow) {
  196. this.options = {
  197. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  198. rowSelection: {
  199. selectedRowKeys: this.selectedRowKeys,
  200. onChange: this.onSelectChange,
  201. type: this.type,
  202. getCheckboxProps: record => ({
  203. props: {
  204. disabled: false,
  205. name: record.id
  206. }
  207. })
  208. },
  209. customRow: (record) => {
  210. return {
  211. on: { // 事件
  212. click: (event) => { // 点击行
  213. // 选择对象
  214. this.mySelect([record.id], [record])
  215. },
  216. dblclick: (event) => {
  217. this.mySelect([record.id], [record])
  218. this.handleSelect()
  219. }
  220. }
  221. }
  222. }
  223. }
  224. this.optionAlertShow = true
  225. } else {
  226. this.options = {
  227. alert: false,
  228. rowSelection: null
  229. }
  230. this.optionAlertShow = false
  231. }
  232. },
  233. handleView (record) {
  234. fetchCheckJob({ id: record.id }).then(res => {
  235. const modal = this.$refs.detailModal
  236. modal.base(res.data)
  237. })
  238. },
  239. handleOk () {
  240. this.$refs.table.refresh()
  241. },
  242. onSelectChange (selectedRowKeys, selectedRows) {
  243. this.selectedRowKeys = selectedRowKeys
  244. this.selectedRows = selectedRows
  245. },
  246. resetSearchForm () {
  247. this.queryParam = {
  248. }
  249. this.$refs.table.refresh(true)
  250. },
  251. base (record, queryParam = {}) {
  252. this.visible = true
  253. this.modalTitle = '选择信息'
  254. this.extraQueryParam = queryParam
  255. this.record = record
  256. if (this.isCreated) {
  257. this.$refs.table.clearSelected()
  258. this.options.rowSelection.type = this.type
  259. this.handleOk()
  260. } else {
  261. this.tableOption()
  262. this.isCreated = true
  263. }
  264. },
  265. handleCancel () {
  266. this.visible = false
  267. this.confirmLoading = false
  268. },
  269. handleSelect () {
  270. if (this.selectedRowKeys.length === 0) {
  271. this.$message.warn('请至少选择一项信息')
  272. } else {
  273. this.confirmLoading = true
  274. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  275. this.confirmLoading = false
  276. this.visible = false
  277. }
  278. },
  279. mySelect (selectedRowKeys, selectedRows) {
  280. if (this.type === 'radio') {
  281. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  282. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  283. } else {
  284. let mySelectedRowKeys
  285. let mySelectedRows = this.selectedRows.filter(item => item.id !== selectedRowKeys[0])
  286. if (this.selectedRowKeys.includes(selectedRowKeys[0])) {
  287. mySelectedRowKeys = this.selectedRowKeys.filter(item => item !== selectedRowKeys[0])
  288. } else {
  289. mySelectedRowKeys = [...selectedRowKeys, ...this.selectedRowKeys]
  290. mySelectedRows = [...mySelectedRows, ...selectedRows]
  291. }
  292. this.$refs.table.updateSelect(mySelectedRowKeys, mySelectedRows)
  293. this.$refs.table.rowSelection.onChange(mySelectedRowKeys, mySelectedRows)
  294. }
  295. }
  296. }
  297. }
  298. </script>