index.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <template>
  2. <div class='point-box'>
  3. <div class='left'>
  4. <ul>
  5. <li>
  6. <span>原始点位信息</span>&nbsp;&nbsp;&nbsp;
  7. <span>{{editData.Point.Description || '--'}}</span>
  8. </li>
  9. <li>
  10. <span>位置标签</span>&nbsp;&nbsp;&nbsp;
  11. <span>{{editData.Point.LocationFlag.toString() || '--'}}</span>
  12. </li>
  13. <li>
  14. <span>设备类型</span>&nbsp;&nbsp;&nbsp;
  15. <span>{{editData.Point.KeyEquipmentType || '--'}}</span>
  16. </li>
  17. <li>
  18. <span>设备参数</span>&nbsp;&nbsp;&nbsp;
  19. <span>{{editData.Point.KeyEquipmentParameter || '--'}}</span>
  20. </li>
  21. <li>
  22. <span>值/单位说明</span>&nbsp;&nbsp;&nbsp;
  23. <span>{{editData.Point.ValueDescription || '--'}}</span>
  24. </li>
  25. <li>
  26. <span>备注</span>&nbsp;&nbsp;&nbsp;
  27. <span>{{editData.Point.Remarks || '--'}}</span>
  28. </li>
  29. </ul>
  30. </div>
  31. <div class='right'>
  32. <el-form class='form' :rules='rules' ref='form' :model='form' label-width='140px'>
  33. <el-form-item
  34. label='对应数据字典'
  35. prop='dict'
  36. :rules='[{ required: true, message: "请输入对应数据字典", trigger: "change" },{ validator: validateDict, trigger: ["blur", "change"] }]'
  37. >
  38. <el-cascader
  39. style='width: 100%;'
  40. :options='options'
  41. v-model='form.dict'
  42. @change='handleChange'
  43. :props='props'
  44. filterable
  45. @active-item-change='handleItemChange'
  46. ></el-cascader>
  47. <div class='dict'>
  48. <!-- <p class='top'>
  49. <i class='el-icon-plus'></i>
  50. <el-button type='text'>添加自定义信息点</el-button>
  51. </p>-->
  52. <p class='btm'>
  53. <el-input
  54. readonly
  55. type='textarea'
  56. :rows='2'
  57. placeholder='信息点的单位及值的说明'
  58. v-model='ValueDescription'
  59. ></el-input>
  60. </p>
  61. </div>
  62. </el-form-item>
  63. <el-form-item label='值处理方式' prop='DataRuleType'>
  64. <el-select v-model='form.DataRuleType' placeholder='请选择'>
  65. <el-option
  66. v-for='item in handleTypeArr'
  67. :key='item.value'
  68. :label='item.label'
  69. :value='item.value'
  70. ></el-option>
  71. </el-select>
  72. </el-form-item>
  73. <!-- components -->
  74. <no-handle ref='noHandle' v-if='form.DataRuleType == "无需处理,直接使用"' :noHandleShow='noHandleShow'></no-handle>
  75. <auto-handle
  76. ref='autoHandle'
  77. v-else-if='form.DataRuleType == "需自动单位转换"'
  78. :unitObj='unitObj'
  79. :autoHandleShow='autoHandleShow'
  80. ></auto-handle>
  81. <enum-handle
  82. ref='enumHandle'
  83. v-else-if='form.DataRuleType == "需按设置枚举转换"'
  84. :enumHandleShow='enumHandleShow'
  85. ></enum-handle>
  86. <formula-handle
  87. ref='formulaHandle'
  88. v-else-if='form.DataRuleType == "需按公式转换"'
  89. :formulaHandleShow='formulaHandleShow'
  90. ></formula-handle>
  91. <split-handle
  92. ref='splitHandle'
  93. v-else-if='form.DataRuleType == "需拆分处理"'
  94. :splitHandleShow='splitHandleShow'
  95. ></split-handle>
  96. </el-form>
  97. <div class='btn-box'>
  98. <el-button type='primary' @click='save'>保存</el-button>
  99. </div>
  100. </div>
  101. </div>
  102. </template>
  103. <script>
  104. //components
  105. import noHandle from './no_handle'
  106. import autoHandle from './auto_handle'
  107. import enumHandle from './enum_handle'
  108. import formulaHandle from './formula_handle'
  109. import splitHandle from './split_handle'
  110. import { mapGetters, mapActions } from 'vuex'
  111. //api
  112. import { getEquipmentAll, getQueryProperty } from '@/fetch/data_plat'
  113. import { updatePoint, batchCreate } from '@/fetch/point_http'
  114. export default {
  115. name: 'point_config_step3_edit',
  116. computed: {
  117. ...mapGetters('project', ['projectId', 'datasourceId', 'protocolType'])
  118. },
  119. data() {
  120. return {
  121. options: [],
  122. optionObj: {},
  123. infoDict: {}, //信息点字典
  124. dataDict: {}, //数据字典
  125. InfomationPoint: null, //信息点
  126. unitObj: {}, //传给自动单位转换的obj
  127. props: {
  128. value: 'code',
  129. label: 'name',
  130. children: 'content'
  131. },
  132. ValueDescription: '', //值/点位描述
  133. form: {
  134. dict: [],
  135. DataRuleType: '无需处理,直接使用'
  136. },
  137. rules: {
  138. DataRuleType: [{ required: true, message: '请选择值处理方式', trigger: 'change' }]
  139. },
  140. handleTypeArr: [
  141. {
  142. label: '无需处理,直接使用',
  143. value: '无需处理,直接使用'
  144. },
  145. {
  146. label: '需自动单位转换',
  147. value: '需自动单位转换'
  148. },
  149. {
  150. label: '需按设置枚举转换',
  151. value: '需按设置枚举转换'
  152. },
  153. {
  154. label: '需按公式转换',
  155. value: '需按公式转换'
  156. },
  157. {
  158. label: '需拆分处理',
  159. value: '需拆分处理'
  160. }
  161. ],
  162. /**值回显******* */
  163. noHandleShow: {},
  164. autoHandleShow: {},
  165. enumHandleShow: {},
  166. formulaHandleShow: {},
  167. splitHandleShow: {}
  168. }
  169. },
  170. props: {
  171. editData: {
  172. type: Object,
  173. default: {}
  174. }
  175. },
  176. components: {
  177. noHandle,
  178. autoHandle,
  179. enumHandle,
  180. formulaHandle,
  181. splitHandle
  182. },
  183. methods: {
  184. validateDict(rule, value, cb) {
  185. if (value.length < 4) {
  186. cb(new Error('请选到第四级(可能本设备没有信息点)'))
  187. } else {
  188. cb()
  189. }
  190. },
  191. //保存
  192. save() {
  193. this.$refs['form'].validate(valid => {
  194. if (valid) {
  195. var flag = this.form.DataRuleType
  196. switch (flag) {
  197. case '无需处理,直接使用':
  198. this.$refs['noHandle'].getForm(noHandle => {
  199. if (noHandle) {
  200. this.saveForm(this.form, noHandle)
  201. } else {
  202. this.errMsg()
  203. }
  204. })
  205. break
  206. case '需自动单位转换':
  207. this.$refs['autoHandle'].getForm(autoHandle => {
  208. if (autoHandle) {
  209. this.saveForm(this.form, autoHandle)
  210. } else {
  211. this.errMsg()
  212. }
  213. })
  214. break
  215. case '需按设置枚举转换':
  216. this.$refs['enumHandle'].getForm(enumHandle => {
  217. if (enumHandle) {
  218. this.saveForm(this.form, enumHandle)
  219. } else {
  220. this.errMsg()
  221. }
  222. })
  223. break
  224. case '需按公式转换':
  225. this.$refs['formulaHandle'].getForm(formulaHandle => {
  226. if (formulaHandle) {
  227. this.saveForm(this.form, formulaHandle)
  228. } else {
  229. this.errMsg()
  230. }
  231. })
  232. break
  233. case '需拆分处理':
  234. this.$refs['splitHandle'].getForm(splitHandle => {
  235. if (splitHandle) {
  236. this.saveForm(this.form, splitHandle)
  237. } else {
  238. this.errMsg()
  239. }
  240. })
  241. break
  242. }
  243. } else {
  244. this.errMsg()
  245. return false
  246. }
  247. })
  248. },
  249. saveForm(basic, other) {
  250. let type = basic.DataRuleType
  251. let basicParams = {
  252. SpecialtyCode: basic.dict[0],
  253. SystemCode: basic.dict[1], //code
  254. EquipmentTypeCode: basic.dict[2],
  255. InfomationPointCode: basic.dict[3],
  256. Specialty: this.dataDict[basic.dict[0]].name, //专业
  257. System: this.dataDict[basic.dict[1]].name, //系统
  258. EquipmentType: this.dataDict[basic.dict[2]].name, //设备
  259. InfomationPoint: this.InfomationPoint, //信息点
  260. DataRuleType: basic.DataRuleType, //值处理方式
  261. DataSourceId: this.datasourceId,
  262. PointId: this.editData.Point.Id //点位ID
  263. }
  264. let updateParams = {
  265. data: {
  266. Content:[{ Id: this.editData.Point.Id }]
  267. },
  268. type: this.protocolType
  269. }
  270. let otherParams = {}
  271. switch (type) {
  272. case '无需处理,直接使用':
  273. otherParams = {
  274. EquipmentMark: other.EquipmentMark
  275. }
  276. updateParams.data.Content[0].EquipmentMark = other.EquipmentMark
  277. break
  278. case '需自动单位转换':
  279. let DataRuleContent1 = JSON.stringify([
  280. {
  281. seq: 1,
  282. ruletype: 'type1',
  283. content: [
  284. {
  285. from: other.unit[0] + '-' + other.unit[1],
  286. to: this.unitObj.unit
  287. }
  288. ]
  289. }
  290. ])
  291. otherParams = {
  292. DataRuleContent: DataRuleContent1,
  293. EquipmentMark: other.EquipmentMark
  294. }
  295. updateParams.data.Content[0].EquipmentMark = other.EquipmentMark
  296. break
  297. case '需按设置枚举转换':
  298. let DataRuleContent2 = other.pointArr.length
  299. ? JSON.stringify([{ seq: 1, ruletype: 'type2', content: other.pointArr }])
  300. : undefined
  301. otherParams = {
  302. EquipmentMark: other.EquipmentMark,
  303. DataRuleContent: DataRuleContent2
  304. }
  305. updateParams.data.Content[0].EquipmentMark = other.EquipmentMark
  306. break
  307. case '需按公式转换':
  308. let subRule = other.from
  309. ? {
  310. seq: 1,
  311. ruletype: 'type4',
  312. content: [
  313. {
  314. from: other.from,
  315. to: other.to
  316. }
  317. ]
  318. }
  319. : undefined
  320. let extractRule = {
  321. seq: 2,
  322. ruletype: 'type5',
  323. content: other.extract
  324. ? [
  325. {
  326. extract: 'number'
  327. }
  328. ]
  329. : []
  330. }
  331. let countRule = other.mark
  332. ? {
  333. seq: 3,
  334. ruletype: 'type6',
  335. content: [
  336. {
  337. calculationtype: other.mark,
  338. value: other.markValue
  339. }
  340. ]
  341. }
  342. : undefined
  343. let DataRuleContent3 = []
  344. if (subRule) {
  345. DataRuleContent3.push(subRule)
  346. }
  347. DataRuleContent3.push(extractRule)
  348. if (countRule) {
  349. DataRuleContent3.push(countRule)
  350. }
  351. DataRuleContent3 = DataRuleContent3.length ? JSON.stringify(DataRuleContent3) : undefined
  352. otherParams = {
  353. EquipmentMark: other.EquipmentMark,
  354. DataRuleContent: DataRuleContent3
  355. }
  356. updateParams.data.Content[0].EquipmentMark = other.EquipmentMark
  357. break
  358. case '需拆分处理':
  359. let SplitPoints = other.devArr.length ? other.devArr : undefined
  360. let DataRuleContent4 = undefined
  361. var enum5 = null
  362. if (other.tranfVal) {
  363. enum5 = { seq: 2, ruletype: 'type2', content: other.pointArr }
  364. } else {
  365. enum5 = { seq: 2, ruletype: 'type2', content: [] }
  366. }
  367. SplitPoints.forEach(ele => {
  368. let cutStr = {
  369. seq: 1,
  370. ruletype: 'type4',
  371. content: [
  372. {
  373. from: ele.SplitStart,
  374. to: ele.SplitEnd
  375. }
  376. ]
  377. }
  378. ele.DataRuleContent = JSON.stringify([cutStr, enum5])
  379. })
  380. otherParams = {
  381. SplitPoints: SplitPoints
  382. }
  383. updateParams.data.Content[0].EquipmentMark = other.eqMark
  384. break
  385. }
  386. let params = [Object.assign(basicParams, otherParams)]
  387. updatePoint(updateParams, res => { this.create(params) })
  388. },
  389. create(params) {
  390. batchCreate(params, res => {
  391. if (res.Result == 'success') {
  392. this.$message({
  393. message: '保存成功',
  394. type: 'success'
  395. })
  396. this.$emit('refresh')
  397. }
  398. })
  399. },
  400. errMsg() {
  401. this.$message({
  402. message: '有必填项未填',
  403. type: 'warning'
  404. })
  405. },
  406. handleChange(arr) {
  407. this.unitObj = this.infoDict[arr[3]]
  408. this.InfomationPoint = this.unitObj ? this.unitObj.infoPointName || '--' : '--'
  409. },
  410. handleItemChange(val, cb) {
  411. if (val.length == 3) {
  412. let params = { type: val[2] }
  413. getQueryProperty(params, res => {
  414. if (res.Result == 'success') {
  415. let data = res.Content
  416. let arr = data
  417. .filter(item => {
  418. return item.inputMode == 'L'
  419. })
  420. .map(item => {
  421. return {
  422. code: item.infoPointCode,
  423. name: item.infoPointName
  424. }
  425. })
  426. this.infoDict = {}
  427. data.forEach(item => {
  428. this.infoDict[item.infoPointCode] = item
  429. })
  430. this.optionObj = {}
  431. this.getOptionItem(this.options, val[2])
  432. if (arr.length) {
  433. this.optionObj.content = arr
  434. } else {
  435. this.optionObj.content = undefined
  436. }
  437. if (typeof cb == 'function') {
  438. cb()
  439. }
  440. }
  441. })
  442. }
  443. },
  444. getOptionItem(arr, code) {
  445. for (var i = 0; i < arr.length; i++) {
  446. if (arr[i].code == code) {
  447. this.optionObj = arr[i]
  448. }
  449. if (arr[i].content && arr[i].content.length > 0) {
  450. this.getOptionItem(arr[i].content, code)
  451. }
  452. }
  453. },
  454. //缓存数据字典
  455. getDataDict(arr) {
  456. for (var i = 0; i < arr.length; i++) {
  457. this.dataDict[arr[i].code] = arr[i]
  458. if (arr[i].content && arr[i].content.length > 0) {
  459. this.getDataDict(arr[i].content)
  460. } else {
  461. this.$set(arr[i], 'content', [])
  462. }
  463. }
  464. },
  465. getEqAll() {
  466. let params = { format: true }
  467. getEquipmentAll(params, res => {
  468. if (res.Result == 'success') {
  469. this.options = res.Content
  470. this.getDataDict(this.options)
  471. }
  472. })
  473. },
  474. init() {
  475. //获取所有的设备
  476. this.getEqAll()
  477. },
  478. //回显数值
  479. async showValue(val) {
  480. await this.getEqAll()
  481. let length = val.RelationList.length
  482. let eqMark = this.editData.Point.EquipmentMark
  483. if (length) {
  484. var data = val.RelationList[0]
  485. let dict = [data.SpecialtyCode, data.SystemCode, data.EquipmentTypeCode]
  486. this.handleItemChange(dict, () => {
  487. this.form = {
  488. dict: [...dict, data.InfomationPointCode],
  489. DataRuleType: data.DataRuleType
  490. }
  491. this.unitObj = this.infoDict[data.InfomationPointCode]
  492. this.InfomationPoint = this.unitObj.infoPointName || '--'
  493. if (typeof this.unitObj.dataSource == 'string') {
  494. if (this.unitObj.dataSource.length) {
  495. this.ValueDescription = this.unitObj.dataSource
  496. } else {
  497. this.ValueDescription = '无信息点单位及值说明'
  498. }
  499. } else {
  500. let str = ''
  501. this.unitObj.dataSource.forEach(ele => {
  502. str = ele.code + '、' + ele.name + ' '
  503. })
  504. this.ValueDescription = str
  505. }
  506. })
  507. if (length == 1) {
  508. let flag = data.DataRuleType
  509. var dataRules = null
  510. switch (flag) {
  511. case '无需处理,直接使用':
  512. this.noHandleShow = {
  513. EquipmentMark: eqMark
  514. }
  515. break
  516. case '需自动单位转换':
  517. dataRules = JSON.parse(data.DataRuleContent)
  518. let auto = dataRules[0].content[0].from.split('-')
  519. this.autoHandleShow = {
  520. EquipmentMark: eqMark,
  521. unit: auto
  522. }
  523. break
  524. case '需按设置枚举转换':
  525. dataRules = JSON.parse(data.DataRuleContent)
  526. let pointArr = dataRules[0].content
  527. this.enumHandleShow = {
  528. EquipmentMark: eqMark,
  529. pointArr: pointArr
  530. }
  531. break
  532. case '需按公式转换':
  533. var cut = null
  534. var count = null
  535. var extractArr = []
  536. if (data.DataRuleContent) {
  537. dataRules = JSON.parse(data.DataRuleContent)
  538. cut = dataRules[0].content[0]
  539. extractArr = dataRules[1].content
  540. count = dataRules[2].content[0]
  541. }
  542. this.formulaHandleShow = {
  543. EquipmentMark: eqMark,
  544. cut: cut,
  545. count: count,
  546. extractArr: extractArr
  547. }
  548. break
  549. case '需拆分处理':
  550. let dataRules = JSON.parse(data.DataRuleContent)
  551. let devArr = val.RelationList.map(ele => {
  552. let arr = JSON.parse(ele.DataRuleContent)
  553. return {
  554. EquipmentMark: ele.EquipmentMark,
  555. SplitStart: arr[0].content[0].from,
  556. SplitEnd: arr[0].content[0].to
  557. }
  558. })
  559. var pointArr = dataRules[1].content
  560. this.splitHandleShow = {
  561. eqMark: eqMark,
  562. EquipmentMark: data.EquipmentMark,
  563. pointArr: pointArr,
  564. devArr: devArr
  565. }
  566. break
  567. }
  568. } else {
  569. let dataRules = JSON.parse(data.DataRuleContent)
  570. let devArr = val.RelationList.map(ele => {
  571. let arr = JSON.parse(ele.DataRuleContent)
  572. return {
  573. EquipmentMark: ele.EquipmentMark,
  574. SplitStart: arr[0].content[0].from,
  575. SplitEnd: arr[0].content[0].to
  576. }
  577. })
  578. let pointArr = dataRules[1].content
  579. this.splitHandleShow = {
  580. eqMark: eqMark,
  581. EquipmentMark: data.EquipmentMark,
  582. pointArr: pointArr,
  583. devArr: devArr
  584. }
  585. }
  586. } else {
  587. this.noHandleShow = {
  588. EquipmentMark: eqMark
  589. }
  590. }
  591. this.noHandleShow.EquipmentMark = eqMark
  592. this.autoHandleShow.EquipmentMark = eqMark
  593. this.enumHandleShow.EquipmentMark = eqMark
  594. this.enumHandleShow.pointArr = this.enumHandleShow.pointArr?this.enumHandleShow.pointArr:[{from: '',to: ''}]
  595. this.formulaHandleShow.EquipmentMark = eqMark
  596. this.splitHandleShow.eqMark = eqMark
  597. this.splitHandleShow.devArr = this.splitHandleShow.devArr?this.splitHandleShow.devArr:[{EquipmentMark: '',SplitStart: 1,SplitEnd: 1}]
  598. this.splitHandleShow.pointArr = this.splitHandleShow.pointArr?this.splitHandleShow.pointArr:[{from: '',to: ''}]
  599. }
  600. },
  601. mounted() {
  602. this.init()
  603. },
  604. watch: {
  605. editData: {
  606. immediate: true,
  607. handler(val) {
  608. this.showValue(val)
  609. }
  610. }
  611. }
  612. }
  613. </script>
  614. <style lang='scss' scoped>
  615. .point-box {
  616. border: 1px solid #ccc;
  617. display: flex;
  618. padding: 20px 0;
  619. max-height: 500px;
  620. overflow: auto;
  621. .left {
  622. width: 40%;
  623. ul li {
  624. display: flex;
  625. height: 40px;
  626. line-height: 40px;
  627. span:nth-of-type(1) {
  628. text-align: right;
  629. width: 120px;
  630. }
  631. }
  632. }
  633. .right {
  634. width: 60%;
  635. text-align: left;
  636. background: #fff;
  637. .form {
  638. width: 80%;
  639. .dict {
  640. .top {
  641. text-align: right;
  642. line-height: 33px;
  643. }
  644. .btm {
  645. margin-top: 5px;
  646. }
  647. }
  648. }
  649. .btn-box {
  650. width: 80%;
  651. margin-top: 20px;
  652. text-align: center;
  653. }
  654. }
  655. }
  656. </style>