<template>
  <view class="container outbound-content">
    <!-- 这里顶部安全是状态栏 -->
    <view class="nav-bar-wrap" :style="{ height: navBarStyle.height, paddingTop: navBarStyle.paddingTop, paddingBottom: navBarStyle.paddingBottom }">
      <view class="content-box" :style="{ color: '#333' }">
        <text>{{ isShowTitle }}</text>
        <view class="arrow-left-icon">
          <van-icon name="arrow-left" size="20px" @click="backArrowleft" />
        </view>
      </view>
    </view>
    <view class="content-box-edit">
      <!-- 文本提示 -->
      <view class="top-box" v-if="isShowTitle == '修改外呼号码' || identification == '邮箱'"> 修改后的外呼号码，将作为您的默认外呼号码，若后期还需修改，可在【我的】-【外呼号码】页面设置 </view>
      <!-- 输入外呼手机号 -->
      <view class="item-box">
        <view class="ipt-item">
          <label class="item-label item-iphone" @click="areaCode">+{{ telephone }} <u-icon :name="areacodeShow ? 'arrow-up' : 'arrow-down'" color="#376cbb" size="28"></u-icon></label>
          <input type="text" v-model="phoneIpt" class="ipt" placeholder="请输入外呼号码" />
        </view>
        <text class="text-box">座机号请填写区号，分机号用"-"分隔，例：02150509999-8888</text>
      </view>
      <!-- 底部确认 和取消 -->
      <view class="bottom-btn">
        <view class="submit-box" @click="submit"> 提交 </view>
        <view class="cancel" v-if="isShowTitle !== '设置外呼号码'" @click="cancelModification"> 取消修改 </view>
      </view>
      <!-- 选择区号部分 -->
      <view class="select-box">
        <u-popup v-model="areacodeShow" mode="bottom" @close="areacodeShow = false">
          <view class="box" style="color: #333333; font-size: 28rpxrpx">请选择您的国际区号</view>
          <view class="box" v-for="item in mobileAreaCode" :key="item.code" style="color: #2c83ff" @click="areacode(item.code)">{{ item.name }}</view>
          <view class="box box-bottom" style="color: #a9afb8" @click="areacodeShow = false">取消</view>
        </u-popup>
      </view>
      <!-- 关注公众号 弹框 -->
      <u-modal
        v-model="goFollowShow"
        :content-style="{ fontSize: '32rpx' }"
        @confirm="goFollowShowBtn"
        :show-cancel-button="true"
        confirm-text="去关注"
        @cancel="cancelDialog"
        :show-title="false"
        :cancel-style="{ borderRight: '1rpx solid #EBEBEB' }"
        :confirm-style="{ fontWeight: '700' }"
      >
        <view class="slot-content">
          <rich-text :nodes="accounts"></rich-text>
        </view>
      </u-modal>
      <!-- 知道的弹框 -->
      <u-modal v-model="show" :content="content" :content-style="{ fontSize: '32rpx' }" @confirm="cancelDialog" :show-title="false" confirm-text="知道了" :confirm-style="{ fontWeight: '700' }">
        <view class="slot-content">
          <rich-text :nodes="content"></rich-text>
        </view>
      </u-modal>
      <freeCharge class="free-charge" :isShowFreeBtn="isShowFree" />
      <Loading />
    </view>
  </view>
</template>

<script>
import { activity } from "@/config/api.js";
import freeCharge from "@/components/freeCharge";
import { MobileAreaCode } from "@/utils/mobileCode";

export default {
  data() {
    return {
      phoneIpt: "",
      isShowTitle: "设置",
      telephone: "86",
      areacodeShow: false,
      identification: "",
      goFollowShow: false,
      accounts: "",
      show: false,
      content: "",
      id: "",
      goOnNextStep: "",
      cellphone: "",
      navBarStyle: {
        height: 60 + "px",
        paddingTop: 40 + "px",
        paddingBottom: "4px",
      },
    };
  },
  components: {
    freeCharge,
  },
  computed: {
    mobileAreaCode() {
      return MobileAreaCode;
    },
  },
  methods: {
    // 显示地区的选项
    areaCode() {
      this.areacodeShow = true;
    },

    // 选择了地区
    areacode(code) {
      this.telephone = code;
      this.areacodeShow = false;
    },

    // 提交
    submit() {
      activity
        .addOutboundMobile({
          ActivityId: Number(this.id),
          OutboundCountryCode: this.telephone,
          OutboundMobile: this.phoneIpt,
        })
        .then((res) => {
          if (res.Ret !== 200) return;
          if (this.identification == "修改" || this.identification == "邮箱") {
            if (this.identification == "邮箱") {
              let pages = getCurrentPages();
              let prevPage = pages[pages.length - 2];
              if (prevPage.$page.fullPath == "/pages/activity/activity" || prevPage.$page.fullPath == "/pages-search/indedxSearch/indedxSearch") {
                const index = prevPage.$vm.collectList.findIndex((item) => item.ActivityId == this.id);
                prevPage.$vm.collectList[index].IsSignup = 1;
              }
            }
            if (this.goOnNextStep == "true") {
              this.accounts = `
							${this.telephone}-${this.phoneIpt}<br/>
							预约成功，已加入您的活动日程<br/><br/>
							
							想要及时获取活动时间变更通知，请关注【查研观向小助手】公众号
						`;
              this.goFollowShow = true;
            } else {
              this.content = `
							${this.telephone}-${this.phoneIpt}<br/><br/>
							预约外呼成功，已加入您的活动日程
						`;
              this.show = true;
            }
          } else {
            uni.navigateBack();
          }
        });
    },

    // 取消修改
    cancelModification() {
      if (this.identification == "修改") {
        if (this.goOnNextStep == "true") {
          this.accounts = `
							${this.cellphone}<br/>
							预约成功，已加入您的活动日程<br/><br/>
							
							想要及时获取活动时间变更通知，请关注【查研观向小助手】公众号
						`;
          this.goFollowShow = true;
        } else {
          this.content = `
							${this.cellphone}<br/><br/>
							预约外呼成功，已加入您的活动日程
						`;
          this.show = true;
        }
      } else {
        uni.navigateBack();
      }
    },

    // 去关注公众号
    goFollowShowBtn() {
      uni.redirectTo({
        url: "/activityPages/accountsOfficial/accountsOfficial",
      });
    },

    // 弹框的取消
    cancelDialog() {
      uni.navigateBack();
    },

    // 右上角的返回
    backArrowleft() {
      if (this.identification == "修改") {
        if (this.goOnNextStep == "true") {
          this.accounts = `
							${this.cellphone}<br/>
							预约成功，已加入您的活动日程<br/><br/>
							
							想要及时获取活动时间变更通知，请关注【查研观向小助手】公众号
						`;
          this.goFollowShow = true;
        } else {
          this.content = `
							${this.cellphone}<br/><br/>
							预约外呼成功，已加入您的活动日程
						`;
          this.show = true;
        }
      } else {
        uni.navigateBack();
      }
    },
    // 初始获取导航栏
    initNavBar() {
      let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
      this.navBarStyle = {
        height: menuButtonInfo.height + menuButtonInfo.top + 8 + "px",
        paddingTop: menuButtonInfo.top - 4 + "px",
        paddingBottom: "4px",
      };
    },
  },
  onLoad(option) {
    this.isShowTitle = option.title;
    this.identification = option.identification;
    this.id = option.id || "";
    this.goOnNextStep = option.goOnNextStep || "";
    this.cellphone = option.cellphone || "";
    this.initNavBar();
  },
};
</script>

<style scoped lang="scss">
.outbound-content {
  background-color: $uni-color-new;
  padding: 200rpx 25rpx 25rpx;
  .nav-bar-wrap {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    align-items: center;
    z-index: 999;
    background-color: #fff;
    .content-box {
      position: relative;
      display: flex;
      align-items: center;
      width: 100%;
      justify-content: center;
      color: #fff;
      font-size: 34rpx;
      .arrow-left-icon {
        position: absolute;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40rpx;
        height: 40rpx;
        left: 39rpx;
        top: 50%;
        transform: translateY(-50%);
        z-index: 99;
      }
    }
  }
  .content-box-edit {
    margin-top: 100rpx;
    padding: 20rpx;
    background-color: #fff;
    border-radius: 8rpx;
  }
  .top-box {
    width: 100%;
    background-color: $uni-bg-color;
    padding: 20rpx 34rpx;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 48rpx;
    color: #666666;
  }
  .item-box {
    width: 100%;
    padding: 0 32rpx;
    .text-box {
      height: 30rpx;
      font-size: 22rpx;
      line-height: 30px;
      color: #999999;
    }
  }
  .ipt-item {
    padding: 33rpx 0 10rpx;
    border-bottom: 1rpx solid #d6d6d6;
    display: flex;
    align-items: center;
    font-size: 28rpx;
    .item-label {
      display: flex;
      justify-content: space-between;
      width: 105rpx;
      color: $uni-color-new;
    }
    .ipt {
      margin-left: 40rpx;
      width: 500rpx;
      font-size: 32rpx;
      color: #666;
    }
  }
  .bottom-btn {
    margin-top: 247rpx;
    font-size: 34rpx;
    text-align: center;
    .submit-box {
      margin: 0 auto;
      width: 500rpx;
      height: 60rpx;
      background: $uni-color-new;
      color: #ffffff;
      line-height: 60rpx;
      border-radius: 4rpx;
    }
    .cancel {
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 30rpx auto;
      width: 500rpx;
      height: 60rpx;
      border: 2px solid $uni-color-new;
      border-radius: 4rpx;
      color: $uni-color-new;
    }
  }
  .select-box {
    width: 100%;

    .box {
      height: 95prx;
      line-height: 95rpx;
      text-align: center;
      font-size: 32rpx;
      border-bottom: 1rpx solid #ebebeb;
    }

    .box-bottom {
      border-bottom: none !important;
    }
  }
}
.slot-content {
  width: 100%;
  padding: 50rpx;
  text-align: center;
  font-size: 32rpx;
  color: #0f1826;
  line-height: 48rpx;
}

.u-model__footer__button.data-v-3626fcec {
  border-right: 1rpx solid #333;
}
</style>
