kpi-threshold-config.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template>
  2. <div>
  3. <div :class="$style.btndiv">
  4. <a-dropdown>
  5. <a-button icon="plus" type="link">添加</a-button>
  6. <a-menu slot="overlay" @click="addClick">
  7. <a-menu-item key="one">一区间阈值</a-menu-item>
  8. <a-menu-item key="two">两区间阈值</a-menu-item>
  9. </a-menu>
  10. </a-dropdown>
  11. </div>
  12. <div :class="$style.formdiv">
  13. <a-form ref="form" :form="form">
  14. <div v-for="(item, index) in form.dynamicItem" :key="index">
  15. <div v-if="index > 0">
  16. <span>或</span>
  17. </div>
  18. <!-- 一区间 -->
  19. <a-form-item v-if="item.type === 'one'">
  20. <span>N</span>
  21. <a-select v-model="item.onesize" :options="sizeOptions" />
  22. <a-select v-model="item.onetype" :options="typeOptions"></a-select>
  23. <a-input-number
  24. v-show="item.onetype === 'const'"
  25. v-model="item.oneconstant"
  26. ></a-input-number>
  27. <a-select
  28. v-show="item.onetype === 'var'"
  29. v-model="item.onevariable"
  30. :options="variableOptions"
  31. ></a-select>
  32. <span v-show="item.onetype === 'var'">(</span>
  33. <a-input
  34. v-show="item.onetype === 'var'"
  35. v-model="item.onekpi"
  36. :class="$style.inputkpi"
  37. :read-only="true"
  38. @click="selectZb(index, 'onekpi', 'onekpiid')"
  39. ></a-input>
  40. <span v-show="item.onetype === 'var'">,</span>
  41. <a-input-number
  42. v-show="item.onetype === 'var'"
  43. v-model="item.onerange"
  44. :class="$style.inputrange"
  45. :max="100"
  46. :min="0"
  47. :precision="0"
  48. placeholder="请输入0-100正整数"
  49. ></a-input-number>
  50. <span v-show="item.onetype === 'var'">期)</span>
  51. </a-form-item>
  52. <!-- 两区间 -->
  53. <a-form-item v-if="item.type === 'two'">
  54. <span v-show="item.twotype1 === 'var'">(</span>
  55. <a-input-number
  56. v-show="item.twotype1 === 'var'"
  57. v-model="item.tworange1"
  58. :class="$style.inputrange"
  59. :max="100"
  60. :min="0"
  61. :precision="0"
  62. placeholder="请输入0-100正整数"
  63. ></a-input-number>
  64. <span v-show="item.twotype1 === 'var'">期,</span>
  65. <a-input
  66. v-show="item.twotype1 === 'var'"
  67. v-model="item.twokpi1"
  68. :class="$style.inputkpi"
  69. :read-only="true"
  70. @click="selectZb(index, 'twokpi1', 'twokpi1id')"
  71. ></a-input>
  72. <span v-show="item.twotype1 === 'var'">)</span>
  73. <a-select
  74. v-show="item.twotype1 === 'var'"
  75. v-model="item.twovariable1"
  76. :options="variableOptions"
  77. ></a-select>
  78. <a-input-number
  79. v-show="item.twotype1 === 'const'"
  80. v-model="item.twoconstant1"
  81. ></a-input-number>
  82. <a-select v-model="item.twotype1" :options="typeOptions"></a-select>
  83. <a-select v-model="item.twosize1" :options="sizeOptions" />
  84. <span>N</span>
  85. <a-select v-model="item.twosize2" :options="sizeOptions" />
  86. <a-select v-model="item.twotype2" :options="typeOptions"></a-select>
  87. <a-input-number
  88. v-show="item.twotype2 === 'const'"
  89. v-model="item.twoconstant2"
  90. ></a-input-number>
  91. <a-select
  92. v-show="item.twotype2 === 'var'"
  93. v-model="item.twovariable2"
  94. :options="variableOptions"
  95. ></a-select>
  96. <span v-show="item.twotype2 === 'var'">(</span>
  97. <a-input
  98. v-show="item.twotype2 === 'var'"
  99. v-model="item.twokpi2"
  100. :class="$style.inputkpi"
  101. :read-only="true"
  102. @click="selectZb(index, 'twokpi2', 'twokpi2id')"
  103. ></a-input>
  104. <span v-show="item.twotype2 === 'var'">,</span>
  105. <a-input-number
  106. v-show="item.twotype2 === 'var'"
  107. v-model="item.tworange2"
  108. :class="$style.inputrange"
  109. :max="100"
  110. :min="0"
  111. :precision="0"
  112. placeholder="请输入0-100正整数"
  113. ></a-input-number>
  114. <span v-show="item.twotype2 === 'var'">期)</span>
  115. </a-form-item>
  116. <div :class="$style.delbtn">
  117. <a-button icon="sd-trash2" @click="deleteItem(item, index)"></a-button>
  118. </div>
  119. </div>
  120. </a-form>
  121. </div>
  122. <iam-audit-modal
  123. :single="true"
  124. :check-type="'radio'"
  125. select-type="table"
  126. :visible="visible"
  127. :treeparams="{
  128. configId: '41',
  129. }"
  130. :columns="columns"
  131. @listSelected="listSelected"
  132. @getCheckNode="getCheckNode"
  133. ></iam-audit-modal>
  134. </div>
  135. </template>
  136. <script>
  137. import iamAuditModal from '@product/iam/components/iam-audit-modal.vue'
  138. import components from './_import-components/kpi-threshold-config-import'
  139. export default {
  140. name: 'KpiThresholdConfig',
  141. components: {
  142. ...components,
  143. iamAuditModal,
  144. },
  145. props: {
  146. /**
  147. * 表单数据
  148. */
  149. value: {
  150. type: String,
  151. default: '',
  152. },
  153. },
  154. data() {
  155. return {
  156. visible: false,
  157. columns: [
  158. {
  159. title: '序号',
  160. dataIndex: 'sortNum',
  161. customRender: (text, record, index) => `${index + 1}`,
  162. width: '80px',
  163. },
  164. {
  165. title: '指标名称',
  166. dataIndex: 'indiName',
  167. },
  168. {
  169. title: '业务分类',
  170. dataIndex: 'busiClass',
  171. },
  172. {
  173. title: '维护单位',
  174. dataIndex: 'createDeptName',
  175. },
  176. ],
  177. addtype: '', // 添加类型
  178. sizeOptions: [
  179. {
  180. value: '>',
  181. label: '>',
  182. },
  183. {
  184. value: '>=',
  185. label: '>=',
  186. },
  187. {
  188. value: '<',
  189. label: '<',
  190. },
  191. {
  192. value: '<=',
  193. label: '<=',
  194. },
  195. {
  196. value: '=',
  197. label: '=',
  198. },
  199. {
  200. value: '!=',
  201. label: '!=',
  202. },
  203. ],
  204. typeOptions: [
  205. {
  206. value: 'const',
  207. label: '常量',
  208. },
  209. {
  210. value: 'var',
  211. label: '变量',
  212. },
  213. ],
  214. variableOptions: [
  215. {
  216. value: 'avg',
  217. label: '平均值',
  218. },
  219. {
  220. value: 'max',
  221. label: '最大值',
  222. },
  223. {
  224. value: 'min',
  225. label: '最小值',
  226. },
  227. ],
  228. form: {
  229. dynamicItem: [],
  230. },
  231. zbindex: 0,
  232. zbfield: '',
  233. zbidfield: '',
  234. }
  235. },
  236. mounted() {
  237. if (this.value !== '') {
  238. this.form.dynamicItem = JSON.parse(this.value)
  239. }
  240. },
  241. methods: {
  242. // 选择指标回写
  243. listSelected(keys, keyinfos) {
  244. this.visible = false
  245. if (keyinfos?.length > 0) {
  246. this.form.dynamicItem[this.zbindex][this.zbfield] = keyinfos[0].indiName
  247. this.form.dynamicItem[this.zbindex][this.zbidfield] = keyinfos[0].id
  248. }
  249. },
  250. getCheckNode(checkNode) {
  251. this.visible = false
  252. },
  253. // 选择指标
  254. selectZb(index, field, idfield) {
  255. this.visible = true
  256. this.zbindex = index // 编辑行index
  257. this.zbfield = field // 编辑指标域
  258. this.zbidfield = idfield // 编辑指标ID域
  259. },
  260. // 添加
  261. addClick(type) {
  262. this.addtype = type.key
  263. if (this.addtype === 'one') {
  264. // 一区间
  265. this.form.dynamicItem.push({
  266. type: 'one',
  267. onesize: '>',
  268. onetype: 'const',
  269. onevariable: 'avg',
  270. })
  271. } else {
  272. // 两区间
  273. this.form.dynamicItem.push({
  274. type: 'two',
  275. twosize1: '<',
  276. twotype1: 'const',
  277. twosize2: '<',
  278. twotype2: 'const',
  279. twovariable1: 'avg',
  280. twovariable2: 'avg',
  281. })
  282. }
  283. this.getConfigVal()
  284. },
  285. // 删除
  286. deleteItem(item, index) {
  287. this.form.dynamicItem.splice(index, 1)
  288. },
  289. // 表单数据
  290. getConfigVal() {
  291. let strval = '' // 前端显示公式
  292. let calval = '' // 计算公式
  293. this.form.dynamicItem?.forEach((item) => {
  294. let strtemp = ''
  295. let caltemp = ''
  296. // 一区间
  297. if (item.type === 'one') {
  298. // 常量
  299. if (item.onetype === 'const') {
  300. strtemp = 'N' + item.onesize + item.oneconstant
  301. caltemp = 'N' + item.onesize + item.oneconstant
  302. } else {
  303. // 变量
  304. strtemp =
  305. 'N' +
  306. item.onesize +
  307. '最新' +
  308. item.onerange +
  309. '期' +
  310. item.onekpi +
  311. '的' +
  312. this.getVarName(item.onevariable)
  313. caltemp =
  314. 'N' +
  315. item.onesize +
  316. '@thresholdService.' +
  317. item.onevariable +
  318. '(#v_' +
  319. item.onekpiid +
  320. ',DEPTCODE,' +
  321. item.onerange +
  322. ')'
  323. }
  324. }
  325. // 两区间
  326. if (item.type === 'two') {
  327. // 1常量
  328. if (item.twotype1 === 'const') {
  329. strtemp = 'N' + this.handleSize(item.twosize1) + item.twoconstant1
  330. caltemp = '(N' + this.handleSize(item.twosize1) + item.twoconstant1
  331. } else {
  332. // 1变量
  333. strtemp =
  334. 'N' +
  335. this.handleSize(item.twosize1) +
  336. '最新' +
  337. item.tworange1 +
  338. '期' +
  339. item.twokpi1 +
  340. '的' +
  341. this.getVarName(item.twovariable1)
  342. caltemp =
  343. '(N' +
  344. this.handleSize(item.twosize1) +
  345. '@thresholdService.' +
  346. item.twovariable1 +
  347. '(#v_' +
  348. item.twokpi1id +
  349. ',DEPTCODE,' +
  350. item.tworange1 +
  351. ')'
  352. }
  353. // 2常量
  354. if (item.twotype2 === 'const') {
  355. strtemp = strtemp + '且N' + item.twosize2 + item.twoconstant2
  356. caltemp = caltemp + ' && N' + item.twosize2 + item.twoconstant2 + ')'
  357. } else {
  358. // 2变量
  359. strtemp =
  360. strtemp +
  361. '且N' +
  362. item.twosize2 +
  363. '最新' +
  364. item.tworange2 +
  365. '期' +
  366. item.twokpi2 +
  367. '的' +
  368. this.getVarName(item.twovariable2)
  369. caltemp =
  370. caltemp +
  371. ' && N' +
  372. item.twosize2 +
  373. '@thresholdService.' +
  374. item.twovariable2 +
  375. '(#v_' +
  376. item.twokpi2id +
  377. ',DEPTCODE,' +
  378. item.tworange2 +
  379. '))'
  380. }
  381. }
  382. if (strval === '') {
  383. strval = strtemp
  384. } else {
  385. strval = strval + '\n或\n' + strtemp
  386. }
  387. if (calval === '') {
  388. calval = caltemp
  389. } else {
  390. calval = calval + ' || ' + caltemp
  391. }
  392. })
  393. // console.log(strval)
  394. // console.log(calval)
  395. return {
  396. strconfig: strval,
  397. calconfig: calval,
  398. dynamicItem: JSON.stringify(this.form.dynamicItem), // 表单数据
  399. }
  400. },
  401. // 获取变量值类型名称
  402. getVarName(val) {
  403. let varname = ''
  404. switch (val) {
  405. case 'avg':
  406. varname = '平均值'
  407. break
  408. case 'max':
  409. varname = '最大值'
  410. break
  411. case 'min':
  412. varname = '最小值'
  413. break
  414. default:
  415. break
  416. }
  417. return varname
  418. },
  419. // 两区间的时候处理twosize1字段
  420. handleSize(val) {
  421. let varsize = ''
  422. switch (val) {
  423. case '<':
  424. varsize = '>'
  425. break
  426. case '<=':
  427. varsize = '>='
  428. break
  429. case '>':
  430. varsize = '<'
  431. break
  432. case '>=':
  433. varsize = '<='
  434. break
  435. default:
  436. break
  437. }
  438. return varsize
  439. },
  440. },
  441. }
  442. </script>
  443. <style module lang="scss">
  444. @use '@/common/design' as *;
  445. .btndiv {
  446. text-align: right;
  447. }
  448. .formdiv {
  449. :global(.ant-select),
  450. :global(.ant-input-number),
  451. :global(.ant-input) {
  452. width: auto !important;
  453. }
  454. .delbtn,
  455. :global(.ant-form-item) {
  456. display: inline-block;
  457. }
  458. .delbtn {
  459. :global(.ant-btn) {
  460. margin: 4px;
  461. color: $white;
  462. background: $red-6;
  463. border: none;
  464. }
  465. }
  466. .inputrange,
  467. .inputkpi {
  468. border: none;
  469. border-bottom: 1px solid $black;
  470. }
  471. }
  472. </style>