addoreditalarm.vue 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. <!--
  2. * @Author: chenlong (陈龙)
  3. * @Date: 2019-11-06 10:14:38
  4. * @LastEditors: wf
  5. * @LastEditTime: 2021-11-19 16:02:33
  6. * @Description: 系统管理>>>告警管理>>>添加|编辑告警
  7. -->
  8. <template>
  9. <div class="system-alarm-type-add" :class="{ 'no-channel': alarmProperty == '1' }">
  10. <dmp-form
  11. :cols="cols"
  12. :data="data"
  13. :inline="true"
  14. labelPosition="top"
  15. :rules="rules"
  16. :errors="errors"
  17. ref="form"
  18. style="width: 800px"
  19. >
  20. <template slot="productId">
  21. <!-- <el-input
  22. v-if="params.todo == 'edit'"
  23. type="text"
  24. v-model="data.productName"
  25. placeholder="限30位,汉字、字母、数字或符号"
  26. maxlength="30"
  27. clearable
  28. ></el-input> -->
  29. <el-cascader
  30. v-model="data.productId"
  31. :options="productOptions"
  32. :props="productTypeProps"
  33. clearable
  34. placeholder=""
  35. ref="pcascader"
  36. @change="productChange"
  37. >
  38. </el-cascader>
  39. </template>
  40. <template slot="communityId">
  41. <el-select v-model="data.communityId">
  42. <el-option v-for="(item, index) in communityArr" :key="index" :label="item.communityName" :value="item.id"></el-option>
  43. </el-select>
  44. </template>
  45. <template slot="deviceId">
  46. <el-select v-model="data.deviceId" placeholder="请选择设备" clearable @change="deviceSelect">
  47. <el-option v-for="item in deviceOptions" :key="item.id" :value="item.id" :label="item.deviceName"></el-option>
  48. </el-select>
  49. </template>
  50. <template slot="name">
  51. <span class="txt" v-if="isReadOnly">{{ data.name }}</span>
  52. <el-input
  53. v-else
  54. type="text"
  55. v-model="data.name"
  56. placeholder="限30位,汉字、字母、数字或符号"
  57. maxlength="30"
  58. clearable
  59. ></el-input>
  60. </template>
  61. <template slot="desc">
  62. <span class="txt" v-if="isReadOnly">{{ data.desc }}</span>
  63. <el-input
  64. v-else
  65. :disabled="isReadOnly"
  66. type="textarea"
  67. resize="none"
  68. v-model="data.desc"
  69. placeholder="输入文字,对该告警进行说明或描述"
  70. :rows="3"
  71. show-word-limit
  72. minlength="0"
  73. maxlength="100"
  74. ></el-input>
  75. </template>
  76. <template slot="alarmRuleList">
  77. <div class="dmp-table_alarm">
  78. <div class="lixian_class" v-if="alarmCategory == 1">
  79. <el-form-item slot="row" class="tip-info" label="测点" prop="measuringCode">
  80. <el-select v-model="measuringCode" placeholder="请选择测点" clearable @change="measureSelect">
  81. <el-option v-for="item in measureOptions" :key="item.id" :value="item.id" :label="item.name"></el-option>
  82. </el-select>
  83. </el-form-item>
  84. <el-table class="avg_table" :data="data.rules" stripe="true">
  85. <el-table-column label="运算符" align="left">
  86. <template slot-scope="scope">
  87. <el-form-item :prop="'rules.' + scope.$index + '.operator'" :rules="rules['rules.operator']">
  88. <span class="txt" v-if="isReadOnly">{{ scope.row.operator }}</span>
  89. <el-select
  90. v-else
  91. v-model="scope.row.operator"
  92. placeholder=""
  93. @change="validateKey('rules.' + scope.$index + '.operator', scope.row.operator)"
  94. :disabled="scope.row.measuringDataType == 1"
  95. clearable
  96. >
  97. <el-option
  98. v-for="item in operatoroptions"
  99. :key="item.id"
  100. :value="item.id"
  101. :label="item.name"
  102. ></el-option>
  103. </el-select>
  104. </el-form-item>
  105. </template>
  106. </el-table-column>
  107. <el-table-column label="条件值" align="left">
  108. <template slot-scope="scope">
  109. <el-form-item :prop="'rules.' + scope.$index + '.value'" :rules="rules['rules.value']">
  110. <template v-if="scope.row.measuringDataType == 1">
  111. <span class="txt" v-if="isReadOnly">{{
  112. toStrById(dictList, scope.row.value, 'specsName', 'specsValue')
  113. }}</span>
  114. <el-select
  115. v-else
  116. v-model="scope.row.value"
  117. @change="validateKey('rules.' + scope.$index + '.value', scope.row.value)"
  118. placeholder=""
  119. clearable
  120. >
  121. <el-option
  122. v-for="item in dictList"
  123. :key="item.specsValue"
  124. :value="item.specsValue"
  125. :label="item.specsName"
  126. ></el-option>
  127. </el-select>
  128. </template>
  129. <template v-else>
  130. <span class="txt" v-if="isReadOnly">{{ scope.row.value }}</span>
  131. <el-input
  132. v-else
  133. v-model.trim="scope.row.value"
  134. :disabled="!scope.row.operator"
  135. @blur="validateKey('rules.' + scope.$index + '.value', scope.row.value)"
  136. maxlength="128"
  137. placeholder="数字"
  138. clearable
  139. ></el-input>
  140. </template>
  141. </el-form-item>
  142. </template>
  143. </el-table-column>
  144. <el-table-column label="条件关系" align="left">
  145. <template slot-scope="scope">
  146. <el-form-item :prop="'rules.' + scope.$index + '.relation'" :rules="rules['rules.relation']">
  147. <span class="txt" v-if="isReadOnly">{{ scope.row.relation }}</span>
  148. <!-- :disabled="scope.$index == 0" -->
  149. <el-select
  150. v-else
  151. v-model="scope.row.relation"
  152. @change="validateKey('rules.' + scope.$index + '.relation', scope.row.relation)"
  153. placeholder=""
  154. >
  155. <el-option
  156. v-for="item in relationOptions"
  157. :key="item.id"
  158. :value="item.id"
  159. :label="item.name"
  160. ></el-option>
  161. </el-select>
  162. </el-form-item>
  163. </template>
  164. </el-table-column>
  165. <el-table-column label="单位" align="left">
  166. <template slot-scope="scope">
  167. <span>{{ scope.row.measuringUnit || '-' }}</span>
  168. </template>
  169. </el-table-column>
  170. <el-table-column v-if="!isReadOnly" label="操作">
  171. <template slot-scope="scope">
  172. <!-- && !scope.row.measuringCode v-if="!(scope.$index == 0)"-->
  173. <i class="icon-del-alarm" title="删除" v-if="!(scope.$index == 0)" @click="delRule(scope.$index)"></i>
  174. <i
  175. class="icon-add-alarm"
  176. title="添加"
  177. v-if="scope.$index == data.rules.length - 1 && measuringCode"
  178. @click="addRule(scope.$index)"
  179. ></i>
  180. </template>
  181. </el-table-column>
  182. </el-table>
  183. </div>
  184. <el-table v-else :data="data.rules" stripe="true">
  185. <el-table-column label="运算符" align="left">
  186. <template slot-scope="scope">
  187. <el-form-item :prop="'rules.' + scope.$index + '.operator'" :rules="rules['rules.operator']">
  188. <span class="txt" v-if="isReadOnly">{{ scope.row.operator }}</span>
  189. <el-select
  190. v-else
  191. v-model="scope.row.operator"
  192. placeholder=""
  193. @change="validateKey('rules.' + scope.$index + '.operator', scope.row.operator)"
  194. :disabled="scope.row.measuringDataType == 1"
  195. @clear="clearOperate(scope.$index)"
  196. clearable
  197. >
  198. <el-option
  199. v-for="item in operatoroptions"
  200. :key="item.id"
  201. :value="item.id"
  202. :label="item.name"
  203. ></el-option>
  204. </el-select>
  205. </el-form-item>
  206. </template>
  207. </el-table-column>
  208. <el-table-column label="条件值" align="left">
  209. <template slot-scope="scope">
  210. <el-form-item :prop="'rules.' + scope.$index + '.value'" :rules="rules['rules.value']">
  211. <template v-if="scope.row.measuringDataType == 1">
  212. <span class="txt" v-if="isReadOnly">{{
  213. toStrById(dictList, scope.row.value, 'specsName', 'specsValue')
  214. }}</span>
  215. <el-select
  216. v-else
  217. v-model="scope.row.value"
  218. @change="validateKey('rules.' + scope.$index + '.value', scope.row.value)"
  219. placeholder=""
  220. clearable
  221. >
  222. <el-option
  223. v-for="item in dictList"
  224. :key="item.specsValue"
  225. :value="item.specsValue"
  226. :label="item.specsName"
  227. ></el-option>
  228. </el-select>
  229. </template>
  230. <template v-else>
  231. <span class="txt" v-if="isReadOnly">{{ scope.row.value }}</span>
  232. <el-input
  233. v-else
  234. v-model.trim="scope.row.value"
  235. :disabled="!scope.row.operator"
  236. @blur="validateKey('rules.' + scope.$index + '.value', scope.row.value)"
  237. maxlength="128"
  238. placeholder="数字"
  239. clearable
  240. ></el-input>
  241. <span class="txt time_txt">分钟</span>
  242. </template>
  243. </el-form-item>
  244. </template>
  245. </el-table-column>
  246. </el-table>
  247. </div>
  248. </template>
  249. <template slot="timeSet">
  250. <div class="time_set">
  251. <div class="time_content" v-for="(item, index) in data.timeList" :key="index">
  252. <div class="timeduring">
  253. <div class="time_picker">
  254. <el-form-item :prop="'timeList.' + index + '.startTime'" :rules="rules.startTime">
  255. <el-time-picker
  256. value-format="HH:mm:ss"
  257. v-model="item.startTime"
  258. placeholder="开始时间"
  259. class="time_start"
  260. >
  261. </el-time-picker>
  262. </el-form-item>
  263. <el-form-item class="end_time" :prop="'timeList.' + index + '.endTime'" :rules="rules.endTime">
  264. <span style="margin: 5px">~</span>
  265. <el-time-picker value-format="HH:mm:ss" v-model="item.endTime" placeholder="结束时间" class="time_end">
  266. </el-time-picker>
  267. </el-form-item>
  268. </div>
  269. <div class="add_img">
  270. <i class="icon_add" @click="addTime"></i>
  271. <i class="icon_delete" v-if="index != 0" @click="deleteTime(index)"></i>
  272. </div>
  273. </div>
  274. </div>
  275. </div>
  276. </template>
  277. <template slot="dayset">
  278. <el-form-item>
  279. <div class="time_sys">
  280. <el-switch v-model="checkFlag" width="45" active-color="#0eaeff" inactive-color="#d8d8d8" @change="changeSwitch">
  281. </el-switch>
  282. <span class="every_day">每天</span>
  283. <ul v-if="!checkFlag" class="ul-time">
  284. <li v-for="(item, index) in dayOption" :key="index" style="cursor: pointer">
  285. <el-checkbox v-model="item.checked" @change="onChange($event)">{{ item.name }}</el-checkbox>
  286. </li>
  287. </ul>
  288. </div>
  289. </el-form-item>
  290. </template>
  291. </dmp-form>
  292. </div>
  293. </template>
  294. <script>
  295. import { bodyContent, addCols, operatorOptions, relationOptions, alarmCategoryOptions, toStrById } from './util';
  296. export default {
  297. props: {
  298. params: Object
  299. },
  300. data() {
  301. const _selft = this;
  302. return {
  303. data: JSON.parse(JSON.stringify(bodyContent)),
  304. alarmCategory: '1',
  305. measuringCode: '',
  306. cols: [],
  307. measureOptions: [],
  308. dictList: [],
  309. rules: {
  310. communityId:this.$valid.selectRequired('社区'),
  311. productId: this.$valid.selectRequired('产品'),
  312. name: [this.$valid.inputRequired('告警名称'), this.$valid.lengthRange(0, 30)],
  313. // measuringCode: this.$valid.selectRequired('测点'),
  314. measuringCode: this.$valid.custome({
  315. validator(rule, value, cb) {
  316. let vv = _selft.measuringCode;
  317. const rl = rule;
  318. if (!vv) {
  319. rl.message = '请选择测点值';
  320. cb(new Error());
  321. } else {
  322. cb();
  323. }
  324. }
  325. }),
  326. startTime: this.$valid.custome({
  327. validator(rule, value, cb) {
  328. const rl = rule;
  329. let regExp = /^[0-2][0-9]\:[0-5][0-9]\:[0-5][0-9]$/;
  330. if (!value) {
  331. rl.message = '请选择时间';
  332. cb(new Error());
  333. } else if (!regExp.test(value)) {
  334. rl.message = '时间格式错误';
  335. cb(new Error());
  336. } else {
  337. cb();
  338. }
  339. }
  340. }),
  341. endTime: this.$valid.custome({
  342. validator(rule, value, cb) {
  343. const rl = rule;
  344. let regExp = /^[0-2][0-9]\:[0-5][0-9]\:[0-5][0-9]$/;
  345. if (!value) {
  346. rl.message = '请选择时间';
  347. cb(new Error());
  348. } else if (!regExp.test(value)) {
  349. rl.message = '时间格式错误';
  350. cb(new Error());
  351. } else {
  352. cb();
  353. }
  354. }
  355. })
  356. // alarmCategory: this.$valid.selectRequired('告警分类')
  357. },
  358. errors: {},
  359. cascaderProps: { value: 'id', expandTrigger: 'hover' },
  360. alarmCategoryOptions,
  361. measuringOptions: [],
  362. operatoroptions: operatorOptions,
  363. copyoperatorOptions: [],
  364. relationOptions,
  365. productIds: [],
  366. alarmProperty: '2',
  367. productTypeProps: {
  368. value: 'id', // 唯一标识
  369. label: 'label', // 标签显示
  370. children: 'children' // 子级
  371. },
  372. deviceOptions: [],
  373. productOptions: [],
  374. isReadOnly: false,
  375. toStrById,
  376. dayOption: [
  377. { id: 2, name: '周一', checked: false },
  378. { id: 3, name: '周二', checked: false },
  379. { id: 4, name: '周三', checked: false },
  380. { id: 5, name: '周四', checked: false },
  381. { id: 6, name: '周五', checked: false },
  382. { id: 7, name: '周六', checked: false },
  383. { id: 1, name: '周日', checked: false }
  384. ],
  385. checkFlag: true
  386. };
  387. },
  388. computed: {
  389. communityArr() {
  390. return this.$store.getters['getAreaSelect'];
  391. }
  392. },
  393. methods: {
  394. getDeviceOptions(id) {
  395. this.$http.get('/sc-community/device/findByProduct?id=' + id).then(({ data }) => {
  396. this.deviceOptions = data;
  397. });
  398. },
  399. getMeasurePointOptions(id) {
  400. let params = { deviceTypeId: id };
  401. this.$http.get('/sc-community/attributes/listBydeviceTypeId', params).then(({ data }) => {
  402. this.measureOptions = data;
  403. });
  404. },
  405. deviceSelect(value) {
  406. let item = _.find(this.deviceOptions, (it) => it.id == value);
  407. this.$set(this.data, 'iotDeviceId', item.iotDeviceId || '');
  408. },
  409. measureSelect(value) {
  410. let results = {};
  411. this.measureOptions.map((item, index) => {
  412. if (item.id == value) {
  413. return (results = item);
  414. }
  415. });
  416. this.$set(this.data, 'attributeId', results.id);
  417. this.$set(this.data, 'identifier', results.identifier);
  418. this.getOperator(results.id || '');
  419. if (this.data.rules.length > 1) {
  420. this.data.rules.splice(1, this.data.rules.length);
  421. }
  422. this.data.rules[0].measuringCode = this.measuringCode;
  423. this.data.rules[0].operator = '';
  424. this.data.rules[0].relation = 'AND';
  425. this.data.rules[0].value = '';
  426. if (!_.isEmpty(results)) {
  427. Object.assign(this.rules, {
  428. 'rules.operator': this.$valid.selectRequired('运算符'),
  429. 'rules.value': this.$valid.selectRequired('条件值'),
  430. 'rules.relation': this.$valid.selectRequired('条件关系')
  431. });
  432. } else if (this.data.rules.length == 1) {
  433. this.$refs.form.$refs.form.clearValidate(['rules.0.operator', 'rules.0.value', 'rules.0.relation']);
  434. delete this.rules['rules.operator'];
  435. delete this.rules['rules.value'];
  436. delete this.rules['rules.relation'];
  437. }
  438. },
  439. getOperator(attributeId) {
  440. let _self = this;
  441. _self.$http.get(`/sc-community/attributes/specs/list?attributeId=${attributeId}`).then(({ status, data = [] }) => {
  442. if (status == 0) {
  443. _self.dictList.splice(0, _self.dictList.length);
  444. if (data.length > 0) {
  445. data.map((it) => {
  446. _self.dictList.push(it);
  447. });
  448. if (_self.dictList.length > 0) {
  449. // eslint-disable-next-line no-param-reassign
  450. _self.data.rules.map((it) => {
  451. it.operator = '=';
  452. });
  453. this.rules['rules.value'] = this.$valid.selectRequired('条件值');
  454. } else {
  455. this.rules['rules.value'] = this.$valid.custome({
  456. validator(rule, value, cb) {
  457. const rl = rule;
  458. if (value) {
  459. if (value >= -99999999 && value <= 99999999) {
  460. cb();
  461. } else {
  462. rl.message = '您输入格式有误,请重新输入';
  463. cb(new Error());
  464. }
  465. } else {
  466. rl.message = '请输入条件值';
  467. cb(new Error());
  468. }
  469. }
  470. });
  471. }
  472. } else {
  473. _self.dictList = _self.dictList.length > 0 ? _self.dictList.splice(0, _self.dictList.length) : [];
  474. }
  475. this.data.rules.map((ita) => {
  476. if (_self.dictList.length > 0) {
  477. ita.measuringDataType = '1';
  478. ita.operator = '=';
  479. } else {
  480. ita.measuringDataType = '2';
  481. }
  482. });
  483. }
  484. });
  485. },
  486. addTime() {
  487. let _self = this;
  488. this.$nextTick(() => {
  489. _self.data.timeList.push({ startTime: '00:00:00', endTime: '23:59:59' });
  490. });
  491. },
  492. deleteTime(index) {
  493. let _self = this;
  494. this.$nextTick(() => {
  495. _self.data.timeList.splice(index, 1);
  496. });
  497. },
  498. changeSwitch() {
  499. let xx = this.checkFlag;
  500. },
  501. onChange(value) {},
  502. validateKey(key, val) {
  503. val && this.$refs.form.$refs.form.clearValidate([key]);
  504. },
  505. measuringChange(id, row) {
  506. const obj = _.find(this.measuringOptions, (v) => v.measuringCode == id);
  507. Object.assign(row, {
  508. operator: '',
  509. value: '',
  510. relation: 'AND',
  511. measuringUnit: ''
  512. });
  513. if (!_.isEmpty(obj)) {
  514. Object.assign(this.rules, {
  515. 'rules[0].measuringCode': this.$valid.selectRequired('测点'),
  516. 'rules.operator': this.$valid.selectRequired('运算符'),
  517. 'rules.value': this.$valid.selectRequired('条件值'),
  518. 'rules.relation': this.$valid.selectRequired('条件关系')
  519. });
  520. const { measuringDataType, measuringUnit, dictList } = obj;
  521. Object.assign(row, {
  522. measuringDataType,
  523. measuringUnit,
  524. dictList
  525. });
  526. if (measuringDataType == 1) {
  527. // eslint-disable-next-line no-param-reassign
  528. row.operator = '=';
  529. this.rules['rules.value'] = this.$valid.selectRequired('条件值');
  530. } else {
  531. this.rules['rules.value'] = this.$valid.custome({
  532. validator(rule, value, cb) {
  533. const rl = rule;
  534. if (value) {
  535. if (value >= -99999999 && value <= 99999999) {
  536. cb();
  537. } else {
  538. rl.message = '您输入格式有误,请重新输入';
  539. cb(new Error());
  540. }
  541. } else {
  542. rl.message = '请输入条件值';
  543. cb(new Error());
  544. }
  545. }
  546. });
  547. }
  548. } else if (this.data.rules.length == 1) {
  549. this.$refs.form.$refs.form.clearValidate(['rules.0.operator', 'rules.0.value', 'rules.0.relation']);
  550. delete this.rules['rules.measuringCode'];
  551. delete this.rules['rules.operator'];
  552. delete this.rules['rules.value'];
  553. delete this.rules['rules.relation'];
  554. }
  555. },
  556. getMeasuring(id, isEdit) {
  557. this.$http.get(`/zoniot-rmcp-web/alarmRule/getRuleMeasuringList?deviceTypeId=${id}`).then(({ status, data = [] }) => {
  558. if (status == 0) {
  559. this.measuringOptions = data;
  560. if (isEdit) {
  561. const rules = this.data.rules.length
  562. ? JSON.parse(JSON.stringify(this.data.rules))
  563. : [
  564. {
  565. id: '',
  566. measuringCode: '',
  567. measuringDataType: '',
  568. operator: '',
  569. value: '',
  570. relation: 'AND',
  571. measuringUnit: ''
  572. }
  573. ];
  574. _.each(rules, (v) => {
  575. const obj = _.find(data, (m) => m.measuringCode == v.measuringCode);
  576. // eslint-disable-next-line no-param-reassign
  577. v.dictList = _.isEmpty(obj) ? [] : obj.dictList;
  578. });
  579. const params = JSON.parse(JSON.stringify(this.params.data));
  580. Object.assign(this.data, params, { rules });
  581. }
  582. }
  583. });
  584. },
  585. productChange(e) {
  586. let lat = _.last(e)
  587. this.measuringOptions = [];
  588. this.data.productId = e;
  589. this.data.deviceId = '';
  590. this.getDeviceOptions(lat);
  591. this.getMeasurePointOptions(lat);
  592. let rec = this.getCascaderObj(lat, this.productOptions);
  593. this.data.iotProductId = rec.iotId || '';
  594. },
  595. delRule(index) {
  596. this.data.rules.splice(index, 1);
  597. if (this.data.rules.length == 0) {
  598. this.data.rules = [
  599. {
  600. id: '',
  601. measuringCode: '',
  602. measuringDataType: this.dictList.length > 0 ? '1' : '2',
  603. operator: '',
  604. value: '',
  605. relation: 'AND',
  606. measuringUnit: ''
  607. }
  608. ];
  609. }
  610. if (this.data.rules[0].relation != 'AND') {
  611. this.data.rules[0].relation = 'AND';
  612. }
  613. },
  614. addRule(index) {
  615. const props = [`rules.${index}.operator`, `rules.${index}.value`, `rules.${index}.relation`];
  616. let count = props.length;
  617. this.$refs.form.$refs.form.validateField(props, (errorMessage) => {
  618. if (!errorMessage) {
  619. count -= 1;
  620. }
  621. if (count == 0 && this.data.rules[0].measuringCode) {
  622. this.data.rules.push({
  623. id: '',
  624. measuringCode: this.data.rules[0].measuringCode || '',
  625. measuringDataType: this.dictList.length > 0 ? '1' : '2',
  626. operator: this.dictList.length > 0 ? '=' : '',
  627. value: '',
  628. relation: 'AND',
  629. measuringUnit: ''
  630. });
  631. } else {
  632. }
  633. });
  634. },
  635. reset() {
  636. const dataBak = JSON.parse(JSON.stringify(this.data));
  637. this.data = JSON.parse(JSON.stringify(bodyContent));
  638. if (this.params.todo == 'add') {
  639. this.productIds = [];
  640. } else {
  641. this.data.id = dataBak.id;
  642. this.data.productId = dataBak.productId;
  643. this.data.alarmProperty = dataBak.alarmProperty;
  644. }
  645. this.$refs.form.resetFields();
  646. },
  647. //深拷贝
  648. deepClone(obj) {
  649. if (typeof obj !== 'object') return;
  650. let newObj = obj instanceof Array ? [] : {};
  651. for (let key in obj) {
  652. if (obj.hasOwnProperty(key)) {
  653. newObj[key] = typeof obj[key] === 'object' ? this.deepClone(obj[key]) : obj[key];
  654. }
  655. }
  656. return newObj;
  657. },
  658. getQueryInfo(id) {
  659. if (this.params && this.params.todo == 'edit') {
  660. this.$http.get(`/sc-community/system/alarmType/findAlarmTypeById?id=${id}`).then(({ data }) => {
  661. this.data = Object.assign(this.data, data);
  662. this.data.productId = [null, null, data.productId + ''];
  663. this.getDeviceOptions(data.productId);
  664. this.getMeasurePointOptions(data.productId);
  665. this.measuringCode = this.data.rules[0].measuringCode ? this.data.rules[0].measuringCode : '';
  666. this.getOperator(this.data.attributeId);
  667. this.setDaysAndTimes(data.days, data.times);
  668. });
  669. }
  670. },
  671. clearOperate(index) {
  672. this.data.rules[index].value = '';
  673. },
  674. getCascaderObj(val, opt) {
  675. if (!(opt && opt.length)) {
  676. return '';
  677. }
  678. let res = '';
  679. const forFn = (opt, val) => {
  680. for (let i = 0; i < opt.length; i += 1) {
  681. const item = opt[i];
  682. if (item.id == val) {
  683. res = item;
  684. break;
  685. }
  686. if (item.children) {
  687. forFn(item.children, val);
  688. }
  689. }
  690. };
  691. forFn(opt, val);
  692. return res;
  693. },
  694. setDaysAndTimes(days = '', times = '-') {
  695. let dayarr = days.split(',');
  696. if (dayarr && dayarr.length > 0) {
  697. if (dayarr[0] == 8) {
  698. this.checkFlag = true;
  699. } else {
  700. this.checkFlag = false;
  701. this.dayOption.map((it) => {
  702. if (dayarr.includes(it.id.toString())) {
  703. it.checked = true;
  704. }
  705. });
  706. }
  707. }
  708. let timearr = times.split(',');
  709. if (timearr && timearr.length > 0) {
  710. timearr.map((ita, idx) => {
  711. let timespan = ita.split('-');
  712. if (timespan && timespan.length > 1) {
  713. let newitem = null;
  714. if (idx == 0) {
  715. this.data.timeList[0].startTime = timespan[0];
  716. this.data.timeList[0].endTime = timespan[1];
  717. } else {
  718. newitem = { startTime: timespan[0], endTime: timespan[1] };
  719. this.data.timeList.push(newitem);
  720. }
  721. } else {
  722. this.data.timeList.push({ startTime: '', endTime: '' });
  723. }
  724. });
  725. }
  726. },
  727. submit() {
  728. let _self = this;
  729. new Promise((res) => {
  730. // resolve();
  731. this.$refs.form.validate(res);
  732. })
  733. .then(() => {
  734. let url = '/sc-community/system/alarmType/add',
  735. method = 'post';
  736. if (this.params.todo == 'edit') {
  737. url = '/sc-community/system/alarmType/edit';
  738. method = 'post';
  739. }
  740. let times = '';
  741. this.data.timeList.map((item, index) => {
  742. if (index == _self.data.timeList.length - 1) {
  743. times += `${item.startTime}-${item.endTime}`;
  744. } else {
  745. times += `${item.startTime}-${item.endTime},`;
  746. }
  747. });
  748. let days = '';
  749. if (!this.checkFlag) {
  750. this.dayOption.map((itemarr, idx) => {
  751. if (itemarr.checked) {
  752. days += itemarr.id + ',';
  753. }
  754. });
  755. days = days.slice(0, days.length - 1);
  756. } else {
  757. days = '8';
  758. }
  759. let newdata = Object.assign(this.data, { days }, { times });
  760. const params = JSON.parse(JSON.stringify(newdata));
  761. params.productId = _.last(params.productId);
  762. const rules = [];
  763. // _.each(params.rules, (v) => {
  764. // if (v.measuringCode) {
  765. // rules.push(v);
  766. // }
  767. // })
  768. // params.rules = rules;
  769. _self.data.rules.map((it, index) => {
  770. if (index >= 1) {
  771. it.measuringCode = _self.data.rules[0].measuringCode;
  772. }
  773. });
  774. const $loading = this.$loading();
  775. this.$http[method](url, params)
  776. .then(({ status, msg }) => {
  777. if (status == 0) {
  778. this.$message.success(msg);
  779. this.params.callback();
  780. this.$emit('close');
  781. } else if (status === 500017) {
  782. this.$set(this.errors, 'name', msg);
  783. } else {
  784. this.$message.error(msg);
  785. }
  786. $loading.close();
  787. })
  788. .catch(() => {
  789. this.$loading.close();
  790. });
  791. })
  792. .catch(() => {});
  793. }
  794. },
  795. created() {
  796. this.copyoperatorOptions = operatorOptions.slice();
  797. this.alarmCategory = this.params.alarmCategory;
  798. // this.deviceOptions=this.params.deviceOptions;
  799. this.productOptions = this.params.productOptions;
  800. if (this.alarmCategory == '2') {
  801. let newaddCols = addCols[0].slice(0, 5);
  802. this.cols = [newaddCols];
  803. } else {
  804. this.cols = addCols;
  805. }
  806. if ((this.params && this.params.todo == 'edit') || this.params.todo == 'view') {
  807. this.getQueryInfo(this.params.data.id);
  808. this.$set(this.data, 'name', this.params.data.alarmName);
  809. //给日期和星期赋值this.params.data.days,this.params.data.times
  810. this.isReadOnly = this.params.todo == 'view';
  811. }
  812. this.$set(this.data, 'alarmCategory', this.alarmCategory);
  813. this.$set(this.data, 'sceneType', '3');
  814. }
  815. };
  816. </script>
  817. <style lang="scss" scoped>
  818. @import './style.scss';
  819. .icon-del-alarm {
  820. display: inline-block;
  821. width: 16px;
  822. height: 16px;
  823. cursor: pointer;
  824. background: url('~@assets/img/menuicon/icon-del.png') no-repeat center;
  825. background-size: 100% 100%;
  826. margin-right: 10px;
  827. }
  828. .icon-add-alarm {
  829. display: inline-block;
  830. width: 16px;
  831. height: 16px;
  832. cursor: pointer;
  833. background: url('~@assets/img/menuicon/icon-add.png') no-repeat center;
  834. background-size: 100% 100%;
  835. }
  836. .time_picker /deep/ .el-form-item {
  837. margin-bottom: 0px;
  838. .el-form-item__error {
  839. padding-top: 7px;
  840. }
  841. &.end_time {
  842. .el-form-item__error {
  843. left: 40px !important;
  844. }
  845. }
  846. }
  847. </style>