<template>
  <div class="mall4j page-allinpay-pwd">
    <view class="other-entrance">
      <view
        class="item"
        @tap="onToSetAllinpayPwd('set')"
      >
        <view class="text">
          修改支付密码
        </view>
        <view class="text-arrow" />
      </view>
      <view
        class="item"
        @tap="onToSetAllinpayPwd('forget')"
      >
        <view class="text">
          忘记支付密码
        </view>
        <view class="text-arrow" />
      </view>
    </view>
  </div>
</template>

<script setup>

const domainAddress = import.meta.env.VITE_APP_DOMAIN_ADDRESS
const { debounce, toAllinPay } = util
const onToSetAllinpayPwd = debounce(function (type) {
  const data = {
    jumpUrl: domainAddress + '/package-user/pages/user-settings/user-settings',
    errorJumpUrl: domainAddress + '/package-user/pages/user-settings/user-settings',
    jumpPageType: 1
  }
  // #ifdef APP-PLUS
  // 如果是app打开，则需要在url后面拼接isSetPayPwd=1，用于判断是否是设置或修改支付密码成功后返回的页面
  data.jumpUrl = domainAddress + '/package-user/pages/redirect/redirect?isSetPayPwd=1'
  data.errorJumpUrl = domainAddress + '/package-user/redirect/redirect?isSetPayPwd=1'
  // #endif
  // #ifdef MP-WEIXIN
  data.jumpPageType = 2
  // #endif
  let url = '/mall4cloud_payment/allinpay/member/update_pay_pwd'
  if (type === 'forget') {
    // 重置支付密码
    url = '/mall4cloud_payment/allinpay/member/reset_pay_pwd'
  }
  uni.showLoading()
  const params = {
    url,
    method: 'PUT',
    dontTrunLogin: true,
    data
  }
  http.request(params).then((res) => {
    uni.hideLoading()
    // #ifdef H5
    window.location.href = res
    // #endif
    // #ifdef MP-WEIXIN
    toAllinPay({
      targetUrl: res
    })
    // #endif
    // #ifdef APP-PLUS
    // eslint-disable-next-line no-undef
    plus.runtime.openURL(res)
    // #endif
  }).catch((err) => {
    uni.hideLoading()
    uni.showToast({
      title: err.msg,
      icon: 'none'
    })
  })
}, 1500)

</script>

<style lang="scss" scoped>
@import "./allinpay-pwd.scss";
</style>
