ProfileSet.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <member-base :show="false"><view class="div member-information">
  3. <view class="div common-header-wrap">
  4. <view :style="'height:'+navHeight+'px'"></view>
  5. <view class="common-header-holder"></view>
  6. <view class="common-header-fixed">
  7. <title-header />
  8. <uni-nav-bar title="个人信息" class="common-header" left-icon="back" @clickLeft="goBack()">
  9. </uni-nav-bar>
  10. </view>
  11. </view>
  12. <view class="div user-avatar">
  13. <uni-file-picker class="common-avatar" v-model="imageValue" fileMediatype="image" mode="grid" :limit="1"
  14. :auto-upload="false" @select="uploadImage"></uni-file-picker>
  15. </view>
  16. <view class="div form">
  17. <flex-line class="menu-item field-line" :show-border="true"><text class="span field-name">用户名</text><view class="div field-line-right membername" slot="right"><text class="text">{{user.member_name}}</text></view></flex-line>
  18. <flex-line class="menu-item field-line" :show-border="true"><text class="span field-name">昵称</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="member_info.member_nickname" /></view></flex-line>
  19. <flex-line class="menu-item field-line" :show-border="true"><text class="span field-name">QQ</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="member_info.member_qq" /></view></flex-line>
  20. <flex-line class="menu-item field-line" :show-border="true"><text class="span field-name">旺旺</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="member_info.member_ww" /></view></flex-line>
  21. <view class="div">
  22. <flex-line class="menu-item" :is-link="true" :show-border="true">
  23. <text class="span line-name">出生日期</text>
  24. <view class="span" slot="right">
  25. <uni-datetime-picker class="common-datetime-picker" type="date" v-model="member_info.member_birthday"
  26. start="1970-1-1" :end="(new Date()).getFullYear()+'-'+((new Date()).getMonth()+1)+'-'+(new Date()).getDate()"></uni-datetime-picker>
  27. </view>
  28. </flex-line>
  29. </view>
  30. <view class="div pt-10 pb-10"><view class="div common-btn ds-button-large" @click="submitInformation">保存</view></view>
  31. </view>
  32. <tui-picture-cropper v-if="cropperOption.imgUrl" :width="cropperOption.autoCropWidth"
  33. :height="cropperOption.autoCropHeight" :imageUrl="cropperOption.img" @ready="cropReady" @cropper="useCrop" @back="cropBack">
  34. </tui-picture-cropper>
  35. </view></member-base>
  36. </template>
  37. <script>
  38. import {getFontSize} from '@/util/common'
  39. import TitleHeader from '../../TitleHeader'
  40. import MemberBase from '../MemberBase'
  41. import tuiPictureCropper from "@/components/thorui/tui-picture-cropper/tui-picture-cropper"
  42. import { mapState, mapMutations } from 'vuex'
  43. import { uploadMemberAvatar, updateMemberInfo } from '../../../api/member'
  44. import flexLine from '../../flexLine'
  45. export default {
  46. components:{
  47. TitleHeader,
  48. MemberBase,
  49. flexLine,
  50. tuiPictureCropper
  51. },
  52. name:'MemberProfileSet',
  53. data(){
  54. return {
  55. navHeight: 0,
  56. imageValue:[],
  57. screenWidth:0,
  58. screenHeight:0,
  59. cropperOption: {
  60. img: '',
  61. canMove: false,
  62. autoCrop: true,
  63. autoCropWidth: 100,
  64. autoCropHeight: 100,
  65. maxImgSize: 500,
  66. outputType: 'png'
  67. },
  68. member_info: {
  69. member_nickname: '',
  70. member_qq: '',
  71. member_ww: '',
  72. member_birthday: ''
  73. }
  74. }
  75. },
  76. mounted(){
  77. // #ifdef MP-WEIXIN
  78. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  79. // #endif
  80. const res = uni.getSystemInfoSync()
  81. this.screenWidth = res.windowWidth
  82. this.screenHeight = res.windowHeight
  83. },
  84. computed:{
  85. fontSize(){
  86. return getFontSize()
  87. },
  88. ...mapState({
  89. user: state => state.member.info
  90. })
  91. },
  92. created: function () {
  93. if (this.user) {
  94. this.member_info.member_nickname = this.user.member_nickname
  95. this.member_info.member_qq = this.user.member_qq
  96. this.member_info.member_ww = this.user.member_ww
  97. this.member_info.member_birthday = this.user.member_birthday
  98. if (this.user.member_avatar) {
  99. this.imageValue = [{
  100. name: 'member_avatar',
  101. extname: 'jpg',
  102. url: this.user.member_avatar
  103. }]
  104. }
  105. }
  106. },
  107. methods:{
  108. showPopup(id){
  109. this.$refs[id].open()
  110. },
  111. hidePopup(id){
  112. this.$refs[id].close()
  113. },
  114. goBack(){uni.navigateBack({delta:1})},
  115. ...mapMutations({
  116. memberEdit: 'memberEdit'
  117. }),
  118. uploadImage(event) {
  119. var file = event.tempFiles[0]
  120. var that = this
  121. that.cropperOption.imgUrl = file.path
  122. that.cropperOption.autoCropWidth = uni.getSystemInfoSync().windowWidth
  123. that.cropperOption.autoCropHeight = uni.getSystemInfoSync().windowWidth
  124. that.cropperOption.maxImgSize = uni.getSystemInfoSync().windowHeight - 40
  125. that.$forceUpdate()
  126. },
  127. useCrop(res) {
  128. var formdata = {
  129. filePath: res.url,
  130. name: 'memberavatar'
  131. }
  132. uni.showLoading({
  133. title: '加载中'
  134. })
  135. uploadMemberAvatar(formdata).then(res => {
  136. this.user.avatar = res.result + '?' + Math.floor(Math.random() * 100)
  137. this.imageValue = [{
  138. name: 'member_avatar',
  139. extname: 'jpg',
  140. url: this.user.avatar
  141. }]
  142. this.memberEdit({
  143. member_avatar: this.user.avatar
  144. })
  145. this.cropperOption.imgUrl = ''
  146. this.$forceUpdate()
  147. uni.hideLoading()
  148. }).catch(error => {
  149. uni.showToast({
  150. icon: 'none',
  151. title: error.message
  152. })
  153. uni.hideLoading()
  154. this.cropperOption.imgUrl = ''
  155. this.$forceUpdate()
  156. })
  157. },
  158. cropReady() {
  159. this.cropperOption.img = this.cropperOption.imgUrl
  160. },
  161. cropBack(){
  162. this.cropperOption.imgUrl=''
  163. this.$forceUpdate()
  164. },
  165. submitInformation () {
  166. updateMemberInfo(this.member_info).then(res => {
  167. this.memberEdit(this.member_info)
  168. uni.showToast({icon:'none',title: res.message})
  169. }).catch(function (error) {
  170. uni.showToast({icon:'none',title: error.message})
  171. })
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss" scoped>
  177. .common-header{
  178. .btn{background: #000;color: #fff;box-shadow: 0px 2px 4px #d2d2d2;}
  179. }
  180. .member-information {
  181. background: #fff;
  182. .form{padding:0 $pageSpace}
  183. .user-avatar {
  184. position: relative;
  185. margin: 2rem auto;
  186. text-align: center;
  187. }
  188. .menu-item {
  189. }
  190. .membername{
  191. justify-content: flex-end;
  192. }
  193. }
  194. </style>