<template>
   <div class="obpm-sofetware-list">
      <div class="obpm-title">
        <div class="d-inline-block">
          <i class="el-icon-office-building title-icon"></i>
          <div class="title-name d-inline-block ml-2">{{$t('special_info')}}</div>
        </div>
        <div class="bar d-inline-block float-right">
          <el-button type="primary" size="small" @click="btnSave">{{$t("btns.save")}}</el-button>
          <el-button size="small" @click="goBack">{{$t("btns.exit")}}</el-button>
        </div>
      </div>
      <div class="mt-3">
        <el-form :inline="true" class="demo-form-inline" :rules="rules" label-width="100px" :model="user" ref="ruleForm">
          <el-row :gutter="20">
            <el-col :span="12">
               <el-form-item :label="$t('label.user_name')" prop="name">
                <el-input v-model="user.name" :placeholder="$t('placeholder.name')" size="small" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item :label="$t('label.account')"  prop="loginno">
                <el-input v-model="user.loginno" :placeholder="$t('placeholder.account')" size="small" clearable></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item :label="$t('label.password')">
                <el-input v-model="password" :placeholder="$t('placeholser.password')" type="password" size="small" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('label.email')">
                <el-input v-model="user.email" :placeholder="$t('placeholder.email')" size="small" clearable></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
   </div>
</template>

<script>
import { saveSuperuser } from "@/service/CommonApi.js";
export default {
  name: 'userinfo',
  props: [
    'user'
  ],
  data(){
    return{
      password: "12345678",
      rules: {
          name: [
            { required: true, message: this.$t('placeholder.name'), trigger: 'blur' },
          ],
          loginno: [
            { required: true, message: this.$t('placeholser.account'), trigger: 'blur' },
          ],
      }
    }
  },

  methods:{
    /**
     * 保存用户信息
     */
    btnSave(){
      this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            let loginpwd = "";
            let user = ""
            if(this.password != '12345678'){
              loginpwd = this.password;
              user = {
                ...this.user,
                loginpwd: loginpwd
              }
            }else{
              user = {
                ...this.user,
                loginpwd: '888888qqqq'
              }
            }
            saveSuperuser(user, {
              onSucess: response => {
                if (response.data.errcode == 0) {
                  this.$message({
                    message: this.$t('msg.ss'),
                    type: 'success'
                  });
                  this.$emit("editSuperuser", response.data.data);
                }else{
                  this.$message.error("$t('msg.error')")
                }
              }
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
    },

    /**
     * 返回
     */
    goBack(){
      this.$router.push({path: '/home/softwarelist'});
    }
  }
}
</script>