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

380 lines
7.3 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="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="@/pages_order/static/center/icon-change.png" mode="widthFix" />
  53. </view>
  54. </view>
  55. <view v-else class="flex avatar is-empty">
  56. <image class="icon" src="@/pages_order/static/comment/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. const res = await this.$fetch('updateInfo', params, false)
  156. if (res.code == 200) {
  157. uni.showToast({
  158. icon: 'success',
  159. title: '保存成功',
  160. });
  161. this.$store.commit('getUserInfo')
  162. setTimeout(() => {
  163. if (this.mode === 'edit') {
  164. this.$utils.navigateBack()
  165. return
  166. }
  167. uni.reLaunch({
  168. url:'/pages/index/index'
  169. })
  170. }, 800)
  171. }
  172. } catch (err) {
  173. console.log('onSubmit err', err)
  174. }
  175. },
  176. },
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .page__view {
  181. width: 100vw;
  182. min-height: 100vh;
  183. background-color: $uni-bg-color;
  184. position: relative;
  185. /deep/ .nav-bar__view {
  186. position: fixed;
  187. top: 0;
  188. left: 0;
  189. }
  190. }
  191. .main {
  192. padding: calc(var(--status-bar-height) + 144rpx) 32rpx 224rpx 32rpx;
  193. }
  194. .card {
  195. padding: 32rpx;
  196. background: #FAFAFF;
  197. border: 2rpx solid #FFFFFF;
  198. border-radius: 32rpx;
  199. & + & {
  200. margin-top: 40rpx;
  201. }
  202. &-header {
  203. font-family: PingFang SC;
  204. font-weight: 500;
  205. font-size: 36rpx;
  206. line-height: 1.4;
  207. color: #252545;
  208. margin-bottom: 32rpx;
  209. }
  210. }
  211. .row {
  212. justify-content: space-between;
  213. font-family: PingFang SC;
  214. font-weight: 400;
  215. line-height: 1.4;
  216. column-gap: 24rpx;
  217. & + & {
  218. margin-top: 32rpx;
  219. }
  220. &-label {
  221. flex: none;
  222. font-size: 26rpx;
  223. color: #8B8B8B;
  224. }
  225. &-content {
  226. font-size: 32rpx;
  227. color: #181818;
  228. }
  229. }
  230. .form {
  231. padding: 8rpx 0 0 0;
  232. &-item {
  233. border-bottom: 2rpx solid #EEEEEE;
  234. &:last-child {
  235. border: none;
  236. }
  237. & + & {
  238. margin-top: 40rpx;
  239. }
  240. &-label {
  241. font-family: PingFang SC;
  242. font-weight: 400;
  243. font-size: 26rpx;
  244. line-height: 1.4;
  245. color: #181818;
  246. }
  247. &-content {
  248. margin-top: 14rpx;
  249. padding: 6rpx 0;
  250. .text {
  251. padding: 2rpx 0;
  252. font-family: PingFang SC;
  253. font-weight: 400;
  254. font-size: 32rpx;
  255. line-height: 1.4;
  256. &.placeholder {
  257. color: #C6C6C6;
  258. }
  259. }
  260. }
  261. }
  262. }
  263. .btn-phone {
  264. text-align: left;
  265. font-family: PingFang SC;
  266. font-weight: 400;
  267. font-size: 32rpx;
  268. line-height: 1.4;
  269. color: #393939;
  270. }
  271. .btn-avatar {
  272. display: inline-block;
  273. width: auto;
  274. border: none;
  275. }
  276. .avatar {
  277. position: relative;
  278. width: 200rpx;
  279. height: 200rpx;
  280. border-radius: 24rpx;
  281. overflow: hidden;
  282. .img {
  283. width: 100%;
  284. height: 100%;
  285. }
  286. .mask {
  287. position: absolute;
  288. top: 0;
  289. left: 0;
  290. width: 100%;
  291. height: 100%;
  292. background: #00000080;
  293. border-radius: 24rpx;
  294. .icon {
  295. width: 64rpx;
  296. height: 64rpx;
  297. }
  298. }
  299. &.is-empty {
  300. background: #F3F2F7;
  301. .icon {
  302. width: 61rpx;
  303. height: auto;
  304. }
  305. }
  306. }
  307. .bottom {
  308. position: fixed;
  309. left: 0;
  310. bottom: 0;
  311. width: 100vw;
  312. // height: 200rpx;
  313. padding: 24rpx 40rpx;
  314. padding-bottom: calc(env(safe-area-inset-bottom) + 24rpx);
  315. background: #FFFFFF;
  316. box-sizing: border-box;
  317. .btn {
  318. width: 100%;
  319. padding: 16rpx 0;
  320. box-sizing: border-box;
  321. font-family: PingFang SC;
  322. font-weight: 500;
  323. font-size: 36rpx;
  324. line-height: 1;
  325. color: #FFFFFF;
  326. background-image: linear-gradient(to right, #4B348F, #845CFA);
  327. border-radius: 41rpx;
  328. }
  329. }
  330. </style>