index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <div class="view-table-content">
  3. <div style="width: 100%">
  4. <div class="view-dataType-title">
  5. <div class="view-dataType-title-btn">
  6. <el-button type="success" @click="openDialog()" :disabled="currentNode.type == 2">新增</el-button>
  7. <el-button type="warning" @click="remove(tableCheckItems)" :disabled="tableCheckItems.length == 0">删除</el-button>
  8. <el-dropdown split-button type="primary" style="margin-left: 10px" trigger="click" @command="handleExport">
  9. 更多
  10. <el-dropdown-menu slot="dropdown">
  11. <el-dropdown-item command="handleImport">导入</el-dropdown-item>
  12. <el-dropdown-item command="handleExport" :disabled="tableData.length == 0">导出</el-dropdown-item>
  13. <el-dropdown-item command="importTemplate">下载数据模板</el-dropdown-item>
  14. </el-dropdown-menu>
  15. </el-dropdown>
  16. </div>
  17. <div class="view-dataType-title-search">
  18. <el-input placeholder="请输入故障现象" v-model="keyWordData" class="input1">
  19. <el-button slot="append" icon="el-icon-search" @click="searchClick(keyWordData)"></el-button>
  20. </el-input>
  21. </div>
  22. </div>
  23. <div class="view-dataType-table">
  24. <LTable ref="table" @selection-change="selection" :defaultFetch="false" :fetch="fetch" :columns="columns" :dataSource="tableData" :options="options" :pagination="tableRequset"></LTable>
  25. </div>
  26. <!-- 添加或修改故障案例对话框 -->
  27. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
  28. <el-form ref="form" :model="form" label-width="80px">
  29. <el-form-item label="机型" prop="aircraftTypeName">
  30. <treeselect :value="form.aircraftTypeName" :normalizer="aircraftTypeNormalizer" :options="aircraftTypeTreeData" :show-count="true" placeholder="请选择机型" @select="aircraftTypeChange" />
  31. </el-form-item>
  32. <el-form-item label="系统" prop="aircraftSystemName">
  33. <el-input v-model="form.aircraftSystemName" placeholder="请输入系统" />
  34. </el-form-item>
  35. <el-form-item label="分系统" prop="aircraftSubsystemName">
  36. <el-input v-model="form.aircraftSubsystemName" placeholder="请输入分系统" />
  37. </el-form-item>
  38. <el-form-item label="故障现象" prop="faultPhenomenon">
  39. <el-input v-model="form.faultPhenomenon" placeholder="请输入故障现象" />
  40. </el-form-item>
  41. <el-form-item label="故障原因" prop="faultCause">
  42. <el-input v-model="form.faultCause" placeholder="请输入故障原因" />
  43. </el-form-item>
  44. </el-form>
  45. <span slot="footer" class="dialog-footer">
  46. <el-button @click="handleClose">取 消</el-button>
  47. <el-button type="primary" @click="submit">确 定</el-button>
  48. </span>
  49. </el-dialog>
  50. <el-dialog title="故障案例详情" :visible.sync="detailVisible" width="1000px" :show-close="false">
  51. <el-descriptions border>
  52. <el-descriptions-item label="机型">{{ detailAircraftType }}</el-descriptions-item>
  53. <el-descriptions-item label="系统">{{ form.aircraftSystemName }}</el-descriptions-item>
  54. <el-descriptions-item label="分系统">{{ form.aircraftSubsystemName }}</el-descriptions-item>
  55. <el-descriptions-item label="故障现象">{{ form.faultPhenomenon }}</el-descriptions-item>
  56. <el-descriptions-item label="故障原因">{{ form.faultCause }}</el-descriptions-item>
  57. <!-- <el-descriptions-item :span="1" label="排故方法">{{ form.troubleshootingMethodPath }}</el-descriptions-item>
  58. <el-descriptions-item label="故障图"><img :src="faultPicturePathUrl" width="200px" /></el-descriptions-item>
  59. <el-descriptions-item label="故障树"><img :src="faultPicturePathUrl" width="200px" /></el-descriptions-item> -->
  60. </el-descriptions>
  61. <span slot="footer" class="dialog-footer">
  62. <el-button @click="detailSubmit">确 定</el-button>
  63. </span>
  64. </el-dialog>
  65. <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  66. <el-upload
  67. ref="upload"
  68. :limit="1"
  69. accept=".xlsx, .xls"
  70. :headers="upload.headers"
  71. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  72. :disabled="upload.isUploading"
  73. :on-progress="handleFileUploadProgress"
  74. :on-success="handleFileSuccess"
  75. :auto-upload="false"
  76. drag
  77. >
  78. <i class="el-icon-upload"></i>
  79. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  80. <div class="el-upload__tip text-center" slot="tip">
  81. <div class="el-upload__tip" slot="tip"><el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据</div>
  82. <span>仅允许导入xls、xlsx格式文件。</span>
  83. </div>
  84. </el-upload>
  85. <div slot="footer" class="dialog-footer">
  86. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  87. <el-button @click="upload.open = false">取 消</el-button>
  88. </div>
  89. </el-dialog>
  90. </div>
  91. </div>
  92. </template>
  93. <script>
  94. import { getFaultCase, addFaultCase, updateFaultCase, removeFaultCase } from '@/api/als/faultCase'
  95. import { deepClone, debounce } from '@/utils/index'
  96. import { getListByIdsApi } from '@/api/als/oss'
  97. import { getItem } from '@/utils/index'
  98. import { getAircaftTypeAndModelTree } from '@/api/als/sideTree'
  99. import Treeselect from '@riophae/vue-treeselect'
  100. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  101. import { flattenTree, download } from '../utils/common'
  102. // import FileUpload from '@/views/als/components/FileUpload'
  103. export default {
  104. name: 'FaultCase',
  105. components: { Treeselect },
  106. data() {
  107. // 这里存放数据
  108. return {
  109. dialogTitle: '新增',
  110. dialogVisible: false,
  111. detailVisible: false,
  112. keyWordData: '',
  113. aircaftModelIdList: [],
  114. currentNodeKey: '',
  115. currentNode: {},
  116. menuTreeData: [],
  117. typeTree: {
  118. children: 'children',
  119. label: 'label'
  120. },
  121. searchValue: '',
  122. columns: [
  123. {
  124. prop: 'aircraftTypeName',
  125. label: '机型',
  126. render: (h, params) => {
  127. const matchedItem = this.aircraftTypeAll.find((item) => params.row.aircraftTypeName.trim() === item.id.trim())
  128. if (matchedItem) {
  129. return h('span', matchedItem.label)
  130. } else {
  131. return h('span', {}, '')
  132. }
  133. }
  134. },
  135. {
  136. prop: 'aircraftSystemName',
  137. label: '系统'
  138. },
  139. {
  140. prop: 'aircraftSubsystemName',
  141. label: '分系统'
  142. },
  143. {
  144. prop: 'faultPhenomenon',
  145. label: '故障现象',
  146. render: (h, params) => {
  147. return h('span', {
  148. domProps: {
  149. innerHTML: params.row.faultPhenomenon ? params.row.faultPhenomenon : params.row.pcontent
  150. }
  151. })
  152. }
  153. },
  154. {
  155. prop: 'faultCause',
  156. label: '故障原因',
  157. render: (h, params) => {
  158. return h('span', {
  159. domProps: {
  160. innerHTML: params.row.faultCause ? params.row.faultCause : params.row.fcontent
  161. }
  162. })
  163. }
  164. },
  165. {
  166. prop: 'viewCount',
  167. label: '浏览次数'
  168. },
  169. // {
  170. // prop: 'createBy',
  171. // label: '创建人'
  172. // },
  173. // {
  174. // prop: 'createTime',
  175. // label: '创建时间'
  176. // },
  177. // {
  178. // prop: 'updateBy',
  179. // label: '最后修改人'
  180. // },
  181. // {
  182. // prop: 'updateTime',
  183. // label: '最后修改时间'
  184. // },
  185. {
  186. button: true,
  187. label: '操作',
  188. width: '240px',
  189. group: [
  190. {
  191. name: '查看',
  192. type: 'text',
  193. round: false,
  194. plain: false,
  195. onClick: (row, index, scope) => {
  196. this.checkDetails(row)
  197. }
  198. },
  199. {
  200. name: '编辑',
  201. type: 'text',
  202. round: false,
  203. plain: false,
  204. onClick: (row, index, scope) => {
  205. this.handUpdate(row)
  206. }
  207. },
  208. {
  209. name: '删除',
  210. type: 'text',
  211. round: false,
  212. plain: false,
  213. onClick: (row, index, scope) => {
  214. this.remove([row])
  215. }
  216. }
  217. ]
  218. }
  219. ],
  220. options: {
  221. stripe: true,
  222. mutiSelect: false,
  223. index: true,
  224. loading: false,
  225. initTable: false,
  226. border: true,
  227. height: 'calc(100vh - 300px)'
  228. },
  229. tableCheckItems: [],
  230. tableData: [],
  231. tableRequset: {
  232. total: 0,
  233. pageIndex: 1,
  234. pageSize: 10,
  235. searchValue: ''
  236. },
  237. form: {
  238. aircraftTypeName: null,
  239. aircraftSystemName: '',
  240. aircraftSubsystemName: '',
  241. faultPhenomenon: '',
  242. faultCause: '',
  243. faultTreePath: '',
  244. faultPicturePath: '',
  245. troubleshootingMethodPath: '',
  246. viewCount: 0,
  247. createBy: '',
  248. createTime: '',
  249. updateBy: '',
  250. updateTime: ''
  251. },
  252. debounceFn: debounce(this.fetch, 500),
  253. faultPicturePathUrl: '',
  254. faultTreePathUrl: '',
  255. upload: {
  256. open: false,
  257. title: '',
  258. isUploading: false,
  259. updateSupport: 0,
  260. headers: { Authorization: getItem('token') },
  261. // 上传的地址
  262. url: '/api/als/faultCase/importData'
  263. },
  264. aircraftTypeTreeData: [],
  265. aircraftTypeAll: [],
  266. detailAircraftType: ''
  267. }
  268. },
  269. watch: {
  270. keyWord() {
  271. this.tableRequset.pageIndex = 1
  272. this.debounceFn()
  273. }
  274. },
  275. mounted() {
  276. this.getAirTypeData()
  277. this.getFaultCaseAPI()
  278. },
  279. methods: {
  280. async removeFaultCaseAPI(params) {
  281. try {
  282. const { code } = await removeFaultCase(params)
  283. if (code === 200) {
  284. this.$message({
  285. type: 'success',
  286. message: '操作成功!'
  287. })
  288. await this.getFaultCaseAPI({ faultPhenomenon: keyWordData })
  289. this.handleClose()
  290. }
  291. } catch (error) {}
  292. },
  293. async getFaultCaseAPI(params) {
  294. if (this.$refs.table) this.$refs.table.clearSelection()
  295. const { keyWord } = this
  296. const { pageSize, pageIndex } = this.tableRequset
  297. const {
  298. data: { list, total }
  299. } = await getFaultCase({ pageSize, pageNum: pageIndex, ...params })
  300. this.tableData = list
  301. this.tableRequset.total = total
  302. },
  303. async getAirTypeData() {
  304. try {
  305. const { data } = await getAircaftTypeAndModelTree()
  306. this.aircraftTypeTreeData = data[0].children
  307. this.aircraftTypeAll = flattenTree(data[0].children)
  308. } catch (error) {}
  309. },
  310. async getFaultCaseByEsAPI(keyWordData) {
  311. console.log(keyWordData)
  312. },
  313. fetch() {
  314. this.getFaultCaseAPI({ faultPhenomenon: keyWordData })
  315. },
  316. async searchClick(keyWordData) {
  317. // this.getFaultCaseByEsAPI(keyWordData)
  318. this.getFaultCaseAPI({ faultPhenomenon: keyWordData })
  319. },
  320. async addFaultCaseAPI() {
  321. try {
  322. const { code } = await addFaultCase({ ...this.form })
  323. if (code === 200) {
  324. this.$message({
  325. type: 'success',
  326. duration: 3000,
  327. message: 'ES数据同步中,稍后查询!'
  328. })
  329. this.handleClose()
  330. this.getFaultCaseAPI({ faultPhenomenon: keyWordData })
  331. }
  332. } catch (error) {}
  333. },
  334. async updateFaultCaseAPI() {
  335. try {
  336. const { code } = await updateFaultCase({ ...this.form })
  337. if (code === 200) {
  338. this.$message({
  339. type: 'success',
  340. message: '操作成功!'
  341. })
  342. this.handleClose()
  343. this.getFaultCaseAPI({ faultPhenomenon: keyWordData })
  344. }
  345. } catch (error) {}
  346. },
  347. openDialog() {
  348. this.dialogTitle = '新增'
  349. this.dialogVisible = true
  350. },
  351. aircraftTypeChange(node) {
  352. this.form.aircraftTypeName = node.id
  353. },
  354. handleClose() {
  355. this.dialogVisible = false
  356. this.form = {
  357. aircraftTypeName: null,
  358. aircraftSystemName: '',
  359. aircraftSubsystemName: '',
  360. faultPhenomenon: '',
  361. faultCause: '',
  362. faultTreePath: '',
  363. faultPicturePath: '',
  364. troubleshootingMethodPath: '',
  365. viewCount: 0,
  366. createBy: '',
  367. createTime: '',
  368. updateBy: '',
  369. updateTime: ''
  370. }
  371. },
  372. handUpdate(row) {
  373. this.dialogTitle = '编辑'
  374. this.form = deepClone(row)
  375. this.form.faultPhenomenon = row.pcontent
  376. this.form.faultCause = row.fcontent
  377. this.dialogVisible = true
  378. },
  379. submit() {
  380. switch (this.dialogTitle) {
  381. case '编辑':
  382. this.updateFaultCaseAPI()
  383. break
  384. case '新增':
  385. this.addFaultCaseAPI()
  386. break
  387. }
  388. },
  389. aircraftTypeNormalizer(node) {
  390. if (node.children && !node.children.length) {
  391. delete node.children
  392. }
  393. return {
  394. id: node.id,
  395. label: node.label,
  396. children: node.children
  397. }
  398. },
  399. selection(val) {
  400. this.tableCheckItems = val
  401. },
  402. remove(row) {
  403. this.$confirm('是否删除该数据', '提示', {
  404. confirmButtonText: '确定',
  405. cancelButtonText: '取消',
  406. type: 'warning'
  407. })
  408. .then(() => {
  409. this.removeFaultCaseAPI(row.map((e) => e.id))
  410. })
  411. .catch(() => {})
  412. },
  413. async checkDetails(row) {
  414. this.form = deepClone(row)
  415. const matchedItem = this.aircraftTypeAll.find((item) => row.aircraftTypeName.trim() === item.id.trim())
  416. this.detailAircraftType = matchedItem.label
  417. // if (row.faultPicturePath) {
  418. // const res = await getListByIdsApi(row.faultPicturePath)
  419. // this.faultPicturePathUrl = res.data[0].url
  420. // const res2 = await getListByIdsApi(row.faultTreePath)
  421. // this.faultTreePathUrl = res.data[0].url
  422. // } else {
  423. // this.faultPicturePathUrl = row.faultPicturePath
  424. // this.faultTreePathUrl = row.faultTreePathUrl
  425. // }
  426. this.form.faultPhenomenon = row.pcontent
  427. this.form.faultCause = row.fcontent
  428. this.detailVisible = true
  429. this.addViewCount(row)
  430. // this.form = deepClone(row)
  431. },
  432. async addViewCount(row) {
  433. try {
  434. await updateFaultCase({ id: row.id, viewCount: ++row.viewCount })
  435. } catch (error) {}
  436. },
  437. detailSubmit() {
  438. this.handleClose()
  439. this.detailVisible = false
  440. },
  441. /** 导入按钮操作 */
  442. handleImport() {
  443. this.upload.title = '警告列表导入'
  444. this.upload.open = true
  445. },
  446. /** 下载模板操作 */
  447. importTemplate() {
  448. download('/faultCase/importTemplate', {}, `faultCase_template_${new Date().getTime()}.xlsx`)
  449. },
  450. // 文件上传中处理
  451. handleFileUploadProgress(event, file, fileList) {
  452. this.upload.isUploading = true
  453. },
  454. // 文件上传成功处理
  455. handleFileSuccess(response, file, fileList) {
  456. if (this.uploadFlag) {
  457. this.upload.open = false
  458. this.upload.isUploading = false
  459. this.$refs.upload.clearFiles()
  460. }
  461. this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', { dangerouslyUseHTMLString: true })
  462. },
  463. // 提交上传文件
  464. submitFileForm() {
  465. this.$refs.upload.submit()
  466. },
  467. // 导出
  468. handleExport() {
  469. download(
  470. '/faultCase/export',
  471. {
  472. ...this.form
  473. },
  474. `faultCase_${new Date().getTime()}.xlsx`
  475. )
  476. }
  477. }
  478. }
  479. </script>
  480. <style lang="scss" scoped>
  481. @import '../index.scss';
  482. </style>