<template>
  <div>
    <el-dialog
      :visible.sync="formVisible"
      width="662px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :center="true"
    >
      <div class="form-title" slot="title">
        申请绑定社交账号
      </div>

      <div class="form-main">
        <div class="form-item">
          <div class="form-label">申请人：</div>
          <div class="form-content flex-center">
            <span
              :style="{
                'background-image': 'url(' + avatar + ')'
              }"
              class="form-avatar"
            ></span>
            <span class="name">{{ name }}</span>
          </div>
        </div>
        <div class="form-item">
          <div class="form-label">关联账户ID：</div>
          <div class="form-content">
            <div class="form-bind-area">
              <div class="band-wechat-btn">微信公众号</div>
              <div class="form-input">
                <el-input v-model="bandId" placeholder="账户ID"></el-input>
              </div>
            </div>
            <div class="form-bind-tips">
              打开微信公众号后台＞设置与开发＞公开信息＞微信号
            </div>
          </div>
        </div>
        <div class="form-item mt40">
          <div class="form-label">后台登录截图：</div>
          <div class="form-content">
            <multi-uploader
              v-model="certPic"
              :limit="9"
              tips="请上传JPG、PNG、JPEG格式图片，文件大小不超过1M"
              :file-size="1"
            ></multi-uploader>
          </div>
        </div>
      </div>

      <div class="submit-btn" @click="submit">提交申请</div>
    </el-dialog>
  </div>
</template>

<script>
import multiUploader from "@/components/multi-uploader";

export default {
  components: {
    multiUploader
  },
  data() {
    return {
      formVisible: false,
      uid: "",
      name: "",
      avatar:
        "https://inn.proginn.com/test/useralbum/10468/avatar104681620985269.jpg",
      bandId: "",
      certPic: [],
      loading: false
    };
  },
  methods: {
    show({ name, uid, avatar }) {
      this.name = name;
      this.uid = uid;
      this.avatar = avatar;

      this.bandId = "";
      this.certPic = [];
      this.formVisible = true;
    },
    async submit() {
      if (this.loading) {
        return;
      }
      if (this.bandId == "") {
        this.$message.error("请填写账户ID");
        return;
      }
      if (this.certPic.length == 0) {
        this.$message.error("请填写上传后台登录截图");
        return;
      }
      this.loading = true;
      let fileParams = this.certPic.map(item => item.url).join(",");
      let params = {
        type: 1,
        file: fileParams,
        account: this.bandId
      };
      let res = await this.$axios.$post("/uapi/enterprise/user_spider/add", {
        ...params
      });
      this.loading = false;
      if (Number(res.status) == 1) {
        this.$message.success("添加成功");
        this.formVisible = false;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.flex-center {
  display: flex;
  align-items: center;
}
.form-title {
  text-align: center;
  height: 20px;
  font-size: 18px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #0b121a;
  line-height: 20px;
}

.form-item {
  display: flex;
  margin-bottom: 14px;
}

.form-label {
  width: 120px;
  text-align: right;
  height: 21px;
  font-size: 15px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #000000;
  line-height: 21px;
}

.form-content {
  flex: 1;
  .name {
    font-size: 15px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;
  }
}

.form-avatar {
  width: 24px;
  height: 24px;
  border-radius: 100%;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  margin-right: 10px;
}
.form-bind-area {
  display: flex;
  align-items: center;
}

.band-wechat-btn {
  width: 123px;
  height: 40px;
  background: #308eff;
  border-radius: 2px;

  line-height: 40px;
  text-align: center;

  font-size: 15px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #ffffff;

  margin-right: 16px;
}
.form-input {
  margin-right: 16px;
}
.form-bind-tips {
  margin-top: 16px;
  font-size: 13px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #0b121a;
}
.mt40 {
  margin-top: 52px;
}

.submit-btn {
  margin: 90px auto 30px;

  width: 188px;
  height: 46px;
  background: #308eff;
  border-radius: 2px;

  text-align: center;
  line-height: 46px;

  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #ffffff;

  cursor: pointer;
}
</style>
