<template>
  <my-modal
    v-model:open="visible"
    title="重置密码"
    :width="400"
    @ok="submitHandle"
  >
    <qm-low-form
      :params="params"
      :fields="fields"
      :label-width="80"
      :rules="rules"
      ref="form"
    >
    </qm-low-form>
  </my-modal>
</template>
<script name="ResetPasswordDialog" lang="ts" setup>
import { ref } from "vue";
import { setValueFromObj } from "@/utils/tool";
import { resetUserPwd } from "@/ap/baseDataConfig";

const form = ref();

const visible = defineModel();
const emit = defineEmits(["success"]);
const props = defineProps<{ curRow: any }>();
const params = ref({
  password: "",
});
params.value = setValueFromObj(params.value, props.curRow);
const fields = ref([
  {
    prop: "password",
    label: "新密码",
    colSpan: 24,
    type: "password",
  },
]);
const rules = {
  password: [{ required: true, message: "请输入初始密码" }],
};

const submitHandle = () => {
  form.value.formRef.validate().then(() => {
    resetUserPwd({
      password: params.value.password,
      userId: props.curRow?.id,
    }).then((res: any) => {
      window.$message.success("操作成功");
      visible.value = false;
      emit("success");
    });
  });
};
</script>
<style lang="less" scoped></style>
