<template>
  <el-dialog
    class="resetpwd-model"
    v-model="state"
    width="600"
    :destroy-on-close="true"
    :align-center="true"
    @closed="onClosed"
  >
    <div class="title">
      <div class="text">重置密码</div>
      <Icon @click="goClose" class="close" icon="ep:close" />
    </div>

    <div :class="['content']">
      <el-form ref="formRef" :model="params" :rules :show-message="false">
        <div class="block-container road-setting">
          <el-form-item prop="password" label="新密码：">
            <el-input v-model="params.password" placeholder="请输入..." />
          </el-form-item>
        </div>
      </el-form>
    </div>

    <template #footer>
      <div class="footer">
        <el-button @click="goClose">取消</el-button>
        <el-button @click="onSubmit" type="primary">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { defaultProps, handleTree } from '@/utils/tree'
import {
  getSimpleDeptList,
  getroleList,
  userCreate,
  getDetails,
  updateUser,
  resetUserPwd
} from '@/api/system/user'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
const emits = defineEmits(['update'])

const state = ref(false)
const row = ref({})
const params = reactive({})
const rules = reactive<any>({
  password: [{ required: true }]
})
const formRef = ref(null)
const diaOpen = async (e) => {
  if (e) {
    row.value = e
  }
  state.value = true
}

const goClose = () => {
  state.value = false
}
const onClosed = () => {
  params.password = ''
}
// 提交
const onSubmit = async () => {
  const base = await new Promise((resolve) => {
    formRef.value?.validate((e) => {
      resolve(e)
    })
  })
  if (!base) {
    return ElMessage.error('请完成数据填写！')
  }
  let res = await resetUserPwd(row.value.id, params.password)
  if (res) {
    goClose()
    return ElMessage.success('重置密码成功！')
  }
}

defineExpose({
  diaOpen
})
</script>

<style lang="scss" scoped>
$base_url: '@/assets/images/home/';

.title {
  height: 48px;
  display: flex;
  align-content: center;
  align-items: center;
  color: white;
  padding: 0 20px;
  font-size: 18px;
  font-weight: 600;
  justify-content: space-between;
  .close {
    cursor: pointer;
  }
}

.content {
  padding: 0 16px;
  // height: 600px;

  .block-container {
    padding-right: 24px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-top: 20px;
  }

  &.disabled {
    :deep(.base-block) {
      pointer-events: none;
    }
    :deep(.road-setting) {
      pointer-events: none;
    }
    :deep(.el-input) {
      background: rgba($color: #ffffff, $alpha: 0.2);
    }
  }
}

.footer {
  // background: rgba(69, 116, 182, 0.36);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 20px 24px;
  color: white;
}
</style>

<style lang="scss">
.resetpwd-model {
  padding: 0;
  box-sizing: border-box;
  // border: 1px solid rgba(255, 255, 255, 0.5);
  background: #0d3561;
  border-radius: 4px;

  .el-dialog__header {
    display: none;
  }
  .el-dialog__footer {
    padding-top: 0;
  }
  .def-btn {
    background: #1270ff;
    border: 1px solid rgba(155, 193, 255, 0.74);
    height: 28px;
    padding: 8px 10px;
    color: white;
    &:hover {
      border: 1px solid rgba(255, 255, 255, 0.8);
    }
  }
}
</style>
