123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <template>
- <view class="my-info-page">
- <!-- 导航区域 -->
- <view class="icon-title-bjcolor-navBar-box">
- <view @click="handleBack" class="nav-bar-icon"></view>
- <text class="nav-bar-title">个人信息</text>
- </view>
- <!-- 头像 -->
- <view class="user-img-box">
- <uni-file-picker limit="1" :del-icon="false" disable-preview :auto-upload="false" v-if="data.icon"
- @select="handleSelect" file-mediatype="image" class="phone-file-picker user-file-picker">
- <image :src="data.icon" class="file-picker-image"></image>
- </uni-file-picker>
- <icon class="head-icon-box" v-else></icon>
- <!-- <view>图片地址:{{data.icon}}</view> -->
- </view>
- <!-- 姓名 -->
- <view class="form-label-input">
- <view class="phone-form-label"><text class="form-label-require">*</text>姓名</view>
- <input v-model="data.realName" placeholder="请输入姓名" />
- </view>
- <!-- 手机号 -->
- <view class="form-label-input">
- <view class="phone-form-label"><text class="form-label-require">*</text>手机号</view>
- <input v-model="data.userName" placeholder="请输入手机号" />
- </view>
- <!-- 证件号 -->
- <view class="form-label-input">
- <view class="phone-form-label"><text class="form-label-require">*</text>证件号</view>
- <input v-model="data.idcard" placeholder="请输入证件号" />
- </view>
- <!-- 电话 -->
- <view></view>
- <!-- 性别 -->
- <view class="form-label-radio">
- <view class="phone-form-label"><text class="form-label-require">*</text>性别</view>
- <view class="form-radio-group">
- <view class="form-radio-item" :class="{genderActive: data.gender===1}" @click="genderSelect(1)">男</view>
- <view class="form-radio-item" :class="{genderActive: data.gender===2}" @click="genderSelect(2)">女</view>
- </view>
- </view>
- <button type="default" class="phone-green-btn info-btn" @click="handleUpdate">修改资料</button>
- </view>
- </template>
- <script setup>
- import * as myApi from "@/api/my.js";
- import {getAliyunPolicy} from "@/api/jiazheng.js"
- import {ref,reactive} from "vue"
- import {onLoad} from "@dcloudio/uni-app"
- const imageStyles = ref({
- width: 120,
- height: 120,
- });
- const data = reactive({
- from: 'shouye', // my | kaoshi | shouye
- gender: 0,
- icon: '',
- realName: '',
- idcard: '',
- userName: '',
- userId: null
- })
- onLoad((options) => {
- data.from = options.from || 'shouye';
- initPage();
- })
- function handleSelect(e) {
- doUploadImage(e.tempFilePaths[0])
- }
- function genderSelect(genderValue){
- data.gender = genderValue;
- }
- function doUploadImage(filePath) {
- const loading = uni.showLoading({
- title: '上传中...',
- mask: true
- });
- try {
- const suffix = filePath.split('.').pop();
- let req = {
- prefix: 'resource/',
- suffix: suffix
- }
- getAliyunPolicy(req).then(res => {
- if (res.code == 0) {
- const policyData = res.data;
- const formData = {
- key: policyData.key,
- policy: policyData.policy,
- OSSAccessKeyId: policyData.accessid,
- signature: policyData.signature,
- success_action_status: '200',
- file: {
- name: policyData.key,
- uri: filePath
- }
- };
- uni.uploadFile({
- url: policyData.uploadUrl,
- filePath: filePath,
- name: 'file',
- formData: formData,
- header: {
- 'Content-Type': 'multipart/form-data'
- },
- success(uploadRes) {
- if (uploadRes.statusCode === 200) {
- data.icon = `${policyData.downloadUrl}/${policyData.key}`;
- uni.showToast({
- title: '上传成功',
- icon: 'success'
- });
- } else {
- uni.showToast({
- title: '上传失败',
- });
- }
- uni.hideLoading();
- },
- fail(err) {
- uni.showToast({
- title: '上传失败',
- });
- uni.hideLoading();
- }
- });
- } else {
- uni.showToast({
- title: '获取凭证失败',
- });
- uni.hideLoading();
- }
- })
- } catch (error) {
- uni.showToast({
- title: '上传失败',
- icon: 'none'
- });
- uni.hideLoading();
- }
- }
- function handleUpdate() {
- const opt = {
- gender: data.gender,
- icon: data.icon,
- idcard: data.idcard,
- realName: data.realName,
- userId: data.userId,
- userName: data.userName,
- }
- myApi.getMineUpdate(opt).then(res => {
- if (res.data) {
- uni.showToast({
- title: '更新成功'
- })
- }
- })
- }
- function handleBack() {
- if (data.from == 'my') {
- uni.redirectTo({
- url: '/pages/client/my/index'
- })
- } else if (data.from == 'kaoshi') {
- uni.redirectTo({
- url: '/pages/client/ShouYe/shouye'
- })
- } else {
- uni.redirectTo({
- url: '/pages/client/ShouYe/shouye'
- })
- }
- }
- function initPage() {
- myApi.getMineUser().then(res => {
- const {gender,icon,idcard,realName,userName,userId} = res.data;
- data.gender = res.data.gender;
- data.icon = res.data.icon;
- data.idcard = res.data.idcard;
- data.realName = res.data.realName;
- data.userName = res.data.userName;
- data.userId = res.data.userId;
- })
- }
- </script>
- <style>
- </style>
|