SbChangeRecordSelectModal.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1300"
  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="queryParam.keyword" placeholder="请输入名称/类型名称" />
  17. </a-form-item>
  18. </a-col>
  19. <a-col :md="6 || 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. <a @click="()=>{ this.advanced = !this.advanced}" style="margin-left: 8px">
  24. {{ advanced ? '收起' : '展开' }}
  25. <a-icon :type="advanced ? 'up' : 'down'" />
  26. </a>
  27. </span>
  28. </a-col>
  29. </a-row>
  30. </a-form>
  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. :scroll="{x: 1200, y: BaseTool.Constant.scrollY}"
  42. showPagination="auto"
  43. >
  44. <span slot="action" slot-scope="record1">
  45. <template>
  46. <a @click="handleView(record1)">查看</a>
  47. </template>
  48. </span>
  49. </s-table>
  50. <detail ref="detailModal" />
  51. </a-card>
  52. <template slot="footer">
  53. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  54. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">确定</a-button>
  55. </template>
  56. </a-modal>
  57. </template>
  58. <script>
  59. import { STable, Ellipsis } from '@/components'
  60. import Detail from './Detail'
  61. import { getSbChangeRecordPage, fetchSbChangeRecord } from '@/api/sb/changeRecord'
  62. export default {
  63. name: 'SbChangeRecordSelectModal',
  64. components: {
  65. STable,
  66. Ellipsis,
  67. Detail
  68. },
  69. props: {
  70. type: {
  71. type: String,
  72. default: 'radio'
  73. },
  74. selectedRowKey: {
  75. type: Array,
  76. default: () => {
  77. return []
  78. }
  79. },
  80. selectedRow: {
  81. type: Array,
  82. default: () => {
  83. return []
  84. }
  85. }
  86. },
  87. data () {
  88. return {
  89. advanced: false,
  90. confirmLoading: false,
  91. mdl: {},
  92. modalTitle: null,
  93. visible: false,
  94. record: null,
  95. // 查询参数
  96. queryParam: {},
  97. extraQueryParam: {},
  98. // 表头
  99. columns: [
  100. {
  101. title: '序号',
  102. dataIndex: 'index',
  103. width: 50,
  104. customRender: (text, record, index) => {
  105. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  106. }
  107. },
  108. {
  109. width: 150,
  110. title: '记录人',
  111. dataIndex: 'createdUserName'
  112. },
  113. {
  114. width: 150,
  115. title: '设备ID',
  116. dataIndex: 'sbId'
  117. },
  118. {
  119. width: 150,
  120. title: '设备名称',
  121. dataIndex: 'sbName'
  122. },
  123. {
  124. width: 150,
  125. title: '更改内容',
  126. dataIndex: 'content'
  127. },
  128. {
  129. width: 150,
  130. title: '原设备位置',
  131. dataIndex: 'oldPositionId'
  132. },
  133. {
  134. width: 150,
  135. title: '修改后设备位置',
  136. dataIndex: 'positionId'
  137. },
  138. {
  139. width: 150,
  140. title: '位号',
  141. dataIndex: 'sbNoId'
  142. },
  143. {
  144. width: 150,
  145. title: '原父设备ID',
  146. dataIndex: 'oldParentId'
  147. },
  148. {
  149. width: 150,
  150. title: '修改后父设备ID',
  151. dataIndex: 'parentId'
  152. },
  153. {
  154. width: 150,
  155. title: '记录时间',
  156. dataIndex: 'createdTime'
  157. },
  158. {
  159. width: 150,
  160. title: '开始时间',
  161. dataIndex: 'startTime'
  162. },
  163. {
  164. width: 150,
  165. title: '结束时间',
  166. dataIndex: 'endTime'
  167. },
  168. {
  169. width: 150,
  170. title: '更改类型 1 位置 2 位号 3 父设备',
  171. dataIndex: 'changeType',
  172. customRender: (text, record, index) => {
  173. return this.BaseTool.Amount.formatter(text)
  174. }
  175. },
  176. {
  177. title: '操作',
  178. key: 'action',
  179. width: '200px',
  180. align: 'center',
  181. scopedSlots: { customRender: 'action' }
  182. }
  183. ],
  184. // 下拉框map
  185. // 加载数据方法 必须为 Promise 对象
  186. loadData: parameter => {
  187. parameter = {
  188. ...parameter,
  189. ...this.queryParam,
  190. ...this.extraQueryParam,
  191. dataScope: {
  192. sortBy: 'desc',
  193. sortName: 'update_time'
  194. }
  195. }
  196. return getSbChangeRecordPage(Object.assign(parameter, this.queryParam))
  197. .then(res => {
  198. return res.data
  199. })
  200. },
  201. selectedRowKeys: [],
  202. selectedRows: [],
  203. options: {
  204. alert: {
  205. show: true,
  206. clear: () => {
  207. this.selectedRowKeys = []
  208. }
  209. },
  210. rowSelection: {
  211. selectedRowKeys: this.selectedRowKeys,
  212. onChange: this.onSelectChange
  213. }
  214. },
  215. optionAlertShow: false,
  216. isCreated: false
  217. }
  218. },
  219. created () {
  220. // 下拉框map
  221. },
  222. methods: {
  223. tableOption () {
  224. if (!this.optionAlertShow) {
  225. this.options = {
  226. alert: {
  227. show: true,
  228. clear: () => {
  229. this.selectedRowKeys = []
  230. }
  231. },
  232. rowSelection: {
  233. selectedRowKeys: this.selectedRowKeys,
  234. onChange: this.onSelectChange,
  235. type: this.type,
  236. getCheckboxProps: record => ({
  237. props: {
  238. disabled: false,
  239. name: record.id
  240. }
  241. })
  242. },
  243. customRow: (record) => {
  244. return {
  245. on: { // 事件
  246. click: (event) => { // 点击行
  247. // 选择对象
  248. this.mySelect([record.id], [record])
  249. },
  250. dblclick: (event) => {
  251. this.mySelect([record.id], [record])
  252. this.handleSelect()
  253. }
  254. }
  255. }
  256. }
  257. }
  258. this.optionAlertShow = true
  259. } else {
  260. this.options = {
  261. alert: false,
  262. rowSelection: null
  263. }
  264. this.optionAlertShow = false
  265. }
  266. },
  267. handleView (record) {
  268. fetchSbChangeRecord({ id: record.id }).then(res => {
  269. const modal = this.$refs.detailModal
  270. modal.base(res.data)
  271. })
  272. },
  273. handleOk () {
  274. this.$refs.table.refresh()
  275. },
  276. onSelectChange (selectedRowKeys, selectedRows) {
  277. this.selectedRowKeys = selectedRowKeys
  278. this.selectedRows = selectedRows
  279. },
  280. resetSearchForm () {
  281. this.queryParam = {}
  282. this.$refs.table.refresh(true)
  283. },
  284. base (record, queryParam = {}) {
  285. this.visible = true
  286. this.modalTitle = '选择信息'
  287. this.extraQueryParam = queryParam
  288. this.record = record
  289. if (this.isCreated) {
  290. this.$refs.table.clearSelected()
  291. this.options.rowSelection.type = this.type
  292. this.handleOk()
  293. } else {
  294. this.tableOption()
  295. this.isCreated = true
  296. }
  297. },
  298. handleCancel () {
  299. this.visible = false
  300. this.confirmLoading = false
  301. },
  302. handleSelect () {
  303. if (this.selectedRowKeys.length === 0) {
  304. this.$message.warn('请至少选择一项信息')
  305. } else {
  306. this.confirmLoading = true
  307. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  308. this.confirmLoading = false
  309. this.visible = false
  310. }
  311. },
  312. mySelect (selectedRowKeys, selectedRows) {
  313. if (this.type === 'radio') {
  314. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  315. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  316. } else {
  317. let mySelectedRowKeys
  318. let mySelectedRows = this.selectedRows.filter(item => item.id !== selectedRowKeys[0])
  319. if (this.selectedRowKeys.includes(selectedRowKeys[0])) {
  320. mySelectedRowKeys = this.selectedRowKeys.filter(item => item !== selectedRowKeys[0])
  321. } else {
  322. mySelectedRowKeys = [...selectedRowKeys, ...this.selectedRowKeys]
  323. mySelectedRows = [...mySelectedRows, ...selectedRows]
  324. }
  325. this.$refs.table.updateSelect(mySelectedRowKeys, mySelectedRows)
  326. this.$refs.table.rowSelection.onChange(mySelectedRowKeys, mySelectedRows)
  327. }
  328. }
  329. }
  330. }
  331. </script>