myInfo.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. <img class="head-img" :src="data.icon" v-if="data.icon">
  13. <icon class="phone-default-userImg" v-else></icon>
  14. </uni-file-picker>
  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. console.log('eee',e)
  69. doUploadImage(e)
  70. }
  71. function genderSelect(genderValue){
  72. data.gender = genderValue;
  73. }
  74. function doUploadImage(params) {
  75. const filePath = params.tempFiles[0];
  76. const fileUrl = params.tempFilePaths;
  77. try {
  78. const suffix = filePath.file.name.split('.').pop();
  79. let req = {
  80. prefix: 'resource/',
  81. suffix: suffix,
  82. }
  83. uni.showLoading({
  84. title: '上传中...',
  85. mask: true
  86. });
  87. getAliyunPolicy(req).then(res => {
  88. if (res.code == 0) {
  89. const policyData = res.data;
  90. const formData = {
  91. key: policyData.key,
  92. policy: policyData.policy,
  93. signature: policyData.signature,
  94. OSSAccessKeyId: policyData.accessid,
  95. success_action_status: '200',
  96. }
  97. uni.uploadFile({
  98. url: policyData.uploadUrl,
  99. filePath: fileUrl[0],
  100. name: 'file',
  101. formData: formData,
  102. success(uploadRes) {
  103. if (uploadRes.statusCode === 200) {
  104. console.log('uploadRes',uploadRes)
  105. data.icon = `${policyData.downloadUrl}/${policyData.key}`;
  106. console.log( `${policyData.downloadUrl}/${policyData.key}`)
  107. uni.showToast({
  108. title: '上传成功',
  109. icon: 'success'
  110. });
  111. } else {
  112. uni.showToast({
  113. icon: 'none',
  114. title: '上传失败',
  115. });
  116. uni.hideLoading();
  117. }
  118. },
  119. fail(err) {
  120. uni.showToast({
  121. icon: 'none',
  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. let arr = [];
  144. if (!data.realName) {
  145. arr.push('姓名');
  146. }
  147. if (!data.userName) {
  148. arr.push('电话');
  149. }
  150. if (!data.icon) {
  151. arr.push('头像');
  152. }
  153. if (!data.idcard) {
  154. arr.push('证件号');
  155. }
  156. if (!data.realName || !data.userName||!data.icon||!data.idcard) {
  157. uni.showToast({
  158. icon: 'none',
  159. title: `请完善${arr.join('、')}信息!`
  160. })
  161. return;
  162. }
  163. const opt = {
  164. gender: data.gender,
  165. icon: data.icon,
  166. idcard: data.idcard,
  167. realName: data.realName,
  168. userId: data.userId,
  169. userName: data.userName,
  170. }
  171. myApi.getMineUpdate(opt).then(res => {
  172. if (res.data) {
  173. uni.showToast({
  174. title: '更新成功'
  175. })
  176. handleBack();
  177. }
  178. })
  179. }
  180. function handleBack() {
  181. const pages = getCurrentPages();
  182. if (pages.length>1) {
  183. uni.navigateBack()
  184. } else {
  185. /* if (data.from == 'my') {
  186. uni.redirectTo({
  187. url: '/pages/client/my/index'
  188. })
  189. } else if (data.from == 'kaoshi') {
  190. uni.redirectTo({
  191. url: '/pages/client/ShouYe/shouye'
  192. })
  193. } else {
  194. uni.redirectTo({
  195. url: '/pages/client/my/index'
  196. })
  197. } */
  198. history.back();
  199. }
  200. }
  201. function initPage() {
  202. myApi.getMineUser().then(res => {
  203. const {gender,icon,idcard,realName,userName,userId} = res.data;
  204. data.gender = res.data.gender;
  205. data.icon = res.data.icon;
  206. data.idcard = res.data.idcard;
  207. data.realName = res.data.realName;
  208. data.userName = res.data.userName;
  209. data.userId = res.data.userId;
  210. })
  211. }
  212. </script>
  213. <style>
  214. </style>