information.vue 7.5 KB

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