index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view class="user-info-wrap">
  3. <view class="nav-bar">
  4. <view class="nav-content">
  5. <view class="nav-info">
  6. <view class="nav-desc">
  7. <view class="nav-name">
  8. <view class="">头像</view>
  9. </view>
  10. </view>
  11. <view @click="uploadImg1(1)" class="arrow-right">
  12. <view class="head-img">
  13. <image v-if="userInfo.selfPhotoUrl" :src="userInfo.selfPhotoUrl" mode=""></image>
  14. <image v-else src="../../static/me/u1796.png" mode=""></image>
  15. </view>
  16. <!-- <u-icon name="arrow-right" color="#666" size="26"></u-icon> -->
  17. </view>
  18. </view>
  19. </view>
  20. <view class="custom-line"></view>
  21. <view class="nav-content">
  22. <view class="nav-info">
  23. <view class="nav-desc">
  24. <view class="nav-name">
  25. <view class="">昵称</view>
  26. </view>
  27. <input class="custom-input" v-model="userInfo.ncikName" type="text" placeholder="请输入昵称">
  28. </view>
  29. <view class="arrow-right">
  30. <!-- <u-icon name="arrow-right" color="#666" size="16"></u-icon> -->
  31. </view>
  32. </view>
  33. </view>
  34. <view class="custom-line"></view>
  35. <view class="nav-content">
  36. <view class="nav-info">
  37. <view class="nav-desc">
  38. <view class="nav-name">
  39. <view class="">性别</view>
  40. </view>
  41. </view>
  42. <view @click="chooseGender()" class="arrow-right">
  43. <view class="change-store">
  44. <text v-if="userInfo.sex == 0">男</text>
  45. <text v-else-if="userInfo.sex == 1">女</text>
  46. <text v-else-if="userInfo.sex == 2">未知</text>
  47. <text v-else>请选择性别</text>
  48. </view>
  49. <u-icon name="arrow-right" color="#666" size="16"></u-icon>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="custom-line"></view>
  54. <view class="nav-content">
  55. <view class="nav-info">
  56. <view class="nav-desc">
  57. <view class="nav-name">
  58. <view class="">生日</view>
  59. </view>
  60. </view>
  61. <view @click="chooseServiceDate()" class="arrow-right">
  62. <view class="change-store">
  63. <text v-if="userInfo.birthday">{{userInfo.birthday}}</text>
  64. <text v-else>请选择生日</text>
  65. </view>
  66. <u-icon name="arrow-right" color="#666" size="16"></u-icon>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="custom-line"></view>
  71. <view class="nav-content">
  72. <view class="nav-info">
  73. <view class="nav-desc">
  74. <view class="nav-name">
  75. <view class="">实名认证</view>
  76. </view>
  77. </view>
  78. <view @click="gotoRealNameAuth()" class="arrow-right">
  79. <view class="change-store">
  80. <text v-if="userInfo.isAttestation">已认证</text>
  81. <text v-else>未实名认证,去认证</text>
  82. </view>
  83. <u-icon name="arrow-right" color="#666" size="16"></u-icon>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. <view @click="saveUserInfo()" class="sure-btn">
  89. <view class="btn">确认</view>
  90. </view>
  91. <!-- 日期时间选择 -->
  92. <u-datetime-picker
  93. :show="dateShow"
  94. v-model="value1"
  95. mode="date"
  96. @confirm="sureChooseDate()"
  97. ></u-datetime-picker>
  98. <!-- 性别选择 -->
  99. <u-picker :show="genderShow" keyName="gender" @confirm="sureChooseGender" :columns="genderList"></u-picker>
  100. </view>
  101. </template>
  102. <script>
  103. export default {
  104. data() {
  105. return {
  106. userInfo: {
  107. auth: true,
  108. ncikName: '',
  109. sex: '',
  110. birthday: '',
  111. selfPhoto: '',
  112. selfPhotoUrl: '',
  113. memberType: '',
  114. isAttestation: ''
  115. },
  116. genderShow: false,
  117. dateShow: false,
  118. value1: '2023-12-12',
  119. // 服务时间
  120. genderList: [
  121. [{gender:'男',id:'0'},
  122. {gender:'女',id:'1'},
  123. {gender:'未知',id:'2'}
  124. ],
  125. ],
  126. imgUrl1: ''
  127. };
  128. },
  129. mounted() {
  130. },
  131. onLoad() {
  132. // 用户信息
  133. let user = uni.getStorageSync('userInfo')
  134. this.userInfo.birthday = user.birthday;
  135. this.userInfo.sex = user.sex;
  136. this.userInfo.ncikName = user.ncikName;
  137. this.userInfo.selfPhoto = user.selfPhoto;
  138. this.getImgUrlByOssId(user.selfPhoto)
  139. this.userInfo.memberType = user.memberType;
  140. this.userInfo.isAttestation = user.isAttestation;
  141. },
  142. methods: {
  143. // 选择性别
  144. chooseGender(){
  145. this.genderShow = true;
  146. },
  147. // 选择值
  148. sureChooseGender(e){
  149. this.genderShow = false;
  150. this.userInfo.sex = e.value[0].id;
  151. },
  152. // 确定选择的服务日期
  153. sureChooseDate(){
  154. this.dateShow = false;
  155. this.userInfo.birthday = this.$formatDate(this.value1)
  156. },
  157. // 选择服务日期
  158. chooseServiceDate(){
  159. this.value1 = Date.now();
  160. this.dateShow = true;
  161. },
  162. // 去会员信息页
  163. gotoMemberInfo(){
  164. uni.navigateTo({
  165. url: '/pages/member/member-info',
  166. })
  167. },
  168. // 去实名认证
  169. gotoRealNameAuth(){
  170. uni.navigateTo({
  171. url: '/pages/me/real-name-auth',
  172. })
  173. },
  174. // 保存用户信息
  175. saveUserInfo(){
  176. // 保存数据
  177. this.$api.saveUserInfo(null,{data:this.userInfo}).then((res)=>{
  178. console.log(res)
  179. // 刷新用户信息
  180. this.$refreshUserLoginInfo();
  181. uni.showToast({
  182. title: "操作成功"
  183. })
  184. uni.navigateTo({
  185. url: '/pages/index/tabbar',
  186. })
  187. }).catch(() =>{
  188. uni.showToast({
  189. title: "操作失败"
  190. })
  191. });
  192. },
  193. getImgUrlByOssId(Id){
  194. this.$api.getImgUrlByOssId(Id).then(res=>{
  195. this.userInfo.selfPhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
  196. });
  197. },
  198. //头像上传
  199. uploadImg1(imgIndex) {
  200. let that = this;
  201. uni.chooseImage({
  202. count: 1,
  203. success: (chooseImageRes) => {
  204. const tempFilePaths = chooseImageRes.tempFilePaths;
  205. uni.uploadFile({
  206. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  207. filePath: tempFilePaths[0],
  208. name: 'file',
  209. header: {
  210. // "Content-Type": "multipart/form-data",
  211. // 'X-Access-Token': uni.getStorageSync('token'),
  212. 'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
  213. },
  214. success: (uploadFileRes) => {
  215. let res = JSON.parse(uploadFileRes.data)
  216. console.log(res.data)
  217. that.userInfo.selfPhoto = res.data.ossId
  218. that.getImgUrlByOssId(res.data.ossId);
  219. }
  220. });
  221. }
  222. });
  223. }
  224. }
  225. };
  226. </script>
  227. <style lang="scss">
  228. .user-info-wrap{
  229. margin-left: 12px;
  230. margin-right: 12px;
  231. /* 导航菜单 */
  232. .nav-bar{
  233. background: #fff;
  234. border-radius: 10px;
  235. margin-top: 12px;
  236. /* 商店信息 */
  237. .nav-content{
  238. padding-top: 10px;
  239. padding-bottom: 6px;
  240. .nav-info{
  241. display: flex;
  242. padding-left: 10px;
  243. align-items: center;
  244. .logo {
  245. width: 12%;
  246. text-align: center;
  247. image{
  248. width: 24px;
  249. height: 24px;
  250. }
  251. }
  252. .nav-desc{
  253. width: 32%;
  254. display: flex;
  255. line-height: 30px;
  256. font-family: PingFangSC-Regular, PingFang SC;
  257. font-weight: 400;
  258. align-items: center;
  259. .custom-input{
  260. font-size: 12px;
  261. }
  262. .nav-name{
  263. width: 60%;
  264. font-size: 14px;
  265. color: #333333;
  266. line-height: 22px;
  267. }
  268. .change-store{
  269. text-align: right;
  270. width: 40%;
  271. font-size: 12px;
  272. color: #333333;
  273. line-height: 22px;
  274. }
  275. }
  276. .arrow-right{
  277. width:68%;
  278. text-align: right;
  279. margin: 0 auto;
  280. cursor: pointer;
  281. padding-top: 3px;
  282. display: flex;
  283. justify-content: flex-end;
  284. align-items: center;
  285. image{
  286. width: 18px;
  287. height: 18px;
  288. }
  289. .head-img {
  290. text-align: center;
  291. padding-right: 20px;
  292. image{
  293. width: 24px;
  294. height: 24px;
  295. }
  296. }
  297. }
  298. }
  299. }
  300. }
  301. .sure-btn{
  302. margin-top: 20px;
  303. width: 100%;
  304. .btn{
  305. text-align: center;
  306. height: 42px;
  307. background: #FFE05C;
  308. border-radius: 27px;
  309. color: #333333;
  310. line-height: 42px;
  311. margin-top: 12px;
  312. font-size: 14px;
  313. }
  314. }
  315. }
  316. </style>