multiAdd.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <vxe-modal
  3. ref="multiAdd"
  4. v-model="show"
  5. :title="'批量添加'"
  6. width="900"
  7. height="auto"
  8. resize
  9. destroy-on-close
  10. @close="cancelButtonClick"
  11. >
  12. <p style="color: red;padding-left:20px">批量生成的点位将按序排在通道末尾的点位后</p>
  13. <vxe-form
  14. ref="form"
  15. :data="formData"
  16. :rules="formRules"
  17. title-align="center"
  18. title-width="100"
  19. >
  20. <vxe-form-item title="数据源" field="dataSource" span="6">
  21. <vxe-select v-model="formData.dataSource" placeholder="数据来源" size="big">
  22. <vxe-option
  23. v-for="item in enums.senderDataSourceEnum"
  24. :key="item.value"
  25. :value="item.value"
  26. :label="item.label"
  27. />
  28. </vxe-select>
  29. </vxe-form-item>
  30. <vxe-form-item title="使用通道" field="tunnelId" span="8">
  31. <vxe-select
  32. v-model="formData.tunnelId"
  33. placeholder="请选择使用通道"
  34. size="medium"
  35. @change="tunnelChange"
  36. >
  37. <vxe-option v-for="item in tunnelList" :key="item.id" :value="item.id" :label="item.tunnelName"/>
  38. </vxe-select>
  39. </vxe-form-item>
  40. <vxe-form-item title="通道数据类型" field="protocolPointType" span="9" title-width="150px">
  41. <vxe-select v-model="formData.protocolPointType" placeholder="请选择通道数据类型" size="medium">
  42. <vxe-option
  43. v-for="item in protocolDataType"
  44. :key="item.value"
  45. :value="item.value"
  46. :label="item.label"
  47. />
  48. </vxe-select>
  49. </vxe-form-item>
  50. <vxe-form-item v-show="formData.dataSource=='GATHER'" title="设备类型" field="eqType" span="6">
  51. <vxe-select v-model="formData.eqType" placeholder="请选择设备类型" size="medium"
  52. @change="flushEqsOfSelectEqType">
  53. <vxe-option
  54. v-for="item in enums.equipmentTypeEnum"
  55. :key="item.value"
  56. :value="item.value"
  57. :label="item.label"
  58. />
  59. </vxe-select>
  60. </vxe-form-item>
  61. <vxe-form-item v-show="formData.dataSource=='GATHER'" title="设备名" field="equipmentId" span="10">
  62. <vxe-select v-model="formData.equipmentId" placeholder="请选择设备名" size="medium"
  63. @change="flushAttrsOfSelectEq">
  64. <vxe-option v-for="(item,index) in eqsOfSelectEqType" :key="index" :value="item.id" :label="item.name"/>
  65. </vxe-select>
  66. </vxe-form-item>
  67. <vxe-form-item v-show="formData.dataSource=='GATHER'" title="设备属性" field="equipmentAttrs" span="14">
  68. <el-select v-model="formData.equipmentAttrs" multiple collapse-tags placeholder="请选择设备属性" size="small">
  69. <el-option
  70. v-for="item in attrsOfSelectEq"
  71. :value="item.id"
  72. :label="item.equipmentAttribute.explanation"
  73. />
  74. </el-select>
  75. </vxe-form-item>
  76. <vxe-form-item
  77. v-show="formData.dataSource=='FORECAST'"
  78. title="预测数据属性"
  79. field="forecastType"
  80. span="10"
  81. title-width="120"
  82. >
  83. <vxe-select v-model="formData.forecastType" placeholder="请选择预测数据属性" @change="forecastDayChange">
  84. <vxe-option v-for="item in enums.forecastType" :key="item.value" :value="item.value" :label="item.label"/>
  85. </vxe-select>
  86. </vxe-form-item>
  87. <vxe-form-item v-show="formData.dataSource=='FORECAST'" title="预测天数" span="10" field="forecastNode">
  88. <el-select
  89. v-model="formData.forecastNode"
  90. multiple
  91. collapse-tags
  92. placeholder="请选择预测天数"
  93. size="small"
  94. @change="forecastNodeChangeEvent"
  95. >
  96. <el-option v-for="item in forecastDay" :key="item.value" :value="item.value" :label="item.label"/>
  97. </el-select>
  98. </vxe-form-item>
  99. <vxe-form-item v-show="formData.dataSource=='FORECAST'" title="预测点位" span="10" field="forecastPointNumber">
  100. <el-select v-model="formData.forecastPointNumber" multiple collapse-tags placeholder="请选择预测点数"
  101. size="small">
  102. <el-option v-for="item in forecastAttributeList" :value="item.pointNumber" :label="item.pointNumber"/>
  103. </el-select>
  104. </vxe-form-item>
  105. <!--占地方用的-->
  106. <div style="height: 300px"/>
  107. <vxe-form-item align="center" span="24">
  108. <vxe-button type="submit" status="primary" :disabled="saveButDisable" @click="submitForm">保存</vxe-button>
  109. <vxe-button @click="cancelButtonClick()">取消</vxe-button>
  110. </vxe-form-item>
  111. </vxe-form>
  112. </vxe-modal>
  113. </template>
  114. <script>
  115. import enumerations from '../../enumeration'
  116. export default {
  117. name: 'MultiAddVue',
  118. props: {
  119. show: {
  120. type: Boolean,
  121. default: false
  122. }
  123. },
  124. data() {
  125. return {
  126. eqsOfSelectEqType: [],
  127. attrsOfSelectEq: [],
  128. forecastDay: [],
  129. forecastAttributeList: [],
  130. saveButDisable: false,
  131. formData: {
  132. eqType: '',
  133. dataSource: 'GATHER',
  134. tunnelId: '',
  135. protocolPointType: '',
  136. equipmentId: '',
  137. forecastType: '',
  138. forecastNode: [],
  139. forecastPointNumber: [],
  140. equipmentAttrs: []
  141. },
  142. tunnelList: [],
  143. formRules: {
  144. dataSource: [{required: true, message: '请选择数据源'}],
  145. tunnelId: [{required: true, message: '请选择通道'}],
  146. protocolPointType: [{required: true, message: '请选择数据类型'}]
  147. },
  148. enums: enumerations,
  149. protocolDataType: enumerations.ProtocolDataType
  150. }
  151. },
  152. mounted() {
  153. this.buildTunnelSelectData()
  154. },
  155. methods: {
  156. /**
  157. * 点击取消或关闭按钮时通知父组件修改值
  158. */
  159. cancelButtonClick() {
  160. this.saveButDisable = false
  161. this.resetForm()
  162. this.$emit('close')
  163. },
  164. /**
  165. * 当所选设备类型发生改变时 刷新设备属性下拉框对应的设备名下拉
  166. */
  167. flushEqsOfSelectEqType() {
  168. this.attrsOfSelectEq = []
  169. this.formData.equipmentAttrs = []
  170. this.formData.equipmentId = null
  171. this.resultHandler(this.getEqsByEqTypeCode(this.formData.eqType)).then(res => {
  172. if (res != null) {
  173. this.eqsOfSelectEqType = res
  174. }
  175. })
  176. },
  177. /**
  178. * 提交表单
  179. */
  180. submitForm() {
  181. const _this = this
  182. _this.saveButDisable = true
  183. this.$refs.form.validate().then(async res => {
  184. let max = 0
  185. max = await this.resultHandler(_this.$axios.get('/dataExchange/senderProtocolDataPoint/maxProtocolNoInTunnel', {params: {tunnelId: _this.formData.tunnelId}})).then(res => {
  186. return res == null ? 0 : res
  187. })
  188. if (this.formData.dataSource == 'GATHER') {
  189. if (this.formData.equipmentAttrs.length == 0) {
  190. _this.$XModal.message({message: '并未选择需要添加的属性'})
  191. return
  192. }
  193. let str = '将'
  194. this.eqsOfSelectEqType.forEach(function (currentValue, index, arr) {
  195. if (currentValue.id == _this.formData.equipmentId) {
  196. str += currentValue.name + '的-'
  197. return false
  198. }
  199. })
  200. const name = new Array()
  201. let i = 0
  202. this.attrsOfSelectEq.forEach(function (currentValue, index, arr) {
  203. i = _this.formData.equipmentAttrs.indexOf(currentValue.id)
  204. if (i >= 0) {
  205. name[i] = currentValue.equipmentAttribute.explanation
  206. }
  207. })
  208. for (const j in name) {
  209. str += '[' + name[j] + ':' + (max * 1 + j * 1 + 1) + ']-'
  210. }
  211. str += name.length + '个状态点依次添加到'
  212. this.tunnelList.forEach(function (currentValue, index, arr) {
  213. if (currentValue.id == _this.formData.tunnelId) {
  214. str += currentValue.tunnelName
  215. return false
  216. }
  217. })
  218. str += '通道的末端(' + (max * 1 + 1) + ')'
  219. this.$XModal.confirm(str).then(type => {
  220. if (type == 'confirm') {
  221. for (const i in _this.formData.equipmentAttrs) {
  222. const param = {
  223. dataSource: _this.formData.dataSource,
  224. tunnelId: _this.formData.tunnelId,
  225. protocolPointType: _this.formData.protocolPointType,
  226. magnification: 1
  227. }
  228. param.gatherPoint = _this.formData.equipmentAttrs[i]
  229. param.protocolPointNo = max * 1 + i * 1 + 1
  230. _this.$axios.post('/dataExchange/senderProtocolDataPoint/saveDataPoint', param).then(res => {
  231. if (res.code == 0) {
  232. _this.$XModal.message({message: '保存转发点位成功'})
  233. _this.saveButDisable = false
  234. } else {
  235. _this.$XModal.message({message: '保存转发点位失败'})
  236. _this.saveButDisable = false
  237. }
  238. })
  239. }
  240. } else {
  241. _this.saveButDisable = false
  242. }
  243. })
  244. } else if (this.formData.dataSource == 'FORECAST') {
  245. if (this.formData.forecastPointNumber.length == 0) {
  246. _this.$XModal.message({message: '并未选择需要添加的预测属性'})
  247. return
  248. }
  249. let str = '将'
  250. this.enums.forecastType.forEach(function (currentValue, index, arr) {
  251. if (currentValue.value == _this.formData.forecastType) {
  252. str += currentValue.label + '的-'
  253. return false
  254. }
  255. })
  256. const days = []
  257. this.forecastDay.forEach(function (currentValue, index, arr) {
  258. var index = _this.formData.forecastNode.indexOf(currentValue.value)
  259. if (index >= 0) {
  260. days[index] = currentValue.label
  261. }
  262. })
  263. for (const j in days) {
  264. str += '[第' + days[j] + ']-'
  265. }
  266. str += '每天' + _this.formData.forecastPointNumber.length + '个预测数据依次添加到'
  267. this.tunnelList.forEach(function (currentValue, index, arr) {
  268. if (currentValue.id == _this.formData.tunnelId) {
  269. str += currentValue.tunnelName
  270. return false
  271. }
  272. })
  273. str += '通道的末端(' + (max * 1 + 1) + ')'
  274. this.$XModal.confirm(str).then(type => {
  275. if (type == 'confirm') {
  276. const param = {
  277. tunnelId: _this.formData.tunnelId,
  278. protocolPointType: _this.formData.protocolPointType,
  279. forecastType: _this.formData.forecastType,
  280. forecastNodes: _this.formData.forecastNode,
  281. pointNumbers: _this.formData.forecastPointNumber
  282. }
  283. _this.$axios.post('/dataExchange/senderProtocolDataPoint/batchSaveForecastPoint', param).then(res => {
  284. if (res.code == 0) {
  285. _this.$XModal.message({message: '保存转发点位成功'})
  286. _this.saveButDisable = false
  287. } else {
  288. _this.$XModal.message({message: '保存转发点位失败'})
  289. _this.saveButDisable = false
  290. }
  291. })
  292. }
  293. })
  294. }
  295. })
  296. },
  297. /**
  298. * 预测天数多选下拉框值发生变化时 补充预测点位下拉框的值
  299. */
  300. forecastNodeChangeEvent() {
  301. if (this.formData.forecastNode.length == 1) {
  302. this.formData.forecastPointNumber = []
  303. for (const i in this.forecastAttributeList) {
  304. this.formData.forecastPointNumber.push(this.forecastAttributeList[i].pointNumber)
  305. }
  306. } else if (this.formData.forecastNode.length == 0) {
  307. this.formData.forecastPointNumber = []
  308. }
  309. },
  310. /**
  311. * 当所选设备发生改变时 刷新该设备下对应的点位
  312. */
  313. flushAttrsOfSelectEq() {
  314. this.formData.equipmentAttrs = []
  315. const params = {
  316. equipmentType: this.formData.eqType,
  317. equipmentId: this.formData.equipmentId
  318. }
  319. if (this.formData.eqType == 'POWERSTATION') {
  320. params.equipmentId = null
  321. }
  322. this.resultHandler(this.$axios.get('/dataExchange/protocolDataPoint/gatherDataPoint', {params: params})).then(res => {
  323. this.attrsOfSelectEq = res
  324. })
  325. },
  326. /**
  327. *根据设备类型获取该类型下的设备属性
  328. * 可以传设备类型的ID 或NAME 即 可以传0 或 POWERSTATION
  329. * @param code
  330. * @returns {*}
  331. */
  332. getEqsByEqTypeCode(typeCode) {
  333. const axios = this.$axios
  334. if (typeCode === 0 || typeCode === 'POWERSTATION') {
  335. // 当设备类型是电站时对数数据进行处理后返回
  336. return new Promise(function (resolve, reject) {
  337. axios.get('/electricField/').then(res => {
  338. if (res.code == 0) {
  339. const eqs = []
  340. res.data.id = res.data.stationCode
  341. eqs.push(res.data)
  342. res.data = eqs
  343. }
  344. resolve(res)
  345. }).catch(error => {
  346. reject(error)
  347. })
  348. })
  349. } else {
  350. return axios.get('/dataExchange/equipmentInfo/' + typeCode)
  351. }
  352. },
  353. /**
  354. *针对于后台返回的信息进行二次处理的方法
  355. * @param promise Promise
  356. * @returns {Promise}
  357. */
  358. resultHandler(promise) {
  359. const message = this.$message
  360. return new Promise(function (resolve, reject) {
  361. promise.then(res => {
  362. if (res.code == 200) {
  363. resolve(res.data)
  364. } else {
  365. message.error(res.msg)
  366. reject(new Error(res.msg))
  367. }
  368. }).catch(error => {
  369. message.error('请求后台时发生异常')
  370. reject(error)
  371. })
  372. })
  373. },
  374. /**
  375. * 查询到所有采集通道
  376. * @returns {*}
  377. */
  378. getAllSenderTunnel() {
  379. return this.$axios.get('/TunnelInfo/getTunnel/Slave')
  380. },
  381. /**
  382. * 预测属性变化时 天数或者小时数随之变化
  383. */
  384. forecastDayChange() {
  385. this.formData.forecastNode = ''
  386. this.forecastAttributeList = []
  387. if (this.formData.forecastType === 'ULTRA_SHORT_AVAILABLE' || this.formData.forecastType === 'ULTRA_SHORT_THEORETICAL') {
  388. this.forecastDay = [{label: '第1小时', value: 0},
  389. {label: '第2小时', value: 1},
  390. {label: '第3小时', value: 2},
  391. {label: '第4小时', value: 3}]
  392. } else {
  393. this.forecastDay = [{label: '第1天', value: 0}, {label: '第2天', value: 1}, {
  394. label: '第3天',
  395. value: 2
  396. }, {label: '第4天', value: 3}, {label: '第5天', value: 4},
  397. {label: '第6天', value: 5}, {label: '第7天', value: 6}, {label: '第8天', value: 7}, {
  398. label: '第9天',
  399. value: 8
  400. }, {label: '第10天', value: 9}, {label: '第11天', value: 10}]
  401. }
  402. this.forecastAttributeList = []
  403. this.resultHandler(this.$axios.get('/dataExchange/ForecastForSendAttribute/' + 0 + '/' + this.formData.forecastType)).then(res => {
  404. this.forecastAttributeList = res
  405. })
  406. },
  407. /**
  408. * 根据所有通道信息构建通道下拉框的 展示数据
  409. */
  410. buildTunnelSelectData() {
  411. this.resultHandler(this.getAllSenderTunnel()).then(res => {
  412. if (res !== null) {
  413. this.tunnelList = res
  414. }
  415. })
  416. },
  417. /**
  418. *对form表单内的数据进行重置
  419. */
  420. resetForm() {
  421. this.formData = {
  422. eqType: '',
  423. dataSource: 'GATHER',
  424. tunnelId: '',
  425. protocolPointType: '',
  426. equipmentId: '',
  427. forecastType: '',
  428. forecastNode: [],
  429. forecastPointNumber: [],
  430. equipmentAttrs: []
  431. }
  432. this.protocolDataType = this.enums.ProtocolDataType
  433. },
  434. tunnelChange() {
  435. this.protocolDataType = []
  436. this.formData.protocolPointType = ''
  437. for (let i = 0; i < this.tunnelList.length; i++) {
  438. if (this.formData.tunnelId === this.tunnelList[i].id) {
  439. if (this.tunnelList[i].tunnelType.substring(0, 3) === 'IEC' || this.tunnelList[i].tunnelType.substring(0, 3) === 'FIL') {
  440. this.protocolDataType = [{label: '遥信开关量', value: 'A', key: 0}, {label: 'ABCD', value: 'ABCD', key: 9}]
  441. } else if (this.tunnelList[i].tunnelType.substring(0, 3) === 'CDT') {
  442. this.protocolDataType = [{label: '遥信开关量', value: 'A', key: 0}, {label: '+AB', value: 'P_AB', key: 1}]
  443. } else {
  444. this.protocolDataType = this.enums.ProtocolDataType
  445. }
  446. }
  447. }
  448. }
  449. }
  450. }
  451. </script>
  452. <style scoped>
  453. </style>