<template>
  <view class="container">
    <view v-for="(item,index) in questions" :key="index">
      <view>{{ item.name }}</view>
      <up-radio-group
          v-model="radioValue[index]"
          placement="column"
          iconPlacement="right"
      >
        <up-radio
            :customStyle="{marginBottom: '8px'}"
            v-for="(item, index) in item.option"
            :key="index"
            :label="item.name"
            :name="item.value"
            @change="radioChange"
        >
        </up-radio>
      </up-radio-group>
    </view>
    <up-button  text="提交1" open-type="getPhoneNumber"
               @getphonenumber="handleSubmit"></up-button>
  </view>
</template>

<script setup>
import {useMixin} from "@/utils/useMixin";
import {ref} from "vue";

const {questions} = useMixin()

const radioValue = ref([])
const handleSubmit = (e) => {
    wx.login({
      success: res => {
        if (res.code) {
          // 发起网络请求，将 code 发送到服务器进行登录
          wx.request({
            url: 'https://yourserver.com/getPhoneNumber', // 替换为你的服务器地址
            method: 'POST',
            data: {
              code: res.code,
              encryptedData: e.detail.encryptedData,
              iv: e.detail.iv
            },
            success: function(response) {
              // 服务器返回解密后的手机号
              console.log(response.data.phoneNumber);
            }
          });
        } else {
          console.log('登录失败！' + res.errMsg);
        }
      }
    });
}
</script>

<style scoped lang="scss">
.container {
  padding: 20px;
  font-size: 14px;
  line-height: 24px;
  background: #FFFFFF;
}
</style>
