<template>
  <view class="page-box">
    <navBar title="转让企业" color="#000" />

    <view class="page-content">
      <!-- <view class="text-center text-red bg-white">{{form.remek}}</view> -->
      <view class="padding">
        <view class="padding bg">
          <u-form
            :model="forms"
            ref="uForm"
            label-position="top"
            :label-style="lableStyle"
          >
            <u-form-item label="本人手机号" :border-bottom="false">
              <u-input
                :disabled="true"
                placeholder="请填写本人手机号"
                v-model="forms.phone"
                inputAlign="text-alight:left"
              />
            </u-form-item>
            <view
              class="margin-bottom"
              style="width: 100%; height: 1rpx; background: #f2f2f2"
            ></view>
            <u-form-item label="短信验证码" :border-bottom="false">
              <view class="flex align-center justify-between" style="width: 100%">
                <u-input
                  placeholder="请填写（必填）"
                  v-model="forms.code"
                  inputAlign="text-alight:left"
                />
                <view class="buttons" @tap="getCode">
                  {{ tips }}
                  <!-- <u-button class="buttons" @tap="getCode">{{tips}}</u-button> -->
                </view>
                <u-toast ref="uToast"></u-toast>
                <u-verification-code
                  :seconds="seconds"
                  @end="end"
                  @start="start"
                  ref="uCode"
                  @change="codeChange"
                ></u-verification-code>
              </view>
            </u-form-item>
            <view
              class="margin-bottom"
              style="width: 100%; height: 1rpx; background: #f2f2f2"
            ></view>
            <u-form-item label="转让人手机号" :border-bottom="false">
              <u-input
                placeholder="请填写（必填） "
                v-model="forms.phone2"
                inputAlign="text-alight:left"
              />
            </u-form-item>
          </u-form>
        </view>

        <view class="margin-top padding bg">
          <u-form
            :model="forms"
            ref="uForm"
            label-position="top"
            :label-style="lableStyle"
          >
            <u-form-item label="企业名称" :border-bottom="false">
              <u-input
                placeholder="请输入企业名称"
                :disabled="true"
                v-model="qiyeInfo.companyName"
                inputAlign="text-alight:left"
              />
            </u-form-item>
            <view
              class="margin-bottom"
              style="width: 100%; height: 1rpx; background: #f2f2f2"
            ></view>
            <view
              class="margin-bottom"
              style="width: 100%; height: 1rpx; background: #f2f2f2"
            ></view>
            <u-form-item label="营业地址" :border-bottom="false">
              <u-input
                placeholder="请输入营业地址"
                :disabled="true"
                v-model="qiyeInfo.companyAddress"
                inputAlign="text-alight:left"
              />
            </u-form-item>
            <view
              class="margin-bottom"
              style="width: 100%; height: 1rpx; background: #f2f2f2"
            ></view>
            <u-form-item label="经营范围" :border-bottom="false">
              <u-input
                placeholder="请输入经营范围"
                :disabled="true"
                v-model="qiyeInfo.companyScope"
                inputAlign="text-alight:left"
              />
            </u-form-item>
            <view
              class="margin-bottom"
              style="width: 100%; height: 1rpx; background: #f2f2f2"
            ></view>
            <u-form-item label="注册资金(万)" :border-bottom="false">
              <u-input
                placeholder="请输入注册资金(万)"
                :disabled="true"
                v-model="qiyeInfo.companyRegisteredFund"
                inputAlign="text-alight:left"
              />
            </u-form-item>
            <view
              class="margin-bottom"
              style="width: 100%; height: 1rpx; background: #f2f2f2"
            ></view>
            <u-form-item label="注册时间" :border-bottom="false">
              <u-input
                placeholder="请输入注册时间"
                :disabled="true"
                v-model="qiyeInfo.createTime"
                inputAlign="text-alight:left"
              />
            </u-form-item>
            <view
              class="margin-bottom"
              style="width: 100%; height: 1rpx; background: #f2f2f2"
            ></view>
            <u-form-item label="资质简介" :border-bottom="false">
              <u-input
                placeholder="请输入资质简介"
                :disabled="true"
                v-model="qiyeInfo.companyDetails"
                inputAlign="text-alight:left"
              />
            </u-form-item>
          </u-form>
        </view>

        <u-button
          @click="submit()"
          class="margin-top"
          :custom-style="customStyle"
          shape="square"
          :hair-line="false"
        >
          转让
        </u-button>
      </view>
    </view>
  </view>
</template>

<script>
import navBar from "@/components/nav-bar/index.vue";

export default {
  data() {
    return {
      forms: {
        phone: "",
        phone2: "",
        code: "",
      },
      // disabled: false,
      lableStyle: {
        color: "#000000",
        fontSize: "30upx",
        fontWeight: "bold",
      },
      customStyle: {
        backgroundColor: "#016BF6",
        color: "#FFFFFF",
        border: 0,
      },
      tips: "",
      // refCode: null,
      seconds: 60,
      qiyeInfo: {},
    };
  },
  components: {
    navBar,
  },
  onLoad(e) {
    this.getQiyeInfo();
    this.forms.phone = uni.getStorageSync("phone");
  },
  onShow() {},
  methods: {
    //查询用户企业
    getQiyeInfo() {
      this.$Request
        .getT("/app/company/selectCompanyByUserId", {
          userId: uni.getStorageSync("userId"),
        })
        .then((res) => {
          if (res.code === 0) {
            this.qiyeInfo = res.data;
          } else {
            uni.showModal({
              showCancel: false,
              title: "查询失败",
              content: res.msg,
            });
          }
        });
    },
    //提交转让
    submit() {
      if (this.forms.phone == "") {
        uni.showToast({
          title: "请输入本人手机号",
          icon: "none",
        });
        return;
      }
      if (this.forms.code == "") {
        uni.showToast({
          title: "请输入验证码",
          icon: "none",
        });
        return;
      }
      if (this.forms.phone2 == "") {
        uni.showToast({
          title: "请输入转让人手机号",
          icon: "none",
        });
        return;
      }
      if (this.forms.phone == this.forms.phone2) {
        uni.showToast({
          title: "请勿转让企业给自己",
          icon: "none",
        });
        return;
      }
      let data = {
        phone: this.forms.phone,
        msg: this.forms.code,
        givePhone: this.forms.phone2,
      };
      this.$Request.post("/app/company/giveCompany", data).then((res) => {
        if (res.code === 0) {
          // uni.showToast({
          // 	title: '转让成功'
          // })
          this.forms = {
            phone: "",
            code: "",
            phone2: "",
          };
          this.goOut();
          // this.getQiyeInfo();
        } else {
          uni.showModal({
            showCancel: false,
            title: "提示",
            content: res.msg,
            confirmColor: "#016BF6",
          });
        }
      });
    },
    goOut() {
      let that = this;
      uni.removeStorageSync("userName");
      uni.removeStorageSync("avatar");
      uni.removeStorageSync("userId");
      uni.removeStorageSync("token");
      uni.removeStorageSync("phone");
      // uni.removeStorageSync('userType')
      uni.removeStorageSync("zhiFuBaoName");
      uni.removeStorageSync("zhiFuBao");
      uni.removeStorageSync("invitationCode");
      uni.removeStorageSync("unionId");
      uni.removeStorageSync("openId");
      uni.removeStorageSync("isVIP");
      // uni.removeStorageSync('userType')
      uni.setStorageSync("userType", 1);
      uni.showToast({
        title: "转让成功,请重新登录！",
        icon: "none",
      });
      setTimeout(() => {
        // uni.reLaunch({
        // 	url:'/pages/public/selectIdentity/selectIdentity'
        // })
        // uni.switchTab({
        // 	url:'/pages/my/index?out=yes'
        // })
        uni.reLaunch({
          url: "/pages/my/index",
        });
      }, 1000);
    },
    codeChange(text) {
      this.tips = text;
    },
    getCode() {
      if (this.$refs.uCode.canGetCode) {
        // 模拟向后端请求验证码
        uni.showLoading({
          title: "正在获取验证码",
        });
        let str = /^[1][3,5,7,8,9][0-9]{9}$/;
        let mobile = this.forms.phone;
        if (str.test(mobile) == false) {
          uni.showToast({
            title: "请输入正确的手机号",
            icon: "none",
          });
          return;
        }
        this.$Request.getT("/app/Login/sendMsg/" + mobile + "/forget").then((res) => {
          if (res.code === 0) {
            uni.hideLoading();
            // 这里此提示会被this.start()方法中的提示覆盖
            this.$u.toast("验证码已发送");
            // 通知验证码组件内部开始倒计时
            this.$refs.uCode.start();
          } else {
            uni.hideLoading();
            uni.showModal({
              showCancel: false,
              title: "短信发送失败",
              content: res.msg ? res.msg : "请一分钟后再获取验证码",
            });
          }
        });
      } else {
        this.$u.toast("倒计时结束后再发送");
      }
    },
    end() {
      this.$u.toast("倒计时结束");
    },
    start() {
      this.$u.toast("倒计时开始");
    },
  },
};
</script>

<style lang="less" scoped>
page {
  background-color: #f7f7f7;
}
.page-box {
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  top: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  .page-content {
    flex: 1;
    overflow: hidden;
    overflow-y: auto;
  }
}
.bg {
  background-color: #ffffff;
  border-radius: 24upx;
}

.u-input__input {
  color: balck !important;
}

.title_btn {
  height: 78upx;
  line-height: 78upx;
  /* background: #f7f7f7; */
}

.buttons {
  border: 2upx solid #1a1a1a;
  border-radius: 45upx;
  // padding: 10upx 25upx;
  width: 200rpx;
  height: 60rpx;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
