<template>
    <!-- 工程管理 新增、编辑 表单组件 -->
    <div >
        <el-form
            label-width="100px"
            size="medium"
            ref="warnAlertParamsRef"
            :model="warnAlertParams"
            :rules="warnAlertParamsRules"
        >
          <el-form-item label="预警处置" prop="remarks" >
            <el-input v-model="warnAlertParams.remarks" :maxlength="50" placeholder="请输入预警处置内容" style="width: 550px;"/>
          </el-form-item>

          <el-form-item  style="display: flex; justify-content: right">
              <el-button type="success" @click="onSubmit">确认</el-button>
              <el-button
                  @click="
                      () => {
                          this.$emit('closeDialog')
                      }
                  "
                  >取消</el-button
              >
          </el-form-item>
        </el-form>
    </div>
</template>

<script>
import {
  handleWarnAlertApi
} from '@/api/base/warnAlert'
export default {
    name: 'FormWarnAlert',
    props: {
        editParams: {
            type: Object,
            default: () => null,
        },
    },
    components: {  },
    created() {

    },
   async mounted() {
       console.log(this.editParams)
        if (this.editParams) {
          await  Object.assign(this.warnAlertParams, this.editParams)
            this.warnAlertParams.isDispose = 1
            this.subSort = 2
        } else {
            this.subSort = 1
        }
    },
    data() {
        return {
            subSort: '', // 提交类型：新增 1 / 修改 2
            open: false,
            warnAlertParams: {
              id: undefined, // id
              isWarn: 0, // 是否预警
              isDispose: 1,//是否处置
              remarks: undefined, // 预警处置
            },
            // 校验规则
            warnAlertParamsRules: {

            },

        }
    },
    methods: {

        /** 改变树结构 */
        changeTree(leaf) {
          leaf.map(item => {
            item.value = item.id
            if(item.children) {
              this.changeTree(item.children)
            }
          })
          return leaf
        },
        /** 级联选择器改变 */
        handleCas(e) {
          this.warnAlertParams.impUnit = e[e.length - 1]
        },
        /** 确认按钮 */
        onSubmit() {
          console.log(this.warnAlertParams)
            this.$refs.warnAlertParamsRef.validate(valid => {
                if (valid) {
                      this.warnAlertParams.isWarn = 0
                      // console.log(this.warnAlertParams+'-----------------------')
                      handleWarnAlertApi(this.warnAlertParams).then(res => {
                        this.$modal.msgSuccess('操作成功')
                        // 2. 成功之后通知父组件关闭弹框
                        this.$emit('closeDialog', true)
                      }).catch(err => {
                        console.log(err)
                      })

                }
            })
        },
    },
}
</script>

<style scoped>
::v-deep .el-select {
    width: 100%;
}
::v-deep .el-form-item__label{
  font-weight: normal;
}
</style>
