SbInfoSelectModal.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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="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" :sm="24">
  20. <a-form-item label="上层设备类型">
  21. <a-tree-select
  22. style="width: 100%"
  23. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  24. :treeData="treeData"
  25. :treeNodeFilterProp="'title'"
  26. :showSearch="true"
  27. v-model="queryParam.parentId"
  28. placeholder="请选择"
  29. >
  30. </a-tree-select>
  31. </a-form-item>
  32. </a-col>-->
  33. <a-col :md="8 || 24" :sm="24">
  34. <span class="table-page-search-submitButtons">
  35. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  36. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  37. </span>
  38. </a-col>
  39. </a-row>
  40. </a-form>
  41. </div>
  42. <div class="table-operator">
  43. </div>
  44. <s-table
  45. ref="table"
  46. size="default"
  47. rowKey="id"
  48. :columns="columns"
  49. :data="loadData"
  50. :alert="options.alert"
  51. :customRow="options.customRow"
  52. :rowSelection="options.rowSelection"
  53. :scroll="{ x: 1300, y: BaseTool.Constant.scrollY }"
  54. showPagination="auto"
  55. >
  56. <span slot="action" slot-scope="record">
  57. <template>
  58. </template>
  59. </span>
  60. <span slot="status" slot-scope="text">
  61. <badge :status="DictCache.COLOR.SB_INFO_STATUS[text]" :text="statusMap[text]" />
  62. </span>
  63. </s-table>
  64. </a-card>
  65. <template slot="footer">
  66. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  67. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">选择</a-button>
  68. </template>
  69. </a-modal>
  70. </template>
  71. <script>
  72. import { STable, Ellipsis } from '@/components'
  73. import { getSbInfoPage, fetchSbInfo, getSbInfoTree } from '@/api/sb/info'
  74. export default {
  75. name: 'SbInfoSelectModal',
  76. components: {
  77. STable,
  78. Ellipsis
  79. },
  80. props: {
  81. type: {
  82. type: String,
  83. default: 'radio'
  84. },
  85. selectedRowKey: {
  86. type: Array,
  87. default: () => {
  88. return []
  89. }
  90. },
  91. selectedRow: {
  92. type: Array,
  93. default: () => {
  94. return []
  95. }
  96. }
  97. },
  98. data () {
  99. return {
  100. confirmLoading: false,
  101. mdl: {},
  102. modalTitle: null,
  103. visible: false,
  104. // 查询参数
  105. queryParam: {
  106. },
  107. extraQueryParam: {
  108. },
  109. depreciationTypeMap: {},
  110. levelMap: {},
  111. statusMap: {},
  112. unitMap: {},
  113. useTypeMap: {},
  114. sourceTypeMap: {},
  115. treeData: [],
  116. // 表头
  117. columns: [
  118. {
  119. title: '设备名称',
  120. checked: true,
  121. dataIndex: 'name'
  122. },
  123. {
  124. title: '设备编号',
  125. dataIndex: 'no',
  126. checked: true
  127. },
  128. {
  129. title: '型号',
  130. checked: true,
  131. dataIndex: 'model'
  132. },
  133. {
  134. title: '设备类型',
  135. dataIndex: 'type',
  136. checked: true,
  137. width: 200,
  138. customRender: (text, record, index) => {
  139. return record.typeName
  140. }
  141. },
  142. {
  143. title: '设备等级',
  144. dataIndex: 'level',
  145. checked: true,
  146. width: 200,
  147. customRender: (text, record, index) => {
  148. return this.BaseTool.Object.getField(this.levelMap, text)
  149. }
  150. },
  151. {
  152. title: '状态',
  153. dataIndex: 'status',
  154. checked: true,
  155. width: 200,
  156. scopedSlots: { customRender: 'status' }
  157. },
  158. {
  159. title: '备注',
  160. dataIndex: 'remark',
  161. width: 200
  162. },
  163. {
  164. title: '操作',
  165. key: 'action',
  166. width: '200px',
  167. align: 'center',
  168. fixed: 'right',
  169. scopedSlots: { width: 200, customRender: 'action' }
  170. }
  171. ],
  172. // 加载数据方法 必须为 Promise 对象
  173. loadData: parameter => {
  174. parameter = {
  175. ...parameter,
  176. ...this.queryParam,
  177. ...this.extraQueryParam,
  178. dataScope: {
  179. sortBy: 'asc',
  180. sortName: 'no'
  181. }
  182. }
  183. return getSbInfoPage(Object.assign(parameter, this.queryParam))
  184. .then(res => {
  185. return res.data
  186. })
  187. },
  188. selectedRowKeys: [],
  189. selectedRows: [],
  190. options: {
  191. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  192. rowSelection: {
  193. selectedRowKeys: this.selectedRowKeys,
  194. onChange: this.onSelectChange
  195. }
  196. },
  197. optionAlertShow: true,
  198. isCreated: false
  199. }
  200. },
  201. created () {
  202. this.tableOption()
  203. this.depreciationTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_DEPRECIATIONTYPE)
  204. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_LEVEL)
  205. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_INFO_STATUS)
  206. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  207. this.sourceTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBTYPE_SOURCETYPE)
  208. this.useTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_UES_TYPE)
  209. },
  210. methods: {
  211. tableOption () {
  212. this.setTree()
  213. if (!this.optionAlertShow) {
  214. this.options = {
  215. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  216. rowSelection: {
  217. selectedRowKeys: this.selectedRowKeys,
  218. onChange: this.onSelectChange,
  219. type: this.type,
  220. getCheckboxProps: record => ({
  221. props: {
  222. disabled: false,
  223. name: record.id
  224. }
  225. })
  226. },
  227. customRow: (record) => {
  228. return {
  229. on: { // 事件
  230. click: (event) => { // 点击行
  231. // 选择对象
  232. this.mySelect([record.id], [record])
  233. },
  234. dblclick: (event) => {
  235. this.mySelect([record.id], [record])
  236. this.handleSelect()
  237. }
  238. }
  239. }
  240. }
  241. }
  242. this.optionAlertShow = true
  243. } else {
  244. this.options = {
  245. alert: false,
  246. rowSelection: null
  247. }
  248. this.optionAlertShow = false
  249. }
  250. },
  251. handleOk () {
  252. this.setTree()
  253. this.$refs.table.refresh()
  254. },
  255. onSelectChange (selectedRowKeys, selectedRows) {
  256. this.selectedRowKeys = selectedRowKeys
  257. this.selectedRows = selectedRows
  258. },
  259. resetSearchForm () {
  260. this.queryParam = {
  261. }
  262. this.$refs.table.refresh(true)
  263. },
  264. /**
  265. * 设置设备类型树
  266. */
  267. setTree (record = {}) {
  268. getSbInfoTree({ id: record.id }).then(res => {
  269. this.treeData = res.data
  270. })
  271. },
  272. base (record, queryParam = {}) {
  273. this.visible = true
  274. this.modalTitle = '选择设备'
  275. this.extraQueryParam = queryParam
  276. if (this.isCreated) {
  277. this.setTree()
  278. this.$refs.table.clearSelected()
  279. this.options.rowSelection.type = this.type
  280. this.handleOk()
  281. } else {
  282. this.tableOption()
  283. this.isCreated = true
  284. }
  285. // this.mySelect(this.selectedRowKeys, this.selectedRows)
  286. },
  287. handleCancel () {
  288. this.visible = false
  289. this.confirmLoading = false
  290. },
  291. handleSelect () {
  292. if (this.selectedRowKeys.length === 0) {
  293. this.$message.warn('请至少选择一项信息')
  294. } else {
  295. this.confirmLoading = true
  296. this.$emit('selected', this.selectedRowKeys, this.selectedRows)
  297. this.confirmLoading = false
  298. this.visible = false
  299. }
  300. },
  301. mySelect (selectedRowKeys, selectedRows) {
  302. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  303. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  304. }
  305. }
  306. }
  307. </script>