<template>
	<!-- 按阈值 -->
	<div>
		<div class="text-c mb-20">
			<p v-for="(r,index) in rule" :key="index">
                <span>{{r.name}}</span>&nbsp;&nbsp;<span>{{r.symbol}}</span>&nbsp;&nbsp;
                <el-input v-model="r.value" placeholder="请输入阈值" type="number" style="width:200px"></el-input>
            </p>
		</div>
		<div slot="footer" class="dialog-footer text-c">
            <el-button @click="cancel()">取 消</el-button>
            <el-button type="primary" @click="ok()">确 定</el-button>
        </div>
	</div>
</template>

<script>
import apiHelper from "@/assets/js/apiHelper.js";
export default {
    name: "WrThreshold",
    // props: ['row','editIndex'],
	data() {
		return {
            codeArr:["",""],
            rule:[],
            DimensionRuleConfigId:"",//基础维度id
            editIndex:-1,
            row:{}
		};
	},
	watch: {},
	created () {},
	mounted () {},
	methods: {
        editModel(index,row){
            this.rule=[];
            this.editIndex = index;
            this.row = row;
            if(index!=-1){
                this.rule = row.ChildValue;
            }else{
                this.getOperatorByPriseRule();
            }
        },
        ok(){
            if(this.rule[0].value==""){
                return;
            }
            let obj = {};
            let myRule = _.cloneDeep(this.rule);
            obj.Id = this.editIndex==-1?"":this.row.Id;//新增的时候是空的
            obj.DimensionRuleId = this.editIndex==-1?this.row.Id:this.row.DimensionRuleId;
            // obj.DimensionRuleConfigId = this.editIndex==-1?this.DimensionRuleConfigId:this.row.DimensionRuleConfigId;//基础维度id
            obj.ViewModel = this.row.ViewModel;
            obj.DimensionRuleName = this.row.DimensionRuleName;
            obj.ParamText = `${myRule[0].value}`;
            obj.ChildValue = myRule;
            obj.OperateType = this.row.OperateType;
            if(this.editIndex !== -1){
                this.$emit('editDataRule',obj);
            }else{
                this.$emit('addDataRule',obj);
            }
        },
        cancel(){
            this.$emit('showRulesDialog');
        },
        // 根据参与子规则获取运算符
        getOperatorByPriseRule(){
            let that = this;
            apiHelper.getOperatorByPriseRule(this.row.DimensionRuleNo, function(res) {
                if (res.flag) {
                    // that.DimensionRuleConfigId=res.data[0].Id;
                    for(let i=0;i<res.data.length;i++){
                        that.rule.push({
                            id:res.data[i].Id,
                            name:res.data[i].BaseDimensionName,
                            symbol:res.data[i].View,
                            value:""
                        });
                    }
                }
            });
        },
	}
};

</script>
<style scoped>
.text-r{text-align: right;}
.text-c{text-align: center;}
.pos-r{position: relative;}
.dis-ib{display: inline-block;}
.mb-10{margin-bottom: 10px;}
.mb-20{margin-bottom: 20px;}
.w-200{width: 200px;}
.card-box{
	border: 1px solid #DCDFE6;
	padding: 20px;
	border-radius: 4px;
}
.delete-btn{
	position: absolute;
	top:10px;
	right: 10px;
}
.t90{
    font-size: 24px;
    transform:rotate(90deg);
    -ms-transform:rotate(90deg); 
}
.form-box{margin-bottom: 20px;}
.form-box .mylabel{
    width: 100px;
    text-align: right;
    vertical-align: middle;
    float: left;
    /* font-size: 14px; */
    color: #606266;
    line-height: 40px;
    padding: 0 12px 0 0;
    box-sizing: border-box;
}
.form-box .mycontent{
    margin-left: 100px;
    position: relative;
    font-size: 0px;
}
.lh-285{
    line-height: 200px;
}
</style>