SbInfoSelectModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <div>
  3. <a-modal
  4. :title="modalTitle"
  5. :width="1300"
  6. :visible="visible"
  7. :confirmLoading="confirmLoading"
  8. class="ant-modal2"
  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" :sm="24">
  21. <a-form-item label="上层设备类型">
  22. <a-tree-select
  23. style="width: 100%"
  24. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  25. :treeData="treeData"
  26. :treeNodeFilterProp="'title'"
  27. :showSearch="true"
  28. v-model="queryParam.parentId"
  29. placeholder="请选择"
  30. >
  31. </a-tree-select>
  32. </a-form-item>
  33. </a-col>-->
  34. <a-col :md="6" :sm="24">
  35. <a-form-item label="车间位置">
  36. <a-select v-model="queryParam.positionId" placeholder="请选择">
  37. <a-select-option
  38. v-for="({id,name}) in sbPositionData"
  39. :key="id"
  40. :label="name"
  41. :value="id">{{ name }}
  42. </a-select-option>
  43. </a-select>
  44. </a-form-item>
  45. </a-col>
  46. <a-col :md="6" :sm="24">
  47. <a-form-item label="设备类型">
  48. <a-tree-select
  49. style="width: 100%"
  50. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  51. :treeData="treeData"
  52. :treeNodeFilterProp="'title'"
  53. :showSearch="true"
  54. placeholder="请选择"
  55. @change="handleChange"
  56. >
  57. </a-tree-select>
  58. </a-form-item>
  59. </a-col>
  60. <a-col :md="8 || 24" :sm="24">
  61. <span class="table-page-search-submitButtons">
  62. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  63. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  64. </span>
  65. </a-col>
  66. </a-row>
  67. </a-form>
  68. </div>
  69. <div class="table-operator" style="margin-bottom: 8px;">
  70. </div>
  71. <s-table
  72. ref="table"
  73. size="default"
  74. rowKey="id"
  75. :columns="columns"
  76. :data="loadData"
  77. :alert="options.alert"
  78. :customRow="options.customRow"
  79. :rowSelection="options.rowSelection"
  80. :scroll="{ x: 1300, y: BaseTool.Constant.scrollY }"
  81. showPagination="auto"
  82. >
  83. <span slot="action" slot-scope="record">
  84. <template>
  85. </template>
  86. </span>
  87. <span slot="status" slot-scope="text">
  88. <badge :status="DictCache.COLOR.SB_INFO_STATUS[text]" :text="statusMap[text]" />
  89. </span>
  90. </s-table>
  91. </a-card>
  92. <template slot="footer">
  93. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  94. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">选择</a-button>
  95. </template>
  96. </a-modal>
  97. </div>
  98. </template>
  99. <script>
  100. import { STable, Ellipsis } from '@/components'
  101. import { getSbInfoPage, fetchSbInfo, getSbInfoTree } from '@/api/sb/info'
  102. import { querySbPosition } from '@/api/sb/position'
  103. import { fetchSbTypeTree } from '@/api/sb/type'
  104. export default {
  105. name: 'SbInfoSelectModal',
  106. components: {
  107. STable,
  108. Ellipsis
  109. },
  110. props: {
  111. type: {
  112. type: String,
  113. default: 'checkbox'
  114. },
  115. selectedRowKey: {
  116. type: Array,
  117. default: () => {
  118. return []
  119. }
  120. },
  121. selectedRow: {
  122. type: Array,
  123. default: () => {
  124. return []
  125. }
  126. }
  127. },
  128. data () {
  129. return {
  130. confirmLoading: false,
  131. mdl: {},
  132. modalTitle: null,
  133. visible: false,
  134. // 查询参数
  135. queryParam: {
  136. },
  137. extraQueryParam: {
  138. },
  139. depreciationTypeMap: {},
  140. levelMap: {},
  141. statusMap: {},
  142. unitMap: {},
  143. useTypeMap: {},
  144. sourceTypeMap: {},
  145. treeData: [],
  146. sbPositionData: [],
  147. typeList: [],
  148. // 表头
  149. columns: [
  150. {
  151. title: '设备名称',
  152. checked: true,
  153. dataIndex: 'name'
  154. },
  155. {
  156. title: '设备编号',
  157. dataIndex: 'no',
  158. checked: true
  159. },
  160. {
  161. title: '设备位号',
  162. checked: true,
  163. dataIndex: 'positionNo'
  164. },
  165. {
  166. title: '型号',
  167. checked: true,
  168. dataIndex: 'model'
  169. },
  170. {
  171. title: '设备类型',
  172. dataIndex: 'type',
  173. checked: true,
  174. width: 200,
  175. customRender: (text, record, index) => {
  176. return record.typeName
  177. }
  178. },
  179. {
  180. title: '设备等级',
  181. dataIndex: 'level',
  182. checked: true,
  183. width: 200,
  184. customRender: (text, record, index) => {
  185. return this.BaseTool.Object.getField(this.levelMap, text)
  186. }
  187. },
  188. {
  189. title: '状态',
  190. dataIndex: 'status',
  191. checked: true,
  192. width: 200,
  193. scopedSlots: { customRender: 'status' }
  194. },
  195. {
  196. title: '备注',
  197. dataIndex: 'remark',
  198. width: 200
  199. },
  200. {
  201. title: '操作',
  202. key: 'action',
  203. width: '200px',
  204. align: 'center',
  205. fixed: 'right',
  206. scopedSlots: { width: 200, customRender: 'action' }
  207. }
  208. ],
  209. // 加载数据方法 必须为 Promise 对象
  210. loadData: parameter => {
  211. parameter = {
  212. ...parameter,
  213. ...this.queryParam,
  214. ...this.extraQueryParam,
  215. typeList: this.typeList,
  216. dataScope: {
  217. sortBy: 'asc',
  218. sortName: 'no'
  219. }
  220. }
  221. return getSbInfoPage(Object.assign(parameter, this.queryParam))
  222. .then(res => {
  223. return res.data
  224. })
  225. },
  226. selectedRowKeys: [],
  227. selectedRows: [],
  228. options: {
  229. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  230. rowSelection: {
  231. selectedRowKeys: this.selectedRowKeys,
  232. onChange: this.onSelectChange
  233. }
  234. },
  235. optionAlertShow: true,
  236. isCreated: false
  237. }
  238. },
  239. created () {
  240. this.tableOption()
  241. this.depreciationTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_DEPRECIATIONTYPE)
  242. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_LEVEL)
  243. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_INFO_STATUS)
  244. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  245. this.sourceTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBTYPE_SOURCETYPE)
  246. this.useTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_UES_TYPE)
  247. querySbPosition().then(res => {
  248. this.sbPositionData = res.data
  249. })
  250. fetchSbTypeTree().then(res => {
  251. this.treeData = res.data
  252. })
  253. },
  254. methods: {
  255. tableOption () {
  256. // this.setTree()
  257. if (!this.optionAlertShow) {
  258. this.options = {
  259. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  260. rowSelection: {
  261. selectedRowKeys: this.selectedRowKeys,
  262. // onChange: this.onSelectChange,
  263. onSelect: (record, selected, selectedRows) => {
  264. console.log(record, selected, selectedRows)
  265. if (selected) {
  266. this.selectedRows.push(record)
  267. }
  268. if (!selected) {
  269. const delIndex = this.selectedRows.findIndex(val => {
  270. return val.id === record.id
  271. })
  272. this.selectedRows.splice(delIndex, 1)
  273. }
  274. // record 点击某一条的所有数据
  275. // selected 点击的一条是否被选中
  276. },
  277. onSelectAll: (selected, selectedRows, changeRows) => {
  278. console.log(selected, selectedRows, changeRows)
  279. if (selected) {
  280. this.selectedRows = this.selectedRows.concat(changeRows)
  281. }
  282. if (!selected) {
  283. let selectedRows = JSON.parse(JSON.stringify(this.selectedRows))
  284. const delIndex = []
  285. selectedRows.forEach((item, index) => {
  286. changeRows.forEach((val, itemIndex) => {
  287. if (item.id === val.id) {
  288. delIndex.push(index)
  289. }
  290. })
  291. })
  292. delIndex.forEach(item => {
  293. delete selectedRows[item]
  294. })
  295. selectedRows = selectedRows.filter(item => {
  296. return item !== undefined
  297. })
  298. this.selectedRows = selectedRows
  299. }
  300. // selected 点击全选是否选中
  301. // selectedRows 点击全选判断所有的选中数据
  302. // changeRows 所有改变选中状态的数据
  303. },
  304. type: this.type,
  305. getCheckboxProps: record => ({
  306. props: {
  307. disabled: false,
  308. name: record.id
  309. }
  310. })
  311. }
  312. // customRow: (record) => {
  313. // return {
  314. // on: { // 事件
  315. // click: (event) => { // 点击行
  316. // // 选择对象
  317. // this.mySelect([record.id], [record])
  318. // },
  319. // dblclick: (event) => {
  320. // this.mySelect([record.id], [record])
  321. // this.handleSelect()
  322. // }
  323. // }
  324. // }
  325. // }
  326. }
  327. this.optionAlertShow = true
  328. } else {
  329. this.options = {
  330. alert: false,
  331. rowSelection: null
  332. }
  333. this.optionAlertShow = false
  334. }
  335. },
  336. handleOk () {
  337. // this.setTree()
  338. this.$refs.table.refresh()
  339. },
  340. onSelectChange (selectedRowKeys, selectedRows) {
  341. this.selectedRowKeys = selectedRowKeys
  342. this.selectedRows = selectedRows
  343. },
  344. resetSearchForm () {
  345. this.queryParam = {
  346. }
  347. this.$refs.table.refresh(true)
  348. },
  349. /**
  350. * 设置设备类型树
  351. */
  352. base (keys, rows) {
  353. this.visible = true
  354. this.modalTitle = '选择设备'
  355. if (this.isCreated) {
  356. this.$refs.table.clearSelected()
  357. this.options.rowSelection.type = this.type
  358. this.handleOk()
  359. } else {
  360. this.tableOption()
  361. this.isCreated = true
  362. }
  363. },
  364. handleCancel () {
  365. this.visible = false
  366. this.confirmLoading = false
  367. this.selectedRowKeys = []
  368. this.selectedRows = []
  369. },
  370. handleSelect () {
  371. if (this.selectedRows.length === 0) {
  372. this.$message.warn('请至少选择一项信息')
  373. } else {
  374. this.confirmLoading = true
  375. this.$emit('selected', this.selectedRows)
  376. this.confirmLoading = false
  377. this.visible = false
  378. }
  379. },
  380. mySelect (selectedRowKeys, selectedRows) {
  381. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  382. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  383. },
  384. handleChange (value, label, extra) {
  385. const data = this.treeData.find(item => item.id === value)
  386. if (data && data.children && data.children.length > 0) {
  387. this.typeList = data.children.map(item => item.id)
  388. } else {
  389. this.typeList = [value]
  390. }
  391. }
  392. }
  393. }
  394. </script>