index.vue 8.9 KB

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