myInfo.vue 6.0 KB

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