index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view class="container home clearfix" :style="{paddingTop:CustomBar+'px'}">
  3. <customer ref="customer" :navbar-data='nvabarData'></customer>
  4. <!-- 主页内容 -->
  5. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading ="true" :loadingType="5"></tui-skeleton>
  6. <view class="container-home tui-skeleton">
  7. <!-- 轮播 -->
  8. <banner :list="bannerImageList" v-if="isRequest"></banner>
  9. <!-- 金刚区菜单 -->
  10. <navbars :list="navBarsList" v-if="isRequest"></navbars>
  11. <!-- 直播 -->
  12. <page-special :templateData="templateData" v-if="isRequest"></page-special>
  13. </view>
  14. <!-- 楼层 -->
  15. <view class="container-section tui-skeleton">
  16. <page-floor :list="pageList" :userIdentity="userIdentity" v-if="isRequest"></page-floor>
  17. <supplier-list :supplierObj="supplierObj" v-if="isRequest"></supplier-list>
  18. </view>
  19. <!-- 侧边 -->
  20. <scroll-top :isScrollTop="isScrollTop" :bottom="50"></scroll-top>
  21. </view>
  22. </template>
  23. <script>
  24. import tuiSkeleton from "@/components/tui-skeleton/tui-skeleton"
  25. import authorize from '@/common/config/authorize.js'
  26. import customer from '@/components/cm-module/homeIndex/customer.vue'
  27. import banner from '@/components/cm-module/homeIndex/banner.vue'
  28. import navbars from '@/components/cm-module/homeIndex/navbars.vue'
  29. import pageFloor from '@/components/cm-module/homeIndex/pageFloor.vue'
  30. import pageSpecial from '@/components/cm-module/homeIndex/pageSpecial.vue'
  31. import supplierList from '@/components/cm-module/homeIndex/supplierList.vue'
  32. import { userInfoLogin } from "@/api/use.js"
  33. import { mapState,mapMutations} from 'vuex';
  34. export default {
  35. components:{
  36. tuiSkeleton,
  37. customer,
  38. banner,
  39. navbars,
  40. pageFloor,
  41. pageSpecial,
  42. supplierList
  43. },
  44. data() {
  45. return {
  46. webviewStyles: {
  47. progress: {
  48. color: '#FF3333'
  49. }
  50. },
  51. nvabarData: {//顶部自定义导航
  52. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  53. showSearch: 0,
  54. title: '采美采购商城', // 导航栏 中间的标题
  55. haveBack:false,
  56. textLeft:this.$store.state.isIphone,
  57. textColor:'#FFFFFF'
  58. },
  59. CustomBar:this.CustomBar,// 顶部导航栏高度
  60. userID:0,
  61. clubStatus:'',
  62. current:0,
  63. mode:'round',
  64. modallayer:false,
  65. isLogin:false,
  66. skeletonShow: true,
  67. userIdentity:'',
  68. flootData:[],//楼层
  69. bannerImageList:[],//轮播
  70. navBarsList:[],//导航分类
  71. templateData:[],
  72. pageList:[],//楼层
  73. supplierObj:{},//供应商列表
  74. isScrollTop:false,
  75. isRequest:false,
  76. }
  77. },
  78. onLoad() {
  79. },
  80. computed: {
  81. ...mapState(['hasLogin','userInfo','identity'])
  82. },
  83. methods: {
  84. ...mapMutations(['login','logout']),
  85. getWxAuthorize(){
  86. authorize.getCode('weixin').then(wechatcode =>{// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  87. authorize.getUserInfo('weixin').then(wxResponse =>{
  88. userInfoLogin({code:wechatcode,encryptedData:wxResponse.encryptedData,iv:wxResponse.iv}).then(response =>{
  89. this.isLogin = true;
  90. this.userID = response.data.userID;
  91. this.userIdentity = response.data.userIdentity;
  92. this.clubStatus = response.data.clubStatus;
  93. this.$store.commit('updateStatus',response.data)
  94. this.login(response.data);
  95. uni.setStorageSync('token',response.data.token)
  96. uni.removeStorageSync('sessionid')
  97. uni.setStorageSync('sessionid','JSESSIONID='+response.data.sessionId)
  98. if(response.data.userIdentity ==1){
  99. this.$api.redirectTo('/seller/pages/index/index')
  100. }else if(response.data.userIdentity === 3){
  101. this.$api.redirectTo('/supplier/pages/index/index')
  102. }
  103. this.getHomeInformation()
  104. }).catch(error =>{
  105. this.isLogin = false;
  106. this.logout()
  107. uni.removeStorageSync('sessionid')
  108. uni.setStorageSync('sessionid','JSESSIONID='+error.data)
  109. this.$store.commit('updateStatus',error.data)
  110. this.getHomeInformation()
  111. })
  112. })
  113. })
  114. },
  115. GetHomeInit(){//金刚区分类
  116. this.CommonService.GetHomeInit({}).then(response =>{
  117. let data = response.data
  118. this.navBarsList = data.topMenuList
  119. }).catch(error =>{
  120. this.$util.msg(error.msg,2000)
  121. })
  122. },
  123. GetHomeTopDataInfo(){//金刚区分类
  124. this.CommonService.GetHomeTopDataInfo({source:2}).then(response =>{
  125. this.templateData = response.data
  126. console.log(this.templateData)
  127. }).catch(error =>{
  128. this.$util.msg(error.msg,2000)
  129. })
  130. },
  131. GetHomeFloorInfo(){//初始化首页楼层数据
  132. this.CommonService.GetHomeDataInfo({userId:this.userID,soure:2}).then(response =>{
  133. let data = response.data;
  134. this.liveList = data.liveList;
  135. this.pageList = data.homePageFloor;
  136. this.supplierObj = data.supplierImage;
  137. console.log(this.pageList)
  138. this.skeletonShow = false;
  139. this.isRequest = true;
  140. }).catch(error =>{
  141. this.$util.msg(error.msg,2000)
  142. })
  143. },
  144. getHomeInformation(){//初始化首页数据
  145. this.CommonService.GetHomeModulesDataInfo({ userId:this.userID }).then(res =>{
  146. let data = res.data;
  147. this.bannerImageList = data.bannerImageList
  148. this.mallPageModules = data.mallPageModules
  149. this.$store.commit('updateAllNum',data.shoppingCartCount)
  150. // this.GetHomeInit()
  151. this.GetHomeFloorInfo()
  152. this.GetHomeTopDataInfo()
  153. }).catch(error =>{
  154. this.$util.msg(error.msg,2000)
  155. })
  156. },
  157. //轮播图切换修改背景色
  158. swiperChange(e) {
  159. const index = e.detail.current;
  160. this.current = index;
  161. },
  162. formatMoney(num){
  163. return num.toString().replace(/\d+/, function (n) { // 先提取整数部分
  164. return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { // 对整数部分添加分隔符
  165. return $1 + ",";
  166. });
  167. });
  168. },
  169. handleBannerActivity(item,index){
  170. switch(index){
  171. case 0:
  172. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  173. break;
  174. }
  175. },
  176. handleClick(data){
  177. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  178. this.$store.commit('setActivity',data)
  179. },
  180. handleCancelClick(data){
  181. this.$store.commit('setActivity',data)
  182. },
  183. navToListPage(nav){//三个分类模块跳转
  184. let self = this;
  185. uni.setStorage({
  186. key: 'commodity_id',
  187. data: nav.id,
  188. success: function () {
  189. self.$api.navToListPage({type:'0',value:nav.classifyName,id:nav.id});
  190. }
  191. })
  192. },
  193. navigateToGoods(nav){//分类导航跳转
  194. let self = this;
  195. uni.setStorage({
  196. key: 'commodity_id',
  197. data: nav.id,
  198. success: function () {
  199. self.$api.navigateToGoods({type:'0',value:nav.classifyName,id:nav.id});
  200. }
  201. })
  202. },
  203. navToDetailPage(id) {//跳转商品详情页
  204. this.modallayer = true;
  205. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  206. },
  207. handleContact(e){
  208. console.log(e.detail.path)
  209. console.log(e.detail.query)
  210. },
  211. navto(url){
  212. this.$api.navigateTo(url)
  213. },
  214. swiperNavtopage(link){
  215. this.$api.navigateTo(`/h5/pages/activity/activity?productID=4204&path=${link}`)
  216. },
  217. telPhoneTo(){
  218. let self = this;
  219. this.$api.get('/home/afterSale',{organizeID:this.userOrganizeID},
  220. response => {
  221. console.log(response.data.contactNumber)
  222. uni.makePhoneCall({
  223. phoneNumber:response.data.contactNumber //仅为示例
  224. });
  225. }
  226. )
  227. }
  228. },
  229. onPageScroll(e){//实时获取到滚动的值
  230. if(e.scrollTop>50){
  231. this.inputActive = 'fixed'
  232. }else{
  233. this.inputActive = 'float'
  234. }
  235. if(e.scrollTop>400){
  236. this.isScrollTop = true
  237. }else{
  238. this.isScrollTop = false
  239. }
  240. },
  241. onPullDownRefresh() {//下拉刷新
  242. this.getHomeInformation()
  243. uni.stopPullDownRefresh()
  244. },
  245. onShareAppMessage(res){//分享转发
  246. if (res.from === 'button') {
  247. // 来自页面内转发按钮
  248. }
  249. return {
  250. title: '采美采购商城-生美/医美采购服务平台',
  251. path: 'pages/tabBar/home/index',
  252. imageUrl:'https://img.caimei365.com/group1/M00/03/8C/Cmis215XHXSAWWkhAAXDP4-6m_c397.png'
  253. }
  254. },
  255. onShow(){
  256. this.modallayer = false
  257. authorize.getSetting().then(res =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  258. if(res == 1){
  259. this.getWxAuthorize()
  260. }else{
  261. this.$api.getComStorage('userInfo').then((resolve) =>{
  262. this.userID = resolve.userID ? resolve.userID :0;
  263. this.getHomeInformation()
  264. }).catch(error =>{
  265. this.getHomeInformation()
  266. })
  267. }
  268. })
  269. }
  270. }
  271. </script>
  272. <style lang="scss">
  273. page{
  274. background-color: #FFFFFF;
  275. }
  276. .container-section{
  277. width: 100%;
  278. height: auto;
  279. background-color: #F7F7F7;
  280. }
  281. </style>