普兆健康管家前端代码仓库
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.

375 lines
7.2 KiB

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