<template>
  <div class="page_personalSign">
    <div class="personalSignTitle">
      <i class="iconfont icon-zuojiantou jiantou" @click="$router.go(-1)"></i>
      <span class="titleName">个性签名</span>
       <span @click="spread" id="copy">修改</span>
    </div>
    <div class="nameBox">
      <van-field
        v-model="message"
        rows="1"
        autosize
        type="textarea"
        placeholder="请填写个性签名"
        maxlength="20"
        :readonly="readonly"
      />
    </div>
  </div>
</template>
<script>
import { getMyInforName, SaveMessage } from "@/api/patient/patient";
import { setRem } from "@/libs/functionRem";
export default {
  data() {
    return {
      message: "",
      admin_user_id: "",
      readonly: true,
      orgid: 0
    };
  },
  methods: {
    getMyInforName(id, orgid) {
      getMyInforName(id, orgid).then(response => {
        if (response.data.state === 1) {
          var Username = response.data.data.Username;
          this.message = Username.message;
        }
      });
    },
    spread() {
      var spancontent = document.getElementById("copy").innerHTML;
      if (spancontent == "修改") {
        this.readonly = false;
        document.getElementById("copy").innerHTML = "保存";
      }
      if (spancontent == "保存") {
        this.SaveMessage();
      }
    },
    SaveMessage() {
      const params = {
        id: this.admin_user_id,
        message: this.message,
        orgid: this.orgid
      };
      SaveMessage(params).then(response => {
        if (response.data.state === 1) {
          var role = response.data.data.role;
          this.$toast("保存成功");
          this.$router.push(
            "/myInfo?id=" + this.admin_user_id + "&orgid=" + this.orgid
          );
        }
      });
    }
  },
  created() {
    setRem();
    var id = this.$route.query.id;
    this.admin_user_id = id;
    var orgid = this.$route.query.orgid;
    this.orgid = orgid;
    this.getMyInforName(id, orgid);
  }
};
</script>

<style lang="scss" scoped>
.page_personalSign {
  height: 100%;
  overflow: hidden;
  background: #fafafa;
  .personalSignTitle {
    background: #fff;
    padding: 0 1.125rem;
    height: 3.125rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    span {
      font-size: 1rem;
    }
  }
  .jiantou {
    font-size: 1.5rem;
    font-weight: 600;
    margin-right: 1rem;
  }
  .titleName {
    font-size: 1.125rem !important;
    font-weight: 600;
  }
  .nameBox {
    margin-top: 1rem;
  }
}
</style>

<style lang="scss">
.page_personalSign {
  .nameBox {
    .van-field__control {
      font-size: 1rem;
    }
  }
}
</style>
