information.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="common_page" :style="{'height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title="个人资料" bgColor="#FFFFFF"></cus-header>
  4. <view class="form" v-if="userInfo">
  5. <view class="avatar">
  6. <view class="title">头像</view>
  7. <view class="adfac" style="margin: 34rpx 0 47rpx;">
  8. <view class="imgbox">
  9. <image class="imgbox-avatar" :src="userInfo.avatarPath||defaultAvatar" @click="changeAvatar"></image>
  10. </view>
  11. <image class="add-avatar" src="https://oss.familydaf.cn/sxsnfile/20251219/0b4d0f26464945dbae17491f1b529229.png" @click="changeAvatar"></image>
  12. </view>
  13. </view>
  14. <view class="item adfacjb">
  15. <view class="left">用户名</view>
  16. <view class="right">
  17. <input class="setinp" v-model="userInfo.realName" placeholder="请输入用户名"></input>
  18. </view>
  19. </view>
  20. <view class="item adfacjb">
  21. <view class="left">身份证号</view>
  22. <view class="right">
  23. <input class="setinp" v-model="userInfo.idCard" placeholder="请输入身份证号"></input>
  24. </view>
  25. </view>
  26. <!-- <view class="item adfacjb">
  27. <view class="left">手机号码</view>
  28. <view class="right">
  29. <up-input v-model="userInfo.phone" border="none" placeholder="请输入手机号码"></up-input>
  30. </view>
  31. </view> -->
  32. <view class="item adfacjb">
  33. <view class="left">家庭公益名称</view>
  34. <view class="right">
  35. <input class="setinp" type="text" v-model="userInfo.welfareName" placeholder="请输入家庭公益名称">
  36. </view>
  37. </view>
  38. <view class="item adfacjb">
  39. <view class="left">家庭公益口号</view>
  40. <view class="right">
  41. <input class="setinp" v-model="userInfo.welfareSlogan" placeholder="请输入家庭公益口号"></input>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="btn" @click="save">保存</view>
  46. <qf-image-cropper :width="500" :height="500" :radius="30" @crop="handleCrop" ref="qicRef" v-if="qicShow"></qf-image-cropper>
  47. </view>
  48. </template>
  49. <script setup name="">
  50. import { BaseApi2 } from '../common/api/baseApi';
  51. import CusHeader from '@/components/CusHeader/index.vue'
  52. import { ref, onMounted, getCurrentInstance, nextTick } from 'vue'
  53. const { proxy } = getCurrentInstance()
  54. const defaultAvatar = ref('https://oss.familydaf.cn/sxsnfile/20251218/3821654e080945998d464f3c3aa64122.png')
  55. const userInfo = ref({
  56. avatarPath:''
  57. })
  58. const qicShow = ref(false)
  59. const save = () => {
  60. // if(!userInfo.value?.avatarPath) return proxy.$showToast('请上传用户头像')
  61. // if(!userInfo.value?.realName) return proxy.$showToast('请输入用户名')
  62. // if(!proxy.$reg.mobile(userInfo.value.phone)) return proxy.$showToast('请输入正确的手机号')
  63. // if(!userInfo.value?.welfareName) return proxy.$showToast('请输入家庭公益名称')
  64. // if(!userInfo.value?.welfareSlogan) return proxy.$showToast('请输入家庭公益口号')
  65. if(userInfo.value.idCard&&!proxy.$reg.idCard(userInfo.value.idCard)) return proxy.$showToast('请输入正确的身份证号')
  66. userInfo.value.id = uni.getStorageSync('userInfo')&&JSON.parse(uni.getStorageSync('userInfo')).id;
  67. proxy.$api.put('/wx/update',userInfo.value).then(({data:res})=>{
  68. if(res.code!==0) return proxy.$showToast(res.msg)
  69. proxy.$showToast('保存成功')
  70. setTimeout(()=>{
  71. uni.reLaunch({
  72. url:'/pages/my'
  73. })
  74. },1000)
  75. })
  76. }
  77. const changeAvatar = () => {
  78. uni.showActionSheet({
  79. itemList: ['从手机相册选择'],
  80. success: (res) => {
  81. if (res.tapIndex === 0) { // 从手机相册选择
  82. chooseLocalImage();
  83. }
  84. }
  85. });
  86. }
  87. // 从本地选择图片并显示
  88. const chooseLocalImage = () => {
  89. uni.chooseImage({
  90. count: 1, // 只能选择一张
  91. sizeType: ['compressed'], // 压缩图片
  92. sourceType: ['album', 'camera'], // 可以从相册或相机选择
  93. success: (res) => {
  94. const tempFilePaths = res.tempFilePaths;
  95. if (tempFilePaths && tempFilePaths.length > 0) {
  96. qicShow.value = true;
  97. nextTick(()=>{
  98. proxy.$refs.qicRef.initImage(tempFilePaths[0],true)
  99. })
  100. }
  101. },
  102. fail: (err) => {
  103. console.error('选择图片失败', err);
  104. }
  105. });
  106. }
  107. const handleCrop = async (e) => {
  108. const result = await uploadFilePromise(e.tempFilePath);
  109. userInfo.value.avatarPath = result||'';
  110. qicShow.value = false;
  111. }
  112. const uploadFilePromise = (url) => {
  113. return new Promise((resolve, reject) => {
  114. let a = uni.uploadFile({
  115. url: BaseApi2+'/sys/oss/upload',
  116. filePath: url,
  117. name: 'file',
  118. success: (res) => {
  119. setTimeout(() => {
  120. let data = JSON.parse(res.data)
  121. if(data&&data.code===0){
  122. resolve(data.data);
  123. }else proxy.$showToast(data?.msg)
  124. }, 1000);
  125. },
  126. fail: err =>{
  127. resolve('');
  128. }
  129. });
  130. });
  131. };
  132. const getUserInfo = () => {
  133. try{
  134. proxy.$api.get(`/wx/${JSON.parse(uni.getStorageSync('userInfo')).id}`).then(({data:res})=>{
  135. if(res.code!==0) return proxy.$showToast(res.msg)
  136. userInfo.value = res.data;
  137. })
  138. }catch(e){
  139. userInfo.value = null
  140. }
  141. }
  142. onMounted(()=>{
  143. getUserInfo()
  144. })
  145. </script>
  146. <style scoped lang="scss">
  147. .common_page{
  148. .form{
  149. background: #FFFFFF;
  150. border-radius: 24rpx;
  151. padding: 14rpx 22rpx 0;
  152. margin-top: 20rpx;
  153. .avatar{
  154. .title{
  155. font-family: PingFang-SC, PingFang-SC;
  156. font-weight: bold;
  157. font-size: 30rpx;
  158. color: #252525;
  159. line-height: 42rpx;
  160. }
  161. .imgbox{
  162. width: 122rpx;
  163. height: 122rpx;
  164. &-avatar{
  165. width: 100%;
  166. height: 100%;
  167. border-radius: 50%;
  168. }
  169. }
  170. .add-avatar{
  171. margin-left: 40rpx;
  172. width: 122rpx;
  173. height: 122rpx;
  174. border-radius: 50%;
  175. }
  176. border-bottom: 1rpx solid #E6E6E6;
  177. }
  178. .item{
  179. height: 110rpx;
  180. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #E6E6E6;
  181. .left{
  182. width: 200rpx;
  183. font-family: PingFang-SC, PingFang-SC;
  184. font-weight: bold;
  185. font-size: 30rpx;
  186. color: #252525;
  187. line-height: 42rpx;
  188. padding-right: 20rpx;
  189. box-sizing: border-box;
  190. }
  191. .right{
  192. width: calc(100% - 200rpx);
  193. }
  194. }
  195. }
  196. .btn{
  197. width: calc(100% - 80rpx);
  198. height: 90rpx;
  199. background: #B7F358;
  200. border-radius: 45rpx;
  201. font-family: PingFang-SC, PingFang-SC;
  202. font-weight: bold;
  203. font-size: 32rpx;
  204. color: #151B29;
  205. line-height: 90rpx;
  206. text-align: center;
  207. letter-spacing: 2rpx;
  208. position: fixed;
  209. left: 40rpx;
  210. bottom: 64rpx;
  211. }
  212. }
  213. </style>