index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <div class="view-table-content">
  3. <div class="view-dataSpecies-left">
  4. <MenuTree :currentNodeKey="currentNodeKey" nodeKey="id" :treedata="menuTreeData" @TreeNodeclick="treeNodeClick" v-bind="treeObj"> </MenuTree>
  5. </div>
  6. <div class="view-dataSpecies-right">
  7. <div class="view-dataType-title">
  8. <div class="view-dataType-title-btn">
  9. <el-button type="success" @click="openDialog()" :disabled="currentNode && currentNode.type == 0">新增</el-button>
  10. <el-button type="warning" @click="remove(tableCheckItems)" :disabled="tableCheckItems.length == 0">删除</el-button>
  11. </div>
  12. <div class="view-dataType-title-search">
  13. <el-input placeholder="请输入关键字" v-model="keyWord" class="input1">
  14. <el-button slot="append" icon="el-icon-search" @click="searchClick"></el-button>
  15. </el-input>
  16. </div>
  17. </div>
  18. <div class="view-dataType-table">
  19. <LTable ref="table" @selection-change="selection" :defaultFetch="false" :fetch="fetch" :columns="columns" :dataSource="tableData" :options="options" :pagination="tableRequset"></LTable>
  20. </div>
  21. <!-- 添加或修改故障诊断结果对话框 -->
  22. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
  23. <el-form ref="form" :model="form" label-width="80px">
  24. <el-form-item label="故障诊断编号" prop="diagnosisId">
  25. <el-input v-model="form.diagnosisId" placeholder="请输入故障诊断编号" />
  26. </el-form-item>
  27. <el-form-item label="架次号" prop="sortieNo">
  28. <el-input v-model="form.sortieNo" placeholder="请输入架次号" />
  29. </el-form-item>
  30. <el-form-item label="机号" prop="aircraftId">
  31. <el-input v-model="form.aircraftId" placeholder="请输入机号" />
  32. </el-form-item>
  33. </el-form>
  34. <span slot="footer" class="dialog-footer">
  35. <el-button @click="handleClose">取 消</el-button>
  36. <el-button type="primary" @click="submit">确 定</el-button>
  37. </span>
  38. </el-dialog>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. import { getFaultDiagnosisResult, getAircaftTypeAndModelTree, addFaultDiagnosisResult, updateFaultDiagnosisResult, removeFaultDiagnosisResult } from '@/api/als/faultDiagnosisResult'
  44. import { deepClone, debounce } from '@/utils/index'
  45. export default {
  46. name: 'FaultDiagnosisResult',
  47. components: {},
  48. data() {
  49. // 这里存放数据
  50. return {
  51. dialogTitle: '新增',
  52. dialogVisible: false,
  53. keyWord: '',
  54. aircaftModelIdList: [],
  55. currentNodeKey: null,
  56. currentNode: null,
  57. menuTreeData: [],
  58. treeObj: {
  59. title: '所属机种',
  60. activityheight: '275px',
  61. searchIcon: false,
  62. configure: {
  63. children: 'children',
  64. label: 'label'
  65. }
  66. },
  67. typeTree: {
  68. children: 'children',
  69. label: 'label'
  70. },
  71. searchValue: '',
  72. columns: [
  73. { prop: 'id', label: '编号' },
  74. {
  75. prop: 'diagnosisId',
  76. label: '故障诊断编号'
  77. },
  78. {
  79. prop: 'sortieNo',
  80. label: '架次号'
  81. },
  82. {
  83. prop: 'aircraftId',
  84. label: '机号'
  85. },
  86. {
  87. prop: 'status',
  88. label: '状态'
  89. },
  90. {
  91. button: true,
  92. label: '操作',
  93. width: '240px',
  94. group: [
  95. {
  96. name: '编辑',
  97. type: 'text',
  98. round: false,
  99. plain: false,
  100. onClick: (row, index, scope) => {
  101. _this.handUpdate(row)
  102. }
  103. },
  104. {
  105. name: '删除',
  106. type: 'text',
  107. round: false,
  108. plain: false,
  109. onClick: (row, index, scope) => {
  110. _this.remove([row])
  111. }
  112. }
  113. ]
  114. }
  115. ],
  116. options: {
  117. stripe: true, // 斑马纹
  118. mutiSelect: true, // 多选框
  119. index: false, // 显示序号, 多选则 mutiSelect
  120. loading: false, // 表格动画
  121. initTable: false, // 是否一挂载就加载数据
  122. border: true,
  123. height: 'calc(100vh - 300px)'
  124. },
  125. tableCheckItems: [],
  126. tableData: [],
  127. tableRequset: {
  128. total: 0,
  129. pageIndex: 1,
  130. pageSize: 10,
  131. searchValue: ''
  132. },
  133. form: {
  134. id: '',
  135. diagnosisId: '',
  136. sortieNo: '',
  137. aircraftId: '',
  138. status: '',
  139. tenantId: '',
  140. version: '',
  141. delFlag: '',
  142. createBy: '',
  143. createTime: '',
  144. updateBy: '',
  145. updateTime: ''
  146. },
  147. debounceFn: debounce(this.fetch, 500)
  148. }
  149. },
  150. watch: {
  151. keyWord() {
  152. this.tableRequset.pageIndex = 1
  153. this.debounceFn()
  154. }
  155. },
  156. mounted() {
  157. this.getAircaftTypeAndModelTreeAPI()
  158. },
  159. methods: {
  160. async getAircaftTypeAndModelTreeAPI(params) {
  161. const { data } = await getAircaftTypeAndModelTree(params)
  162. this.menuTreeData = data
  163. if (data.length) {
  164. this.currentNodeKey = data[0].value
  165. this.currentNode = data[0]
  166. this.aircaftModelIdList = this.getTreeLeafData(data[0]?.children).map((e) => e.id)
  167. this.getFaultDiagnosisResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  168. }
  169. },
  170. async removeFaultDiagnosisResultAPI(params) {
  171. try {
  172. const { success } = await removeFaultDiagnosisResult(params)
  173. if (success) {
  174. this.$message({
  175. type: 'success',
  176. message: '操作成功!'
  177. })
  178. await this.getFaultDiagnosisResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  179. this.handleClose()
  180. }
  181. } catch (error) {}
  182. },
  183. getTreeLeafData(list) {
  184. const newArr = []
  185. function getLeaf(data, arr) {
  186. data.forEach((e) => {
  187. if (e.type === 1) {
  188. arr.push(e)
  189. }
  190. if (e.children.length) {
  191. getLeaf(e.children, arr)
  192. }
  193. })
  194. }
  195. getLeaf(list, newArr)
  196. return newArr
  197. },
  198. async getFaultDiagnosisResultAPI(params) {
  199. if (this.$refs.table) this.$refs.table.clearSelection()
  200. const { keyWord } = this
  201. const { pageSize, pageIndex } = this.tableRequset
  202. const {
  203. data: { list, total }
  204. } = await getFaultDiagnosisResult({ pageSize, pageIndex, keyWord, ...params })
  205. this.tableData = list
  206. this.tableRequset.total = total
  207. },
  208. fetch() {
  209. this.getFaultDiagnosisResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  210. },
  211. searchClick() {
  212. this.getFaultDiagnosisResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  213. },
  214. async addFaultDiagnosisResultAPI() {
  215. try {
  216. delete this.form.aircaftModelName
  217. const { success } = await addFaultDiagnosisResult({ ...this.form })
  218. if (success) {
  219. this.$message({
  220. type: 'success',
  221. message: '操作成功!'
  222. })
  223. this.getFaultDiagnosisResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  224. }
  225. } catch (error) {}
  226. },
  227. async updateFaultDiagnosisResultAPI() {
  228. try {
  229. const { success } = await updateFaultDiagnosisResult({ ...this.form })
  230. if (success) {
  231. this.$message({
  232. type: 'success',
  233. message: '操作成功!'
  234. })
  235. this.getFaultDiagnosisResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  236. }
  237. } catch (error) {}
  238. },
  239. treeNodeClick(data) {
  240. this.$refs.table.clearSelection()
  241. this.currentNodeKey = data.id
  242. this.currentNode = data
  243. this.aircaftModelIdList = this.getTreeLeafData(data.children.length ? data.children : [data]).map((e) => e.id)
  244. this.getFaultDiagnosisResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  245. },
  246. openDialog() {
  247. this.dialogTitle = '新增'
  248. this.dialogVisible = true
  249. this.form.aircaftModelName = this.currentNode.label
  250. this.form.aircaftModelId = this.currentNode.id
  251. },
  252. handleClose() {
  253. this.dialogVisible = false
  254. this.form = {
  255. id: '',
  256. diagnosisId: '',
  257. sortieNo: '',
  258. aircraftId: '',
  259. status: '',
  260. tenantId: '',
  261. version: '',
  262. delFlag: '',
  263. createBy: '',
  264. createTime: '',
  265. updateBy: '',
  266. updateTime: ''
  267. }
  268. },
  269. handUpdate(row) {
  270. this.dialogTitle = '编辑'
  271. this.form = deepClone(row)
  272. this.dialogVisible = true
  273. },
  274. submit() {
  275. switch (this.dialogTitle) {
  276. case '编辑':
  277. this.updateFaultDiagnosisResultAPI()
  278. this.handleClose()
  279. break
  280. case '新增':
  281. this.addFaultDiagnosisResultAPI()
  282. this.handleClose()
  283. break
  284. }
  285. },
  286. selection(val) {
  287. this.tableCheckItems = val
  288. },
  289. remove(row) {
  290. this.$confirm('是否删除该数据', '提示', {
  291. confirmButtonText: '确定',
  292. cancelButtonText: '取消',
  293. type: 'warning'
  294. })
  295. .then(() => {
  296. this.removeFaultDiagnosisResultAPI(row.map((e) => e.id))
  297. })
  298. .catch(() => {})
  299. }
  300. }
  301. }
  302. </script>
  303. <style lang="scss" scoped>
  304. @import '../index.scss';
  305. </style>