index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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="lifeId">
  25. <el-input v-model="form.lifeId" placeholder="请输入寿命预测编号" />
  26. </el-form-item>
  27. <el-form-item label="机号" prop="aircraftId">
  28. <el-input v-model="form.aircraftId" placeholder="请输入机号" />
  29. </el-form-item>
  30. <el-form-item label="部件名称" prop="name">
  31. <el-input v-model="form.name" placeholder="请输入部件名称" />
  32. </el-form-item>
  33. <el-form-item label="型号" prop="model">
  34. <el-input v-model="form.model" placeholder="请输入型号" />
  35. </el-form-item>
  36. <el-form-item label="所属系统" prop="system">
  37. <el-input v-model="form.system" placeholder="请输入所属系统" />
  38. </el-form-item>
  39. <el-form-item label="剩余时长" prop="remainTiem">
  40. <el-input v-model="form.remainTiem" placeholder="请输入剩余时长" />
  41. </el-form-item>
  42. </el-form>
  43. <span slot="footer" class="dialog-footer">
  44. <el-button @click="handleClose">取 消</el-button>
  45. <el-button type="primary" @click="submit">确 定</el-button>
  46. </span>
  47. </el-dialog>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import { getLifePredictionResult, getAircaftTypeAndModelTree, addLifePredictionResult, updateLifePredictionResult, removeLifePredictionResult } from '@/api/als/lifePredictionResult'
  53. import { deepClone, debounce } from '@/utils/index'
  54. export default {
  55. name: 'LifePredictionResult',
  56. components: {},
  57. data() {
  58. // 这里存放数据
  59. return {
  60. dialogTitle: '新增',
  61. dialogVisible: false,
  62. keyWord: '',
  63. aircaftModelIdList: [],
  64. currentNodeKey: null,
  65. currentNode: null,
  66. menuTreeData: [],
  67. treeObj: {
  68. title: '所属机种',
  69. activityheight: '275px',
  70. searchIcon: false,
  71. configure: {
  72. children: 'children',
  73. label: 'label'
  74. }
  75. },
  76. typeTree: {
  77. children: 'children',
  78. label: 'label'
  79. },
  80. searchValue: '',
  81. columns: [
  82. { prop: 'id', label: '编号' },
  83. {
  84. prop: 'lifeId',
  85. label: '寿命预测编号'
  86. },
  87. {
  88. prop: 'aircraftId',
  89. label: '机号'
  90. },
  91. {
  92. prop: 'name',
  93. label: '部件名称'
  94. },
  95. {
  96. prop: 'model',
  97. label: '型号'
  98. },
  99. {
  100. prop: 'system',
  101. label: '所属系统'
  102. },
  103. {
  104. prop: 'methodType',
  105. label: '处理方式'
  106. },
  107. {
  108. prop: 'remainTiem',
  109. label: '剩余时长'
  110. },
  111. {
  112. prop: 'status',
  113. label: '状态'
  114. },
  115. {
  116. button: true,
  117. label: '操作',
  118. width: '240px',
  119. group: [
  120. {
  121. name: '编辑',
  122. type: 'text',
  123. round: false,
  124. plain: false,
  125. onClick: (row, index, scope) => {
  126. _this.handUpdate(row)
  127. }
  128. },
  129. {
  130. name: '删除',
  131. type: 'text',
  132. round: false,
  133. plain: false,
  134. onClick: (row, index, scope) => {
  135. _this.remove([row])
  136. }
  137. }
  138. ]
  139. }
  140. ],
  141. options: {
  142. stripe: true, // 斑马纹
  143. mutiSelect: true, // 多选框
  144. index: false, // 显示序号, 多选则 mutiSelect
  145. loading: false, // 表格动画
  146. initTable: false, // 是否一挂载就加载数据
  147. border: true,
  148. height: 'calc(100vh - 300px)'
  149. },
  150. tableCheckItems: [],
  151. tableData: [],
  152. tableRequset: {
  153. total: 0,
  154. pageIndex: 1,
  155. pageSize: 10,
  156. searchValue: ''
  157. },
  158. form: {
  159. id: '',
  160. lifeId: '',
  161. aircraftId: '',
  162. name: '',
  163. model: '',
  164. system: '',
  165. methodType: '',
  166. remainTiem: '',
  167. status: '',
  168. tenantId: '',
  169. version: '',
  170. delFlag: '',
  171. createBy: '',
  172. createTime: '',
  173. updateBy: '',
  174. updateTime: ''
  175. },
  176. debounceFn: debounce(this.fetch, 500)
  177. }
  178. },
  179. watch: {
  180. keyWord() {
  181. this.tableRequset.pageIndex = 1
  182. this.debounceFn()
  183. }
  184. },
  185. mounted() {
  186. this.getAircaftTypeAndModelTreeAPI()
  187. },
  188. methods: {
  189. async getAircaftTypeAndModelTreeAPI(params) {
  190. const { data } = await getAircaftTypeAndModelTree(params)
  191. this.menuTreeData = data
  192. if (data.length) {
  193. this.currentNodeKey = data[0].value
  194. this.currentNode = data[0]
  195. this.aircaftModelIdList = this.getTreeLeafData(data[0]?.children).map((e) => e.id)
  196. this.getLifePredictionResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  197. }
  198. },
  199. async removeLifePredictionResultAPI(params) {
  200. try {
  201. const { success } = await removeLifePredictionResult(params)
  202. if (success) {
  203. this.$message({
  204. type: 'success',
  205. message: '操作成功!'
  206. })
  207. await this.getLifePredictionResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  208. this.handleClose()
  209. }
  210. } catch (error) {}
  211. },
  212. getTreeLeafData(list) {
  213. const newArr = []
  214. function getLeaf(data, arr) {
  215. data.forEach((e) => {
  216. if (e.type === 2) {
  217. arr.push(e)
  218. }
  219. if (e.children.length) {
  220. getLeaf(e.children, arr)
  221. }
  222. })
  223. }
  224. getLeaf(list, newArr)
  225. return newArr
  226. },
  227. async getLifePredictionResultAPI(params) {
  228. if (this.$refs.table) this.$refs.table.clearSelection()
  229. const { keyWord } = this
  230. const { pageSize, pageIndex } = this.tableRequset
  231. const {
  232. data: { list, total }
  233. } = await getLifePredictionResult({ pageSize, pageIndex, keyWord, ...params })
  234. this.tableData = list
  235. this.tableRequset.total = total
  236. },
  237. fetch() {
  238. this.getLifePredictionResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  239. },
  240. searchClick() {
  241. this.getLifePredictionResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  242. },
  243. async addLifePredictionResultAPI() {
  244. try {
  245. delete this.form.aircaftModelName
  246. const { success } = await addLifePredictionResult({ ...this.form })
  247. if (success) {
  248. this.$message({
  249. type: 'success',
  250. message: '操作成功!'
  251. })
  252. this.getLifePredictionResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  253. }
  254. } catch (error) {}
  255. },
  256. async updateLifePredictionResultAPI() {
  257. try {
  258. const { success } = await updateLifePredictionResult({ ...this.form })
  259. if (success) {
  260. this.$message({
  261. type: 'success',
  262. message: '操作成功!'
  263. })
  264. this.getLifePredictionResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  265. }
  266. } catch (error) {}
  267. },
  268. treeNodeClick(data) {
  269. this.$refs.table.clearSelection()
  270. this.currentNodeKey = data.id
  271. this.currentNode = data
  272. this.aircaftModelIdList = this.getTreeLeafData(data.children.length ? data.children : [data]).map((e) => e.id)
  273. this.getLifePredictionResultAPI({ aircaftModelIdList: this.aircaftModelIdList })
  274. },
  275. openDialog() {
  276. this.dialogTitle = '新增'
  277. this.dialogVisible = true
  278. this.form.aircaftModelName = this.currentNode.label
  279. this.form.aircaftModelId = this.currentNode.id
  280. },
  281. handleClose() {
  282. this.dialogVisible = false
  283. this.form = {
  284. id: '',
  285. lifeId: '',
  286. aircraftId: '',
  287. name: '',
  288. model: '',
  289. system: '',
  290. methodType: '',
  291. remainTiem: '',
  292. status: '',
  293. tenantId: '',
  294. version: '',
  295. delFlag: '',
  296. createBy: '',
  297. createTime: '',
  298. updateBy: '',
  299. updateTime: ''
  300. }
  301. },
  302. handUpdate(row) {
  303. this.dialogTitle = '编辑'
  304. this.form = deepClone(row)
  305. this.dialogVisible = true
  306. },
  307. submit() {
  308. switch (this.dialogTitle) {
  309. case '编辑':
  310. this.updateLifePredictionResultAPI()
  311. this.handleClose()
  312. break
  313. case '新增':
  314. this.addLifePredictionResultAPI()
  315. this.handleClose()
  316. break
  317. }
  318. },
  319. selection(val) {
  320. this.tableCheckItems = val
  321. },
  322. remove(row) {
  323. this.$confirm('是否删除该数据', '提示', {
  324. confirmButtonText: '确定',
  325. cancelButtonText: '取消',
  326. type: 'warning'
  327. })
  328. .then(() => {
  329. this.removeLifePredictionResultAPI(row.map((e) => e.id))
  330. })
  331. .catch(() => {})
  332. }
  333. }
  334. }
  335. </script>
  336. <style lang="scss" scoped>
  337. @import '../index.scss';
  338. </style>