index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="user-content">
  3. <!-- 头部 -->
  4. <view class="user-head" @click="toUserPage">
  5. <view class="user-photo">
  6. <open-data type="userAvatarUrl"></open-data>
  7. <u-image v-show="!hasLogin" src="/static/logo.png" width="100" height="100"></u-image>
  8. </view>
  9. <view class="user-info">
  10. <view v-if="hasLogin" class="user-info-item">{{user.mobile||'--'}}</view>
  11. <view v-if="hasLogin" class="user-info-item">注册时间:{{user.registerTime||'--'}}</view>
  12. <u-button v-else="!hasLogin" plain size="mini" shape="circle" @click="toLoginPage">立即登录</u-button>
  13. </view>
  14. <view v-if="hasLogin">
  15. <u-icon name="arrow-right" color="#fff"></u-icon>
  16. </view>
  17. </view>
  18. <view class="my-ledou" v-if="hasLogin">
  19. <view class="user-jifen">
  20. <view>我的乐豆:<text>{{user.currentGold||0}}</text></view>
  21. <u-image mode="scaleToFill" width="35rpx" height="35rpx" src="/static/ledou.png"></u-image>
  22. </view>
  23. <view>
  24. <u-button size="mini" type="warning" shape="circle" @click="toLdPage">查看明细</u-button>
  25. </view>
  26. </view>
  27. <!-- 列表 -->
  28. <view class="user-list">
  29. <u-cell-group>
  30. <u-cell-item v-if="hasLogin" icon="order" icon-size="38" :icon-style="{color:'#ff5500'}" index="0" @click="toPage" title="我的订单"></u-cell-item>
  31. <u-cell-item v-if="hasLogin" icon="gift" icon-size="40" :icon-style="{color:'#aa55ff'}" index="5" @click="toPage" title="我的奖品"></u-cell-item>
  32. <u-cell-item v-if="hasLogin" icon="coupon" icon-size="40" :icon-style="{color:'#f29100'}" index="6" @click="toPage" title="我的礼品卡"></u-cell-item>
  33. <u-cell-item v-if="hasLogin" icon="list-dot" icon-size="36" :icon-style="{color:'#00aaff'}" index="1" @click="toPage" title="投递记录"></u-cell-item>
  34. <u-cell-item icon="question-circle" icon-size="39" :icon-style="{color:'#19be6b'}" index="2" @click="toPage" title="常见问题"></u-cell-item>
  35. <u-cell-item icon="phone" icon-size="40" :icon-style="{color:'#f00'}" @click="callPhone" title="联系客服"></u-cell-item>
  36. <u-cell-item icon="file-text" icon-size="40" :icon-style="{color:'#ffaa00'}" index="3" @click="toPage" title="服务协议"></u-cell-item>
  37. <u-cell-item icon="info-circle" icon-size="38" :icon-style="{color:'#55aa00'}" index="4" @click="toPage" title="关于我们"></u-cell-item>
  38. <u-cell-item icon="error-circle" icon-size="38" :icon-style="{color:'#aaaaff'}" :value="version" @click="checkUpdate" title="版本检查"></u-cell-item>
  39. </u-cell-group>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import { checkLogin, getUserInfo } from '@/api/login.js'
  45. export default {
  46. data() {
  47. return {
  48. hasLogin: false,
  49. userData: {},
  50. version: ''
  51. };
  52. },
  53. onShow() {
  54. checkLogin().then(res => {
  55. this.hasLogin = res.status == 200
  56. if(this.hasLogin){
  57. this.getUserInfo()
  58. }else{
  59. // uni.navigateTo({
  60. // url:"/pages/login/login"
  61. // })
  62. }
  63. })
  64. },
  65. computed: {
  66. user() {
  67. return this.userData
  68. }
  69. },
  70. onLoad() {
  71. // 开启分享
  72. uni.showShareMenu({
  73. withShareTicket: true,
  74. menus: ['shareAppMessage', 'shareTimeline']
  75. })
  76. },
  77. methods:{
  78. // 获取用户信息
  79. getUserInfo(){
  80. getUserInfo().then(res => {
  81. console.log(res,'getUserInfo')
  82. if(res.status == 200){
  83. this.$u.vuex("vuex_userData",res.data)
  84. this.userData = res.data
  85. console.log(this.userData,'-----用户信息')
  86. }
  87. })
  88. },
  89. // 获取当前小程序版本
  90. getVersion(){
  91. const accountInfo = uni.getAccountInfoSync();
  92. this.version = accountInfo.miniProgram.version
  93. // console.log(accountInfo,accountInfo.miniProgram.appId,'ppppppppp'); // 小程序 appId
  94. },
  95. // 检查更新
  96. checkUpdate(){
  97. if (uni.canIUse('getUpdateManager')) {
  98. const updateManager = uni.getUpdateManager()
  99. updateManager.onCheckForUpdate(function (res) {
  100. console.log('onCheckForUpdate====', res)
  101. // 请求完新版本信息的回调
  102. if (res.hasUpdate) {
  103. console.log('res.hasUpdate====')
  104. updateManager.onUpdateReady(function () {
  105. uni.showModal({
  106. title: '更新提示',
  107. content: '新版本已经准备好,是否重启应用?',
  108. success: function (res) {
  109. console.log('success====', res)
  110. // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
  111. if (res.confirm) {
  112. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  113. updateManager.applyUpdate()
  114. }
  115. }
  116. })
  117. })
  118. updateManager.onUpdateFailed(function () {
  119. // 新的版本下载失败
  120. uni.showModal({
  121. title: '已经有新版本了哟~',
  122. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  123. })
  124. })
  125. }
  126. })
  127. }
  128. },
  129. // 打开对应的页面
  130. toPage(index){
  131. console.log(index)
  132. let pageUrl=[
  133. '/pagesA/order/order',
  134. '/pages/userCenter/deliveryRecord',
  135. '/pages/userCenter/question',
  136. '/pages/agreement/agreement?fromPage=usercenter',
  137. '/pages/userCenter/aboutUs',
  138. '/pagesA/luckDraw/myJp?fromPage=usercenter',
  139. '/pagesA/giftCard/giftCard'
  140. ]
  141. uni.navigateTo({
  142. url: pageUrl[index]
  143. })
  144. },
  145. // 电话客服
  146. callPhone () {
  147. uni.makePhoneCall({
  148. phoneNumber: this.$store.state.vuex_kfMobile
  149. })
  150. },
  151. // 跳转
  152. toUserPage(){
  153. // 未登录跳转登录,已登录跳转用户信息页
  154. if(this.hasLogin){
  155. uni.navigateTo({
  156. url: '/pages/userCenter/userInfo/userInfo'
  157. })
  158. }else{
  159. this.toLoginPage()
  160. }
  161. },
  162. // 乐豆明细
  163. toLdPage(){
  164. uni.navigateTo({
  165. url: '/pages/userCenter/ldDetailed'
  166. })
  167. },
  168. bindGetUserInfo(res){
  169. console.log(res)
  170. },
  171. toLoginPage(){
  172. uni.navigateTo({
  173. url: '/pages/login/login'
  174. })
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss">
  180. .user-content{
  181. width: 100%;
  182. .user-head{
  183. background: #01c9b2;
  184. display: flex;
  185. align-items: center;
  186. padding: 35rpx 55rpx;
  187. .user-info{
  188. flex-grow: 1;
  189. padding: 0 20rpx;
  190. color: #FFFFFF;
  191. .user-info-item{
  192. margin: 10rpx 0;
  193. }
  194. }
  195. .user-photo{
  196. width: 100rpx;
  197. height: 100rpx;
  198. border-radius: 50%;
  199. overflow: hidden;
  200. margin-right: 5rpx;
  201. }
  202. }
  203. .my-ledou{
  204. background: #FFFFFF;
  205. border-radius: 15upx;
  206. display: flex;
  207. align-items: center;
  208. justify-content: space-between;
  209. padding: 20upx;
  210. margin: 20upx;
  211. box-shadow: 0upx 3upx 6upx #eee;
  212. .user-jifen{
  213. display: flex;
  214. align-items: center;
  215. text{
  216. font-size: 40upx;
  217. font-weight: bold;
  218. color: red;
  219. }
  220. >view{
  221. &:first-child{
  222. display: flex;
  223. align-items: center;
  224. }
  225. }
  226. }
  227. }
  228. .user-list{
  229. border-radius: 15upx;
  230. margin: 20upx;
  231. overflow: hidden;
  232. box-shadow: 0upx 3upx 6upx #eee;
  233. }
  234. .user-btn{
  235. padding: 85rpx 200rpx;
  236. }
  237. }
  238. </style>