SbInfoTree.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <template>
  2. <a-card :bordered="false">
  3. <a-row :gutter="8" v-show="visible">
  4. <a-col :span="4">
  5. <a-tree
  6. @expand="onExpand"
  7. :expandedKeys="expandedKeys"
  8. :autoExpandParent="true"
  9. @select="onSelect"
  10. :selectedKeys="selectedKeys"
  11. :treeData="treeData"
  12. />
  13. </a-col>
  14. <a-col :span="20">
  15. <div>
  16. <div class="table-page-search-wrapper">
  17. <a-form layout="inline">
  18. <a-row :gutter="48">
  19. <a-col :md="8" :sm="24">
  20. <a-form-item label="关键字">
  21. <a-input v-model="queryParam.keyword" placeholder="请输入名称/编码"/>
  22. </a-form-item>
  23. </a-col>
  24. <a-col :md="6" :sm="24">
  25. <a-form-item label="型号">
  26. <a-input v-model="queryParam.model" placeholder="请输入原厂编号"/>
  27. </a-form-item>
  28. </a-col>
  29. <a-col :md="8" :sm="24">
  30. <a-form-item label="所属区域">
  31. <a-select @change="handleAreaChange" v-model="queryParam.useArea" placeholder="请选择">
  32. <a-select-option
  33. v-for="({deptId, name}) in areaList"
  34. :key="deptId"
  35. :label="name"
  36. :value="deptId">{{ name }}
  37. </a-select-option>
  38. </a-select>
  39. </a-form-item>
  40. </a-col>
  41. <a-col :md="8" :sm="24">
  42. <a-form-item label="所属公司">
  43. <a-select @change="handleCompanyChange" v-model="queryParam.useCompany" placeholder="请选择">
  44. <a-select-option
  45. v-for="({deptId, name}) in companyList"
  46. :key="deptId"
  47. :label="name"
  48. :value="deptId">{{ name }}
  49. </a-select-option>
  50. </a-select>
  51. </a-form-item>
  52. </a-col>
  53. <a-col :md="8" :sm="24">
  54. <a-form-item label="所属项目">
  55. <a-select @change="handleProjectChange" v-model="queryParam.useProject" placeholder="请选择">
  56. <a-select-option
  57. v-for="({deptId, name}) in projectList"
  58. :key="deptId"
  59. :label="name"
  60. :value="deptId">{{ name }}
  61. </a-select-option>
  62. </a-select>
  63. </a-form-item>
  64. </a-col>
  65. <a-col :md="8" :sm="24">
  66. <a-form-item label="所属部门">
  67. <a-select @change="handleDeptChange" v-model="queryParam.useDept" placeholder="请选择">
  68. <a-select-option
  69. v-for="({deptId, name}) in deptList"
  70. :key="deptId"
  71. :label="name"
  72. :value="deptId">{{ name }}
  73. </a-select-option>
  74. </a-select>
  75. </a-form-item>
  76. </a-col>
  77. <a-col :md="8" :sm="24">
  78. <a-form-item label="设备状态">
  79. <a-select @change="handleDeptChange" v-model="queryParam.status" placeholder="请选择">
  80. <a-select-option
  81. v-for="(label,value) in statusMap"
  82. :key="value"
  83. :label="label"
  84. :value="parseInt(value)">{{ label }}
  85. </a-select-option>
  86. </a-select>
  87. </a-form-item>
  88. </a-col>
  89. <a-col :md="6 || 24" :sm="24">
  90. <span class="table-page-search-submitButtons">
  91. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  92. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  93. </span>
  94. </a-col>
  95. </a-row>
  96. </a-form>
  97. </div>
  98. <div class="table-operator">
  99. <a-button v-if="$auth('sb-infos-add')" type="primary" icon="plus" @click="handleAdd">新增</a-button>
  100. <a-button style="margin-left: 8px" v-if="$auth('sb-infos-export')" type="primary" icon="download" @click="doExport">导出</a-button>
  101. <a-button style="margin-left: 8px" v-if="$auth('sb-infos-export')" type="primary" icon="upload" @click="doImport">初始化导入</a-button>
  102. <a-button style="margin-left: 8px" v-if="$auth('sb-infos-export')" type="primary" icon="upload" @click="doImportDe">折旧导入</a-button>
  103. <a-button style="margin-left: 8px" v-if="$auth('sb-infos-export')" type="primary" icon="upload" @click="printQcode()">打印</a-button>
  104. <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0 && $auth('sb-infos-del')">
  105. <a-menu slot="overlay">
  106. <a-popconfirm title="是否要删除所选数据?" @confirm="batchDelete()">
  107. <a-menu-item key="1"><a-icon type="delete" /><a>删除</a></a-menu-item>
  108. </a-popconfirm>
  109. </a-menu>
  110. <a-button style="margin-left: 8px">
  111. 批量操作 <a-icon type="down" />
  112. </a-button>
  113. </a-dropdown>
  114. </div>
  115. <s-table
  116. ref="table"
  117. size="default"
  118. rowKey="id"
  119. :widthSpace="true"
  120. :columns="columns"
  121. :data="loadData"
  122. :alert="options.alert"
  123. :rowSelection="options.rowSelection"
  124. :scroll="{x: BaseTool.Constant.scrollX, y: BaseTool.Constant.scrollY }"
  125. showPagination="auto"
  126. >
  127. <span slot="action" slot-scope="record">
  128. <template>
  129. <a @click="handleView(record)">查看</a>
  130. <a-divider type="vertical" />
  131. <a v-if="$auth('sb-infos-edit')" @click="handleEdit(record)">修改</a>
  132. <!--<a-divider type="vertical" />
  133. <a-popconfirm v-if="$auth('sb-infos-del')" title="是否要删除该设备?" @confirm="batchDelete(record.id)">
  134. <a>删除</a>
  135. </a-popconfirm>
  136. <a-divider type="vertical" />
  137. <a @click="handleCopy(record)">复制</a>-->
  138. <a-divider v-if="record.status != 2" type="vertical" />
  139. <a-popconfirm v-if="record.status != 2" title="是否要启用该设备?" @confirm="handleStart(record)">
  140. <a>启用</a>
  141. </a-popconfirm>
  142. <a-divider v-if="record.status != 7" type="vertical" />
  143. <a-popconfirm v-if="record.status != 7" title="是否要停用该设备?" @confirm="handleStop(record)">
  144. <a>停用</a>
  145. </a-popconfirm>
  146. <a-divider type="vertical" />
  147. <a @click="printQcode(record)">打印</a>
  148. </template>
  149. </span>
  150. <span slot="status" slot-scope="text">
  151. <badge
  152. :status="DictCache.COLOR.SB_INFO_STATUS[text]"
  153. :text="statusMap[text]" />
  154. </span>
  155. <span slot="wbFile" slot-scope="record">
  156. <template>
  157. <a @click="handleRepairFilePreview(record)">预览</a>
  158. <a-divider type="vertical" />
  159. <a @click="handleRepairFileDownload(record)">下载</a>
  160. </template>
  161. </span>
  162. <span slot="useFile" slot-scope="record">
  163. <template>
  164. <a @click="handleUseFilePreview(record)">预览</a>
  165. <a-divider type="vertical" />
  166. <a @click="handleUseFileDownload(record)">下载</a>
  167. </template>
  168. </span>
  169. <span slot="checkFile" slot-scope="record">
  170. <template>
  171. <a @click="handleCheckFilePreview(record)">预览</a>
  172. <a-divider type="vertical" />
  173. <a @click="handleCheckFileDownload(record)">下载</a>
  174. </template>
  175. </span>
  176. </s-table>
  177. </div>
  178. </a-col>
  179. </a-row>
  180. <base-form ref="baseModal" @ok="handleOk"/>
  181. <detail ref="detailModal" @ok="handleOk"/>
  182. <download-modal ref="downloadModal"/>
  183. <preview-modal ref="previewModal"/>
  184. <import-form-add ref="importModal" @ok="handleOk"/>
  185. <print-sb-code ref="printSbCode"/>
  186. </a-card>
  187. </template>
  188. <script>
  189. import { STable, Ellipsis } from '@/components'
  190. import BaseForm from './modules/BaseForm'
  191. import Detail from './modules/Detail'
  192. import DownloadModal from '@/views/download/DownloadModal'
  193. import PreviewModal from '@/views/preview/PreviewModal'
  194. import { updateSbInfo, getSbInfoPage, getSbInfoTree, deleteSbInfos, fetchSbInfo, exportSbInfo } from '@/api/sb/info'
  195. import { queryDept, getDeptsAllByParentId } from '@/api/upms/dept'
  196. import BaseTool from '../../../utils/tool'
  197. import ImportFormAdd from './modules/ImportFormAdd'
  198. import PrintSbCode from '@/views/sb/info/modules/PrintSbCode'
  199. export default {
  200. name: 'SbInfoTree',
  201. components: {
  202. STable,
  203. Ellipsis,
  204. BaseForm,
  205. Detail,
  206. DownloadModal,
  207. PreviewModal,
  208. PrintSbCode,
  209. ImportFormAdd
  210. },
  211. props: {
  212. filter: {
  213. type: Number,
  214. default: -1
  215. }
  216. },
  217. data () {
  218. return {
  219. // 查询参数
  220. queryParam: {
  221. filter: this.filter,
  222. isChild: this.DictCache.VALUE.SB_IS_CHILD.IS_PARENT
  223. },
  224. depreciationTypeMap: {},
  225. visible: true,
  226. levelMap: {},
  227. unitMap: {},
  228. areaList: {},
  229. companyList: {},
  230. projectList: {},
  231. deptList: {},
  232. useTypeMap: {},
  233. statusMap: {},
  234. expandedKeys: [],
  235. selectedKeys: [],
  236. sourceTypeMap: {},
  237. treeData: [],
  238. // 表头
  239. columns: [
  240. {
  241. title: '序号',
  242. dataIndex: 'index',
  243. checked: true,
  244. customRender: (text, record, index) => {
  245. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  246. }
  247. },
  248. {
  249. title: '设备名称',
  250. checked: true,
  251. dataIndex: 'name'
  252. },
  253. {
  254. title: '设备编号',
  255. dataIndex: 'no',
  256. checked: true
  257. },
  258. {
  259. title: '自编号',
  260. checked: true,
  261. dataIndex: 'zbh'
  262. },
  263. {
  264. title: '车牌号',
  265. checked: true,
  266. dataIndex: 'cph'
  267. },
  268. {
  269. title: '规格型号',
  270. checked: true,
  271. dataIndex: 'model'
  272. },
  273. {
  274. title: '财务编码',
  275. dataIndex: 'financingNo'
  276. },
  277. {
  278. title: '设备类型',
  279. checked: true,
  280. dataIndex: 'type',
  281. customRender: (text, record, index) => {
  282. return record.typeName
  283. }
  284. },
  285. {
  286. title: '自定义类型',
  287. checked: true,
  288. dataIndex: 'useType',
  289. customRender: (text, record, index) => {
  290. return this.BaseTool.Object.getField(this.useTypeMap, text)
  291. }
  292. },
  293. {
  294. title: '设备等级',
  295. checked: true,
  296. dataIndex: 'level',
  297. customRender: (text, record, index) => {
  298. return this.BaseTool.Object.getField(this.levelMap, text)
  299. }
  300. },
  301. {
  302. title: '设备原值',
  303. dataIndex: 'initialValue',
  304. customRender: (text, record, index) => {
  305. return this.BaseTool.Amount.formatter(text)
  306. }
  307. },
  308. {
  309. title: '单位',
  310. dataIndex: 'unit',
  311. customRender: (text, record, index) => {
  312. return BaseTool.Object.getField(this.unitMap, text)
  313. }
  314. },
  315. {
  316. title: '保管人',
  317. dataIndex: 'saveUser'
  318. },
  319. {
  320. title: '购置日期',
  321. dataIndex: 'buyDate'
  322. },
  323. {
  324. title: '投用日期',
  325. dataIndex: 'startDate'
  326. },
  327. {
  328. title: '下次检定日期',
  329. dataIndex: 'nextCheckDate'
  330. },
  331. {
  332. title: '总行驶里程',
  333. dataIndex: 'totalMiles'
  334. },
  335. {
  336. title: '总行驶小时',
  337. dataIndex: 'totalHours'
  338. },
  339. {
  340. title: '保修截至日期',
  341. dataIndex: 'guaranteeDate'
  342. },
  343. {
  344. title: '预计工作年限',
  345. dataIndex: 'workYear'
  346. },
  347. {
  348. title: '预计报废日期',
  349. dataIndex: 'retirementDate'
  350. },
  351. {
  352. title: '折旧方式',
  353. dataIndex: 'depreciationType',
  354. customRender: (text, record, index) => {
  355. return this.BaseTool.Object.getField(this.depreciationTypeMap, text)
  356. }
  357. },
  358. {
  359. title: '状态',
  360. checked: true,
  361. dataIndex: 'status',
  362. scopedSlots: { customRender: 'status' }
  363. },
  364. {
  365. title: '操作',
  366. key: 'action',
  367. checked: true,
  368. align: 'center',
  369. // fixed: 'right',
  370. scopedSlots: { customRender: 'action' }
  371. }
  372. ],
  373. // 加载数据方法 必须为 Promise 对象
  374. loadData: parameter => {
  375. parameter = {
  376. ...parameter,
  377. ...this.queryParam,
  378. dataScope: {
  379. sortBy: 'desc',
  380. sortName: 'update_time'
  381. }
  382. }
  383. return getSbInfoPage(Object.assign(parameter, this.queryParam))
  384. .then(res => {
  385. return res.data
  386. })
  387. },
  388. selectedRowKeys: [],
  389. selectedRows: [],
  390. options: {
  391. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  392. rowSelection: {
  393. selectedRowKeys: this.selectedRowKeys,
  394. onChange: this.onSelectChange
  395. }
  396. },
  397. optionAlertShow: false
  398. }
  399. },
  400. created () {
  401. this.tableOption()
  402. this.depreciationTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_DEPRECIATIONTYPE)
  403. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_LEVEL)
  404. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_INFO_STATUS)
  405. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  406. this.sourceTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBTYPE_SOURCETYPE)
  407. this.useTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_USE_TYPE)
  408. },
  409. methods: {
  410. tableOption () {
  411. this.setTree()
  412. if (!this.optionAlertShow) {
  413. this.options = {
  414. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  415. rowSelection: {
  416. selectedRowKeys: this.selectedRowKeys,
  417. onChange: this.onSelectChange,
  418. getCheckboxProps: record => ({
  419. props: {
  420. disabled: false,
  421. name: record.id
  422. }
  423. })
  424. }
  425. }
  426. this.optionAlertShow = true
  427. } else {
  428. this.options = {
  429. alert: false,
  430. rowSelection: null
  431. }
  432. this.optionAlertShow = false
  433. }
  434. },
  435. batchDelete (id) {
  436. let ids = []
  437. if (this.BaseTool.String.isBlank(id)) {
  438. const length = this.selectedRows.length
  439. if (length === 0) {
  440. this.$message.info('请选择要删除的记录')
  441. return
  442. }
  443. ids = this.selectedRows.map(item => item.id)
  444. } else {
  445. ids = [id]
  446. }
  447. deleteSbInfos(ids).then(res => {
  448. this.$message.info('删除成功')
  449. this.handleOk()
  450. this.$refs.table.clearSelected()
  451. })
  452. },
  453. handleEdit (record) {
  454. fetchSbInfo({ id: record.id }).then(res => {
  455. this.visible = false
  456. const modal = this.$refs.baseModal
  457. modal.base(res.data)
  458. })
  459. },
  460. printQcode (record) {
  461. let recordList = []
  462. console.log(record, this.selectedRows)
  463. if (this.BaseTool.String.isBlank(record)) {
  464. const length = this.selectedRows.length
  465. if (length === 0) {
  466. this.$message.info('请选择要打印的记录')
  467. return
  468. }
  469. recordList = this.selectedRows
  470. } else {
  471. recordList = [record]
  472. }
  473. this.$refs.printSbCode.base(recordList)
  474. },
  475. handleStart (record) {
  476. record.status = 2
  477. updateSbInfo(record).then(res => {
  478. this.$message.info('已启用')
  479. })
  480. },
  481. handleStop (record) {
  482. record.status = 7
  483. updateSbInfo(record).then(res => {
  484. this.$message.info('已停用')
  485. })
  486. },
  487. handleAdd () {
  488. this.visible = false
  489. this.$refs.baseModal.base()
  490. },
  491. handleView (record) {
  492. fetchSbInfo({ id: record.id }).then(res => {
  493. this.visible = false
  494. const modal = this.$refs.detailModal
  495. modal.base(res.data)
  496. })
  497. },
  498. handleAreaChange (value) {
  499. getDeptsAllByParentId({ deptId: value, nature: this.DictCache.VALUE.SYS_DEPT_NATURE.FEN_GONG_SI }).then(res => {
  500. this.companyList = res.data
  501. })
  502. },
  503. handleCompanyChange (value) {
  504. getDeptsAllByParentId({ deptId: value, nature: this.DictCache.VALUE.SYS_DEPT_NATURE.XIANG_MU_BU }).then(res => {
  505. this.projectList = res.data
  506. })
  507. },
  508. handleProjectChange (value) {
  509. getDeptsAllByParentId({ deptId: value, nature: this.DictCache.VALUE.SYS_DEPT_NATURE.BU_MEN }).then(res => {
  510. this.deptList = res.data
  511. })
  512. },
  513. handleDeptChange (value) {
  514. getDeptsAllByParentId({ deptId: value, nature: this.DictCache.VALUE.SYS_DEPT_NATURE.BAN_ZU }).then(res => {
  515. this.groupList = res.data
  516. })
  517. },
  518. handleCopy (record) {
  519. this.visible = false
  520. fetchSbInfo({ id: record.id }).then(res => {
  521. const modal = this.$refs.baseModal
  522. res.data.id = null
  523. modal.base(res.data)
  524. })
  525. },
  526. handleOk () {
  527. this.visible = true
  528. this.setTree()
  529. this.$refs.table.refresh()
  530. },
  531. onSelectChange (selectedRowKeys, selectedRows) {
  532. this.selectedRowKeys = selectedRowKeys
  533. this.selectedRows = selectedRows
  534. },
  535. resetSearchForm () {
  536. this.queryParam = {
  537. filter: this.filter,
  538. isChild: this.DictCache.VALUE.SB_IS_CHILD.IS_PARENT
  539. }
  540. this.visible = true
  541. this.$refs.table.refresh(true)
  542. },
  543. doExport () {
  544. const parameter = {
  545. ...this.queryParam
  546. }
  547. exportSbInfo(parameter).then(file => {
  548. this.BaseTool.UPLOAD.downLoadExportExcel(file)
  549. })
  550. },
  551. setTree (record = {}) {
  552. queryDept({ nature: this.DictCache.VALUE.SYS_DEPT_NATURE.JITUAN }).then(res => {
  553. this.areaList = res.data
  554. })
  555. getSbInfoTree().then(res => {
  556. this.treeData = res.data
  557. })
  558. },
  559. onSelect: function (selectedKeys, info) {
  560. this.selectedKeys = selectedKeys
  561. this.queryParam.isChild = null
  562. this.queryParam.id = selectedKeys.length > 0 ? selectedKeys[0] : ''
  563. this.$refs.table.refresh(true)
  564. },
  565. onExpand (expandedKeys) {
  566. this.expandedKeys = expandedKeys
  567. this.autoExpandParent = false
  568. },
  569. handleRepairFilePreview (record) {
  570. console.log(record, 87878)
  571. this.$refs.previewModal.base(record.id, this.DictCache.VALUE.FILE_MODULE.SBINFO_REPAIRFILE)
  572. },
  573. handleRepairFileDownload (record) {
  574. // this.$refs.downloadModal.base(record.id, this.DictCache.VALUE.FILE_MODULE.SBINFO_REPAIRFILE, getDownloadUrl(record.id))
  575. },
  576. handleUseFilePreview (record) {
  577. this.$refs.previewModal.base(record.id, this.DictCache.VALUE.FILE_MODULE.SBINFO_USEFILE)
  578. },
  579. handleUseFileDownload (record) {
  580. // this.$refs.downloadModal.base(record.id, this.DictCache.VALUE.FILE_MODULE.SBINFO_USEFILE, getDownloadUrl(record.id))
  581. },
  582. handleCheckFilePreview (record) {
  583. this.$refs.previewModal.base(record.id, this.DictCache.VALUE.FILE_MODULE.SBINFO_RECHECKFILE)
  584. },
  585. handleCheckFileDownload (record) {
  586. // this.$refs.downloadModal.base(record.id, this.DictCache.VALUE.FILE_MODULE.SBINFO_RECHECKFILE, getDownloadUrl(record.id))
  587. },
  588. doImport () {
  589. if (this.queryParam.useCompany == null) {
  590. this.$message.error('请先选择公司')
  591. return
  592. }
  593. if (this.queryParam.useProject == null) {
  594. this.$message.error('请先选择项目部')
  595. return
  596. }
  597. this.$refs.importModal.base(this.queryParam.useCompany, this.queryParam.useProject)
  598. },
  599. doImportDe () {
  600. this.queryParam.useCompany = null
  601. this.queryParam.useProject = null
  602. this.$refs.importModal.base()
  603. }
  604. }
  605. }
  606. </script>