myInfo.vue 5.1 KB

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