myInfo.vue 5.7 KB

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