myInfo.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <view class="my-info-page">
  3. <!-- 导航区域 -->
  4. <customNavbarVue title="个人信息" :show-back-btn="true" @back="handleBack"></customNavbarVue>
  5. <!-- 头像 -->
  6. <view class="user-img-box">
  7. <view class="user-title">头像</view>
  8. <uni-file-picker return-type="object" v-model="data.images" :del-icon="false" mode="grid" disable-preview :auto-upload="false"
  9. @select="handleSelect" file-mediatype="image" class="phone-file-picker user-file-picker">
  10. </uni-file-picker>
  11. <icon class="user-jt-icon" :style="{ backgroundImage: 'url(' + data.jtIcon + ')' }"></icon>
  12. </view>
  13. <!-- 姓名 -->
  14. <view class="form-label-input">
  15. <view class="phone-form-label"><text class="form-label-require">*</text>姓名</view>
  16. <input v-model="data.realName" placeholder="请输入姓名" />
  17. <icon :style="{ backgroundImage: 'url(' + data.jtIcon + ')' }"></icon>
  18. </view>
  19. <!-- 手机号 -->
  20. <view class="form-label-input">
  21. <view class="phone-form-label"><text class="form-label-require">*</text>手机号</view>
  22. <input v-model="data.userName" placeholder="请输入手机号" />
  23. <icon :style="{ backgroundImage: 'url(' + data.jtIcon + ')' }"></icon>
  24. </view>
  25. <!-- 证件号 -->
  26. <view class="form-label-input">
  27. <view class="phone-form-label"><text class="form-label-require">*</text>证件号</view>
  28. <input v-model="data.idcard" placeholder="请输入证件号" />
  29. <icon :style="{ backgroundImage: 'url(' + data.jtIcon + ')' }"></icon>
  30. </view>
  31. <view class="form-label-input">
  32. <view class="phone-form-label"><text class="form-label-require">*</text>具体地址</view>
  33. <input v-model="data.dizhi" placeholder="请输入具体地址" />
  34. <icon :style="{ backgroundImage: 'url(' + data.jtIcon + ')' }"></icon>
  35. </view>
  36. <button type="default" class="phone-green-btn info-btn" @click="handleUpdate">修改资料</button>
  37. </view>
  38. </template>
  39. <script setup>
  40. import customNavbarVue from "@/components/custom-navbar/custom-navbar.vue";
  41. import * as myApi from "@/api/my.js";
  42. import {getAliyunPolicy} from "@/api/jiazheng.js"
  43. import {ref,reactive} from "vue"
  44. import {onLoad} from "@dcloudio/uni-app"
  45. import cacheManager from '@/utils/cacheManager.js';
  46. const defaultImage1 = ref({
  47. url:'', extname: 'png', name: 'moren.png'
  48. })
  49. const imageStyles = ref({
  50. width: '50rpx',
  51. height: '50rpx',
  52. background: 'red'
  53. });
  54. const data = reactive({
  55. from: 'shouye', // my | kaoshi | shouye
  56. icon: '',
  57. realName: '',
  58. idcard: '',
  59. userName: '',
  60. userId: null,
  61. images: null,
  62. jtIcon: '',
  63. dizhi: ''
  64. })
  65. onLoad((options) => {
  66. data.from = options.from || 'shouye';
  67. data.jtIcon= cacheManager.get('projectImg').nav_bar_jt_bottom;
  68. defaultImage1.url= cacheManager.get('projectImg').user_default_img;
  69. initPage();
  70. })
  71. function handleSelect(e) {
  72. doUploadImage(e)
  73. }
  74. function genderSelect(genderValue){
  75. data.gender = genderValue;
  76. }
  77. function doUploadImage(params) {
  78. const filePath = params.tempFiles[0];
  79. const fileUrl = params.tempFilePaths;
  80. try {
  81. const suffix = filePath.file.name.split('.').pop();
  82. let req = {
  83. prefix: 'resource/',
  84. suffix: suffix,
  85. }
  86. uni.showLoading({
  87. title: '上传中...',
  88. mask: true
  89. });
  90. getAliyunPolicy(req).then(res => {
  91. if (res.code == 0) {
  92. const policyData = res.data;
  93. const formData = {
  94. key: policyData.key,
  95. policy: policyData.policy,
  96. signature: policyData.signature,
  97. OSSAccessKeyId: policyData.accessid,
  98. success_action_status: '200',
  99. }
  100. uni.uploadFile({
  101. url: policyData.uploadUrl,
  102. filePath: fileUrl[0],
  103. name: 'file',
  104. formData: formData,
  105. success(uploadRes) {
  106. if (uploadRes.statusCode === 200) {
  107. console.log('uploadRes',uploadRes)
  108. data.icon = `${policyData.downloadUrl}/${policyData.key}`;
  109. console.log( `${policyData.downloadUrl}/${policyData.key}`)
  110. uni.showToast({
  111. title: '上传成功',
  112. icon: 'success'
  113. });
  114. data.images = { url: data.icon, extname: 'png', name: 'touxiang.png' }
  115. } else {
  116. uni.showToast({
  117. icon: 'none',
  118. title: '上传失败',
  119. });
  120. uni.hideLoading();
  121. }
  122. },
  123. fail(err) {
  124. uni.showToast({
  125. icon: 'none',
  126. title: '上传失败',
  127. });
  128. uni.hideLoading();
  129. }
  130. });
  131. } else {
  132. uni.showToast({
  133. title: '获取凭证失败',
  134. });
  135. uni.hideLoading();
  136. }
  137. })
  138. } catch (error) {
  139. uni.showToast({
  140. title: '上传失败',
  141. icon: 'none'
  142. });
  143. uni.hideLoading();
  144. }
  145. }
  146. function handleUpdate() {
  147. let arr = [];
  148. if (!data.realName) {
  149. arr.push('姓名');
  150. }
  151. if (!data.userName) {
  152. arr.push('电话');
  153. }
  154. if (!data.icon) {
  155. arr.push('头像');
  156. }
  157. if (!data.idcard) {
  158. arr.push('证件号');
  159. }
  160. if (!data.realName || !data.userName||!data.icon||!data.idcard) {
  161. uni.showToast({
  162. icon: 'none',
  163. title: `请完善${arr.join('、')}信息!`
  164. })
  165. return;
  166. }
  167. const opt = {
  168. dizhi: data.dizhi,
  169. icon: data.icon,
  170. idcard: data.idcard,
  171. realName: data.realName,
  172. userId: data.userId,
  173. userName: data.userName,
  174. }
  175. myApi.getMineUpdate(opt).then(res => {
  176. if (res.data) {
  177. uni.showToast({
  178. title: '更新成功'
  179. })
  180. handleBack();
  181. }
  182. })
  183. }
  184. function handleBack() {
  185. uni.navigateBack()
  186. }
  187. function initPage() {
  188. myApi.getMineUser().then(res => {
  189. const {gender,icon,idcard,realName,userName,userId} = res.data;
  190. data.gender = res.data.gender;
  191. data.icon = res.data.icon;
  192. data.idcard = res.data.idcard;
  193. data.realName = res.data.realName;
  194. data.userName = res.data.userName;
  195. data.userId = res.data.userId;
  196. data.images = data.icon?{ url: data.icon, extname: 'png', name: 'touxiang.png' }:defaultImage1.value
  197. })
  198. }
  199. </script>
  200. <style>
  201. </style>