index.vue 23 KB

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