<template>
  <view class="container outbound-content">
    <!-- 这里顶部安全是状态栏 -->
    <view class="status_bar" color="#000000" :style="'height:' + demoTop + 'px;'"> </view>
    <!-- 自定义状态栏 -->
    <view class="status_title">
      <u-icon name="arrow-left" size="38" @click="backArrowleft"></u-icon>
      <view class="status_center">{{ isShowTitle }}</view>
    </view>
    <!-- 文本提示 -->
    <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="#3385FF" 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" style="color: #2c83ff" @click="areacode('86')">大陆+86</view>
        <view class="box" style="color: #2c83ff" @click="areacode('852')">香港+852</view>
        <view class="box" style="color: #2c83ff" @click="areacode('886')">台湾+886</view>
        <view class="box" style="color: #2c83ff" @click="areacode('1')">美国+1</view>
        <view class="box" style="color: #2c83ff" @click="areacode('65')">新加坡+65</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" />
  </view>
</template>

<script>
import { activity } from "@/config/api.js";
import freeCharge from "@/components/freeCharge";
export default {
  data() {
    return {
      phoneIpt: "",
      isShowTitle: "设置",
      telephone: "86",
      areacodeShow: false,
      identification: "",
      goFollowShow: false,
      accounts: "",
      show: false,
      content: "",
      demoTop: "",
      id: "",
      goOnNextStep: "",
      cellphone: "",
    };
  },
  components: {
    freeCharge,
  },
  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();
      }
    },
  },
  onLoad(option) {
    this.isShowTitle = option.title;
    this.identification = option.identification;
    this.id = option.id || "";
    this.goOnNextStep = option.goOnNextStep || "";
    this.cellphone = option.cellphone || "";
    const res = uni.getSystemInfoSync();
    this.demoTop = res.safeArea.top;
  },
};
</script>

<style scoped lang="scss">
.outbound-content {
  /* 自定义状态栏 */
  .status_bar {
    width: 100%;
  }

  /* 自定义导航栏 */
  .status_title {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    width: 100%;
    height: 88rpx;
    padding: 10rpx 62rpx 15rpx 30rpx;
    background-color: #ffffff;
    box-sizing: border-box;
  }
  .status_center {
    margin: 0 auto;
    font-size: 34rpx;
    font-weight: 400;
    color: #000000;
  }
  .top-box {
    width: 100%;
    background-color: #f7f7f7;
    padding: 20rpx 34rpx;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 48rpx;
    color: #666666;
  }
  .item-box {
    width: 100%;
    margin-top: 35rpx;
    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: #3385ff;
    }
    .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: 368rpx;
      height: 80rpx;
      background: linear-gradient(268deg, #2ddbff 0%, #1599ff 49%, #005eff 100%);
      color: #ffffff;
      line-height: 80rpx;
      border-radius: 4rpx;
    }
    .cancel {
      margin: 30rpx auto;
      width: 368rpx;
      height: 80rpx;
      border: 2px solid #2c83ff;
      border-radius: 4rpx;
      line-height: 80rpx;
      color: #2c83ff;
    }
  }
  .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>
