<template>
  <a-modal
    :visible="true"
    :width="800"
    :title="$t('member.form.重置密码')"
    @cancel="handcancel(thethis)"
    :footer="null"
  >
    <a-spin :spinning="false">
      <a-form-model
        ref="ruleForm"
        :model="form"
        v-bind="formLayout"
        :rules="rules"
      >
        <a-form-model-item style="display: none">
          <a-input
            allow-clear
            autocomplete="off"
            v-decorator="['operateType']"
            type="hidden"
          />
          <a-input
            allow-clear
            autocomplete="off"
            v-model="form.memberId"
            type="hidden"
          />
        </a-form-model-item>
        <a-row class="form-row" :gutter="[16, 0]">
 
          <!-- 密码 -->
          <a-col
            :lg="12"
            :md="12"
            :sm="24"
            v-if="!(form && form.id && (form.id > 0 || form.id != ''))"
          >
            <a-form-model-item :label="$t('member.form.密码')" prop="password">
              <a-input-password
                :placeholder="$t('member.form.密码')"
                type="password"
                v-model="form.password"
              />
            </a-form-model-item>
          </a-col>
          <!-- 提交和重置 -->
          <a-col :lg="24" :md="24" :sm="24">
            <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
              <a-button type="primary" @click="on_Submit"> {{$t('提交')}} </a-button>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>
<script>
import {
  formLayout,
  rules,
  isHaveData,
  handcancel,
  LimitLength,
} from "@/common/components/Commonality/Form/js/form.js";
import { resetPassword, createPassword } from "@/baseConfigComponents/api/member.js";
export default {
  props: ["data", "that", "refresh"],
  mounted() {
    if (this.data && this.data.isModify) {
      this.form.status = !this.form.status;
      this.form.memberId = this.data.memberId;
      this.form.password = createPassword();
    }
  },
  data() {
    this.thethis = this;
    return {
      isModify: false,
      // 布局
      formLayout,
      // 表单初始格式
      form: {
        id: 0,
        memberId: 0,
        password: "",
      },
      // 验证规则
      rules: {
        password: [rules.required, rules.required, rules.LimitLength(0, 30)],
      },
    };
  },

  methods: {
    // 重置表单元素
    clearInfo() {
      this.form = {
        memberId: this.form.memberId,
        password: "",
      };
    },
    // 关闭
    handcancel,
    // 提交（更改）表单
    on_Submit(type) {
      var that = this;
      // 提示框确认
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          that.info = { ...that.form };
          resetPassword(that.info).then((res) => {
            that.$message.success("操作成功");
            // that.$emit("refresh");
            that.handcancel(that);
          });
        }
      });
    },
  },
  components: {},
};
</script>
