index.vue 23 KB

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