鸿宇研学生前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

382 lines
7.3 KiB

3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
  1. <template>
  2. <view class="page__view">
  3. <navbar title="修改信息" leftClick @leftClick="$utils.navigateBack" color="#191919" bgColor="#FFFFFF" />
  4. <view class="main">
  5. <view class="card">
  6. <view class="card-header">个人信息</view>
  7. <view class="form">
  8. <uv-form
  9. ref="form"
  10. :model="form"
  11. :rules="rules"
  12. errorType="toast"
  13. >
  14. <view class="form-item">
  15. <uv-form-item prop="name" :customStyle="formItemStyle">
  16. <view class="form-item-label">昵称</view>
  17. <view class="form-item-content input">
  18. <input
  19. type="nickname"
  20. placeholder="请输入"
  21. placeholderStyle="color: #C6C6C6; font-size: 32rpx; font-weight: 400;"
  22. v-model="form.name"
  23. />
  24. </view>
  25. </uv-form-item>
  26. </view>
  27. <view class="form-item">
  28. <uv-form-item prop="phone" :customStyle="formItemStyle">
  29. <view class="form-item-label">电话</view>
  30. <view class="form-item-content input">
  31. <formInput v-if="form.phone" v-model="form.phone"></formInput>
  32. <view v-else>
  33. <button
  34. class="btn btn-phone"
  35. open-type="getPhoneNumber"
  36. @getphonenumber="getPhone"
  37. >
  38. <view class="text placeholder">获取电话号码</view>
  39. </button>
  40. </view>
  41. </view>
  42. </uv-form-item>
  43. </view>
  44. <view class="form-item">
  45. <uv-form-item prop="phone" :customStyle="formItemStyle">
  46. <view class="form-item-label">头像</view>
  47. <view class="form-item-content input">
  48. <button class="btn btn-avatar" :plain="true" :hairline="false" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  49. <view v-if="form.avatar" class="avatar">
  50. <image class="img" :src="form.avatar" mode="aspectFill"></image>
  51. <view class="flex mask">
  52. <image class="icon" src="@/static/image/icon-change.png" mode="widthFix" />
  53. </view>
  54. </view>
  55. <view v-else class="flex avatar is-empty">
  56. <image class="icon" src="@/static/image/icon-plus.png" mode="widthFix" />
  57. </view>
  58. </button>
  59. </view>
  60. </uv-form-item>
  61. </view>
  62. </uv-form>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="bottom">
  67. <button class="btn" @click="onSubmit">保存</button>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import { mapState } from 'vuex'
  73. import formInput from '@/pages_order/components/formInput.vue'
  74. export default {
  75. components: {
  76. formInput,
  77. },
  78. props: {
  79. mode: {
  80. type: String,
  81. default: null,
  82. }
  83. },
  84. data() {
  85. return {
  86. form: {
  87. name: null,
  88. phone: null,
  89. avatar: null,
  90. },
  91. rules: {
  92. 'name': {
  93. type: 'string',
  94. required: true,
  95. message: '请输入昵称',
  96. },
  97. 'phone': {
  98. type: 'string',
  99. required: true,
  100. message: '请输入手机号',
  101. },
  102. 'avatar': {
  103. type: 'array',
  104. required: true,
  105. message: '请选择头像',
  106. },
  107. },
  108. formItemStyle: { padding: 0 },
  109. }
  110. },
  111. computed: {
  112. ...mapState(['userInfo']),
  113. },
  114. onLoad(arg) {
  115. this.mode = arg.mode
  116. this.form.name = this.userInfo.name || ''
  117. this.form.phone = this.userInfo.phone || ''
  118. this.form.avatar = this.userInfo.avatar || ''
  119. },
  120. methods: {
  121. onChooseAvatar(res) {
  122. this.$Oss.ossUpload(res.target.avatarUrl)
  123. .then(url => {
  124. this.form.avatar = url
  125. })
  126. },
  127. getPhone(e){
  128. this.$api('bindPhone', {
  129. code : e.detail.code
  130. }, res => {
  131. if(res.code == 200){
  132. if(res.success){
  133. this.form.phone = res.result
  134. }else{
  135. uni.showModal({
  136. title: res.message
  137. })
  138. }
  139. }
  140. })
  141. },
  142. async onSubmit() {
  143. try {
  144. await this.$refs.form.validate()
  145. const {
  146. name,
  147. phone,
  148. avatar,
  149. } = this.form
  150. const params = {
  151. name,
  152. phone,
  153. avatar,
  154. }
  155. // todo: check 415 Unsupported Media Type
  156. const res = await this.$fetch('updateInfo', params, false)
  157. if (res.code == 200) {
  158. uni.showToast({
  159. icon: 'success',
  160. title: '保存成功',
  161. });
  162. this.$store.commit('getUserInfo')
  163. setTimeout(() => {
  164. if (this.mode === 'edit') {
  165. this.$utils.navigateBack()
  166. return
  167. }
  168. uni.reLaunch({
  169. url:'/pages/index/index'
  170. })
  171. }, 800)
  172. }
  173. } catch (err) {
  174. console.log('onSubmit err', err)
  175. }
  176. },
  177. },
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. .page__view {
  182. width: 100vw;
  183. min-height: 100vh;
  184. background: $uni-bg-color;
  185. position: relative;
  186. /deep/ .nav-bar__view {
  187. position: fixed;
  188. top: 0;
  189. left: 0;
  190. }
  191. }
  192. .main {
  193. padding: calc(var(--status-bar-height) + 144rpx) 32rpx 224rpx 32rpx;
  194. }
  195. .card {
  196. padding: 32rpx;
  197. background: #FFFFFF;
  198. border: 2rpx solid #FFFFFF;
  199. border-radius: 32rpx;
  200. & + & {
  201. margin-top: 40rpx;
  202. }
  203. &-header {
  204. font-family: PingFang SC;
  205. font-weight: 500;
  206. font-size: 36rpx;
  207. line-height: 1.4;
  208. color: #252545;
  209. margin-bottom: 32rpx;
  210. }
  211. }
  212. .row {
  213. justify-content: space-between;
  214. font-family: PingFang SC;
  215. font-weight: 400;
  216. line-height: 1.4;
  217. column-gap: 24rpx;
  218. & + & {
  219. margin-top: 32rpx;
  220. }
  221. &-label {
  222. flex: none;
  223. font-size: 26rpx;
  224. color: #8B8B8B;
  225. }
  226. &-content {
  227. font-size: 32rpx;
  228. color: #181818;
  229. }
  230. }
  231. .form {
  232. padding: 8rpx 0 0 0;
  233. &-item {
  234. border-bottom: 2rpx solid #EEEEEE;
  235. &:last-child {
  236. border: none;
  237. }
  238. & + & {
  239. margin-top: 40rpx;
  240. }
  241. &-label {
  242. font-family: PingFang SC;
  243. font-weight: 400;
  244. font-size: 26rpx;
  245. line-height: 1.4;
  246. color: #181818;
  247. }
  248. &-content {
  249. margin-top: 14rpx;
  250. padding: 6rpx 0;
  251. .text {
  252. padding: 2rpx 0;
  253. font-family: PingFang SC;
  254. font-weight: 400;
  255. font-size: 32rpx;
  256. line-height: 1.4;
  257. &.placeholder {
  258. color: #C6C6C6;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. .btn-phone {
  265. text-align: left;
  266. font-family: PingFang SC;
  267. font-weight: 400;
  268. font-size: 32rpx;
  269. line-height: 1.4;
  270. color: #393939;
  271. }
  272. .btn-avatar {
  273. display: inline-block;
  274. width: auto;
  275. border: none;
  276. }
  277. .avatar {
  278. position: relative;
  279. width: 200rpx;
  280. height: 200rpx;
  281. border-radius: 24rpx;
  282. overflow: hidden;
  283. .img {
  284. width: 100%;
  285. height: 100%;
  286. }
  287. .mask {
  288. position: absolute;
  289. top: 0;
  290. left: 0;
  291. width: 100%;
  292. height: 100%;
  293. background: #00000080;
  294. border-radius: 24rpx;
  295. .icon {
  296. width: 64rpx;
  297. height: 64rpx;
  298. }
  299. }
  300. &.is-empty {
  301. background: #F3F2F7;
  302. .icon {
  303. width: 61rpx;
  304. height: auto;
  305. }
  306. }
  307. }
  308. .bottom {
  309. position: fixed;
  310. left: 0;
  311. bottom: 0;
  312. width: 100vw;
  313. // height: 200rpx;
  314. padding: 24rpx 40rpx;
  315. padding-bottom: calc(env(safe-area-inset-bottom) + 24rpx);
  316. background: #FFFFFF;
  317. box-sizing: border-box;
  318. .btn {
  319. width: 100%;
  320. padding: 14rpx 0;
  321. box-sizing: border-box;
  322. font-family: PingFang SC;
  323. font-weight: 500;
  324. font-size: 36rpx;
  325. line-height: 1;
  326. color: #FFFFFF;
  327. background: linear-gradient(to right, #21FEEC, #019AF9);
  328. border: 2rpx solid #00A9FF;
  329. border-radius: 41rpx;
  330. }
  331. }
  332. </style>