From a2ddd3bec584b6eb91ab8845353fdb40c9b37ebe Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期一, 02 九月 2024 17:22:17 +0800
Subject: [PATCH] 初步完成

---
 src/pages/mine/mine.vue |  128 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 108 insertions(+), 20 deletions(-)

diff --git a/src/pages/mine/mine.vue b/src/pages/mine/mine.vue
index c86ad67..52ee4d2 100644
--- a/src/pages/mine/mine.vue
+++ b/src/pages/mine/mine.vue
@@ -7,24 +7,31 @@
 			</button>
 
 		</view>
-		<fui-list :topBorder='false'>
-			<fui-list-cell arrow :bottomBorder='false' :padding="['20rpx', '32rpx', '20rpx', '32rpx']">
-				<view class="fui-list__item">
-					<text>鏄电О</text>
-					<text class="fui-text__explain">{{userInfo.nickname}}</text>
-					<!-- <input type="nickname" class="fui-text__explain weui-input" placeholder="璇疯緭鍏ユ樀绉�" /> -->
-				</view>
-			</fui-list-cell>
-			<fui-list-cell arrow :bottomBorder='false' :padding="['20rpx', '32rpx', '20rpx', '32rpx']">
-				<view class="fui-list__item">
-					<text>鎵嬫満鍙�</text>
-					<text class="fui-text__explain">{{userInfo.phone}}</text>
-				</view>
-			</fui-list-cell>
-			<fui-list-cell arrow @click="goApply" :bottomBorder='false' :padding="['20rpx', '32rpx', '20rpx', '32rpx']">
-				<text>鐢宠鎺ュ崟</text>
-			</fui-list-cell>
-		</fui-list>
+		<up-cell title="鏄电О" :border="false">
+			<template #value>
+				<up-form labelPosition="left" :model="userInfo" ref="formRef" labelWidth='90' v-if="showEdit">
+					<up-form-item prop="enterpriseInfo.businessLicense" ref="item1">
+						<up-input v-model="userInfo.nickname" type="nickname" @blur="blurNickName" border="none"
+							placeholder="璇疯緭鍏ユ樀绉�" :readonly='!showEdit'>
+							<template #suffix>
+								<up-button @tap="saveUserNikename" text="淇濆瓨" type="success" form-type="submit"
+									size="mini"></up-button>
+							</template>
+							<!-- <template #suffix v-else>
+								<up-icon name="edit-pen" @click='isShow'></up-icon>
+							</template> -->
+						</up-input>
+						
+					</up-form-item>
+				</up-form>
+				<text v-else>{{userInfo.nickname}}</text>
+			</template>
+			<template #right-icon v-if='!showEdit'>
+				<up-icon name="edit-pen" @click='isShow'></up-icon>
+			</template>
+		</up-cell>
+		<up-cell title="鎵嬫満鍙�" :value="userInfo.phone" isLink :border="false"></up-cell>
+		<up-cell @click="goApply" title="鐢宠鎺ュ崟" isLink :border="false"></up-cell>
 		<!-- <view class="tabbtns">
 			<up-button color='#fece01' class="text-69" text="淇濆瓨" @click=''></up-button>
 		</view> -->
@@ -32,6 +39,9 @@
 </template>
 
 <script setup>
+	import {
+		apiBaseUrl
+	} from '@/common/setting/constVarsHelper.js';
 	import {
 		onLoad,
 		onShow
@@ -45,7 +55,8 @@
 	const {
 		$upload,
 		$api,
-		$db
+		$db,
+		$util
 	} = getCurrentInstance().appContext.config.globalProperties
 	onLoad(() => {
 		// getUser()
@@ -60,24 +71,97 @@
 		phone: '',
 		userWorker: false
 	})
+	let showEdit = ref(false)
 	// let src = "http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg"
 	const goApply = () => {
 		uni.navigateTo({
 			url: '/pages/mine/apply'
 		});
 	}
+	const isShow = () => {
+		showEdit.value = true
+	}
 	const onChooseAvatar = (e) => {
 		const {
 			avatarUrl
 		} = e.detail
-		avatarUrlImg.value = avatarUrl
+		console.log(typeof(avatarUrl), avatarUrl, 'avatarUrl鈥�');
+		avatarUrlImg = avatarUrl
+		uploadFile(avatarUrl)
+	}
+	const uploadFile = (val) => {
+		let userToken = $db.get("userToken");
+		uni.uploadFile({
+			url: apiBaseUrl + 'api/UpFile/UpdateFile',
+			filePath: val,
+			fileType: 'image',
+			name: 'file',
+			header: {
+				'Accept': 'application/json',
+				'Content-Type': 'multipart/form-data',
+				'Authorization': 'Bearer ' + userToken
+			},
+			formData: {
+				'method': 'images.upload',
+				'upfile': val
+			},
+			success: (uploadFileRes) => {
+				//console.log("浜や簰鎴愬姛");
+				//console.log(uploadFileRes);
+				let res = JSON.parse(uploadFileRes.data);
+				let obj = {
+					Avatar: res.data
+				}
+				console.log(res.data, res, 'res.data', obj);
+				$api.saveUser(obj).then(res => {
+					if (res.code == 1) {
+						$util.showToast({
+							title: "澶村儚淇濆瓨鎴愬姛锛�",
+							icon: "success"
+						})
+						getUser()
+					}
+				})
+			},
+			fail: (error) => {
+				console.log("浜や簰澶辫触");
+				console.log(error);
+				if (error && error.response) {
+					$upload.showError(error.response);
+				}
+			},
+			complete: () => {
+				setTimeout(function() {
+						uni.hideLoading();
+					},
+					250);
+			}
+		});
 	}
 	const getUser = (e) => {
 		$api.getUser().then(res => {
 			userInfo.nickname = res.data.nickname
 			userInfo.phone = res.data.phone
+			avatarUrlImg = res.data.avatar
 			$db.set('userInfo', JSON.stringify(res.data))
 		})
+	}
+	const saveUserNikename = (val) => {
+		$api.saveUser({
+			Nickname: userInfo.nickname
+		}).then(res => {
+			if (res.code == 1) {
+				$util.showToast({
+					title: "鏄电О淇濆瓨鎴愬姛锛�",
+					icon: "success"
+				})
+				getUser()
+				showEdit.value = false
+			}
+		})
+	}
+	const blurNickName = (val) => {
+		userInfo.nickname = val
 	}
 </script>
 
@@ -110,4 +194,8 @@
 		color: #7F7F7F;
 		flex-shrink: 0;
 	}
+	
+	.u-form-item__body{
+		padding: 0 !important;
+	}
 </style>
\ No newline at end of file

--
Gitblit v1.9.1