<template>

  <el-dialog
    v-model="state"
    width="600"
    class="event-handle-dialog"
    :align-center="true"
  >
    <template #header>
      <div class="header">处置</div>
    </template>
    
    <div class="container">

      <el-form :label-width="100">

        <el-form-item required label="处置：">
          <el-radio-group v-model="type">
            <el-radio :value="1">上报事件</el-radio>
            <el-radio :value="2">消除事件</el-radio>
          </el-radio-group>
        </el-form-item>

        <!-- <el-form-item v-if="type === 1" required label="处置人员：">

          <el-select :teleported="false" v-model="params.member" placeholder="请选择">
            <el-option
              v-for="item in []"
              :key="item.id"
              :value="item.id"
              :label="item.name"
            />
            <template #empty>
              没有数据
            </template>
          </el-select>
          
        </el-form-item> -->

        <el-form-item v-if="type === 2" required label="原因：">
          <el-input v-model="params.dispelCause" placeholder="请输入" :rows="5" resize="none" type="textarea" :maxlength="200" show-word-limit />
        </el-form-item>

      </el-form>

    </div>

    <template #footer >
  
      <div class="footer">
        <el-button :style="{ color: '#666666' }" @click="state = false">取消</el-button>
        <el-button v-loading="questing" @click="onSubmit" type="primary">确定</el-button>
      </div>

    </template>
  
  </el-dialog>
  
  </template>
  
  <script lang='ts' setup>
  
  import { ref, reactive, defineExpose } from 'vue'
  import { cancelEvent, postEvent } from '@/api/event'
  import { ElMessage } from 'element-plus'
  
  const state = ref(false)
  const type = ref(1)

  const params = reactive<any>({
    id: '',
    // member: [],
    dispelCause: ''
  })

  const questing = ref(false)
  
  const emits = defineEmits(['update'])
  
  const diaOpen = ({ id }) => {
    state.value = true
    params.id = id
    params.number = []
    params.dispelCause = ''
    type.value = 1
  }

  const onSubmit = () => {

    if (questing.value) {
      return
    }

    // 上报事件
    if (type.value === 1) {
      questing.value = true
      postEvent(params).then(res => {
        state.value = false
        ElMessage.success('操作成功！')
        emits('update')
      }).finally(() => {
        questing.value = false
      })
    }


    // 消除事件
    if (type.value === 2) {

      if(!params.dispelCause) return ElMessage.warning('请先填写原因！')

      questing.value = true
      cancelEvent(params).then(res => {
        if (res) {
          state.value = false
          ElMessage.success('操作成功！')
          emits('update')
        }
      }).finally(() => {
        questing.value = false
      })
    }

    
  }
  
  defineExpose({
    diaOpen
  })
  
  </script>
  
  <style lang='scss' scoped>
  
  .header {
    height: 48px;
    padding: 0px 20px;
    background: rgb(11, 36, 77);
    display: flex;
    align-items: center;
    color: white;
    font-size: 18px;
    font-weight: 600;
  }
  
  .container {
    padding: 12px 30px;
    box-sizing: border-box;
    position: relative;
    .lines {
      font-size: 14px;
      position: absolute;
      top: 12px;
      left: 12px;
      color: white;
      z-index: 2;
      line-height: 22px;
    }
  }

  .footer {
    // background: rgba(69, 116, 182, 0.36);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 24px 20px 24px;
    color: white;
  }
  
  </style>
  
  <style lang="scss">
  
  
  .event-handle-dialog {
    padding: 0;
    background: rgb(11, 36, 77);

    --el-text-color-regular: white;

    .el-button {
      // color: rgb(11, 36, 77);
    }

    .el-dialog__header {
      padding: 0;
    }

    .el-dialog__footer {
      padding-top: 0;
    }

    .el-select__wrapper.is-focused{
      box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
    }

    .el-textarea {
      .el-textarea__inner {
        border-radius: 0;
        background: transparent;
        box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
      }
      .el-input__count {
        background: transparent;
      }
    }

    .el-select__popper {
      background: #1B446D;
      border: none;
      color: white;
      .el-select-dropdown__empty {
        color: white;
      }
    }

    .el-popper.is-light .el-popper__arrow::before {
      border: none;
      background: #1B446D;
    }

  }
  
  </style>