鸿宇研学生前端代码
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.

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