userinfo.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <view>
  3. <view class="usermain">
  4. <view class="usermain-item">
  5. <view>头像</view>
  6. <view @click="uploadImg()">
  7. <image src="../../static/logo.png" v-if="avatar == null" mode="" style="width: 111rpx; height: 111rpx; border-radius: 50%"></image>
  8. <image v-else :src="avatar" mode="" style="width: 111rpx; height: 111rpx; border-radius: 50%"></image>
  9. </view>
  10. </view>
  11. <view class="usermain-item item-padding">
  12. <view>用户名</view>
  13. <view>
  14. <view class="cu-form-group">
  15. <input v-model="userName" placeholder="请输入用户名" />
  16. </view>
  17. </view>
  18. </view>
  19. <view class="usermain-item item-padding">
  20. <view>年龄</view>
  21. <view>
  22. <view class="cu-form-group">
  23. <input v-model="age" />
  24. </view>
  25. </view>
  26. </view>
  27. <!-- <view class="usermain-item item-padding">
  28. <view >姓名</view>
  29. <view class="cu-form-group">
  30. <input v-model="realName" placeholder="请填写您的真实姓名" />
  31. </view>
  32. </view> -->
  33. <view class="usermain-item item-padding">
  34. <view>手机</view>
  35. <view>
  36. <view class="cu-form-group">
  37. <input v-model="phone" placeholder="请输入联系电话" />
  38. </view>
  39. </view>
  40. </view>
  41. <view class="usermain-item item-padding">
  42. <view>性别</view>
  43. <view>
  44. <view class="cu-form-group">
  45. <u-radio-group v-model="sex">
  46. <u-radio shape="circle" active-color="#2FB57A" :name="1">男</u-radio>
  47. <u-radio shape="circle" active-color="#2FB57A" :name="2">女</u-radio>
  48. </u-radio-group>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="footer-btn">
  54. <view class="usermain-btn" @click="messagebtn()">保存</view>
  55. </view>
  56. <!-- 用于图片压缩的canvas画布 -->
  57. <canvas
  58. :style="{
  59. width: cw + 'px',
  60. height: cw + 'px',
  61. position: 'absolute',
  62. zIndex: -1,
  63. left: '-10000rpx',
  64. top: '-10000rpx'
  65. }"
  66. canvas-id="zipCanvas"
  67. ></canvas>
  68. <!--画布结束-->
  69. </view>
  70. </template>
  71. <script>
  72. import configdata from '../../common/config.js'
  73. import getLessLimitSizeImage from '@/utils/imageCompress.js'
  74. export default {
  75. data() {
  76. return {
  77. phone: '',
  78. avatar: '../../static/logo.png',
  79. userName: '',
  80. nickName: '',
  81. userId: '',
  82. realName: '',
  83. weChatId: '',
  84. password: '',
  85. platform: '',
  86. createTime: '',
  87. money: '',
  88. jiFen: '',
  89. status: '',
  90. zhiFuBao: '',
  91. zhiFuBaoName: '',
  92. sex: 1,
  93. age: 0,
  94. //画板边长默认是屏幕宽度,正方形画布
  95. cw: uni.getSystemInfoSync().windowWidth
  96. }
  97. },
  98. onLoad(e) {
  99. this.getUserInfo()
  100. // this.avatar = uni.getStorageSync('avatar')
  101. },
  102. methods: {
  103. goMyAddress() {
  104. uni.navigateTo({
  105. url: '../jifen/myaddress'
  106. })
  107. },
  108. uploadImg() {
  109. let token = uni.getStorageSync('token')
  110. if (!token) {
  111. this.goLoginInfo()
  112. return
  113. }
  114. let that = this
  115. var url = null
  116. uni.showActionSheet({
  117. // itemList按钮的文字接受的是数组
  118. itemList: ['查看头像', '从相册选择图片'],
  119. success(e) {
  120. var index = e.tapIndex
  121. if (index === 0) {
  122. // 用户点击了预览当前图片
  123. // 可以自己实现当前头像链接的读取
  124. let url = that.avatar
  125. let arr = []
  126. arr.push(url)
  127. uni.previewImage({
  128. // 预览功能图片也必须是数组的
  129. urls: arr
  130. })
  131. } else if (index === 1) {
  132. uni.chooseImage({
  133. count: 1,
  134. sourceType: ['album'],
  135. success: (res) => {
  136. for (let i = 0; i < res.tempFiles.length; i++) {
  137. //这里的id和页面中写的html代码的canvas的id要一致
  138. let canvasId = 'zipCanvas'
  139. //原图的路径
  140. let imagePath = res.tempFiles[i].path
  141. //大小限制
  142. let limitSize = 1024 * 2
  143. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  144. let drawWidth = uni.getSystemInfoSync().windowWidth
  145. let that = this
  146. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, that, (resPath) => {
  147. uni.showLoading({
  148. title: '上传中'
  149. })
  150. let token = uni.getStorageSync('shopToken')
  151. uni.uploadFile({
  152. url: that.config('APIHOST1') + '/admin/new-file/upload',
  153. filePath: resPath,
  154. header: {
  155. token: token
  156. },
  157. name: 'file',
  158. success: (uploadFileRes) => {
  159. url = JSON.parse(uploadFileRes.data)
  160. that.avatar = url.data
  161. uni.hideLoading()
  162. },
  163. fail: () => {
  164. uni.showToast({
  165. title: '上传失败',
  166. icon: 'error'
  167. })
  168. }
  169. })
  170. })
  171. }
  172. }
  173. })
  174. }
  175. }
  176. })
  177. },
  178. config: function (name) {
  179. var info = null
  180. if (name) {
  181. var name2 = name.split('.') //字符分割
  182. if (name2.length > 1) {
  183. info = configdata[name2[0]][name2[1]] || null
  184. } else {
  185. info = configdata[name] || null
  186. }
  187. if (info == null) {
  188. let web_config = cache.get('web_config')
  189. if (web_config) {
  190. if (name2.length > 1) {
  191. info = web_config[name2[0]][name2[1]] || null
  192. } else {
  193. info = web_config[name] || null
  194. }
  195. }
  196. }
  197. }
  198. return info
  199. },
  200. getUserInfo() {
  201. this.$Request.get('/sys/user/info').then((res) => {
  202. if (res.code == 0) {
  203. this.$queue.setData('avatar', res.user.userEntity.avatar)
  204. this.$queue.setData('userId', res.user.userId)
  205. this.$queue.setData('userName', res.user.userEntity.userName)
  206. this.$queue.setData('phone', res.user.userEntity.phone)
  207. this.$queue.setData('age', res.user.userEntity.age)
  208. this.sex = res.user.userEntity.sex
  209. this.age = res.user.userEntity.age
  210. this.phone = res.user.userEntity.phone
  211. this.avatar = res.user.userEntity.avatar
  212. this.userName = res.user.userEntity.userName
  213. if (this.userName == null) {
  214. this.userName = res.user.userEntity.nickName
  215. } else {
  216. this.userName = res.user.userEntity.userName
  217. }
  218. }
  219. uni.hideLoading()
  220. })
  221. },
  222. // 保存
  223. messagebtn() {
  224. let that = this
  225. if (!that.userName) {
  226. // this.$queue.showToast('用户名不能为空');
  227. uni.showToast({
  228. title: '用户名不能为空',
  229. icon: 'none'
  230. })
  231. } else if (!that.phone) {
  232. // this.$queue.showToast('用户名不能为空');
  233. uni.showToast({
  234. title: '联系电话不能为空',
  235. icon: 'none'
  236. })
  237. } else {
  238. uni.showModal({
  239. title: '温馨提示',
  240. content: '确定保存信息',
  241. success: (e) => {
  242. if (e.confirm) {
  243. that.$Request
  244. .postJson('/shop/shopmoney/updateUser', {
  245. userName: that.userName,
  246. avatar: that.avatar,
  247. phone: that.phone,
  248. sex: that.sex,
  249. age: that.age
  250. })
  251. .then((res) => {
  252. if (res.code === 0) {
  253. uni.showToast({
  254. title: '保存成功',
  255. icon: 'none'
  256. })
  257. setTimeout(function () {
  258. uni.navigateBack()
  259. }, 1000)
  260. } else {
  261. uni.showToast({
  262. title: res.msg,
  263. icon: 'none'
  264. })
  265. }
  266. })
  267. }
  268. }
  269. })
  270. }
  271. }
  272. }
  273. // userphone(){
  274. // uni.navigateTo({
  275. // url:'/pages/my/userphone'
  276. // })
  277. // }
  278. }
  279. </script>
  280. <style>
  281. page {
  282. /* background: #1c1b20; */
  283. }
  284. .usermain {
  285. background: #ffffff;
  286. /* color: #fff; */
  287. }
  288. .usermain-item {
  289. display: flex;
  290. align-items: center;
  291. margin: 0 40rpx;
  292. padding: 10rpx 0;
  293. justify-content: space-between;
  294. border-bottom: 1rpx solid #e5e5e5;
  295. /* border-bottom: 2rpx solid #f2f2f2; */
  296. }
  297. .usermain-item.item-padding {
  298. /* padding: 0; */
  299. }
  300. .cu-form-group {
  301. padding: 0;
  302. background: #ffffff;
  303. text-align: right;
  304. }
  305. .cu-form-group input {
  306. background: #ffffff;
  307. font-size: 28rpx;
  308. /* color: #fff; */
  309. }
  310. .footer-btn {
  311. margin-top: 150rpx;
  312. }
  313. .footer-btn .usermain-btn {
  314. /* color: #FFFFFF; */
  315. background: #fcd202;
  316. text-align: center;
  317. width: 450rpx;
  318. height: 80rpx;
  319. font-size: 28rpx;
  320. line-height: 80rpx;
  321. margin: 0 auto;
  322. border-radius: 40rpx;
  323. }
  324. </style>