<template>
  <div class="Box" id="top">
    <div
      class="module_1"
      style="position: relative; background-color: #7868ca; height: 800px"
    >
      <video
        ref="videoPlayer"
        style="position: absolute; right: 250px"
        src="https://video.metavatar.cc/sv/979bc5a-18841d2371c/979bc5a-18841d2371c.mp4"
        max-width="800px"
        height="800px"
        autoplay
        muted
        controls
        loop="loop"
      />
      <!-- <img src="../../assets/img/metavatar_live/suiMang_live@2x.png" width="100%" height="100%" /> -->
      <div class="titleBox">
        <div class="title_item1" v-if="characters == 1">邃芒慧影</div>
        <div class="title_item1_y" v-if="characters == 1">
          数字人内容生产从未如此高效便捷
        </div>

        <div class="desc" v-if="characters == 1">
          <div>文字，语音，源视频多种驱动方式支持随时生产内容，紧跟热点</div>
          <div>高自然度，逼真度让您的数字人完全跨过恐怖谷</div>
        </div>
        <!-- 英文部分 -->
        <div class="title_item1" v-if="characters != 1">MetaNeuver</div>
        <div class="title_item1_y" v-if="characters != 1">
          Supports multimodal user input, text, voice, and source video.
        </div>

        <div class="desc" v-if="characters != 1">
          <div>
            Allows your digital human to seamlessly cross the uncanny valley,
            ensuring an immersive and believable experience.enabling content
            production at any time and keeping up with all the latest trends.
          </div>
          <div v-if="false">
            High naturalness and realism let your digital human completely cross
            the uncanny valley
          </div>
        </div>

        <div
          class="title_btn"
          @click="showBox"
          v-if="$store.state.publicObj.showTryItNow"
        >
          {{ characters == 1 ? "立刻体验" : "Try it now" }}
        </div>
      </div>
      <div class="md1" id="md1"></div>
    </div>

    <div class="module_2">
      <div class="title" v-if="characters == 1">
        只需
        <img
          src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/3@2x.png"
        />
        步完成一条数字人视频内容生成
      </div>
      <div class="title" v-if="characters != 1">
        Just
        <img
          src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/3@2x.png"
        />
        step to complete the generation of digital human video content
      </div>
      <div class="images">
        <li>
          <img
            v-if="characters == 1"
            src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/001@2x.png"
            alt=""
          />
          <img
            v-if="characters != 1"
            src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/001_en.jpg"
            alt=""
          />
        </li>
        <li>
          <img
            v-if="characters == 1"
            src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/002@2x.png"
            alt=""
          />
          <img
            v-if="characters != 1"
            src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/002_en.jpg"
            alt=""
          />
        </li>
        <li>
          <img
            v-if="characters == 1"
            src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/003@2x.png"
            alt=""
          />
          <img
            v-if="characters != 1"
            src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/003_en.jpg"
            alt=""
          />
        </li>
        <li class="videoLi">
          <div class="imgBox1" @click="goSetVedio(isPlayed)">
            <img
              v-if="isPlayed"
              class="play"
              src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/play.png"
              title="click to play"
            />
            <img
              v-else
              class="play"
              src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/pause.png"
              title="click to pause"
            />
            <!-- <video ref="videoII" src="https://video.metavatar.cc/sv/2474483a-188345f1cb5/2474483a-188345f1cb5.mp4" /> -->
            <video
              ref="videoII"
              src="https://video.metavatar.cc/sv/979bc5a-18841d2371c/979bc5a-18841d2371c.mp4"
            />
          </div>
          <!-- <img src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/004@2x.png" alt="" /> -->
        </li>
      </div>
    </div>

    <div class="module_3">
      <div class="title" v-if="characters == 1">中之人驱动</div>
      <div class="title" v-if="characters != 1">“中の人” driving</div>
      <img
        v-if="characters == 1"
        src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/huibo333_zh.png"
        alt=""
      />
      <img
        v-if="characters != 1"
        src="https://suimang.oss-accelerate.aliyuncs.com/builtin/static/pc/assets/img/metavatar_live/huibo333_1_en.png"
        alt=""
      />
    </div>

    <el-dialog
      :title="
        characters == 1
          ? '留下您的信息，我们会尽快与您取得联系'
          : 'Tell us about yourself, we ll be in touch right away.'
      "
      :visible.sync="dialogVisible"
      width="34%"
    >
      <el-form
        ref="form"
        :rules="characters == 1 ? rules : rulesEnglish"
        :model="form"
      >
        <el-form-item class="width" prop="name">
          <el-input
            v-model="form.name"
            maxlength="10"
            :placeholder="characters == 1 ? '姓名' : 'Name'"
          ></el-input>
        </el-form-item>
        <el-form-item class="width" prop="phone">
          <el-input
            v-model="form.phone"
            :placeholder="characters == 1 ? '手机' : 'Phone'"
          ></el-input>
        </el-form-item>
        <el-form-item class="width" prop="email">
          <el-input v-model="form.email" placeholder="Email"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">{{
          characters == 1 ? "取 消" : "Cancel"
        }}</el-button>
        <el-button type="primary" @click="submit()">{{
          characters == 1 ? "提 交" : "Submit"
        }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import "swiper/dist/js/swiper";
import "swiper/dist/css/swiper.css";
import Swiper from "swiper";
import { mapState, mapActions } from "vuex";

export default {
  data() {
    return {
      isPlayed: true,
      //零时存放
      charactersMy: 1,
      //

      userName: "",
      phone: "",
      email: "",

      form: {
        name: "",
        phone: "",
        email: "",
      },

      rules: {
        name: [
          {
            required: true,
            min: 1,
            max: 10,
            message: "此项必填，内容最大10个字符!",
            trigger: "blur",
          },
        ],
        phone: [
          {
            required: true,
            trigger: "change",
            message: "请先输手机号",
            trigger: "blur",
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              // var mobile = /^1[0|1|2|3|4|5|6|7|8|9]\d{9}$/,
              let phone = /^1[35789]\d{9}$/;
              if (value && !phone.test(value)) {
                callback("抱歉，请输入正确的手机号");
              }
              callback(errors);
            },
          },
        ],
        email: [
          {
            required: true,
            trigger: "change",
            message: "请输入邮箱!",
            trigger: "blur",
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              // var mobile = /^1[0|1|2|3|4|5|6|7|8|9]\d{9}$/,
              let email = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
              if (value && !email.test(value)) {
                callback("抱歉，请输入正确的邮箱");
              }
              callback(errors);
            },
          },
        ],
      },
      rulesEnglish: {
        name: [
          {
            required: true,
            min: 1,
            max: 10,
            message: "This item is required !",
            trigger: "blur",
          },
        ],
        phone: [
          {
            required: true,
            trigger: "change",
            message: "Please enter your cell phone number",
            trigger: "blur",
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              let phone = /^1[35789]\d{9}$/;
              if (value && !phone.test(value)) {
                callback("Sorry, please enter the correct cell phone number");
              }
              callback(errors);
            },
          },
        ],
        email: [
          {
            required: true,
            trigger: "change",
            message: "Please enter email!",
            trigger: "blur",
          },
          {
            validator(rule, value, callback, source, options) {
              var errors = [];
              let email = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
              if (value && !email.test(value)) {
                callback("Sorry, please enter the correct email address");
              }
              callback(errors);
            },
          },
        ],
      },
      // characters: 1, //1=》中文 2=》英文
      timeFlag: 5,
      dialogVisible: false,
    };
  },
  methods: {
    ...mapActions(["setCharacters"]),

    goSetVedio(flag) {
      if (flag) {
        this.$refs["videoII"].play();
      } else {
        this.$refs["videoII"].pause();
      }
      this.isPlayed = !flag;
    },
    change(value) {
      console.log(value);
      this.setCharacters(value);
    },

    showBox() {
      this.dialogVisible = true;
    },
    goView(id) {
      document.querySelector("#" + id).scrollIntoView({
        behavior: "smooth", //定义动画过渡效果"auto"或 "smooth" 之一。默认为 "auto"。
        block: "start", //定义垂直方向的对齐， "start", "center", "end", 或 "nearest"之一。默认为 "start"。
        inline: "nearest", //"start", "center", "end", 或 "nearest"之一。默认为 "nearest"。
      });
      // console.log(document.querySelector(id),);
    },
    goPages(path) {
      this.$router.push(`/${path}`);
    },
    submit() {
      this.$refs.form.validate((valid) => {
        console.log(valid);
        if (valid) {
          let params = {
            mallName: this.form.email, //邮箱
            applicant: this.form.name, //姓名
            phone: this.form.phone, //电话
          };
          this.$axios({
            method: "post",
            url: "/C/api/wxMallApply/add",
            headers: {
              "Content-Type": "application/json;charset=UTF-8",
            },
            data: params,
          })
            .then((res) => {
              this.form.email = "";
              this.form.name = "";
              this.form.phone = "";
              this.$message.success(
                this.characters == 1 ? "提交成功" : "submit successfully"
              );
              this.dialogVisible = false;
            })
            .catch((err) => {
              this.$message.error(err.message);
            });
        }
      });
    },
  },
  computed: {
    ...mapState({
      characters: (state) => state.publicObj.characters,
    }),
  },

  mounted() {
    // console.log();
    // this.$refs["vidoe"].play();
    new Swiper(".swiper-container", {
      slidesPerView: 3,
      spaceBetween: 30,
      centeredSlides: true,
      loop: true,

      // 如果需要分页器
      pagination: {
        el: ".swiper-pagination",
        clickable: true, // 分页器可以点击
      },

      // 如果需要前进后退按钮
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },

      // 如果需要滚动条
      scrollbar: {
        el: ".swiper-scrollbar",
      },
    });
  },
  created() {
    this.$nextTick(() => {
      this.goView("top");
      this.$refs.videoPlayer.muted = false;
      this.$refs.videoPlayer.play();
    });
  },
};
</script>

<style lang="scss" scoped>
.Box {
  width: 100%;
  overflow: hidden;
}
.topBox {
  width: 90%;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  // background-color: rgba(255, 255, 255, 0.1);
}
.logoBox {
  margin-top: 35px;
  margin-left: 35px;
  margin-bottom: 35px;
  float: left;
  overflow: hidden;
}
.logo {
  float: left;
  //   width: 60px;
  //   height: 30px;
}
.logoTitle {
  float: left;
  line-height: 30px;
  margin-left: 10px;
  font-size: 22px;
}
.categoryBox {
  height: 30px;
  width: 600px;
  float: left;
  margin-top: 20px;
  margin-left: 16%;
  display: flex;
  justify-content: space-between;
  cursor: pointer;
}
.categoryitem {
  width: 110px;
  line-height: 30px;
  color: #7d7d7d;
  font-size: 15px;
  // background-color: #16e9d6
}
.cutBox {
  float: right;
  margin-top: 35px;
  margin-right: 50px;
  overflow: hidden;
  cursor: pointer;
}
.cutImg {
  width: 30px;
  height: 20px;
  float: left;
  margin-top: 10px;
  margin-right: 10px;
}
.en {
  float: left;
  font-size: 15px;
}

.module_1 {
  width: 100%;
  // height: 1080px;
  // background-color: aquamarine;
  // background-image: url("../../assets/img/bg.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  overflow: hidden;
  position: relative;
  margin-top: 80px;
  background-color: #f1f4f7;
  .titleBox {
    width: 36%;
    position: absolute;
    top: 240px;
    left: 194px;
    overflow: hidden;
    // color: #323232;
    color: #fff;
    .title_item1 {
      margin-bottom: 14px;
      font-size: 60px;
    }
    .title_item1_y {
      // margin-bottom: 14px;
      font-size: 36px;
    }
    .title_item2 {
      margin-bottom: 20px;
      font-size: 42px;
    }
    .title_item3 {
      font-size: 16px;
      line-height: 30px;
    }
    .title_btn {
      margin-top: 60px;
      height: 60px;
      width: 220px;
      text-align: center;
      line-height: 60px;
      color: #fff;
      // color: #323232;
      border-radius: 40px;
      border: #fff solid 3px;
      // border: #323232 solid 3px;
      font-size: 18px;
      cursor: pointer;
      transition: all 0.3s;
      &:hover {
        color: #16e9d6;
        border: #16e9d6 solid 3px;
      }
    }
    .desc {
      margin-top: 29px;
      font-size: 16px;
      line-height: 36px;
    }
  }
}
.module_2 {
  height: 760px;
  background: #ffffff;
  padding-top: 32px;
  padding-left: 116px;
  padding-right: 85px;

  .title {
    text-align: center;
    margin-bottom: 72px;
    font-size: 36px;
    img {
      position: relative;
      top: 18px;
      width: 59px;
      height: 60px;
    }
  }
  .images {
    display: flex;
    justify-content: space-between;
    li {
      list-style: none;
      margin-right: 9px;
      > img {
        width: 423px;
        height: 540px;
        cursor: pointer;
        transition: all 0.3s;
        &:hover {
          box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.548);
          transform: translateY(-20px);
        }
      }
    }
  }

  .videoLi {
    overflow: hidden;
    .imgBox1 {
      position: relative;
      float: left;
      width: 100%;
      height: 100%;
      cursor: pointer;
      .play {
        position: absolute;
        top: 42%;
        left: 38%;
        transform: translate(-50%, -50%);
        width: 100px;
        height: 100px;
        z-index: 99;
        transition: all 0.3s;
        transform: scale(10);
        opacity: 0;
      }
      // background-color: #16e9d6;
      video {
        background-color: #7868ca;
        width: 423px;
        height: 540px;
      }
      &:hover {
        .play {
          transform: scale(1);
          opacity: 1;
        }
      }
    }
  }
}
.module_3 {
  height: 810px;
  background-color: #ebeef7;
  padding-top: 33px;
  text-align: center;
  transition: all 0.3s;
  .title {
    text-align: center;
    font-size: 48px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #4d4d4d;
    line-height: 36px;
    margin-bottom: 44px;
  }
  img {
    width: 1250px;
    height: 665px;
    opacity: 0.85;
    transition: all 0.3s;
    &:hover {
      opacity: 1;
    }
  }
}
</style>
