index copy.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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" style="width: calc(100% - 460px)">
  8. <div class="view-dataType-title">
  9. <div class="view-dataType-title-btn">
  10. <el-button type="success" @click="openDialog()" :disabled="currentConfigNodeKey === '' || currentConfigNodeKey === '1'">新增</el-button>
  11. <el-button type="warning" @click="remove(tableCheckItems)" :disabled="tableCheckItems.length == 0">删除</el-button>
  12. <!-- <el-button type="primary">导入模板</el-button>
  13. <el-button type="primary">导出模板</el-button> -->
  14. </div>
  15. <div class="view-dataType-title-search">
  16. <el-input placeholder="请输入机型/HMC码" v-model="keyWord" class="input1">
  17. <el-button slot="append" icon="el-icon-search" @click="searchClick"></el-button>
  18. </el-input>
  19. </div>
  20. </div>
  21. <div class="view-dataType-table">
  22. <el-table :data="tableData" class="table" @selection-change="selection">
  23. <el-table-column type="selection" width="55" align="center"> </el-table-column>
  24. <el-table-column prop="model" width="250" align="center" label="机型">
  25. <template slot-scope="scope">{{ changeModel(scope.row.model) }} </template>
  26. </el-table-column>
  27. <el-table-column prop="hmcCode" width="250" align="center" label="HMC码"> </el-table-column>
  28. <el-table-column prop="formula" label="公式" align="center">
  29. <template slot-scope="scope">
  30. <span><MathJax ref="MathJax" :formula="handleConvertFormula(scope.row.model, scope.row.formula)" /></span>
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="操作" align="center" width="300">
  34. <template slot-scope="scope">
  35. <el-button :disabled="scope.row.isEdit == 0" @click="handUpdate(scope.row)" type="text" size="small">编辑</el-button>
  36. <el-button :disabled="scope.row.isEdit == 0" @click="remove(scope.row)" type="text" size="small">删除</el-button>
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. <el-pagination
  41. background
  42. :total="tableRequset.total"
  43. :page-size="tableRequset.pageSize"
  44. :page-sizes="[10, 20, 30, 40, 50]"
  45. layout="sizes,total, prev, pager, next, jumper"
  46. @size-change="handleSizeChange"
  47. @current-change="handleIndexChange"
  48. style="padding: 20px; text-align: center"
  49. >
  50. </el-pagination>
  51. </div>
  52. <!-- 添加或修改判故逻辑对话框 -->
  53. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="60%" :before-close="handleClose">
  54. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  55. <el-form-item label="机型" prop="model">
  56. <el-select v-model="form.model" placeholder="请选择机型">
  57. <el-option v-for="item in aircaftModelAll" :key="item.aircaftModelId" :label="item.aircaftModelName" :value="item.aircaftModelId"> </el-option>
  58. </el-select>
  59. </el-form-item>
  60. <el-form-item label="HMC码" prop="hmcCode">
  61. <el-input v-model="form.hmcCode" placeholder="请输入HMC码" />
  62. </el-form-item>
  63. <el-col :span="24">
  64. <el-form-item label="公式">
  65. <MathJax ref="MathJax" :formula="form.formula" />
  66. </el-form-item>
  67. </el-col>
  68. <el-col :span="24">
  69. <el-form-item label="参数">
  70. <el-button @click="addParams(item)" type="primary" v-for="(item, index) in paramsList" :key="index">{{ item }}</el-button>
  71. </el-form-item>
  72. </el-col>
  73. <el-col :span="24">
  74. <el-form-item label="数字">
  75. <el-button @click="addNumber(item)" type="primary" v-for="(item, index) in numberList" :key="index">{{ item }}</el-button>
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="24">
  79. <el-form-item label="运算符">
  80. <el-button @click="addSymbol(item)" type="primary" v-for="(item, index) in operatorList" :key="index">{{ item }}</el-button>
  81. </el-form-item>
  82. </el-col>
  83. </el-form>
  84. <span slot="footer" class="dialog-footer">
  85. <el-button @click="handleClose">取 消</el-button>
  86. <el-button type="primary" @click="submit">确 定</el-button>
  87. </span>
  88. </el-dialog>
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. import { getJudgeFaultLogic, getAircaftTypeAndModelTree, addJudgeFaultLogic, updateJudgeFaultLogic, removeJudgeFaultLogic } from '@/api/als/judgeFaultLogic'
  94. import { getAirConfigParams } from '@/api/als/airConfigParams'
  95. import { deepClone, debounce } from '@/utils/index'
  96. import { getDict } from '@/api/dict'
  97. import { getModel } from '@/api/als/model'
  98. import { getAircaftModelAll, getAircaftCatalogAll } from '@/api/als/aircraft'
  99. import { useMessage } from '@/utils/element-ui'
  100. export default {
  101. name: 'JudgeFaultLogic',
  102. components: {},
  103. data() {
  104. // 这里存放数据
  105. return {
  106. dialogTitle: '新增',
  107. dialogVisible: false,
  108. keyWord: '',
  109. aircaftModelIdList: [],
  110. currentNodeKey: '',
  111. currentNode: {},
  112. currentConfigNodeKey: '',
  113. menuTreeData: [],
  114. configTreeData: [],
  115. modelData: [],
  116. treeObj: {
  117. title: '所属机种',
  118. activityheight: '275px',
  119. searchIcon: false,
  120. configure: {
  121. children: 'children',
  122. label: 'label'
  123. }
  124. },
  125. configurationTreeObj: {
  126. title: '飞机构型',
  127. activityheight: '275px',
  128. searchIcon: false,
  129. configure: {
  130. children: 'children',
  131. label: 'name'
  132. }
  133. },
  134. typeTree: {
  135. children: 'children',
  136. label: 'label'
  137. },
  138. searchValue: '',
  139. tableCheckItems: [],
  140. tableData: [],
  141. tableRequset: {
  142. total: 0,
  143. pageIndex: 1,
  144. pageSize: 20,
  145. searchValue: ''
  146. },
  147. form: {
  148. id: '',
  149. model: '',
  150. hmcCode: '',
  151. formula: ''
  152. },
  153. rules: {
  154. // model: [{ required: true, message: '机型不能为空', trigger: 'change' }],
  155. // hmcCode: [{ required: true, message: 'HMC码不能为空', trigger: 'blur' }],
  156. // parameterColumn: [{ required: true, message: '参数列不能为空', trigger: 'change' }]
  157. },
  158. debounceFn: debounce(this.fetch, 500),
  159. aircaftModelAll: [],
  160. allAirConfig: [],
  161. btnList: [],
  162. operatorList: ['+', '-', '*', '/', '>', '<', '≥', '≤', '(', ')', '&&', '||', '==', '≠', '删除', '清空'],
  163. numberList: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.'],
  164. paramsList: ['年纪', '月收入', '抵押品价值', '信用评分', '有担保人']
  165. }
  166. },
  167. watch: {
  168. keyWord() {
  169. this.tableRequset.pageIndex = 1
  170. this.debounceFn()
  171. }
  172. },
  173. mounted() {
  174. // this.getJudgeFaultLogicAPI()
  175. this.getAircaftTypeAndModelTreeAPI()
  176. },
  177. methods: {
  178. async getAircaftTypeAndModelTreeAPI(params) {
  179. const { data } = await getAircaftTypeAndModelTree(params)
  180. this.menuTreeData = data
  181. const { data: airConfigData } = await getAirConfiguration()
  182. this.allAirConfig = airConfigData
  183. const getAircaftModelAllParams = {
  184. aircaftTypeCode: '',
  185. aircaftTypeId: '',
  186. queryParam: ''
  187. }
  188. const { data: data1 } = await getAircaftModelAll(getAircaftModelAllParams)
  189. this.aircaftModelAll = data1
  190. },
  191. async removeJudgeFaultLogicAPI(params) {
  192. try {
  193. const { code } = await removeJudgeFaultLogic(params)
  194. if (code === 200) {
  195. this.$message({
  196. type: 'success',
  197. message: '操作成功!'
  198. })
  199. await this.getJudgeFaultLogicAPI()
  200. this.handleClose()
  201. }
  202. } catch (error) {}
  203. },
  204. getTreeLeafData(list) {
  205. const newArr = []
  206. function getLeaf(data, arr) {
  207. data.forEach((e) => {
  208. if (e.type === 1) {
  209. arr.push(e)
  210. }
  211. if (e.children.length) {
  212. getLeaf(e.children, arr)
  213. }
  214. })
  215. }
  216. getLeaf(list, newArr)
  217. return newArr
  218. },
  219. async getJudgeFaultLogicAPI(params) {
  220. if (this.$refs.table) this.$refs.table.clearSelection()
  221. const { keyWord } = this
  222. const { pageSize, pageIndex } = this.tableRequset
  223. const {
  224. data: { list, total }
  225. } = await getJudgeFaultLogic({ pageSize, pageNum: pageIndex, keyWord, ...params })
  226. this.tableData = list
  227. this.tableData.forEach((item, index) => {
  228. if (index == 0) {
  229. item.formula = '年纪 ≥ 25 && ( 月收入 ≥ 10000 || 抵押品价值 ≥ 500000 ) / ( 信用评分 ≥ 700 || 有担保人 == 1 )'
  230. } else {
  231. item.formula = ''
  232. }
  233. })
  234. // this.tableData = list.map((item) => {
  235. // return { ...item, formula: '年纪 ≥ 25 && ( 月收入 ≥ 10000 || 抵押品价值 ≥ 500000 ) / ( 信用评分 ≥ 700 || 有担保人 == 1 )' }
  236. // })
  237. this.tableRequset.total = total
  238. const getAircaftModelAllParams = {
  239. aircaftTypeCode: '',
  240. aircaftTypeId: '',
  241. queryParam: ''
  242. }
  243. const { data: data1 } = await getAircaftModelAll(getAircaftModelAllParams)
  244. this.aircaftModelAll = data1
  245. },
  246. fetch() {
  247. this.getJudgeFaultLogicAPI()
  248. },
  249. searchClick() {
  250. this.getJudgeFaultLogicAPI()
  251. },
  252. async addJudgeFaultLogicAPI() {
  253. this.form.parameterColumn = this.form.parameterColumn.toString()
  254. try {
  255. delete this.form.aircaftModelName
  256. const { code } = await addJudgeFaultLogic({ ...this.form })
  257. if (code === 200) {
  258. this.$message({
  259. type: 'success',
  260. message: '操作成功!'
  261. })
  262. this.getJudgeFaultLogicAPI()
  263. this.handleClose()
  264. }
  265. } catch (error) {}
  266. },
  267. async updateJudgeFaultLogicAPI() {
  268. this.form.parameterColumn = this.form.parameterColumn.toString()
  269. try {
  270. const { code } = await updateJudgeFaultLogic({ ...this.form })
  271. if (code === 200) {
  272. this.$message({
  273. type: 'success',
  274. message: '操作成功!'
  275. })
  276. this.getJudgeFaultLogicAPI()
  277. this.handleClose()
  278. }
  279. } catch (error) {}
  280. },
  281. async treeNodeClick(data) {
  282. this.currentNode = data
  283. let dataTree = []
  284. if (data.type === 1) {
  285. const { data: data1 } = await getAirConfiguration({ aircraftType: data.id })
  286. dataTree = data1
  287. this.getAirConfigParamsAPI({ aircraftType: data.id })
  288. this.currentNodeKey = data.id
  289. }
  290. this.configTreeData = []
  291. const topNode = { id: '1', name: '整机', children: [] }
  292. topNode.children = handleTree(dataTree, 'id')
  293. this.configTreeData.push(topNode)
  294. },
  295. treeConfigNodeClick(data) {
  296. this.$refs.table.clearSelection()
  297. this.currentConfigNodeKey = this.form.sysId = data.id
  298. this.currentConfigNode = data
  299. this.getAirConfigParamsAPI({ sysId: this.currentConfigNodeKey })
  300. },
  301. changeModel(item) {
  302. const matchedItem = this.aircaftModelAll?.find((i) => item === i.aircaftModelId)
  303. if (matchedItem) {
  304. return matchedItem.aircaftModelName
  305. } else {
  306. return item
  307. }
  308. },
  309. openDialog() {
  310. this.dialogTitle = '新增'
  311. this.dialogVisible = true
  312. this.form.aircraftType = this.currentNode.id
  313. this.form.sysId = this.currentConfigNodeKey
  314. },
  315. handleClose() {
  316. this.dialogVisible = false
  317. this.form = {
  318. id: '',
  319. model: '',
  320. hmcCode: '',
  321. formula: ''
  322. }
  323. },
  324. handleIndexChange(val) {
  325. this.tableRequset.pageIndex = val
  326. this.getJudgeFaultLogicAPI()
  327. },
  328. handleSizeChange(val) {
  329. this.tableRequset.pageSize = val
  330. this.getJudgeFaultLogicAPI()
  331. },
  332. handUpdate(row) {
  333. this.dialogTitle = '编辑'
  334. this.form = deepClone(row)
  335. // this.$set(this.form, 'formula', '$$年纪 \\geq 25 \\&\\& (月收入 \\geq 10000 \\parallel 抵押品价值\\geq 500000)\\&\\&(信用评分\\geq 700 \\parallel 有担保人= 1)$$')
  336. // this.form.formula = ''
  337. this.dialogVisible = true
  338. },
  339. submit() {
  340. let c = this.form.formula.slice(2, this.form.formula.length - 2).split(' ')
  341. console.log('c', c)
  342. let newFormula = c.map((item) => (item === '\\&\\&' ? '&&' : item))
  343. this.form.formulatr = newFormula.join(' ')
  344. console.log('this.form', this.form)
  345. // this.$refs['form'].validate((valid) => {
  346. // if (valid) {
  347. // switch (this.dialogTitle) {
  348. // case '编辑':
  349. // this.updateJudgeFaultLogicAPI()
  350. // break
  351. // case '新增':
  352. // this.addJudgeFaultLogicAPI()
  353. // break
  354. // }
  355. // }
  356. // })
  357. },
  358. selection(val) {
  359. this.tableCheckItems = val
  360. },
  361. remove(row) {
  362. this.$confirm('是否删除该机种', '提示', {
  363. confirmButtonText: '确定',
  364. cancelButtonText: '取消',
  365. type: 'warning'
  366. })
  367. .then(() => {
  368. this.removeJudgeFaultLogicAPI(row.map((e) => e.id))
  369. })
  370. .catch(() => {})
  371. },
  372. // 增加参数
  373. addParams(params) {
  374. let formula = deepClone(this.form.formula)
  375. // 先拿到当前的字符 去除前后 $$ 符号 以空格分隔
  376. let c = formula.slice(2, formula.length - 2).split(' ')
  377. if (this.paramsList.find((i) => i == c[c.length - 1])) {
  378. useMessage('error', '不能连续输入两个参数')
  379. return
  380. } else if (this.numberList.find((i) => i == c[c.length - 1])) {
  381. useMessage('error', '参数和数字不能相邻')
  382. return
  383. } else {
  384. c.push(params)
  385. const str = c.join(' ')
  386. this.form.formula = `$$${str}$$`
  387. }
  388. },
  389. // 增加数字
  390. addNumber(number) {
  391. let formula = deepClone(this.form.formula)
  392. // 先拿到当前的字符 去除前后 $$ 符号 以空格分隔
  393. let c = formula.slice(2, formula.length - 2).split(' ')
  394. if (number == '.' && !this.numberList.find((i) => i == c[c.length - 1])) {
  395. useMessage('error', '小数点前必须为数字')
  396. return
  397. }
  398. if (this.paramsList.find((i) => i == c[c.length - 1])) {
  399. useMessage('error', '参数和数字不能相邻')
  400. return
  401. } else {
  402. c.push(number)
  403. const str = c.join(' ')
  404. this.form.formula = `$$${str}$$`
  405. }
  406. },
  407. // 增加运算符
  408. addSymbol(item) {
  409. let n = deepClone(this.form.formula)
  410. const syf = ['+', '-', '*', '/', '>', '<', '≥', '≤', '&&', '||', '≠', '==', '\\&\\&']
  411. if (item == '删除') {
  412. if (n.length == 0) {
  413. return
  414. } else {
  415. let c = n.slice(2, n.length - 2).split(' ')
  416. let j = c.slice(0, c.length - 1)
  417. if (j.length == 0) {
  418. this.form.formula = ''
  419. return
  420. } else {
  421. const str = j.join(' ')
  422. this.form.formula = `$$${str}$$`
  423. return
  424. }
  425. }
  426. }
  427. if (item == '清空') {
  428. this.form.formula = ''
  429. } else {
  430. // 如果是空
  431. if (n.length == 0) {
  432. // 第一位不能输入 syf 里面的任意字符
  433. if (syf.find((i) => i == item)) {
  434. useMessage('error', '第一位不能输入运算符')
  435. return
  436. }
  437. this.form.formula = `$$${item}$$`
  438. } else {
  439. let c = n.slice(2, n.length - 2).split(' ')
  440. // 不能连续输入 syf 里面的任意字符
  441. if (syf.find((i) => i == c[c.length - 1]) && syf.find((i) => i == item)) {
  442. useMessage('error', '不能连续输入运算符')
  443. return
  444. }
  445. if (item == '&&') {
  446. c.push('\\&\\&')
  447. const str = c.join(' ')
  448. this.form.formula = `$$${str}$$`
  449. } else {
  450. c.push(item)
  451. const str = c.join(' ')
  452. this.form.formula = `$$${str}$$`
  453. }
  454. }
  455. }
  456. },
  457. // 转换公式
  458. async handleConvertFormula(aircraftType, formula) {
  459. // '年纪 ≥ 25 && (月收入 ≥ 10000 || 抵押品价值 ≥ 500000) && (信用评分 ≥ 700 || 有担保人 == 1)'
  460. // '$$年纪 \\geq 25 \\&\\& (月收入 \\geq 10000 \\parallel 抵押品价值\\geq 500000)\\&\\&(信用评分\\geq 700 \\parallel 有担保人= 1)$$'
  461. let c = formula.split(' ')
  462. let newFormula = c.map((item, index) => {
  463. if (item == '&&') {
  464. return '\\&\\&'
  465. } else {
  466. return item
  467. }
  468. })
  469. const str = newFormula.join(' ')
  470. return `$$${str}$$`
  471. },
  472. // 查找相匹配的括号的位置 (公式数组,传入的括号型号,传入括号的位置)
  473. findBracketPos(formulaArray, bracketType, position) {
  474. // stack用来存储多层括号,findPos为最终匹配上的括号位置
  475. let stack = [],
  476. findPos
  477. if (bracketType == '(') {
  478. console.log('findPos1', findPos)
  479. for (let i = position + 1; i < formulaArray.length; i++) {
  480. console.log('findPos3', findPos)
  481. if (formulaArray[i] == '(') {
  482. stack.push('(')
  483. } else if (formulaArray[i] == ')') {
  484. if (stack.length !== 0) {
  485. stack.pop()
  486. } else {
  487. findPos = i
  488. console.log('findPos2', findPos)
  489. break
  490. }
  491. }
  492. }
  493. } else if (bracketType == ')') {
  494. for (let i = formulaArray.length - 1; i > 0; i--) {
  495. if (formulaArray[i] == ')') {
  496. stack.push(')')
  497. } else if (formulaArray[i] == '(') {
  498. if (stack.length !== 0) {
  499. stack.pop()
  500. } else {
  501. findPos = i
  502. break
  503. }
  504. }
  505. }
  506. }
  507. return findPos
  508. }
  509. }
  510. }
  511. </script>
  512. <style lang="scss">
  513. @import '../index.scss';
  514. .table {
  515. width: 100%;
  516. height: calc(100vh - 280px);
  517. overflow: scroll;
  518. }
  519. ::-webkit-scrollbar {
  520. display: none;
  521. }
  522. </style>