index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <div class='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. type='textarea'
  55. :rows='2'
  56. placeholder='信息点的单位及值的说明'
  57. v-model='form.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. form: {
  124. dict: [],
  125. ValueDescription: '',
  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. ValueDescription: basic.ValueDescription //信息点单位和值说明
  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. ValueDescription: data.ValueDescription || '',
  468. DataRuleType: data.DataRuleType
  469. }
  470. this.unitObj = this.infoDict[data.InfomationPointCode]
  471. this.InfomationPoint = this.unitObj.infoPointName || '--'
  472. })
  473. if (length == 1) {
  474. let flag = data.DataRuleType
  475. var dataRules = null
  476. switch (flag) {
  477. case '无需处理,直接使用':
  478. this.noHandleShow = {
  479. EquipmentMark: data.EquipmentMark
  480. }
  481. break
  482. case '需自动单位转换':
  483. dataRules = JSON.parse(data.DataRuleContent)
  484. let auto = dataRules[0].content[0].from.split('-')
  485. this.autoHandleShow = {
  486. EquipmentMark: data.EquipmentMark,
  487. unit: auto
  488. }
  489. break
  490. case '需按设置枚举转换':
  491. dataRules = JSON.parse(data.DataRuleContent)
  492. let pointArr = dataRules[0].content
  493. this.enumHandleShow = {
  494. EquipmentMark: data.EquipmentMark,
  495. pointArr: pointArr
  496. }
  497. break
  498. case '需按公式转换':
  499. var cut = null
  500. var count = null
  501. var extractArr = []
  502. if (data.DataRuleContent) {
  503. dataRules = JSON.parse(data.DataRuleContent)
  504. cut = dataRules[0].content[0]
  505. extractArr = dataRules[1].content
  506. count = dataRules[2].content[0]
  507. }
  508. this.formulaHandleShow = {
  509. EquipmentMark: data.EquipmentMark,
  510. cut: cut,
  511. count: count,
  512. extractArr: extractArr
  513. }
  514. break
  515. }
  516. } else {
  517. let dataRules = JSON.parse(data.DataRuleContent)
  518. let devArr = val.RelationList.map(ele => {
  519. let arr = JSON.parse(ele.DataRuleContent)
  520. return {
  521. EquipmentMark: ele.EquipmentMark,
  522. SplitStart:arr[0].content[0].from ,
  523. SplitEnd: arr[0].content[0].to
  524. }
  525. })
  526. let pointArr = dataRules[1].content;
  527. this.splitHandleShow = {
  528. EquipmentMark: data.EquipmentMark,
  529. pointArr: pointArr,
  530. devArr: devArr
  531. }
  532. }
  533. }
  534. }
  535. },
  536. mounted() {
  537. this.init()
  538. },
  539. watch: {
  540. editData: {
  541. immediate: true,
  542. handler(val) {
  543. this.showValue(val)
  544. }
  545. }
  546. }
  547. }
  548. </script>
  549. <style lang='scss' scoped>
  550. .box {
  551. border: 1px solid #ccc;
  552. display: flex;
  553. padding: 20px 0;
  554. .left {
  555. width: 40%;
  556. ul li {
  557. display: flex;
  558. height: 40px;
  559. line-height: 40px;
  560. span:nth-of-type(1) {
  561. text-align: right;
  562. width: 120px;
  563. }
  564. }
  565. }
  566. .right {
  567. width: 60%;
  568. .form {
  569. width: 80%;
  570. .dict {
  571. .top {
  572. text-align: right;
  573. line-height: 33px;
  574. }
  575. .btm {
  576. margin-top: 5px;
  577. }
  578. }
  579. }
  580. .btn-box {
  581. margin-top: 20px;
  582. text-align: center;
  583. }
  584. }
  585. }
  586. </style>