index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <template>
  2. <div class="view-table-content">
  3. <div class="view-dataSpecies-left" style="display: flex; width: 430px">
  4. <MenuTree :currentNodeKey="currentNodeKey" nodeKey="id" :treedata="menuTreeData" @TreeNodeclick="treeNodeClick" v-bind="treeObj" style="width: 250px"> </MenuTree>
  5. <MenuTree :currentNodeKey="currentConfigNodeKey" nodeKey="id" :treedata="configTreeData" @TreeNodeclick="treeConfigNodeClick" v-bind="configurationTreeObj" style="width: 250px"> </MenuTree>
  6. </div>
  7. <div class="view-dataSpecies-right">
  8. <div class="view-dataType-title">
  9. <div class="view-dataType-title-btn">
  10. <!-- <el-button type="success" @click="openDialog()" :disabled="currentConfigNodeKey === ''">新增</el-button> -->
  11. <el-button type="success" @click="openDialog()" :disabled="!(currentNode.type == 2) || currentConfigNodeKey == ''">新增</el-button>
  12. <el-button type="warning" @click="remove(tableCheckItems)" :disabled="tableCheckItems.length == 0">删除</el-button>
  13. <el-dropdown split-button type="primary" style="margin-left: 10px" trigger="click" @command="handleExport">
  14. 更多
  15. <el-dropdown-menu slot="dropdown">
  16. <el-dropdown-item command="importOperation">导入</el-dropdown-item>
  17. <el-dropdown-item command="allExport" :disabled="tableData.length == 0">导出</el-dropdown-item>
  18. <el-dropdown-item command="downloadTemplate">下载数据模板</el-dropdown-item>
  19. </el-dropdown-menu>
  20. </el-dropdown>
  21. </div>
  22. <!-- <div class="view-dataType-title-search">
  23. <el-input placeholder="请输入关键字" v-model="keyWord" class="input1">
  24. <el-button slot="append" icon="el-icon-search" @click="searchClick"></el-button>
  25. </el-input>
  26. </div> -->
  27. </div>
  28. <div class="view-dataType-table">
  29. <LTable ref="table" @selection-change="selection" :defaultFetch="false" :fetch="fetch" :columns="columns" :dataSource="tableData" :options="options" :pagination="tableRequset"></LTable>
  30. </div>
  31. <!-- 添加或修改有寿件对话框 -->
  32. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
  33. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  34. <el-form-item label="机型" prop="airModelId">
  35. <el-select v-model="form.airModelId" placeholder="请选择机型" disabled>
  36. <el-option v-for="item in aircaftModelAll" :key="item.aircaftModelId" :label="item.aircaftModelName" :value="item.aircaftModelId"> </el-option>
  37. </el-select>
  38. </el-form-item>
  39. <el-form-item label="编目" prop="airId">
  40. <el-select v-model="form.airId" placeholder="请选择编目" disabled>
  41. <el-option v-for="item in aircaftCatalogAll" :key="item.aircaftCatalogId" :label="item.aircaftCatalogCode" :value="item.aircaftCatalogId"> </el-option>
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item label="构型" prop="configId">
  45. <el-select v-model="form.configId" placeholder="请选择构型" disabled>
  46. <el-option v-for="item in configAll" :key="item.id" :label="item.name" :value="item.id"> </el-option>
  47. </el-select>
  48. </el-form-item>
  49. <el-form-item label="部件名称" prop="componentName">
  50. <el-input v-model="form.componentName" placeholder="请输入部件名称" />
  51. </el-form-item>
  52. <el-form-item label="部件型号" prop="componentModel">
  53. <el-input v-model="form.componentModel" placeholder="请输入部件型号" />
  54. </el-form-item>
  55. <el-form-item label="部件编码" prop="componentNum">
  56. <el-input v-model="form.componentNum" placeholder="请输入部件编码" />
  57. </el-form-item>
  58. <el-form-item label="出厂日期" prop="factoryDate">
  59. <el-date-picker placement="bottom-start" clearable v-model="form.factoryDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择出厂日期"></el-date-picker>
  60. </el-form-item>
  61. <el-form-item label="当前安装飞机" label-width="110px" prop="currentInstallAircraft">
  62. <el-input v-model="form.currentInstallAircraft" placeholder="请输入当前安装飞机" />
  63. </el-form-item>
  64. <el-form-item label="工作时次" prop="workTime">
  65. <el-input v-model="form.workTime" placeholder="请输入工作时次" />
  66. </el-form-item>
  67. <el-form-item label="额定寿命" prop="ratedLifetime">
  68. <el-input v-model="form.ratedLifetime" placeholder="请输入额定寿命" />
  69. </el-form-item>
  70. <el-form-item label="剩余寿命" prop="remainingLifetime">
  71. <el-input v-model="form.remainingLifetime" placeholder="请输入剩余寿命" />
  72. </el-form-item>
  73. </el-form>
  74. <span slot="footer" class="dialog-footer">
  75. <el-button @click="handleClose">取 消</el-button>
  76. <el-button type="primary" @click="submit">确 定</el-button>
  77. </span>
  78. </el-dialog>
  79. <!-- 导入 -->
  80. <ImportDialog ref="ImportDialog" @submitCallBack="ImportDialogCallBack" />
  81. </div>
  82. </div>
  83. </template>
  84. <script>
  85. import { getLifetimeSpareParts, addLifetimeSpareParts, updateLifetimeSpareParts, removeLifetimeSpareParts, downLoadLifetimeSpareParts, exportLifetimeSparePartsExcel } from '@/api/als/lifetimeSpareParts'
  86. import { getAircaftCatalogTree, getAircaftTypeAndModelTree } from '@/api/als/sideTree'
  87. import { getAvmatCatalog } from '@/api/basicData/dataSailingMaterialMaterialCoding'
  88. import { getAirConfiguration } from '@/api/als/airConfiguration'
  89. import { deepClone, debounce } from '@/utils/index'
  90. import { handleTree, flattenTree } from '../utils/common'
  91. import { getAircaftModelAll, getAircaftCatalogAll } from '@/api/als/aircraft'
  92. import ImportDialog from './importDialog/index.vue'
  93. export default {
  94. name: 'LifetimeSpareParts',
  95. components: { ImportDialog },
  96. data() {
  97. // 这里存放数据
  98. return {
  99. dialogTitle: '新增',
  100. dialogVisible: false,
  101. keyWord: '',
  102. aircaftModelIdList: [],
  103. currentNodeKey: '',
  104. currentNode: {},
  105. currentConfigNodeKey: '',
  106. currentConfigNode: {},
  107. menuTreeData: [],
  108. configTreeData: [],
  109. treeObj: {
  110. title: '所属机种',
  111. activityheight: '275px',
  112. searchIcon: false,
  113. configure: {
  114. children: 'children',
  115. label: 'label'
  116. }
  117. },
  118. configurationTreeObj: {
  119. title: '飞机构型',
  120. activityheight: '275px',
  121. searchIcon: false,
  122. configure: {
  123. children: 'children',
  124. label: 'name'
  125. }
  126. },
  127. typeTree: {
  128. children: 'children',
  129. label: 'label'
  130. },
  131. searchValue: '',
  132. columns: [
  133. { prop: 'id', label: '编号' },
  134. {
  135. prop: 'airModelId',
  136. label: '机型',
  137. render: (h, params) => {
  138. const matchedItem = this.aircaftModelAll.find((item) => params.row.airModelId === item.aircaftModelId)
  139. if (matchedItem) {
  140. return h('span', matchedItem.aircaftModelName)
  141. } else {
  142. return h('span', params.row.airModelId)
  143. }
  144. }
  145. },
  146. {
  147. prop: 'airId',
  148. label: '编目',
  149. render: (h, params) => {
  150. const matchedItem = this.aircaftCatalogAll.find((item) => params.row.airId.trim() === item.aircaftCatalogId.trim())
  151. if (matchedItem) {
  152. return h('span', matchedItem.aircaftCatalogCode)
  153. } else {
  154. return h('span', params.row.airId)
  155. }
  156. }
  157. },
  158. {
  159. prop: 'configId',
  160. label: '构型',
  161. render: (h, params) => {
  162. const matchedItem = this.configAll.find((item) => params.row.configId.trim() === item.id.trim())
  163. if (matchedItem) {
  164. return h('span', matchedItem.name)
  165. } else {
  166. return h('span', params.row.configId)
  167. }
  168. }
  169. },
  170. {
  171. prop: 'componentName',
  172. label: '部件名称'
  173. },
  174. {
  175. prop: 'componentModel',
  176. label: '部件型号'
  177. },
  178. {
  179. prop: 'componentNum',
  180. label: '部件编码'
  181. },
  182. {
  183. prop: 'factoryDate',
  184. label: '出厂日期'
  185. },
  186. {
  187. prop: 'currentInstallAircraft',
  188. label: '当前安装飞机'
  189. },
  190. {
  191. prop: 'workTime',
  192. label: '工作时次'
  193. },
  194. {
  195. prop: 'ratedLifetime',
  196. label: '额定寿命'
  197. },
  198. {
  199. prop: 'remainingLifetime',
  200. label: '剩余寿命'
  201. },
  202. {
  203. button: true,
  204. label: '操作',
  205. width: '240px',
  206. group: [
  207. {
  208. name: '编辑',
  209. type: 'text',
  210. round: false,
  211. plain: false,
  212. onClick: (row, index, scope) => {
  213. this.handUpdate(row)
  214. }
  215. },
  216. {
  217. name: '删除',
  218. type: 'text',
  219. round: false,
  220. plain: false,
  221. onClick: (row, index, scope) => {
  222. this.remove([row])
  223. }
  224. }
  225. ]
  226. }
  227. ],
  228. options: {
  229. stripe: false, // 斑马纹
  230. mutiSelect: true, // 多选框
  231. index: false, // 显示序号, 多选则 mutiSelect
  232. loading: false, // 表格动画
  233. initTable: false, // 是否一挂载就加载数据
  234. border: true,
  235. height: 'calc(100vh - 300px)'
  236. },
  237. tableCheckItems: [],
  238. tableData: [],
  239. avmatTableData: [],
  240. tableRequset: {
  241. total: 0,
  242. pageIndex: 1,
  243. pageSize: 20,
  244. searchValue: ''
  245. },
  246. avmatTableRequset: {
  247. total: 0,
  248. pageIndex: 1,
  249. pageSize: 20,
  250. searchValue: ''
  251. },
  252. form: {
  253. id: '',
  254. airId: '',
  255. airModelId: '',
  256. configId: '',
  257. componentName: '',
  258. componentModel: '',
  259. componentNum: '',
  260. factoryDate: '',
  261. currentInstallAircraft: '',
  262. workTime: '',
  263. ratedLifetime: '',
  264. remainingLifetime: '',
  265. remarks: '',
  266. tenantId: '',
  267. delFlag: '',
  268. version: '',
  269. createBy: '',
  270. createTime: '',
  271. updateBy: '',
  272. updateTime: ''
  273. },
  274. debounceFn: debounce(this.fetch, 500),
  275. aircaftModelAll: [],
  276. aircaftCatalogAll: [],
  277. configAll: [],
  278. rules: {
  279. airId: [{ required: true, message: '编目不能为空', trigger: 'blur' }],
  280. airModelId: [{ required: true, message: '机型不能为空', trigger: 'blur' }],
  281. configId: [{ required: true, message: '构型不能为空', trigger: 'blur' }],
  282. componentName: [{ required: true, message: '部件名称不能为空', trigger: 'blur' }],
  283. componentModel: [{ required: true, message: '部件型号不能为空', trigger: 'blur' }],
  284. componentNum: [{ required: true, message: '部件编码不能为空', trigger: 'blur' }],
  285. factoryDate: [{ required: true, message: '出厂日期不能为空', trigger: 'blur' }],
  286. currentInstallAircraft: [{ required: true, message: '当前安装飞机不能为空', trigger: 'blur' }],
  287. workTime: [{ required: true, message: '工作时次不能为空', trigger: 'blur' }],
  288. ratedLifetime: [{ required: true, message: '额定寿命不能为空', trigger: 'blur' }]
  289. }
  290. }
  291. },
  292. watch: {
  293. keyWord() {
  294. this.tableRequset.pageIndex = 1
  295. this.debounceFn()
  296. }
  297. },
  298. mounted() {
  299. this.getAircaftTypeAndModelTreeAPI()
  300. },
  301. methods: {
  302. async getAircaftTypeAndModelTreeAPI(params) {
  303. const { data } = await getAircaftCatalogTree(params)
  304. this.menuTreeData = data
  305. const { pageSize, pageIndex } = this.avmatTableRequset
  306. const {
  307. data: { list, totalCount }
  308. } = await getAvmatCatalog({
  309. pageIndex,
  310. pageSize,
  311. avmatCategoriesId: '',
  312. avmatType: '1'
  313. })
  314. this.avmatTableData = flattenTree(list)
  315. this.avmatTableRequset.total = totalCount
  316. const getAircaftModelAllParams = {
  317. aircaftTypeCode: '',
  318. aircaftTypeId: '',
  319. queryParam: ''
  320. }
  321. const { data: data1 } = await getAircaftModelAll(getAircaftModelAllParams)
  322. this.aircaftModelAll = data1
  323. const { data: data2 } = await getAircaftCatalogAll({
  324. keyWord: '',
  325. aircaftModelIdList: []
  326. })
  327. this.aircaftCatalogAll = flattenTree(data2)
  328. },
  329. async removeLifetimeSparePartsAPI(params) {
  330. try {
  331. const { code } = await removeLifetimeSpareParts(params)
  332. if (code === 200) {
  333. this.$message({
  334. type: 'success',
  335. message: '操作成功!'
  336. })
  337. await this.getLifetimeSparePartsAPI({ configId: this.currentConfigNodeKey })
  338. this.handleClose()
  339. }
  340. } catch (error) {}
  341. },
  342. getTreeLeafData(list) {
  343. const newArr = []
  344. function getLeaf(data, arr) {
  345. data.forEach((e) => {
  346. if (e.type === 1) {
  347. arr.push(e)
  348. }
  349. if (e.children.length) {
  350. getLeaf(e.children, arr)
  351. }
  352. })
  353. }
  354. getLeaf(list, newArr)
  355. return newArr
  356. },
  357. async getLifetimeSparePartsAPI(params) {
  358. if (this.$refs.table) this.$refs.table.clearSelection()
  359. const { keyWord } = this
  360. const { pageSize, pageIndex } = this.tableRequset
  361. const {
  362. data: { list, totalCount }
  363. } = await getLifetimeSpareParts({ pageSize, pageNum: pageIndex, keyWord, ...params })
  364. this.tableData = list
  365. this.tableRequset.total = totalCount
  366. },
  367. fetch() {
  368. this.getLifetimeSparePartsAPI({ configId: this.currentConfigNodeKey })
  369. },
  370. searchClick() {
  371. this.getLifetimeSparePartsAPI({ configId: this.currentConfigNodeKey })
  372. },
  373. async addLifetimeSparePartsAPI() {
  374. this.$refs['form'].validate(async (valid) => {
  375. if (valid) {
  376. try {
  377. delete this.form.aircaftModelName
  378. const { code } = await addLifetimeSpareParts({ ...this.form })
  379. if (code === 200) {
  380. this.$message({
  381. type: 'success',
  382. message: '操作成功!'
  383. })
  384. this.getLifetimeSparePartsAPI({ configId: this.currentConfigNodeKey })
  385. this.handleClose()
  386. }
  387. } catch (error) {}
  388. }
  389. })
  390. },
  391. async updateLifetimeSparePartsAPI() {
  392. this.$refs['form'].validate(async (valid) => {
  393. if (valid) {
  394. try {
  395. const { code } = await updateLifetimeSpareParts({ ...this.form })
  396. if (code === 200) {
  397. this.$message({
  398. type: 'success',
  399. message: '操作成功!'
  400. })
  401. this.getLifetimeSparePartsAPI({ configId: this.currentConfigNodeKey })
  402. this.handleClose()
  403. }
  404. } catch (error) {}
  405. }
  406. })
  407. },
  408. async treeNodeClick(data) {
  409. // this.$refs.table.clearSelection()
  410. this.currentAirId = this.form.airId = data.id
  411. this.currentAirModelId = this.form.airModelId = data.parentId
  412. this.currentNode = data
  413. // this.form.aircraftType = data.label
  414. // this.getAirInstallAPI(this.currentNodeKey)
  415. let dataTree = []
  416. if (data.type === 1) {
  417. const { data: data1 } = await getAirConfiguration({ aircraftType: data.id })
  418. dataTree = data1
  419. } else if (data.type === 2) {
  420. const { data: data1 } = await getAirConfiguration({ aircraftType: data.parentId })
  421. dataTree = data1
  422. }
  423. this.configAll = dataTree
  424. this.configTreeData = []
  425. const topNode = { id: 1, name: '整机', children: [] }
  426. // topNode.children = data1
  427. topNode.children = handleTree(dataTree, 'id')
  428. this.configTreeData.push(topNode)
  429. },
  430. treeConfigNodeClick(data) {
  431. this.$refs.table.clearSelection()
  432. this.currentConfigNodeKey = this.form.configId = data.id
  433. this.currentConfigNode = data
  434. // const dataTree = this.configTreeData
  435. // console.log('dataTree', dataTree)
  436. // this.configNodeIdList = String(this.getAllTreeData(dataTree[0].children.length ? dataTree[0].children : [dataTree[0]]).map((e) => e.id))
  437. // console.log('this.configNodeIdList', this.configNodeIdList)
  438. // this.getAirInstallAPI({ configId: this.configNodeIdList })
  439. this.getLifetimeSparePartsAPI({ configId: this.currentConfigNodeKey })
  440. },
  441. openDialog() {
  442. this.dialogTitle = '新增'
  443. this.dialogVisible = true
  444. this.form.aircaftModelName = this.currentNode.label
  445. this.form.aircaftModelId = this.currentNode.id
  446. },
  447. handleClose() {
  448. this.dialogVisible = false
  449. this.form.componentName = ''
  450. this.form.componentModel = ''
  451. this.form.componentNum = ''
  452. this.form.factoryDate = ''
  453. this.form.currentInstallAircraft = ''
  454. this.form.workTime = ''
  455. this.form.ratedLifetime = ''
  456. this.form.remainingLifetime = ''
  457. this.form.remarks = ''
  458. this.form.tenantId = ''
  459. this.form.delFlag = ''
  460. this.form.version = ''
  461. this.form.createBy = ''
  462. this.form.createTime = ''
  463. this.form.updateBy = ''
  464. this.form.updateTime = ''
  465. },
  466. handUpdate(row) {
  467. this.dialogTitle = '编辑'
  468. this.form = deepClone(row)
  469. this.dialogVisible = true
  470. },
  471. submit() {
  472. switch (this.dialogTitle) {
  473. case '编辑':
  474. this.updateLifetimeSparePartsAPI()
  475. break
  476. case '新增':
  477. this.addLifetimeSparePartsAPI()
  478. break
  479. }
  480. },
  481. selection(val) {
  482. this.tableCheckItems = val
  483. },
  484. remove(row) {
  485. this.$confirm('是否删除该机种', '提示', {
  486. confirmButtonText: '确定',
  487. cancelButtonText: '取消',
  488. type: 'warning'
  489. })
  490. .then(() => {
  491. this.removeLifetimeSparePartsAPI(row.map((e) => e.id))
  492. })
  493. .catch(() => {})
  494. },
  495. //更多按钮
  496. handleExport(type) {
  497. this[type]()
  498. },
  499. //导入
  500. importOperation() {
  501. this.$refs.ImportDialog.triggerDialog()
  502. },
  503. //导入回写
  504. ImportDialogCallBack() {
  505. this.getAircaftTypeAndModelTreeAPI()
  506. },
  507. //导出全部
  508. async allExport() {
  509. // const params = {
  510. // queryParam: this.searchValue
  511. // }
  512. await exportLifetimeSparePartsExcel({})
  513. },
  514. //下载模板
  515. async downloadTemplate() {
  516. await downLoadLifetimeSpareParts()
  517. }
  518. }
  519. }
  520. </script>
  521. <style lang="scss">
  522. @import '../index.scss';
  523. </style>