index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view class="content">
  3. <image src="https://soap.cliu.cc/chumeng/indexBanner.png" class="content_banner"></image>
  4. <view style="padding: 0 24rpx 2rpx 24rpx;">
  5. <view class="content_item flexB" v-for="(item, i) in list" :key="i" @click="getUrl(item.name, item.url)">
  6. <view class="flexM">
  7. <text>{{ item.name }}</text>
  8. <text>{{ item.tip }}</text>
  9. </view>
  10. <image :src="`${'../../static/index/' + item.icon}`"></image>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import { wxLogin, getOpenid } from '@/api/index.js'
  17. export default {
  18. data() {
  19. return {
  20. data: {},
  21. list: [
  22. {
  23. name: '肥皂下单',
  24. tip: '大卫博士竹炭植物精油皂',
  25. icon: 'soap.png',
  26. url: '../Buy_soap_tape/goods?type=soap'
  27. }
  28. ]
  29. }
  30. },
  31. onShow() {
  32. let wxcode = this.getUrlParam('code')
  33. // 回调
  34. if (!uni.getStorageSync('token') && wxcode) {
  35. wxLogin({ code: wxcode }).then(res => {
  36. uni.hideLoading()
  37. if (res.code == 200) {
  38. this.checkLogin(res.data)
  39. } else {
  40. uni.showModal({
  41. title: '提示',
  42. content: res.msg,
  43. showCancel: false
  44. })
  45. }
  46. })
  47. return
  48. }
  49. // 有token
  50. if (uni.getStorageSync('userInfo') && uni.getStorageSync('token')) {
  51. this.showALL()
  52. } else {
  53. this.toWxchatLogin("/", null)
  54. return false
  55. }
  56. },
  57. methods: {
  58. // 跳转微信授权
  59. toWxchatLogin(url, state) {
  60. url = url || '/pages/index/index';
  61. state = state || 'cli';
  62. const redirect_uri = encodeURIComponent(`${this.$config.redirect_uri}/#${url}`);
  63. const auth = () =>
  64. (window.location.href = `${this.$config.wxURL}?appid=${
  65. this.$config.appid
  66. }&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`);
  67. auth();
  68. },
  69. //获取code值方法
  70. getUrlParam(name) {
  71. var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); //构造一个含有目标参数的正则表达式对象
  72. var r = window.location.search.substr(1).match(reg); //匹配目标参数
  73. if (r != null) return decodeURIComponent(r[2]);
  74. // return null; //返回参数值
  75. return ''; //返回参数值
  76. },
  77. // 批发商显示所有操作
  78. showALL() {
  79. let userInfo = uni.getStorageSync('userInfo')
  80. if (userInfo.level == 3) {
  81. this.list = [
  82. {
  83. name: '退货',
  84. tip: '订单退货或取消',
  85. icon: 'tui.png',
  86. url: '../return/list'
  87. },
  88. {
  89. name: '调货',
  90. tip: '款式或尺码调换',
  91. icon: 'huan.png',
  92. url: ''
  93. },{
  94. name: '肥皂下单',
  95. tip: '大卫博士竹炭植物精油皂',
  96. icon: 'soap.png',
  97. url: '../Buy_soap_tape/goods?type=soap'
  98. },{
  99. name: '胶带下单',
  100. tip: '品牌周边产品效应',
  101. icon: 'tape.png',
  102. url: '../Buy_soap_tape/goods?type=tape'
  103. }
  104. ]
  105. }
  106. },
  107. checkLogin(data) {
  108. // 登录后
  109. if (data.token) {
  110. uni.showLoading({ title: '加载中', mask: true })
  111. uni.setStorageSync('token', data.token)
  112. uni.setStorageSync('userInfo', data.user)
  113. this.showALL()
  114. uni.hideLoading()
  115. } else if (!data.token && data.openid) {
  116. uni.showModal({
  117. title: '提示',
  118. content: data.msg,
  119. showCancel: false,
  120. success: res => {
  121. uni.reLaunch({
  122. url: '../login/login?type=index' + '&openid=' + data.openid
  123. })
  124. }
  125. })
  126. } else if (!data.token && !data.openid) {
  127. uni.showModal({
  128. title: '错误提示',
  129. content: data.msg,
  130. showCancel: false
  131. })
  132. }
  133. },
  134. // 跳转页面
  135. getUrl(name, url) {
  136. if (uni.getStorageSync('token')) {
  137. if (name == '调货') {
  138. uni.toast('该功能暂未开通')
  139. return
  140. }
  141. uni.navigateTo({
  142. url: url
  143. })
  144. }
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .content {
  151. &_banner {
  152. width: 100%;
  153. height: 476rpx;
  154. margin-bottom: 32rpx;
  155. }
  156. &_item {
  157. background-color: #fff;
  158. margin-bottom: 24rpx;
  159. padding: 24rpx 40rpx;
  160. border-radius: 16rpx 16rpx 16rpx 16rpx;
  161. .flexM {
  162. text:nth-child(1) {
  163. font-size: 36rpx;
  164. font-family: PingFang SC-Bold, PingFang SC;
  165. font-weight: bold;
  166. color: #333333;
  167. margin-bottom: 10rpx;
  168. }
  169. text:nth-child(2) {
  170. font-size: 28rpx;
  171. font-family: PingFang SC-Regular, PingFang SC;
  172. font-weight: 400;
  173. color: #999999;
  174. }
  175. }
  176. image {
  177. width: 100rpx;
  178. height: 100rpx;
  179. }
  180. }
  181. }
  182. </style>