<template>
  <div class="silderWrap">
    <div class="silderList">
      <div class="silderItem"
           @click="visiable =true">
        <img src="@/assets/images/silder/silder4.svg"
             alt />
        <p>申请入驻</p>
        <div class="line"></div>
      </div>
      <el-popover placement="left"
                  trigger="hover"
                  popper-class="Mopopver">
        <div>
          <p class="hoverTitle">咨询电话：</p>
          <p class="hoverMsg">400-8851569</p>
        </div>
        <div class="silderItem"
             slot="reference">
          <img src="@/assets/images/silder/silder2.svg"
               alt />
          <p>电话咨询</p>
          <div class="line"></div>
        </div>
      </el-popover>
      <el-popover placement="left"
                  trigger="hover"
                  popper-class="Mopopver">
        <div>
          <div class="code-item">
            <img src="../assets/images/download.png"
                 width="111px"
                 height="111px"
                 alt />
            <p>扫码下载APP</p>
          </div>
        </div>
        <div class="silderItem"
             slot="reference">
          <img src="@/assets/images/silder/silder3.svg"
               alt />
          <p>APP下载</p>
          <div class="line"></div>
        </div>
      </el-popover>
      <el-popover placement="left"
                  trigger="hover"
                  popper-class="Mopopver">
        <div>
          <div class="code-item">
            <img src="../assets/images/public-code.jpg"
                 width="111px"
                 height="111px"
                 alt />
            <p>微信订阅号</p>
          </div>
        </div>
        <div class="silderItem"
             slot="reference">
          <img src="@/assets/images/silder/silder1.svg"
               alt />
          <p>关注微信</p>
          <!-- <div class="line"></div> -->
        </div>
      </el-popover>
    </div>
    <div class="goTop"
         v-if="showgo"
         @click="gotop">
      <img src="@/assets/images/silder/silder5.svg"
           alt />
    </div>
    <el-dialog title="申请入驻"
               :visible.sync="visiable"
               append-to-body
               width="450px"
               :close-on-click-modal="false"
               destroy-on-close>
      <el-form ref="form"
               :model="form"
               :rules="maskRules">
        <el-form-item prop="name">
          <el-input v-model="form.name"
                    placeholder="请输入机构名称"></el-input>
        </el-form-item>
        <el-form-item prop="city">
          <el-input v-model="form.city"
                    placeholder="请输入所在城市"></el-input>
        </el-form-item>
        <el-form-item prop="linkman">
          <el-input v-model="form.linkman"
                    placeholder="请输入联系人姓名"></el-input>
        </el-form-item>
        <el-form-item prop="mobileNo">
          <el-input v-model="form.mobileNo"
                    placeholder="请输入手机号"></el-input>
        </el-form-item>
        <p class="submsg">我们会在您提交信息后24小时内与您取得联系，请保持电话畅通</p>
        <el-form-item>
          <div class="submitBtn"
               @click="submitInfo">提交</div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import axios from "axios";
import qs from 'qs'
import Bus from '../views/index/blocks/eventBus'
import { scrollAnimation } from '@/util/scroll'
export default {
  props: ["showForm"],
  data () {
    return {
      showgo: false,
      visiable: false,
      form: {
        name: "",
        city: "",
        linkman: "",
        mobileNo: "",
      },
      maskRules: {
        name: [{ required: true, message: "请输入机构名称" }],
        city: [{ required: true, message: "请输入所在城市" }],
        linkman: [{ required: true, message: "请输入联系人姓名" }],
        mobileNo: [
          { required: true, message: "请输入手机号" },
          {
            pattern: /^1[3456789]\d{9}$/,
            message: "请输入正确的手机号",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created () {
    Bus.$on('joinIn', (res => {
      console.log(res)
      this.visiable = res
    }))
  },
  mounted () {
    var vm = this;
    window.onscroll = function () {
      if (document.documentElement.scrollTop > 300) {
        vm.showgo = true;
      } else {
        vm.showgo = false;
      }
    };
  },
  methods: {
    gotop () {
      const currentY = document.documentElement.scrollTop || document.body.scrollTop
      scrollAnimation(currentY, 0)
    },
    submitInfo () {
      this.$refs["form"].validate((res) => {
        if (res) {
          console.log("发送请求");
          axios({
            url: "https://test.kj.colexiu.com/api-user/tenantApply/add",
            method: "post",
            data: qs.stringify(this.form),
            headers: {
              "Content-type": "application/x-www-form-urlencoded",
            },
          }).then((res) => {
            if (res.data.code === 200) {
              this.$message.success("发送成功");
              this.visiable = false;
            } else {
              this.$message.error("发送失败");
            }
          });
        }
      });
    },
  },
  watch: {
    showForm (val) {
      console.log('调用')
      this.visiable = val;
    },
    visiable (val) {
      this.$emit("changeStatus", val);

      if (!val) {
        this.$nextTick(() => {
          this.$refs["form"].resetFields();
        })

      }
    },
  },
};
</script>
<style lang="less">
.silderWrap {
  position: fixed;
  top: 50%;
  right: 70px;
  z-index: 200;
  .silderList {
    background-color: #fff;
    width: 64px;
    height: 268px;

    border: 1px solid #ececec;

    .silderItem {
      cursor: pointer;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 11px 0 0;
      font-size: 12px;
      overflow: hidden;
      p {
        margin-top: 8px;
        color: #666666;
      }
      .line {
        margin-top: 10px;
        width: 48px;
        height: 1px;
        background-color: #ececec;
      }
      &:hover {
        p {
          color: #2dc7aa;
        }
        img {
          filter: drop-shadow(#2dc7aa 80px 0);
          transform: translateX(-80px);
        }
      }
    }

    .silderItem {
      cursor: pointer;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 11px 0 0;
      font-size: 12px;
      overflow: hidden;
      p {
        margin-top: 8px;
        color: #666666;
      }
      .line {
        margin-top: 10px;
        width: 48px;
        height: 1px;
        background-color: #ececec;
      }
      &:hover {
        p {
          color: #2dc7aa;
        }
        img {
          filter: drop-shadow(#2dc7aa 80px 0);
          transform: translateX(-80px);
        }
      }
    }
  }

  .goTop {
    cursor: pointer;
    margin-top: 20px;
    background-color: #fff;
    width: 64px;
    height: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 28px;
    border: 1px solid #ececec;
    overflow: hidden;
    &:hover {
      img {
        filter: drop-shadow(#2dc7aa 80px 0);
        transform: translateX(-80px);
      }
    }
  }
}
.submitBtn {
  width: 100%;
  height: 50px;
  line-height: 50px;
  background-color: #2dc7aa;
  color: #fff;
  text-align: center;
  border-radius: 5px;
  margin-top: 50px;
  cursor: pointer;
  &:hover {
    background-color: #2ac0a3;
  }
}
.submsg {
  color: #999;
}
.Mopopver {
  /deep/.code-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .hoverTitle {
    font-size: 12px;
    font-weight: 400;
    color: #999999;
    line-height: 17px;
  }
  /deep/.hoverMsg {
    padding-top: 5px;
    font-size: 16px;
    color: #1a1a1a;
    line-height: 22px;
    font-weight: 700;
  }
  .silderItem {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 11px 0 0;
    font-size: 12px;
    overflow: hidden;
    p {
      margin-top: 8px;
      color: #666666;
    }
    .line {
      margin-top: 10px;
      width: 48px;
      height: 1px;
      background-color: #ececec;
    }
    &:hover {
      p {
        color: #2dc7aa;
      }
      img {
        filter: drop-shadow(#2dc7aa 80px 0);
        transform: translateX(-80px);
      }
    }
  }
}
</style>