| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <template>
- <div>
- <!-- <div>{{ datas }}</div>
- <br />
- <div>{{ sourceTypeList }}</div> -->
- <el-row>
- <el-col :span="14">
- <el-row>
- <el-col :span="24">
- <el-radio-group v-model="weekDay">
- <el-radio-button label="1">星期一</el-radio-button>
- <el-radio-button label="2">星期二</el-radio-button>
- <el-radio-button label="3">星期三</el-radio-button>
- <el-radio-button label="4">星期四</el-radio-button>
- <el-radio-button label="5">星期五</el-radio-button>
- <el-radio-button label="6">星期六</el-radio-button>
- <el-radio-button label="7">星期日</el-radio-button>
- </el-radio-group>
- </el-col>
- </el-row>
- </el-col>
- <el-col :span="10">
- <el-row type="flex" justify="end">
- <el-col :span="11">
- <el-button type="primary" size="medium" @click="addBtnClick">新增规则</el-button>
- <el-popover placement="bottom" title="复制到" trigger="click" @show="copyToPanelShow" v-model="copyToPanelVisible">
- <div class="copytoPanel">
- <el-card>
- <el-checkbox-group v-model="copyToSelects">
- <el-checkbox label="1">周一</el-checkbox>
- <el-checkbox label="2">周二</el-checkbox>
- <el-checkbox label="3">周三</el-checkbox>
- <el-checkbox label="4">周四</el-checkbox>
- <el-checkbox label="5">周五</el-checkbox>
- <el-checkbox label="6">周六</el-checkbox>
- <el-checkbox label="7">周日</el-checkbox>
- </el-checkbox-group>
- <br />
- <el-button type="primary" @click="copyToClick">复制</el-button>
- </el-card>
- </div>
- <el-button slot="reference" type="primary">复制到</el-button>
- </el-popover>
- </el-col>
- </el-row>
- </el-col>
- </el-row>
- <el-empty
- v-if="datas[sourceType] == undefined || datas[sourceType][weekDay] == undefined || datas[sourceType][weekDay].length == 0"
- description="未找到数据"></el-empty>
- <div v-else v-for="(item, index) in datas[sourceType][weekDay]" :key="item" class="ruleDiv">
- <div class="sonruleDiv">
- <el-time-picker placeholder="开始时间" value-format="HH:mm:ss" v-model="item.times" is-range range-separator="至"
- @input="timeInput(item.times)" clearable=false clear-icon="">
- </el-time-picker>
- <el-select v-model="item.fieldcode" placholeder="请选择属性" @change="sourceTypeItemChanged(item, item.fieldcode)">
- <el-option v-for="sourceTypeItem in sourceTypeList" :key="sourceTypeItem.sysFieldCode"
- :label="sourceTypeItem.name" :value="sourceTypeItem.sysFieldCode">
- </el-option>
- </el-select>
- <el-select v-model="item.operator" placeholder="请选择操作" @change="operatorChanged(item, item.operator)">
- <el-option v-for="operatorsItem in item.operators" :key="operatorsItem.key" :label="operatorsItem.value"
- :value="operatorsItem.key">
- </el-option>
- </el-select>
- <el-input-number v-if="item.sourceValues == undefined || item.sourceValues.length==0"
- v-model="item.value" :precision="2" :step="0.1" @change="onInputChange" ></el-input-number>
- <el-select v-else v-model="item.value" placeholder="请选择操作" @change="valueChanged(item, item.value)">
- <el-option v-for="sourceValueItem in item.sourceValues" :key="sourceValueItem.key"
- :label="sourceValueItem.value" :value="sourceValueItem.key"
- @click.native="sourceValueItemClick(sourceValueItem, item)">
- </el-option>
- </el-select>
- <el-button type="primary" @click.native="removeClick(item, index)">移除</el-button>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- props: {
- sourceType: String,
- datas: Object,
- sourceTypeList: Array,
- },
- name: "SocWebAddDialogCom",
- data() {
- return {
- weekDay: "1",
- copyToSelects: [],
- copyToPanelVisible:false
- };
- },
- mounted() { },
- methods: {
- addBtnClick() {
- if (this.datas[this.sourceType] == undefined) {
- this.datas[this.sourceType] = {};
- }
- if (this.datas[this.sourceType][this.weekDay] == undefined) {
- this.datas[this.sourceType][this.weekDay] = [];
- }
- let weekDayDatas = this.datas[this.sourceType][this.weekDay];
- let newData = {
- id: "",
- ruleId: "",
- fieldcode: "",
- //@ApiModelProperty(value = "操作符,GT(大于)、GTE(大于等于)、LT(小于)、LTE(小于等 于)、EQUALS(等于)、STARTS_WITH(以什么开始)、 ENDS_WITH(以什么结束)、CONTAIN(包含)")
- operator: "",
- value: "",
- valueText: "",
- //@ApiModelProperty(value = "报警源类型:4:烟雾传感器;5: 温湿度采集器;6:水浸; 7:门磁、窗磁;8:卷帘门门磁;9:地磁;10燃气报警器;20:报警防区")
- sourceType: this.sourceType,
- //@ApiModelProperty(value = "规则使用周期:1.周一,2.周二,3.周三,4.周四,5.周五,6.周六,7.周日")
- weekDay: this.weekDay,
- startTime: "00:00:00",
- endTime: "23:59:59",
- times: ["00:00:00", "23:59:59"]
- };
- if (newData.fieldcode == undefined || newData.fieldcode == "") {
- if (this.sourceTypeList != undefined && this.sourceTypeList.length > 0) {
- newData.fieldcode = this.sourceTypeList[0].sysFieldCode;
- }
- }
- if (newData.operator == undefined || newData.operator == "") {
- if (this.sourceTypeList != undefined && this.sourceTypeList.length > 0
- && this.sourceTypeList[0].operatorsList != undefined
- && this.sourceTypeList[0].operatorsList.length > 0) {
- newData.operator = this.sourceTypeList[0].operatorsList[0].key
- }
- }
- if (newData.value == undefined || newData.value == "") {
- if (this.sourceTypeList != undefined && this.sourceTypeList.length > 0
- && this.sourceTypeList[0].specsList != undefined
- && this.sourceTypeList[0].specsList.length > 0) {
- newData.value = this.sourceTypeList[0].specsList[0].key
- newData.valueText = this.sourceTypeList[0].specsList[0].value;
- }
- }
- this.initDataItem(newData, newData.fieldcode);
- weekDayDatas.push(newData);
- this.$forceUpdate();
- },
- copyToClick() {
- if (this.copyToSelects.length == 0) {
- this.$message({ message: "请选择需要复制到的星期!", type: 'warning' });
- return;
- }
- if (this.datas[this.sourceType] == undefined ||
- this.datas[this.sourceType][this.weekDay] == undefined ||
- this.datas[this.sourceType][this.weekDay].length == 0) {
- this.$message({ message: "没有可复制的数据", type: 'warning' });
- return;
- }
- this.copyToSelects.forEach(i => {
- let tempData = JSON.stringify(this.datas[this.sourceType][this.weekDay]);
- let newData = JSON.parse(tempData);
- newData.forEach(newDataItem => {
- newDataItem.weekDay=i;
- })
- this.datas[this.sourceType][i] = newData;
- });
- this.copyToPanelVisible = false;
- this.$forceUpdate();
- return true;
- },
- sourceTypeItemChanged(item, type) {
- this.initDataItem(item, type);
- this.$forceUpdate();
- },
- initDataItem(item, type) {
- let exist = this.sourceTypeList.find(i => i.sysFieldCode == type)
- if (exist == undefined) {
- item.operators = [];
- item.sourceValues = [];
- }
- else {
- item.operators = exist.operatorsList;
- item.sourceValues = exist.specsList;
- }
- return item;
- },
- operatorChanged(item, value) {
- this.$forceUpdate();
- },
- valueChanged(item, value) {
- this.$forceUpdate();
- },
- timeInput(value) {
- this.$forceUpdate();
- },
- onInputChange()
- {
- this.$forceUpdate();
- },
- removeClick(item, index) {
- if (this.datas[this.sourceType] == undefined) {
- this.datas[this.sourceType] = {};
- }
- if (this.datas[this.sourceType][this.weekDay] == undefined) {
- this.datas[this.sourceType][this.weekDay] = [];
- }
- let weekDayDatas = this.datas[this.sourceType][this.weekDay];
- if (weekDayDatas.length > index) {
- weekDayDatas.splice(index, 1)
- this.$forceUpdate();
- }
- },
- sourceValueItemClick(sourceValueItem, item) {
- console.log(sourceValueItem, item);
- },
- copyToPanelShow() {
- this.copyToSelects = [];
- }
- },
- };
- </script>
- <style lang="scss" scoped>
- .ruleDiv {
- margin-top: 20px;
- .sonruleDiv {
- margin-top: 10px;
- .el-button {
- margin-left: 20px;
- }
- }
- }
- .copytoPanel {
- .el-checkbox {
- width: 50px;
- margin-top: 10px;
- }
- }
- </style>
|