kpi-indi-form.vue 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. <template>
  2. <audit-form-top-banner :handel-save-form="saveForm" :form-data="mode" @handelSaveForm="saveForm">
  3. <sd-detail-form
  4. ref="kpiIndiForm"
  5. form-id="kpiIndiDef"
  6. page-id="kpi/def/definition/kpiIndiDef"
  7. :record-id="this.$route.query.record ? parseInt(this.$route.query.record) : null"
  8. :class="[$style.form, { [$style.readOnlyForm]: mode === 'VIEW' }]"
  9. :read-only="mode === 'VIEW'"
  10. @close="close(true)"
  11. @saved="saved"
  12. @sdFormReady="sdFormReady"
  13. >
  14. <template v-slot="{ model, fields }">
  15. <table>
  16. <tr>
  17. <td style="padding-left:5px;border:none">
  18. <audit-advanced-group
  19. :expand="basicExpand"
  20. :expand-str="'basicExpand'"
  21. :group-label="'基本信息'"
  22. tablestyle="''"
  23. @changedClick="changedClick"
  24. ></audit-advanced-group>
  25. </td>
  26. </tr>
  27. </table>
  28. <table v-show="basicExpand">
  29. <tr>
  30. <td class="ant-form-item-label ant-form-item-label" :class="$style.firstTd"></td>
  31. <td class="ant-form-item-control-wrapper" :class="$style.firstTd"></td>
  32. <td class="ant-form-item-label ant-form-item-label" :class="$style.firstTd"></td>
  33. <td class="ant-form-item-control-wrapper" :class="$style.firstTd"></td>
  34. <sd-form-item-td name="id" label="ID" :colspan="3" :hidden="true"> </sd-form-item-td>
  35. </tr>
  36. <tr>
  37. <!-- 指标名称 -->
  38. <sd-form-item-td name="indiName" label="指标名称"> </sd-form-item-td>
  39. <!-- 指标编号 -->
  40. <sd-form-item-td name="indiNo" label="指标编号">
  41. <a-form-model-item
  42. :rules="[
  43. {
  44. pattern: '^[A-Za-z0-9-_]+$',
  45. message: '只能包含英文字母、数字、下横线,请重新输入',
  46. trigger: 'change',
  47. },
  48. { validator: handleIndiNo },
  49. ]"
  50. prop="indiNo"
  51. >
  52. <a-input v-model="model.indiNo"></a-input>
  53. </a-form-model-item>
  54. </sd-form-item-td>
  55. </tr>
  56. <tr>
  57. <!-- 指标状态 -->
  58. <sd-form-item-td name="indiStatus" label="指标状态"> </sd-form-item-td>
  59. <!-- 指标值单位 -->
  60. <sd-form-item-td name="indiUnit" label="指标值单位"> </sd-form-item-td>
  61. </tr>
  62. <tr>
  63. <!-- 指标时间维度--新建时可编辑,保存后只可查看不可编辑 -->
  64. <td v-if="!!model.id" class="ant-form-item-label">
  65. <label>指标时间维度</label>
  66. </td>
  67. <td v-if="!!model.id" class="ant-form-item-control-wrapper">
  68. <span v-if="model.indiFrequency === '1'">日</span>
  69. <span v-if="model.indiFrequency === '2'">周</span>
  70. <span v-if="model.indiFrequency === '3'">月</span>
  71. <span v-if="model.indiFrequency === '4'">季度</span>
  72. <span v-if="model.indiFrequency === '5'">半年</span>
  73. <span v-if="model.indiFrequency === '6'">年</span>
  74. </td>
  75. <sd-form-item-td
  76. v-else
  77. name="indiFrequency"
  78. label="指标时间维度"
  79. component="a-radio-group"
  80. >
  81. </sd-form-item-td>
  82. <!-- 指标性质 -->
  83. <sd-form-item-td name="indiAttr" label="指标性质"> </sd-form-item-td>
  84. </tr>
  85. <tr>
  86. <!-- 业务分类 -->
  87. <sd-form-item-td name="busiClass" label="业务分类">
  88. <sd-tree-picker
  89. v-model="model.busiClass"
  90. single
  91. :load-tree-data="loadTreeDataBusi"
  92. a-select
  93. @change="busiChange"
  94. >
  95. </sd-tree-picker>
  96. </sd-form-item-td>
  97. <!-- 业务分类ID -->
  98. <sd-form-item-td :hidden="true" name="busiClassId" label="业务分类ID" />
  99. <!-- 业务分类name -->
  100. <sd-form-item-td :hidden="true" name="busiClassName" label="业务分类名称" />
  101. <!-- 数据来源 -->
  102. <sd-form-item-td name="dataFrom" label="数据来源" component="a-radio-group">
  103. </sd-form-item-td>
  104. </tr>
  105. <tr v-show="model.dataFrom === 'system'">
  106. <!-- 数据源 -->
  107. <td class="ant-form-item-label">
  108. <label
  109. title="数据源"
  110. :class="model.dataFrom === 'system' ? 'ant-form-item-required' : 'ant-form-item'"
  111. >
  112. 数据源
  113. </label></td
  114. >
  115. <sd-form-item-td name="databaseName" :label="null" :colspan="3">
  116. <a-form-model-item
  117. :rules="[
  118. {
  119. required: model.dataFrom === 'system' ? true : false,
  120. trigger: ['change', 'blur'],
  121. },
  122. ]"
  123. prop="databaseName"
  124. >
  125. <a-input
  126. v-model="model.databaseName"
  127. :read-only="true"
  128. @click="selectDatabase"
  129. ></a-input>
  130. </a-form-model-item>
  131. <a-button :loading="connect" :disabled="database === undefined" @click="testDatabase"
  132. >测试数据源</a-button
  133. >
  134. </sd-form-item-td>
  135. </tr>
  136. <tr v-show="false">
  137. <sd-form-item-td name="databaseId" label="数据源ID" :colspan="3"> </sd-form-item-td
  138. ></tr>
  139. <tr v-show="model.dataFrom === 'system'">
  140. <!-- SQL -->
  141. <td class="ant-form-item-label">
  142. <label
  143. title="SQL"
  144. :class="model.dataFrom === 'system' ? 'ant-form-item-required' : 'ant-form-item'"
  145. >
  146. SQL
  147. </label></td
  148. >
  149. <sd-form-item-td name="indiCalSql" :label="null" :colspan="3">
  150. <a-form-model-item
  151. :rules="[
  152. {
  153. required: model.dataFrom === 'system' ? true : false,
  154. trigger: ['change', 'blur'],
  155. },
  156. ]"
  157. prop="indiCalSql"
  158. >
  159. <a-textarea v-model="model.indiCalSql" :rows="2" />
  160. </a-form-model-item>
  161. <a-button :loading="SQLconnect" @click="checkSQL">校验SQL</a-button>
  162. </sd-form-item-td>
  163. </tr>
  164. <tr v-show="false">
  165. <!-- 因子指标 -->
  166. <sd-form-item-td name="indiFactors" label="因子指标" :colspan="3"> </sd-form-item-td>
  167. </tr>
  168. <tr v-show="model.dataFrom === 'calculate'">
  169. <!-- 计算公式描述 -->
  170. <td class="ant-form-item-label">
  171. <label
  172. title="计算公式"
  173. :class="model.dataFrom === 'calculate' ? 'ant-form-item-required' : 'ant-form-item'"
  174. >
  175. 计算公式
  176. </label></td
  177. >
  178. <sd-form-item-td name="indiCalFormulaDesc" :label="null" :colspan="3">
  179. <template v-slot:read-and-edit="editable">
  180. <kpi-formula-editor
  181. ref="formulaindi"
  182. :read-only="mode === 'VIEW'"
  183. :default-list="
  184. model.indiFactors !== undefined ? JSON.parse(model.indiFactors) : []
  185. "
  186. :data-list="dataList"
  187. :zbid="zbid"
  188. @change="changeFormula"
  189. />
  190. </template>
  191. </sd-form-item-td>
  192. </tr>
  193. <tr>
  194. <!-- 说明 -->
  195. <sd-form-item-td name="indiDesc" label="说明" :colspan="3">
  196. <a-textarea v-model="model.indiDesc" :rows="3" />
  197. </sd-form-item-td>
  198. </tr>
  199. <tr>
  200. <!-- 是否自动下发报送任务 -->
  201. <sd-form-item-td name="autoTask" label="是否自动下发报送任务"> </sd-form-item-td>
  202. <!-- 维护人员 -->
  203. <sd-form-item-td name="creatorAccount" label="创建人账号" :hidden="true">
  204. </sd-form-item-td>
  205. <sd-form-item-td name="creatorName" label="维护人员"> </sd-form-item-td>
  206. </tr>
  207. <tr>
  208. <!-- 维护单位 -->
  209. <sd-form-item-td name="createDeptId" label="创建部门id" :hidden="true">
  210. </sd-form-item-td>
  211. <sd-form-item-td name="createDeptName" label="维护单位"> </sd-form-item-td>
  212. <!-- 维护日期 -->
  213. <sd-form-item-td name="creationTime" label="维护日期"> </sd-form-item-td>
  214. </tr>
  215. <tr>
  216. <!-- 监测范围 -->
  217. <sd-form-item-td name="monitorRange" label="监测范围" component="a-radio-group">
  218. </sd-form-item-td>
  219. </tr>
  220. <tr>
  221. <!-- 阈值说明 -->
  222. <sd-form-item-td name="thresholdDesc" label="阈值说明" :colspan="3">
  223. <a-textarea v-model="model.thresholdDesc" :rows="3" />
  224. </sd-form-item-td>
  225. </tr>
  226. </table>
  227. <table>
  228. <tr
  229. ><td :colspan="4">
  230. <sd-form-item name="kpiIndiOrgEntities" :label="null">
  231. <template v-slot:read-and-edit="{ editable }">
  232. <audit-advanced-group
  233. :expand="expandC"
  234. :expand-str="'expandC'"
  235. :group-label="'监测单位列表'"
  236. @changedClick="changedClick"
  237. ><template>
  238. <template>
  239. <div :class="$style.wrapper">
  240. <div v-show="editable" :class="$style.btnselect">
  241. <a-button type="link" :class="$style.batchselect" @click="selectDept">
  242. <a-icon type="plus-circle" :theme="'filled'" />
  243. 添加监测单位
  244. </a-button>
  245. <a-button
  246. type="link"
  247. :class="$style.batchselect"
  248. :disabled="selectedRowKeys.length === 0"
  249. @click="syncIndiVal"
  250. >
  251. <a-icon type="sd-sync" :theme="'filled'" />
  252. 同步指标设定值
  253. </a-button>
  254. <a-button
  255. type="link"
  256. :class="$style.batchselect"
  257. :disabled="selectedRowKeys.length === 0"
  258. @click="selectSubmiter"
  259. >
  260. <a-icon type="sd-user" :theme="'filled'" />
  261. 设置报送人
  262. </a-button>
  263. </div>
  264. </div>
  265. </template>
  266. <xm-child-table
  267. ref="monitorForm"
  268. v-model="model.kpiIndiOrgEntities"
  269. :read-only="!editable"
  270. label=""
  271. :fields="
  272. [
  273. {
  274. caption: '序号',
  275. name: 'sortNum',
  276. dataType: 'number',
  277. attr: {},
  278. },
  279. ].concat(Array.from(fields.kpiIndiOrgEntities.attr.dync))
  280. "
  281. :columns="childColumns"
  282. :width="1200"
  283. :addbuttonvisiable="false"
  284. @onSelectChange="onSelectChange"
  285. >
  286. <!-- 阈值-红 -->
  287. <template v-slot:redThresholdDesc="{ field, text, record, index }">
  288. <a-input
  289. v-if="mode !== 'VIEW'"
  290. v-model="record.redThresholdDesc"
  291. :read-only="true"
  292. @click="configThreshold(index, field)"
  293. />
  294. <div v-else>{{ record.redThresholdDesc }}</div>
  295. </template>
  296. <!-- 阈值-黄 -->
  297. <template v-slot:yellowThresholdDesc="{ field, text, record, index }">
  298. <a-input
  299. v-if="mode !== 'VIEW'"
  300. v-model="record.yellowThresholdDesc"
  301. :read-only="true"
  302. @click="configThreshold(index, field)"
  303. />
  304. <div v-else>{{ record.yellowThresholdDesc }}</div>
  305. </template>
  306. <!-- 阈值-绿 -->
  307. <template v-slot:greenThresholdDesc="{ field, text, record, index }">
  308. <a-input
  309. v-if="mode !== 'VIEW'"
  310. v-model="record.greenThresholdDesc"
  311. :read-only="true"
  312. @click="configThreshold(index, field)"
  313. />
  314. <div v-else>{{ record.greenThresholdDesc }}</div>
  315. </template>
  316. <!-- 监测单位 -->
  317. <template v-slot:monitorDeptName="{ field, text, record }">
  318. <a-input
  319. v-if="mode !== 'VIEW'"
  320. v-model="record.monitorDeptName"
  321. :read-only="true"
  322. />
  323. <div v-else>{{ record.monitorDeptName }}</div>
  324. </template>
  325. <!-- 报送人 -->
  326. <template v-slot:submitters="{ field, text, record, index }">
  327. <sd-form-item
  328. v-if="mode !== 'VIEW'"
  329. :name="field.name"
  330. :label="null"
  331. :input-props="{
  332. defaultValue:
  333. record.submitters !== undefined &&
  334. typeof record.submitters !== 'object'
  335. ? JSON.parse(record.submitters)
  336. : record.submitters,
  337. }"
  338. @change="changeSubmitters($event, index)"
  339. />
  340. <div v-else>{{ record.submitterName }}</div>
  341. </template>
  342. <!-- 报送部门 -->
  343. <template v-slot:submitterDeptName="{ field, text, record }">
  344. <a-input
  345. v-if="mode !== 'VIEW'"
  346. v-model="record.submitterDeptName"
  347. :read-only="true"
  348. />
  349. <div v-else>{{ record.submitterDeptName }}</div>
  350. </template>
  351. </xm-child-table>
  352. </template>
  353. </audit-advanced-group>
  354. </template>
  355. </sd-form-item></td
  356. >
  357. </tr>
  358. </table>
  359. <!-- 选择数据源 -->
  360. <iam-audit-modal
  361. :single="true"
  362. :check-type="'radio'"
  363. select-type="table"
  364. :visible="databaseVisible"
  365. :columns="databaseColumns"
  366. :treeparams="{
  367. configId: '61',
  368. }"
  369. @listSelected="listSelected"
  370. @getCheckNode="getCheckNode"
  371. @handleCancel="handleselectsjyCancel"
  372. ></iam-audit-modal>
  373. <!-- 阈值配置器 -->
  374. <a-modal
  375. ref="thresholdModal"
  376. title="阈值配置器"
  377. :destroy-on-close="true"
  378. :visible="thresholdVisible"
  379. width="1200px"
  380. @ok="handleOk"
  381. @cancel="handleCancel"
  382. >
  383. <kpi-threshold-config ref="thresholdConfig" :value="editFormVal"></kpi-threshold-config>
  384. </a-modal>
  385. </template>
  386. </sd-detail-form>
  387. </audit-form-top-banner>
  388. </template>
  389. <script>
  390. import axios from '@/common/services/axios-instance'
  391. import crossWindowWatcher from '@/common/services/cross-window-watcher'
  392. import { message } from '@/common/one-ui'
  393. import pickValues from '@/common/services/pick-values'
  394. import sdTreePicker from '@/common/components/sd-tree-picker.vue'
  395. import sdUserPicker from '@/common/components/sd-user-picker.vue'
  396. import auditFormTopBanner from '@product/iam/components/audit-form-top-banner'
  397. import auditAdvancedGroup from '@product/iam/components/audit-advanced-group'
  398. import auditAdvancedGroupMixins from '@product/iam/components/audit-advanced-group-mixins'
  399. import iamAuditModal from '@product/iam/components/iam-audit-modal.vue'
  400. import kpiFormulaEditor from '../components/kpi-formula-editor'
  401. import kpiThresholdConfig from '../components/kpi-threshold-config.vue'
  402. import KpiService from '../kpi-service'
  403. import components from './_import-components/kpi-indi-form-import'
  404. import 'element-ui/lib/theme-chalk/index.css'
  405. export default {
  406. name: 'KpiIndiForm',
  407. metaInfo: {
  408. title: '指标定义表单',
  409. },
  410. components: {
  411. ...components,
  412. auditAdvancedGroup,
  413. auditFormTopBanner,
  414. kpiFormulaEditor,
  415. kpiThresholdConfig,
  416. iamAuditModal,
  417. },
  418. mixins: [auditAdvancedGroupMixins],
  419. data() {
  420. return {
  421. databaseVisible: false, // 数据源选择
  422. thresholdVisible: false, // 阈值配置器
  423. connect: false, // 测试数据源连接按钮状态
  424. SQLconnect: false, // 校验SQL连接按钮状态
  425. expandC: true,
  426. mode: null,
  427. saveFlag: true,
  428. basicExpand: true,
  429. childColumns: [
  430. {
  431. title: '序号',
  432. dataIndex: 'sortNum',
  433. width: '60px',
  434. customRender: (text, record, index) => `${index + 1}`,
  435. },
  436. { dataIndex: 'id', sdHidden: true },
  437. { dataIndex: 'indiId', sdHidden: true },
  438. { dataIndex: 'monitorDeptId', sdHidden: true },
  439. { dataIndex: 'monitorDeptCode', sdHidden: true },
  440. { dataIndex: 'monitorDeptName', title: '监测单位' },
  441. { dataIndex: 'submitterId', sdHidden: true },
  442. { dataIndex: 'submitterAccount', sdHidden: true },
  443. { dataIndex: 'submitterName', title: '报送人姓名', sdHidden: true },
  444. { dataIndex: 'submitters', title: '报送人' },
  445. { dataIndex: 'submitterDeptId', sdHidden: true },
  446. { dataIndex: 'submitterDeptCode', sdHidden: true },
  447. { dataIndex: 'submitterDeptName', title: '报送部门' },
  448. { dataIndex: 'redThreshold', sdHidden: true },
  449. { dataIndex: 'redThresholdValue', sdHidden: true },
  450. { dataIndex: 'redThresholdDesc', title: '指标阈值(红)' },
  451. { dataIndex: 'yellowThreshold', sdHidden: true },
  452. { dataIndex: 'yellowThresholdValue', sdHidden: true },
  453. { dataIndex: 'yellowThresholdDesc', title: '指标阈值(黄)' },
  454. { dataIndex: 'greenThreshold', sdHidden: true },
  455. { dataIndex: 'greenThresholdValue', sdHidden: true },
  456. { dataIndex: 'greenThresholdDesc', title: '指标阈值(绿)' },
  457. { dataIndex: 'izSelf', title: '是否本单位', sdHidden: true },
  458. ],
  459. dataList: [],
  460. databaseColumns: [
  461. {
  462. title: '序号',
  463. dataIndex: 'sortNum',
  464. customRender: (text, record, index) => `${index + 1}`,
  465. width: '80px',
  466. },
  467. {
  468. title: '数据源名称',
  469. dataIndex: 'name',
  470. },
  471. {
  472. title: '数据库类型',
  473. dataIndex: 'databaseType',
  474. },
  475. {
  476. title: 'IP地址',
  477. dataIndex: 'host',
  478. },
  479. {
  480. title: '端口号',
  481. dataIndex: 'port',
  482. },
  483. {
  484. title: '数据库名称',
  485. dataIndex: 'useSchema',
  486. },
  487. {
  488. title: '用户名',
  489. dataIndex: 'userName',
  490. sdHidden: true,
  491. },
  492. {
  493. title: 'password',
  494. dataIndex: 'password',
  495. sdHidden: true,
  496. },
  497. ],
  498. busicateColumns: [
  499. {
  500. title: '序号',
  501. dataIndex: 'sortNum',
  502. customRender: (text, record, index) => `${index + 1}`,
  503. width: '80px',
  504. },
  505. ],
  506. defaultExpandedKeys: [], // 默认展开部门节点
  507. rootNode: undefined, // 根节点
  508. hierarchical: undefined, // 分级授权
  509. selectedRowKeys: [], // 选择的子表行
  510. treeparams: {
  511. // 业务分类树
  512. configId: 101,
  513. },
  514. zbid: this.$route.query.record ? this.$route.query.record : '',
  515. editFormVal: '',
  516. database: undefined,
  517. }
  518. },
  519. methods: {
  520. handleselectsjyCancel() {
  521. this.databaseVisible = false
  522. },
  523. changeFormula(value) {
  524. let Formulav = ''
  525. let FormulavDesc = ''
  526. value.forEach((v, index) => {
  527. if (v.type === 'obj') {
  528. Formulav += v.key
  529. FormulavDesc += v.value
  530. } else {
  531. Formulav += v.value
  532. FormulavDesc += v.value
  533. }
  534. })
  535. this.$refs.kpiIndiForm.setFieldValue('indiCalFormulaDesc', FormulavDesc)
  536. this.$refs.kpiIndiForm.setFieldValue('indiCalFormula', Formulav)
  537. this.$refs.kpiIndiForm.setFieldValue('indiFactors', JSON.stringify(value))
  538. },
  539. // 页面加载完成后
  540. sdFormReady() {
  541. this.mode = this.$refs.kpiIndiForm.formData.mode
  542. if (this.$route.query.mode === 'view') {
  543. this.mode = 'VIEW'
  544. }
  545. },
  546. // 保存
  547. saveForm() {
  548. // 保存子表数据
  549. this.$refs.kpiIndiForm.setFieldValue('kpiIndiOrgEntities', this.$refs.monitorForm.value)
  550. // 校验计算公式需要选择指标 dataFrom === 'calculate'
  551. const zsfs = this.$refs.kpiIndiForm.getFieldValue('dataFrom')
  552. let flag = true
  553. if (zsfs === 'calculate') {
  554. const gsdesc = this.$refs.kpiIndiForm.getFieldValue('indiCalFormulaDesc')
  555. const gs = this.$refs.kpiIndiForm.getFieldValue('indiCalFormula')
  556. if (gs.indexOf('#') === -1) {
  557. flag = false
  558. }
  559. }
  560. var jobFrequency = this.$refs.kpiIndiForm.getFieldValue('jobFrequency')
  561. var jobCron = this.$refs.kpiIndiForm.getFieldValue('jobCron')
  562. var id = this.$refs.kpiIndiForm.getFieldValue('id')
  563. const params = {
  564. id: id,
  565. jobFrequency: jobFrequency,
  566. jobCron: jobCron,
  567. }
  568. KpiService.hasJobFrequency(params).then((res) => {
  569. if (res) {
  570. message.error('该时间维度已存在,请重新选择!')
  571. } else {
  572. this.$refs.kpiIndiForm.validateFields().then(() => {
  573. if (!flag) {
  574. message.error('计算公式中必须选择至少一项指标!')
  575. } else {
  576. message.success('保存成功').then(() => {
  577. this.$refs.kpiIndiForm.saveBtnClick()
  578. })
  579. }
  580. })
  581. }
  582. })
  583. },
  584. saved() {
  585. this.close(true)
  586. },
  587. close(flag) {
  588. crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
  589. window.close()
  590. },
  591. handleIndiNo(rule, value, callback) {
  592. const id = this.$refs.kpiIndiForm.getFieldValue('id')
  593. // 编号重复校验
  594. KpiService.hasIndiNo(id, value)
  595. .then((res) => {
  596. if (res) {
  597. callback(new Error('编号重复,请重新输入'))
  598. } else {
  599. callback()
  600. }
  601. })
  602. .catch((err) => {
  603. // eslint-disable-next-line no-console
  604. console.log(err)
  605. message.error('出错了,请联系管理员', 1)
  606. callback(new Error('编号校验出错,请联系管理员'))
  607. })
  608. },
  609. listSelected(keys, keyinfos) {
  610. // 数据源数据赋值
  611. this.databaseVisible = false
  612. if (keyinfos?.length > 0) {
  613. this.database = keyinfos[0]
  614. this.$refs.kpiIndiForm.setFieldValue('databaseName', keyinfos[0].name)
  615. this.$refs.kpiIndiForm.setFieldValue('databaseId', parseInt(keyinfos[0].id))
  616. }
  617. },
  618. getCheckNode(checkNode) {
  619. // 数据源弹窗选择
  620. this.databaseVisible = false
  621. },
  622. selectDatabase() {
  623. // 选择数据源
  624. this.databaseVisible = true
  625. },
  626. testDatabase() {
  627. this.connect = true
  628. // 测试数据源
  629. const databaseBean = {
  630. databaseType: this.database?.databaseType,
  631. host: this.database?.host,
  632. port: this.database?.port,
  633. useSchema: this.database?.useSchema,
  634. userName: this.database?.userName,
  635. password: this.database?.password,
  636. }
  637. axios({
  638. url: 'api/xcoa-mobile/v1/iamfinsysdatabase/testDbConnection',
  639. method: 'post',
  640. data: databaseBean,
  641. })
  642. .then((res) => {
  643. if (res.data.indexOf('成功') !== -1) {
  644. message.success(res.data, 1)
  645. } else {
  646. message.error(res.data, 1)
  647. }
  648. setTimeout(() => {
  649. this.connect = false
  650. }, 2000)
  651. })
  652. .catch((err) => {
  653. // eslint-disable-next-line no-console
  654. console.log(err)
  655. message.error('出错了,请联系管理员', 1)
  656. setTimeout(() => {
  657. this.connect = false
  658. }, 2000)
  659. })
  660. },
  661. checkSQL() {
  662. // 校验SQL
  663. this.SQLconnect = true
  664. const databaseID = this.$refs.kpiIndiForm.getFieldValue('databaseId') // 数据源ID
  665. const sql = this.$refs.kpiIndiForm.getFieldValue('indiCalSql') // SQL
  666. const param = {
  667. id: databaseID,
  668. sql: sql,
  669. }
  670. KpiService.validateSQL(param)
  671. .then((res) => {
  672. if (res.indexOf('成功') !== -1) {
  673. message.success(res, 1)
  674. } else {
  675. message.error(res, 1)
  676. }
  677. setTimeout(() => {
  678. this.SQLconnect = false
  679. }, 2000)
  680. })
  681. .catch((err) => {
  682. // eslint-disable-next-line no-console
  683. console.log(err)
  684. message.error('出错了,请联系管理员', 1)
  685. setTimeout(() => {
  686. this.SQLconnect = false
  687. }, 2000)
  688. })
  689. },
  690. // 获取用于选择的业务类型分类树
  691. loadTreeDataBusi(id) {
  692. const topDepId = !id ? 0 : id
  693. const params = {
  694. type: this.treeparams.type,
  695. }
  696. return KpiService.getCategoryTree(topDepId, this.treeparams, params)
  697. .then((res) => {
  698. const treeNode = res.data
  699. return this.mapCategoryItems(treeNode)
  700. })
  701. .catch((e) => {
  702. message.error({ content: '应用类型获取失败' })
  703. })
  704. },
  705. mapCategoryItems(items) {
  706. return (items || []).map((item) => {
  707. const result = {
  708. id: item.id + '',
  709. name: item.text,
  710. // checkable: true,
  711. isLeaf: item.leaf,
  712. checkable: !item.expandable,
  713. }
  714. return result
  715. })
  716. },
  717. busicateHandleCancel() {
  718. this.busicateVisible = false
  719. },
  720. configThreshold(index, field) {
  721. // 阈值配置器
  722. this.editIndex = index // 编辑行index
  723. this.editFieldDesc = field.name // 编辑阈值
  724. // 阈值公式字段
  725. switch (field.name) {
  726. case 'redThresholdDesc':
  727. // 红
  728. this.editField = 'redThreshold'
  729. break
  730. case 'yellowThresholdDesc':
  731. // 黄
  732. this.editField = 'yellowThreshold'
  733. break
  734. case 'greenThresholdDesc':
  735. // 绿
  736. this.editField = 'greenThreshold'
  737. break
  738. default:
  739. break
  740. }
  741. const fieldForm = this.editField + 'Value'
  742. this.editFormVal = this.$refs.monitorForm.value[this.editIndex][fieldForm]
  743. // 阈值配置器
  744. this.thresholdVisible = true
  745. },
  746. handleOk() {
  747. // 阈值赋值
  748. const configVal = this.$refs.thresholdConfig.getConfigVal() // 阈值配置器返回值
  749. const fieldForm = this.editField + 'Value'
  750. this.$refs.monitorForm.value[this.editIndex][fieldForm] = configVal.dynamicItem // 阈值表单数据
  751. this.$refs.monitorForm.value[this.editIndex][this.editFieldDesc] = configVal.strconfig // 阈值描述-显示用
  752. this.$refs.monitorForm.value[this.editIndex][this.editField] = configVal.calconfig.replace(
  753. /DEPTCODE/g,
  754. this.$refs.monitorForm.value[this.editIndex].monitorDeptCode
  755. ) // 阈值公式
  756. this.thresholdVisible = false
  757. },
  758. handleCancel() {
  759. this.thresholdVisible = false
  760. },
  761. onSelectChange(keys) {
  762. // 所选子表行
  763. this.selectedRowKeys = keys
  764. },
  765. selectSubmiter() {
  766. // 设置报送人
  767. pickValues(
  768. sdUserPicker, // 第一个参数:使用的选择器组件
  769. // 第二个参数:传递给选择器的props。默认选中的值、是否单选等,都可以传递
  770. {
  771. single: true, // 单选
  772. }
  773. )
  774. // 用户选择完成后,promise返回选中的值。用户取消返回undefined
  775. .then((values) => {
  776. // 子表行报送人员赋值 code name
  777. if (values && values[0]) {
  778. // 获取报送人部门信息
  779. KpiService.getSubmitterInfo('', values[0].code)
  780. .then((res) => {
  781. if (res) {
  782. // 子表赋值
  783. this.selectedRowKeys?.forEach((item) => {
  784. this.$refs.monitorForm.value[item].submitters = JSON.stringify(values) // 报送人
  785. this.$refs.monitorForm.value[item].submitterId = res.submitterId // 报送人id
  786. this.$refs.monitorForm.value[item].submitterAccount = res.submitterAccount // 报送人account
  787. this.$refs.monitorForm.value[item].submitterName = res.submitterName // 报送人名称
  788. this.$refs.monitorForm.value[item].submitterDeptId = res.submitterDeptId // 报送人部门id
  789. this.$refs.monitorForm.value[item].submitterDeptCode = res.submitterDeptCode // 报送人部门code
  790. this.$refs.monitorForm.value[item].submitterDeptName = res.submitterDeptName // 报送人部门名称
  791. })
  792. // 更新子表数据
  793. this.$refs.kpiIndiForm.setFieldValue(
  794. 'kpiIndiOrgEntities',
  795. this.$refs.monitorForm.value
  796. )
  797. // 刷新子表值
  798. this.$refs.monitorForm.fnupdate(this.$refs.monitorForm.value)
  799. }
  800. })
  801. .catch((err) => {
  802. // eslint-disable-next-line no-console
  803. console.log(err)
  804. message.error('出错了,请联系管理员')
  805. })
  806. }
  807. })
  808. .catch((err) => {
  809. // eslint-disable-next-line no-console
  810. console.log(err)
  811. message.error('出错了,请联系管理员')
  812. })
  813. },
  814. syncIndiVal() {
  815. // 同步指标设定值
  816. const datasource = []
  817. const mform = this.$refs.monitorForm.value // 子表值
  818. // 生成阈值选择器数据源--《监测单位列表》中‘指标阈值(红)、指标阈值(黄)、指标阈值(绿)’都不为空的‘监测单位’
  819. mform?.forEach((item) => {
  820. // 筛选‘指标阈值(红)、指标阈值(黄)、指标阈值(绿)’都不为空的‘监测单位’
  821. if (item.redThreshold && item.yellowThreshold && item.greenThreshold) {
  822. datasource.push({
  823. id: item.monitorDeptId, // 监测部门ID
  824. name: item.monitorDeptName, // 监测部门
  825. monitorDeptCode: item.monitorDeptCode,
  826. redThreshold: item.redThreshold,
  827. redThresholdDesc: item.redThresholdDesc,
  828. yellowThreshold: item.yellowThreshold,
  829. yellowThresholdDesc: item.yellowThresholdDesc,
  830. greenThreshold: item.greenThreshold,
  831. greenThresholdDesc: item.greenThresholdDesc,
  832. excellentVal: item.excellentVal,
  833. fineVal: item.fineVal,
  834. avgVal: item.avgVal,
  835. lowVal: item.lowVal,
  836. badVal: item.badVal,
  837. })
  838. }
  839. })
  840. // 选择弹框
  841. pickValues(
  842. sdTreePicker, // 第一个参数:使用的选择器组件
  843. // 第二个参数:传递给选择器的props。默认选中的值、是否单选等,都可以传递
  844. {
  845. loadTreeData: () => {
  846. return datasource
  847. },
  848. single: true,
  849. }
  850. )
  851. // 用户选择完成后,promise返回选中的值。用户取消返回undefined
  852. .then((values) => {
  853. // 赋值所选子表行指标阈值及参考值的配置内容
  854. if (values && values[0]) {
  855. // 子表赋值
  856. this.selectedRowKeys?.forEach((item) => {
  857. this.$refs.monitorForm.value[item].redThreshold = values[0].redThreshold
  858. this.$refs.monitorForm.value[item].redThresholdDesc = values[0].redThresholdDesc
  859. this.$refs.monitorForm.value[item].yellowThreshold = values[0].yellowThreshold
  860. this.$refs.monitorForm.value[item].yellowThresholdDesc = values[0].yellowThresholdDesc
  861. this.$refs.monitorForm.value[item].greenThreshold = values[0].greenThreshold
  862. this.$refs.monitorForm.value[item].greenThresholdDesc = values[0].greenThresholdDesc
  863. this.$refs.monitorForm.value[item].excellentVal = values[0].excellentVal
  864. this.$refs.monitorForm.value[item].fineVal = values[0].fineVal
  865. this.$refs.monitorForm.value[item].avgVal = values[0].avgVal
  866. this.$refs.monitorForm.value[item].lowVal = values[0].lowVal
  867. this.$refs.monitorForm.value[item].badVal = values[0].badVal
  868. })
  869. // 刷新子表值
  870. this.$refs.monitorForm.fnupdate(this.$refs.monitorForm.value)
  871. }
  872. })
  873. .catch((err) => {
  874. // eslint-disable-next-line no-console
  875. console.log(err)
  876. message.error('出错了,请联系管理员')
  877. })
  878. },
  879. selectDept() {
  880. // 选择监测单位
  881. pickValues(
  882. sdTreePicker, // 第一个参数:使用的选择器组件
  883. // 第二个参数:传递给选择器的props。默认选中的值、是否单选等,都可以传递
  884. {
  885. loadTreeData: (id) => {
  886. return this.loadTreeData(id)
  887. },
  888. }
  889. )
  890. // 用户选择完成后,promise返回选中的值。用户取消返回undefined
  891. .then((values) => {
  892. // 新增子表行
  893. if (values && values[0]) {
  894. // 监测单位唯一性判断
  895. const monitor = this.$refs.monitorForm.value
  896. const flag = values.filter((vitem) => {
  897. return monitor?.find((ditem) => {
  898. return vitem.code === ditem.monitorDeptCode
  899. })
  900. })
  901. if (flag && flag[0]) {
  902. message.warning('监测单位重复,请重新选择。')
  903. return false
  904. }
  905. // 判断是否本单位
  906. const deptId = this.$refs.kpiIndiForm.getFieldValue('createDeptId') // 创建部门ID
  907. const monitorDeptIds = [] // 监测单位IDS
  908. values?.forEach((item) => {
  909. monitorDeptIds.push(item.id)
  910. })
  911. KpiService.sameCompany(deptId, monitorDeptIds)
  912. .then((res) => {
  913. // 增加子表行
  914. values?.forEach((item) => {
  915. this.$refs.monitorForm.value.push({
  916. monitorDeptId: item.id, // 监测单位ID
  917. monitorDeptCode: item.code, // 监测单位code
  918. monitorDeptName: item.name, // 监测单位name
  919. izSelf: res[item.id] + '', // 是否本单位
  920. submitters: '[]',
  921. submitterId: '',
  922. submitterAccount: '',
  923. submitterName: '',
  924. submitterDeptId: '',
  925. submitterDeptCode: '',
  926. submitterDeptName: '',
  927. redThreshold: '',
  928. redThresholdValue: '',
  929. redThresholdDesc: '',
  930. yellowThreshold: '',
  931. yellowThresholdValue: '',
  932. yellowThresholdDesc: '',
  933. greenThreshold: '',
  934. greenThresholdValue: '',
  935. greenThresholdDesc: '',
  936. })
  937. })
  938. })
  939. .catch((err) => {
  940. // eslint-disable-next-line no-console
  941. console.log(err)
  942. message.error('出错了,请联系管理员')
  943. })
  944. }
  945. })
  946. .catch((err) => {
  947. // eslint-disable-next-line no-console
  948. console.log(err)
  949. message.error('出错了,请联系管理员')
  950. })
  951. },
  952. loadTreeData(id) {
  953. // 监测单位组织机构
  954. if (!id) {
  955. const expandedKey = this.defaultExpandedKeys
  956. if (Array.isArray(this.rootNode)) {
  957. return Promise.all(
  958. this.rootNode.map((rootNode) => {
  959. return KpiService.getGroupTree({
  960. expandedKey,
  961. rootNode,
  962. hierarchical: this.hierarchical,
  963. levPath: true,
  964. })
  965. })
  966. ).then((nodes) => {
  967. return nodes.map((node) => node[0])
  968. })
  969. } else {
  970. return KpiService.getGroupTree({
  971. expandedKey,
  972. rootNode: this.rootNode,
  973. hierarchical: this.hierarchical,
  974. levPath: true,
  975. })
  976. }
  977. } else {
  978. return KpiService.getChildNodes(id, {
  979. type: 'G',
  980. isContainSub: false,
  981. hierarchical: this.hierarchical,
  982. levPath: true,
  983. }).then((res) => {
  984. return res.map((item) => {
  985. item.checkable = true
  986. return item
  987. })
  988. })
  989. }
  990. },
  991. busiChange(val) {
  992. // 业务分类id,name赋值
  993. if (val && val[0]) {
  994. this.$refs.kpiIndiForm.setFieldValue('busiClassId', val[0].id)
  995. this.$refs.kpiIndiForm.setFieldValue('busiClassName', val[0].name)
  996. }
  997. },
  998. changeSubmitters(val, index) {
  999. // 报送人信息赋值
  1000. if (val && val[0]) {
  1001. // 获取报送人部门信息
  1002. KpiService.getSubmitterInfo('', val[0].code)
  1003. .then((res) => {
  1004. if (res) {
  1005. // 子表赋值
  1006. this.$refs.monitorForm.value[index].submitters = JSON.stringify(val)
  1007. this.$refs.monitorForm.value[index].submitterId = res.submitterId // 报送人id
  1008. this.$refs.monitorForm.value[index].submitterAccount = res.submitterAccount // 报送人account
  1009. this.$refs.monitorForm.value[index].submitterName = res.submitterName // 报送人名称
  1010. this.$refs.monitorForm.value[index].submitterDeptId = res.submitterDeptId // 报送人部门id
  1011. this.$refs.monitorForm.value[index].submitterDeptCode = res.submitterDeptCode // 报送人部门code
  1012. this.$refs.monitorForm.value[index].submitterDeptName = res.submitterDeptName // 报送人部门名称
  1013. // 更新子表数据
  1014. this.$refs.kpiIndiForm.setFieldValue(
  1015. 'kpiIndiOrgEntities',
  1016. this.$refs.monitorForm.value
  1017. )
  1018. }
  1019. })
  1020. .catch((err) => {
  1021. // eslint-disable-next-line no-console
  1022. console.log(err)
  1023. message.error('出错了,请联系管理员')
  1024. })
  1025. } else {
  1026. // 清空报送人信息
  1027. this.$refs.monitorForm.value[index].submitters = '[]'
  1028. this.$refs.monitorForm.value[index].submitterId = '' // 报送人id
  1029. this.$refs.monitorForm.value[index].submitterAccount = '' // 报送人account
  1030. this.$refs.monitorForm.value[index].submitterName = '' // 报送人名称
  1031. this.$refs.monitorForm.value[index].submitterDeptId = '' // 报送人部门id
  1032. this.$refs.monitorForm.value[index].submitterDeptCode = '' // 报送人部门code
  1033. this.$refs.monitorForm.value[index].submitterDeptName = '' // 报送人部门名称
  1034. // 更新子表数据
  1035. this.$refs.kpiIndiForm.setFieldValue('kpiIndiOrgEntities', this.$refs.monitorForm.value)
  1036. }
  1037. },
  1038. },
  1039. }
  1040. </script>
  1041. <style module lang="scss">
  1042. @use '@/common/design' as *;
  1043. @import '@/webflow/sd-flow-form.scss';
  1044. .form {
  1045. :global(td.ant-form-item-label > label) {
  1046. white-space: normal !important;
  1047. }
  1048. .connect-btn {
  1049. float: right;
  1050. font-weight: 400;
  1051. font-size: 16px;
  1052. top: 8px;
  1053. cursor: pointer;
  1054. margin-right: 10px;
  1055. }
  1056. .first-td {
  1057. border: none !important;
  1058. padding: 0;
  1059. }
  1060. .btnselect {
  1061. position: relative;
  1062. top: 4px;
  1063. right: 100px;
  1064. float: right;
  1065. .batchselect {
  1066. z-index: 100;
  1067. margin-left: 10px;
  1068. }
  1069. }
  1070. }
  1071. .read-only-form {
  1072. :global(.ant-form-item-required):before {
  1073. display: none;
  1074. }
  1075. }
  1076. </style>