<template>
  <view>
    <view class="tips"></view>
    <view class="search_container">
      <input
        type="text"
        v-model="inputValue1"
        class="search_public"
        confirm-type="done"
        disabled="true"
      />
      <button class="search_btn" type="submit" @click="getSubmit1">前往</button>
    </view>

    <view class="search_container marTop20">
      <input
        type="text"
        v-model="inputValue2"
        class="search_public"
        disabled="true"
      />
      <button class="search_btn" type="submit" @click="getSubmit2">前往</button>
    </view>
  </view>
</template>
  
  <script>
import { deviceUrlInfo } from "@/api/public.js";
export default {
  data() {
    return {
      state: "",
      openId: "",
      flowUrl: "",
      wifiUrl: "",
      inputValue1: "流量充值",
      inputValue2: "远程配网",
    };
  },
  onLoad(e) {
    this.state = e.state;
    this.openId = e.openId;
    this.deviceUrlInfo();
  },

  methods: {
    ///获取用户信息
    deviceUrlInfo() {
      deviceUrlInfo({
        state: this.state,
        openId: this.openId,
      }).then((res) => {
        if (res.code === 0) {
          this.flowUrl = res.data.flowUrl;
          this.wifiUrl = res.data.wifiUrl;
        }
      });
    },

    getSubmit1() {
      if (this.flowUrl.length === 0) {
        deviceUrlInfo({
          state: this.state,
          openId: this.openId,
        }).then((res) => {
          if (res.code === 0) {
            this.flowUrl = res.data.flowUrl;
            this.wifiUrl = res.data.wifiUrl;
            window.location.href = this.flowUrl;
          } else {
            uni.showToast({
              title: res.message,
              icon: "none",
              mask: true,
              duration: 2000,
            });
          }
        });
      } else {
        window.location.href = this.flowUrl;
      }
    },

    getSubmit2() {
      if (this.wifiUrl.length === 0) {
        deviceUrlInfo({
          state: this.state,
          openId: this.openId,
        }).then((res) => {
          if (res.code === 0) {
            this.flowUrl = res.data.flowUrl;
            this.wifiUrl = res.data.wifiUrl;
            window.location.href = this.wifiUrl;
          } else {
            uni.showToast({
              title: res.message,
              icon: "none",
              mask: true,
              duration: 2000,
            });
          }
        });
      } else {
        window.location.href = this.wifiUrl;
      }
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.tips {
  padding-top: 45%;
  margin-left: 20rpx;
  margin-right: 20rpx;
  font-size: 30rpx;
}

.search_container {
  display: flex;
  flex-direction: row;
  margin-top: 20rpx;
}

.search_public {
  background: #ededed;
  height: 80rpx;
  line-height: 80rpx;
  margin-left: 40rpx;
  margin-right: 20rpx;
  border-radius: 50rpx;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: black;
}

.search_btn {
  height: 80rpx;
  line-height: 80rpx;
  margin-top: 20rpx;
  width: 200rpx;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 30rpx;
  border-radius: 50rpx;
  margin-right: 40rpx;
}

.marTop20 {
  margin-top: 50rpx;
}

.explain {
  font-size: 25rpx;
  margin-top: 40rpx;
  margin-left: 20rpx;
  margin-right: 20rpx;
}
</style>