myinfo.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <view class="myinfo">
  3. <!-- 顶部信息 -->
  4. <view class="myinfo_top">
  5. <view @click="tologin()" class="userImg">
  6. <u--image width='128rpx' height="128rpx" :src="myinfo.img" shape="circle"></u--image>
  7. </view>
  8. <view @click="tologin()" class="myinfo_text">
  9. <view class="myinfo_name">
  10. <text class="userName" >{{myinfo.name}}</text>
  11. <!-- <view class="myinfo_id">
  12. id:{{myinfo.id}}
  13. </view> -->
  14. </view>
  15. <!-- <view class="myinfo_qm">
  16. {{myinfo.qm}}
  17. </view> -->
  18. </view>
  19. <view @click="toUserInfo()">
  20. <u--image width="40rpx" height="40rpx" src="/static/myinfo/iconm_bianj.png" ></u--image>
  21. </view>
  22. </view>
  23. <!-- 中段菜单 -->
  24. <view class="myinfo_menus">
  25. <view class="myinfo_title">
  26. 常用功能
  27. </view>
  28. <view class="menus">
  29. <view v-for="item in list" :key="item.id">
  30. <view class="menus_item" @click="openLink(item)">
  31. <u-badge v-if="item.name == '我的订单'" :absolute="true" :offset='offset'
  32. numberType="overflow" type="error" max="99" :value="myinfo.orderCount"></u-badge>
  33. <u--image width="64rpx" height="64rpx" :src="item.url" ></u--image>
  34. {{item.name}}
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 下段菜单 -->
  40. <view class="myinfo_menus">
  41. <view class="myinfo_title">
  42. 其他
  43. </view>
  44. <view class="menus_foot">
  45. <view @click="openLink(item)" v-for="item in list2" :key="item.id">
  46. <view class="menus_foot_item">
  47. <view style="display: flex;align-items: center;">
  48. <u--image width="48rpx" height="48rpx" :src="item.url" ></u--image>
  49. <view style="margin-left: 20rpx;">{{item.name}}</view>
  50. </view>
  51. <u--image width="48rpx" height="48rpx" src="/static/myinfo/btn_right.png" ></u--image>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view v-if="showGetwxinfo" class="wxinfo">
  57. <view class='getwxinput'>
  58. <input type='nickname' name='nickname' :value='userInfo.nickname' @blur="onchangenickname" placeholder="点击获取微信昵称" />
  59. </view>
  60. <button type="balanced" open-type="chooseAvatar" @chooseavatar="onChooseavatar">
  61. 点击获取头像
  62. </button>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import {myInfo,modifyInfo} from '@/http/api/common.js'
  68. export default {
  69. data() {
  70. return {
  71. offset:[-10,-10],
  72. myinfo:{
  73. name:'未登录',
  74. id:'0',
  75. qm:'无',
  76. orderCount:'0',
  77. isVendor:'0',
  78. cartCount:'0',
  79. img:'https://cdn.uviewui.com/uview/album/1.jpg',
  80. },
  81. userInfo:{
  82. nickname:'',
  83. avatar:''
  84. },
  85. list:[
  86. {
  87. id:1,
  88. url:'/static/myinfo/iconm_xiaoxi.png',
  89. name:'消息中心',
  90. linkto:'/pages/myinfo/notifiesPage'
  91. },
  92. {
  93. id:2,
  94. url:'/static/myinfo/iconm_gouwu.png',
  95. name:'购物车',
  96. openType:'switchTab',
  97. linkto:'/pages/market/market'
  98. },
  99. {
  100. id:3,
  101. url:'/static/myinfo/icon_dingdang.png',
  102. name:'我的订单',
  103. linkto:'/pages/market/allOrder'
  104. },
  105. {
  106. id:4,
  107. url:'/static/myinfo/icomm_jilu.png',
  108. name:'浏览记录',
  109. linkto:'/pages/market/BrowsingHistory?showType=jilu'
  110. },
  111. ],
  112. list2:[
  113. {
  114. id:1,
  115. url:'/static/myinfo/icomx_wodgongy.png',
  116. name:'供应申报',
  117. linkto:'/supplierPages/pages/supplier/SupplyDeclaration'
  118. },
  119. {
  120. id:2,
  121. url:'/static/myinfo/icomx_gysrz.png',
  122. name:'供应商入驻',
  123. linkto:'/supplierPages/pages/supplier/SupplierEntryForm'
  124. },
  125. {
  126. id:3,
  127. url:'/static/myinfo/icomx_souc.png',
  128. name:'我的收藏',
  129. linkto:'/pages/market/BrowsingHistory?showType=shouchang'
  130. },
  131. {
  132. id:31,
  133. url:'/static/myinfo/iconx_wodwd.png',
  134. name:'我的问答',
  135. linkto:'/pages/home/exchangeNew?showType=mywenda'
  136. },
  137. {
  138. id:4,
  139. url:'/static/myinfo/icomx_dizhi.png',
  140. name:'我的地址',
  141. linkto:'/pages/myinfo/address'
  142. },
  143. {
  144. id:5,
  145. url:'/static/myinfo/icomx_message.png',
  146. name:'意见反馈',
  147. linkto:'/pages/myinfo/userInfo?showType=fangkui'
  148. },
  149. // {
  150. // id:4,
  151. // url:'/static/myinfo/iconx_xitongg.png',
  152. // name:'设置'
  153. // },
  154. ],
  155. showGetwxinfo:false,
  156. }
  157. },
  158. onShow() {
  159. if(uni.getStorageSync('AppAuthorization')){
  160. // 获取个人信息
  161. this.getmyInfo()
  162. }
  163. },
  164. methods: {
  165. async getmyInfo(){
  166. let res = await myInfo()
  167. console.log(res?.data?.data?.image);
  168. if (!res.data.data.image || res.data.data.image == '') {
  169. this.showGetwxinfo = true
  170. return
  171. }else{
  172. this.showGetwxinfo = false
  173. }
  174. if (res.data.code == 200) {
  175. this.myinfo.name = res.data.data.nickName
  176. this.myinfo.img = res.data.data.image
  177. this.myinfo.orderCount = res.data.data?.orderCount || 0
  178. this.myinfo.isVendor= res.data.data?.isVendor || 0
  179. this.myinfo.cartCount = res.data.data?.cartCount || 0
  180. uni.setStorageSync('shoppingCartTotal',this.myinfo.cartCount)
  181. if (this.myinfo.cartCount != 0) {
  182. uni.setTabBarBadge({
  183. index: 3,
  184. text: this.myinfo.cartCount
  185. });
  186. }else{
  187. uni.hideTabBarRedDot({
  188. index: 3,
  189. });
  190. }
  191. }
  192. },
  193. onchangenickname(e){
  194. this.userInfo.nickname = e.detail.value
  195. },
  196. async onChooseavatar(e) {
  197. let avatarUrl = 'data:image/jpeg;base64,' + uni.getFileSystemManager().readFileSync(e.detail.avatarUrl,'base64')
  198. this.userInfo.avatar = avatarUrl
  199. let res = await modifyInfo({
  200. nickname:this.userInfo.nickname,
  201. images:this.userInfo.avatar
  202. })
  203. if (res.data.code == 200) {
  204. this.getmyInfo()
  205. }
  206. this.showGetwxinfo=false
  207. },
  208. uploadFilePromise(file) {
  209. return new Promise((resolve, reject) => {
  210. let a = uni.uploadFile({
  211. url: env.BASEURL + '/open/upload/uploadFile', // 仅为示例,非真实的接口地址
  212. filePath: file.url,
  213. name: 'file',
  214. success: (res) => {
  215. const fileData = JSON.parse(res.data)
  216. if (fileData.code == 500) {
  217. resolve('')
  218. }else{
  219. const fileData = JSON.parse(res.data)
  220. resolve(fileData.data.fileUrl)
  221. }
  222. }
  223. });
  224. })
  225. },
  226. tologin(){
  227. if(uni.getStorageSync('AppAuthorization')){
  228. //登录
  229. return
  230. }
  231. uni.navigateTo({
  232. url: '/pages/myinfo/login'
  233. });
  234. },
  235. toUserInfo(){
  236. if(!uni.getStorageSync('AppAuthorization')){
  237. uni.navigateTo({
  238. url: '/pages/myinfo/login'
  239. });
  240. //登录
  241. return
  242. }
  243. uni.navigateTo({
  244. url: '/pages/myinfo/userInfo'
  245. });
  246. },
  247. openLink(data){
  248. console.log(data.name,data.openType);
  249. if (data?.linkto) {
  250. if (data.openType == 'switchTab') {
  251. uni.switchTab({
  252. url: data.linkto
  253. });
  254. }else{
  255. if (data.name == '供应商入驻' && this.myinfo?.isVendor == '1') {
  256. uni.showToast({
  257. title: '您已经入驻供应商了',
  258. icon: 'none'
  259. });
  260. }else{
  261. uni.navigateTo({
  262. url: data.linkto
  263. });
  264. }
  265. }
  266. }
  267. }
  268. }
  269. }
  270. </script>
  271. <style>
  272. .myinfo{
  273. background: linear-gradient(180deg, #D3E5FF 0%, rgba(246,246,246,0.2) 100%);
  274. }
  275. .userImg{
  276. width: 128rpx;
  277. height: 128rpx;
  278. }
  279. .userName{
  280. min-width: 64rpx;
  281. height: 45rpx;
  282. font-size: 32rpx;
  283. font-weight: bold;
  284. color: #333333;
  285. line-height: 36rpx;
  286. }
  287. .myinfo_top{
  288. display: flex;
  289. width: 90vw;
  290. margin: 0 auto;
  291. align-items: center;
  292. padding-top: 40rpx;
  293. }
  294. .myinfo_text{
  295. margin-left: 40rpx;
  296. min-width: 460rpx;
  297. }
  298. .myinfo_name{
  299. display: flex;
  300. align-items: center;
  301. }
  302. .myinfo_id{
  303. margin-left: 20rpx;
  304. width: 145rpx;
  305. height: 40rpx;
  306. background: linear-gradient(180deg, #46A6FF 0%, #96CBFB 100%);
  307. border-radius: 24rpx 24rpx 24rpx 24rpx;
  308. opacity: 1;
  309. text-align: center;
  310. font-size: 24rpx;
  311. font-weight: 400;
  312. color: #FFFFFF;
  313. line-height: 36rpx;
  314. }
  315. .myinfo_qm{
  316. height: 40rpx;
  317. font-size: 28rpx;
  318. font-weight: 400;
  319. color: #999999;
  320. line-height: 36rpx;
  321. }
  322. .myinfo_menus{
  323. width: 90vw;
  324. margin: 0 auto;
  325. background-color: white;
  326. margin-top: 40rpx;
  327. border-radius: 24rpx 24rpx 24rpx 24rpx;
  328. opacity: 1;
  329. }
  330. .myinfo_title{
  331. font-size: 40rpx;
  332. padding: 30rpx 0 30rpx 40rpx;
  333. width: 128rpx;
  334. height: 45rpx;
  335. font-size: 32rpx;
  336. font-weight: bold;
  337. color: #333333;
  338. line-height: 45rpx;
  339. }
  340. .menus_item{
  341. display: flex;
  342. flex-direction: column;
  343. align-items: center;
  344. font-size: 28rpx;
  345. font-weight: 400;
  346. color: #333333;
  347. line-height: 36rpx;
  348. position: relative
  349. }
  350. .menus{
  351. padding-bottom: 40rpx;
  352. display: flex;
  353. justify-content: space-around;
  354. }
  355. .menus_foot{
  356. width: 90%;
  357. margin: 0 auto;
  358. }
  359. .menus_foot_item{
  360. display: flex;
  361. align-items: center;
  362. height: 100rpx;
  363. justify-content: space-between;
  364. }
  365. .getwxinput{
  366. text-align: center;
  367. margin: 20rpx 0;
  368. }
  369. .wxinfo{
  370. position: fixed;
  371. z-index: 10000;
  372. top: 30vh;
  373. width: 600rpx;
  374. height: 330rpx;
  375. left: 55rpx;
  376. background: #e7e7e7;
  377. border-radius: 10rpx;
  378. padding: 20rpx;
  379. display: flex;
  380. flex-direction: column;
  381. align-items: center;
  382. justify-content: center;
  383. }
  384. </style>