<!--
  Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.

  https://www.mall4j.com/

  未经允许，不可做商业用途！

  版权所有，侵权必究！
-->

<template>
  <view class="Mall4j component-sign-acct-protocol">
    <uni-popup
      ref="sharePopRef"
      background-color="#fff"
      :is-mask-click="false"
      class="pop-mask"
    >
      <view class="popup">
        <view class="title-box">
          <text class="title">
            {{ $t('qianYueXieYi') }}
          </text>
          <view
            class="close"
            @tap="onPopClose"
          >
            <image
              class="del-img"
              src="@/static/images/close.png"
            />
          </view>
        </view>
        <view class="input-con amount-input-con">
          <view class="title">
            <text class="star">
              *
            </text>
            <text class="txt">
              {{ $t('xieYiLeiBie') }}
            </text>
          </view>
          <radio-group @change="onChangeSignAcctType">
            <radio
              style="transform:scale(0.8);"
              value="2"
              :checked="dataForm.signAcctType === '2'"
              :disabled="legalAcctProtocolNo ? true : undefined"
              color="#082BA6"
            >
              {{ $t('duiSiQianYue') }}
            </radio>
            <radio
              style="transform:scale(0.8);"
              value="3"
              :checked="dataForm.signAcctType === '3'"
              :disabled="acctProtocolNo ? true : undefined"
              color="#082BA6"
            >
              {{ $t('duiGongQianYue') }}
            </radio>
          </radio-group>
        </view>
        <view
          class="footer-btn"
          @tap="onSubmit"
        >
          {{ $t('queRen') }}
        </view>
      </view>
    </uni-popup>
  </view>
</template>
<script setup>
import { reactive } from 'vue'
const props = defineProps({
  acctProtocolNo: {
    type: String,
    default: ''
  },
  legalAcctProtocolNo: {
    type: String,
    default: ''
  },
  mobile: {
    type: String,
    default: ''
  },
  legalCardNumber: {
    type: Number,
    default: 0
  }
})

const domainAddress = import.meta.env.VITE_APP_H5_DOMAIN
const dataForm = reactive({
  signAcctType: '' // 签约类型 1.个人 2.法人 3.企业
})

const sharePopRef = ref(null)
const init = () => {
  sharePopRef.value.open('center')
}
const onChangeSignAcctType = (val) => {
  dataForm.signAcctType = val.detail.value
}
const onSubmit = () => {
  if (dataForm.signAcctType === '') {
    uni.showToast({
      title: $t('qingXuanZeQianYueLeiBie'),
      icon: 'none',
      duration: 1000
    })
    return
  }
  if (dataForm.signAcctType === '3' && (props.mobile === '' || props.mobile === null)) {
    uni.showToast({
      title: $t('qingXianBangDingShouJiHao'),
      icon: 'none',
      duration: 1000
    })
    return
  }
  if (dataForm.signAcctType === '2' && props.legalCardNumber === 0) {
    uni.showToast({
      title: $t('qingXianBangDingFaRenZhangHu'),
      icon: 'none',
      duration: 1000
    })
    return
  }
  const data = {
    signAcctType: dataForm.signAcctType,
    jumpUrl: `${domainAddress}/package-settings/pages/store-settings-financial/store-settings-financial?isSignSuccess=1`,
    noContractUrl: `${domainAddress}/package-settings/pages/store-settings-financial/store-settings-financial?isSignSuccess=0`,
    jumpPageType: 1
  }
  // #ifdef APP-PLUS
  data.jumpUrl = domainAddress + '/package-user/pages/redirect/redirect?isSignSuccess=1'
  data.noContractUrl = domainAddress + '/package-user/pages/redirect/redirect?isSignSuccess=0'
  // #endif
  // #ifdef MP-WEIXIN
  data.jumpPageType = 2
  // #endif
  const params = {
    url: '/shop/allinpay/company/signAcctProtocol',
    method: 'POST',
    data
  }
  http.request(params).then(({ data: res }) => {
    // #ifdef H5
    window.location.href = res
    // #endif
    // #ifdef MP-WEIXIN
    wx.navigateToMiniProgram({
      appId: 'wxc46c6d2eed27ca0a', // 通联小程序 appId
      path: 'pages/merchantAddress/merchantAddress', // 通联小程序页面路径
      extraData: { targetUrl: res.targetUrl }, // 商户拼接的请求报文
      envVersion: 'release' // develop 开发版 trial 体验版 release 正式版
    })
    // #endif
    // #ifdef APP-PLUS
    plus.runtime.openURL(res)
    // #endif
  })
}
const onPopClose = () => {
  sharePopRef.value.close()
}
defineExpose({
  init
})
</script>

<style lang="scss" scoped>
@use './sign-acct-protocol.scss';
</style>
