index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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 style="width: 100%">
  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. <!-- <el-button type="primary">导入模板</el-button>
  12. <el-button type="primary">导出模板</el-button> -->
  13. </div>
  14. <div class="view-dataType-title-search">
  15. <el-input placeholder="请输入机型/HMC码" v-model="keyWord" class="input1">
  16. <el-button slot="append" icon="el-icon-search" @click="searchClick"></el-button>
  17. </el-input>
  18. </div>
  19. </div>
  20. <div class="view-dataType-table">
  21. <LTable ref="table" @selection-change="selection" :defaultFetch="false" :fetch="fetch" :columns="columns" :dataSource="tableData" :options="options" :pagination="tableRequset"></LTable>
  22. </div>
  23. <!-- 添加或修改判故逻辑对话框 -->
  24. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
  25. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  26. <el-form-item label="机型" prop="model">
  27. <el-input v-model="form.model" placeholder="请输入机型" />
  28. </el-form-item>
  29. <el-form-item label="HMC码" prop="hmcCode">
  30. <el-input v-model="form.hmcCode" placeholder="请输入HMC码" />
  31. </el-form-item>
  32. <el-form-item label="参数列" prop="parameterColumn">
  33. <el-checkbox-group v-model="form.parameterColumn">
  34. <div style="column-count: 3">
  35. <el-checkbox v-for="dict in dictData" :key="dict.dictValue" :value="dict.dictValue" :label="dict.dictLabel">{{ dict.dictLabel }}</el-checkbox>
  36. </div>
  37. </el-checkbox-group>
  38. </el-form-item>
  39. <el-form-item label="模型" prop="pattern">
  40. <el-select v-model="form.pattern" placeholder="请选择模型">
  41. <el-option v-for="item in modelData.list" :key="item.id" :label="item.name" :value="item.id" />
  42. </el-select>
  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. </div>
  51. </div>
  52. </template>
  53. <script>
  54. import { getJudgeFaultLogic, getAircaftTypeAndModelTree, addJudgeFaultLogic, updateJudgeFaultLogic, removeJudgeFaultLogic } from '@/api/als/judgeFaultLogic'
  55. import { deepClone, debounce } from '@/utils/index'
  56. import { getDict } from '@/api/dict'
  57. import { getModel } from '@/api/als/model'
  58. export default {
  59. name: 'JudgeFaultLogic',
  60. components: {},
  61. data() {
  62. // 这里存放数据
  63. return {
  64. dialogTitle: '新增',
  65. dialogVisible: false,
  66. keyWord: '',
  67. aircaftModelIdList: [],
  68. currentNodeKey: null,
  69. currentNode: null,
  70. menuTreeData: [],
  71. dictData: [],
  72. modelData: [],
  73. treeObj: {
  74. title: '所属机种',
  75. activityheight: '275px',
  76. searchIcon: false,
  77. configure: {
  78. children: 'children',
  79. label: 'label'
  80. }
  81. },
  82. typeTree: {
  83. children: 'children',
  84. label: 'label'
  85. },
  86. searchValue: '',
  87. columns: [
  88. { prop: 'id', label: '编号' },
  89. {
  90. prop: 'model',
  91. label: '机型'
  92. },
  93. {
  94. prop: 'hmcCode',
  95. label: 'HMC码'
  96. },
  97. {
  98. prop: 'parameterColumn',
  99. label: '参数列'
  100. },
  101. {
  102. prop: 'pattern',
  103. label: '模型',
  104. render: (h, params) => {
  105. const matchedItem = this.modelData.list.find((item) => params.row.pattern === item.id)
  106. if (matchedItem) {
  107. return h('span', matchedItem.name)
  108. } else {
  109. return h('span', {}, '')
  110. }
  111. }
  112. },
  113. {
  114. button: true,
  115. label: '操作',
  116. width: '240px',
  117. group: [
  118. {
  119. name: '编辑',
  120. type: 'text',
  121. round: false,
  122. plain: false,
  123. onClick: (row, index, scope) => {
  124. this.handUpdate(row)
  125. }
  126. },
  127. {
  128. name: '删除',
  129. type: 'text',
  130. round: false,
  131. plain: false,
  132. onClick: (row, index, scope) => {
  133. this.remove([row])
  134. }
  135. }
  136. ]
  137. }
  138. ],
  139. options: {
  140. stripe: true, // 斑马纹
  141. mutiSelect: true, // 多选框
  142. index: false, // 显示序号, 多选则 mutiSelect
  143. loading: false, // 表格动画
  144. initTable: false, // 是否一挂载就加载数据
  145. border: true,
  146. height: 'calc(100vh - 300px)'
  147. },
  148. tableCheckItems: [],
  149. tableData: [],
  150. tableRequset: {
  151. total: 0,
  152. pageIndex: 1,
  153. pageSize: 10,
  154. searchValue: ''
  155. },
  156. form: {
  157. id: '',
  158. model: '',
  159. hmcCode: '',
  160. parameterColumn: [],
  161. pattern: '',
  162. remarks: '',
  163. tenantId: '',
  164. delFlag: '',
  165. version: '',
  166. createBy: '',
  167. createTime: '',
  168. updateBy: '',
  169. updateTime: ''
  170. },
  171. rules: {
  172. model: [{ required: true, message: '机型不能为空', trigger: 'blur' }],
  173. hmcCode: [{ required: true, message: 'HMC码不能为空', trigger: 'blur' }],
  174. parameterColumn: [{ required: true, message: '参数列不能为空', trigger: 'blur' }],
  175. pattern: [{ required: true, message: '模型不能为空', trigger: 'blur' }]
  176. },
  177. debounceFn: debounce(this.fetch, 500)
  178. }
  179. },
  180. watch: {
  181. keyWord() {
  182. this.tableRequset.pageIndex = 1
  183. this.debounceFn()
  184. }
  185. },
  186. mounted() {
  187. this.getDict()
  188. this.getModelAPI()
  189. this.getJudgeFaultLogicAPI()
  190. // this.getAircaftTypeAndModelTreeAPI()
  191. },
  192. methods: {
  193. async getDict() {
  194. const { data } = await getDict('als_parameter_column')
  195. this.dictData = data
  196. },
  197. async getModelAPI() {
  198. const { data } = await getModel({ pageSize: 100, pageNum: 1, ...{ type: 5 } })
  199. this.modelData = data
  200. },
  201. async getAircaftTypeAndModelTreeAPI(params) {
  202. const { data } = await getAircaftTypeAndModelTree(params)
  203. this.menuTreeData = data
  204. if (data.length) {
  205. this.currentNodeKey = data[0].value
  206. this.currentNode = data[0]
  207. this.aircaftModelIdList = this.getTreeLeafData(data[0]?.children).map((e) => e.id)
  208. this.getJudgeFaultLogicAPI()
  209. }
  210. },
  211. async removeJudgeFaultLogicAPI(params) {
  212. try {
  213. const { code } = await removeJudgeFaultLogic(params)
  214. if (code === 200) {
  215. this.$message({
  216. type: 'success',
  217. message: '操作成功!'
  218. })
  219. await this.getJudgeFaultLogicAPI()
  220. this.handleClose()
  221. }
  222. } catch (error) {}
  223. },
  224. getTreeLeafData(list) {
  225. const newArr = []
  226. function getLeaf(data, arr) {
  227. data.forEach((e) => {
  228. if (e.type === 1) {
  229. arr.push(e)
  230. }
  231. if (e.children.length) {
  232. getLeaf(e.children, arr)
  233. }
  234. })
  235. }
  236. getLeaf(list, newArr)
  237. return newArr
  238. },
  239. async getJudgeFaultLogicAPI(params) {
  240. if (this.$refs.table) this.$refs.table.clearSelection()
  241. const { keyWord } = this
  242. const { pageSize, pageIndex } = this.tableRequset
  243. const {
  244. data: { list, totalCount }
  245. } = await getJudgeFaultLogic({ pageSize, pageIndex, keyWord, ...params })
  246. this.tableData = list
  247. this.tableRequset.total = totalCount
  248. },
  249. fetch() {
  250. this.getJudgeFaultLogicAPI()
  251. },
  252. searchClick() {
  253. this.getJudgeFaultLogicAPI()
  254. },
  255. async addJudgeFaultLogicAPI() {
  256. this.form.parameterColumn = this.form.parameterColumn.toString()
  257. this.$refs['form'].validate(async (valid) => {
  258. if (valid) {
  259. try {
  260. delete this.form.aircaftModelName
  261. const { code } = await addJudgeFaultLogic({ ...this.form })
  262. if (code === 200) {
  263. this.$message({
  264. type: 'success',
  265. message: '操作成功!'
  266. })
  267. this.getJudgeFaultLogicAPI()
  268. this.handleClose()
  269. }
  270. } catch (error) {}
  271. }
  272. })
  273. },
  274. async updateJudgeFaultLogicAPI() {
  275. this.form.parameterColumn = this.form.parameterColumn.toString()
  276. try {
  277. const { code } = await updateJudgeFaultLogic({ ...this.form })
  278. if (code === 200) {
  279. this.$message({
  280. type: 'success',
  281. message: '操作成功!'
  282. })
  283. this.getJudgeFaultLogicAPI()
  284. this.handleClose()
  285. }
  286. } catch (error) {}
  287. },
  288. treeNodeClick(data) {
  289. this.$refs.table.clearSelection()
  290. this.currentNodeKey = data.id
  291. this.currentNode = data
  292. this.aircaftModelIdList = this.getTreeLeafData(data.children.length ? data.children : [data]).map((e) => e.id)
  293. this.getJudgeFaultLogicAPI()
  294. },
  295. openDialog() {
  296. this.dialogTitle = '新增'
  297. this.dialogVisible = true
  298. // this.form.aircaftModelName = this.currentNode.label
  299. // this.form.aircaftModelId = this.currentNode.id
  300. },
  301. handleClose() {
  302. this.dialogVisible = false
  303. this.form = {
  304. id: '',
  305. model: '',
  306. hmcCode: '',
  307. parameterColumn: [],
  308. pattern: '',
  309. remarks: '',
  310. tenantId: '',
  311. delFlag: '',
  312. version: '',
  313. createBy: '',
  314. createTime: '',
  315. updateBy: '',
  316. updateTime: ''
  317. }
  318. },
  319. handUpdate(row) {
  320. this.dialogTitle = '编辑'
  321. this.form = deepClone(row)
  322. this.form.parameterColumn = this.form.parameterColumn.split(',')
  323. this.dialogVisible = true
  324. },
  325. submit() {
  326. switch (this.dialogTitle) {
  327. case '编辑':
  328. this.updateJudgeFaultLogicAPI()
  329. break
  330. case '新增':
  331. this.addJudgeFaultLogicAPI()
  332. break
  333. }
  334. },
  335. selection(val) {
  336. this.tableCheckItems = val
  337. },
  338. remove(row) {
  339. this.$confirm('是否删除该机种', '提示', {
  340. confirmButtonText: '确定',
  341. cancelButtonText: '取消',
  342. type: 'warning'
  343. })
  344. .then(() => {
  345. this.removeJudgeFaultLogicAPI(row.map((e) => e.id))
  346. })
  347. .catch(() => {})
  348. }
  349. }
  350. }
  351. </script>
  352. <style lang="scss">
  353. @import '../index.scss';
  354. </style>