index.vue 23 KB

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