index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 :list="liveList" v-if="isRequest"></page-special>
  13. </view>
  14. <!-- 楼层 -->
  15. <view class="container-section tui-skeleton">
  16. <page-floor :list="pageList" :userIdentity="userIdentity"></page-floor>
  17. <supplier-list :list="supplierList" 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 { pageList,liveList,supplierDataList } from '@/common/json/data.json.js' //本地数据
  33. import { userInfoLogin } from "@/api/use.js"
  34. import { mapState,mapMutations} from 'vuex';
  35. export default {
  36. components:{
  37. tuiSkeleton,
  38. customer,
  39. banner,
  40. navbars,
  41. pageFloor,
  42. pageSpecial,
  43. supplierList
  44. },
  45. data() {
  46. return {
  47. webviewStyles: {
  48. progress: {
  49. color: '#FF3333'
  50. }
  51. },
  52. nvabarData: {//顶部自定义导航
  53. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  54. showSearch: 0,
  55. title: '采美采购商城', // 导航栏 中间的标题
  56. haveBack:false,
  57. textLeft:this.$store.state.isIphone,
  58. textColor:'#FFFFFF'
  59. },
  60. CustomBar:this.CustomBar,// 顶部导航栏高度
  61. userID:0,
  62. clubStatus:'',
  63. current:0,
  64. mode:'round',
  65. modallayer:false,
  66. isLogin:false,
  67. skeletonShow: true,
  68. userIdentity:'',
  69. flootData:[],//楼层
  70. bannerImageList:[],//轮播
  71. navBarsList:[],//导航分类
  72. liveList:liveList,
  73. pageList:pageList,//楼层
  74. supplierList:supplierDataList,//供应商列表
  75. isScrollTop:false,
  76. isRequest:false,
  77. }
  78. },
  79. onLoad() {
  80. },
  81. computed: {
  82. ...mapState(['hasLogin','userInfo','identity'])
  83. },
  84. methods: {
  85. ...mapMutations(['login','logout']),
  86. getWxAuthorize(){
  87. authorize.getCode('weixin').then(wechatcode =>{// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  88. authorize.getUserInfo('weixin').then(wxResponse =>{
  89. userInfoLogin({code:wechatcode,encryptedData:wxResponse.encryptedData,iv:wxResponse.iv}).then(response =>{
  90. this.isLogin = true;
  91. this.userID = response.data.userID;
  92. this.userIdentity = response.data.userIdentity;
  93. this.clubStatus = response.data.clubStatus;
  94. this.$store.commit('updateStatus',response.data)
  95. this.login(response.data);
  96. uni.setStorageSync('token',response.data.token)
  97. uni.removeStorageSync('sessionid')
  98. uni.setStorageSync('sessionid','JSESSIONID='+response.data.sessionId)
  99. if(response.data.userIdentity ==1){
  100. this.$api.redirectTo('/seller/pages/index/index')
  101. }else if(response.data.userIdentity === 3){
  102. this.$api.redirectTo('/supplier/pages/index/index')
  103. }
  104. this.getHomeInformation()
  105. }).catch(error =>{
  106. this.isLogin = false;
  107. this.logout()
  108. uni.removeStorageSync('sessionid')
  109. uni.setStorageSync('sessionid','JSESSIONID='+error.data)
  110. this.$store.commit('updateStatus',error.data)
  111. this.getHomeInformation()
  112. })
  113. })
  114. })
  115. },
  116. GetHomeInit(){//金刚区分类
  117. this.CommonService.GetHomeInit({}).then(response =>{
  118. let data = response.data
  119. this.navBarsList = data.topMenuList
  120. }).catch(error =>{
  121. this.$util.msg(error.msg,2000)
  122. })
  123. },
  124. GetHomeFloorInfo(){//初始化首页楼层数据
  125. this.CommonService.GetHomeFloorInfo({}).then(response =>{
  126. let data = response.data
  127. this.flootData = data
  128. data.forEach((item,index) => {
  129. switch(item.type){
  130. case 3:
  131. this.supplierList = item.floorData
  132. break;
  133. case 4:
  134. this.specialList = item.floorData
  135. break;
  136. case 5:
  137. this.specialProList = item.floorData
  138. break;
  139. case 6:
  140. this.pagesList = item.subFloors
  141. break;
  142. }
  143. })
  144. }).catch(error =>{
  145. this.$util.msg(error.msg,2000)
  146. })
  147. },
  148. getHomeInformation(){//初始化首页数据
  149. this.CommonService.GetHomeModulesDataInfo({ userId:this.userID }).then(res =>{
  150. let data = res.data;
  151. this.bannerImageList = data.bannerImageList
  152. this.mallPageModules = data.mallPageModules
  153. this.$store.commit('updateAllNum',data.shoppingCartCount)
  154. this.GetHomeInit();
  155. this.GetHomeRecommendInfo()
  156. this.GetHomeFloorInfo()
  157. }).catch(error =>{
  158. this.$util.msg(error.msg,2000)
  159. })
  160. },
  161. GetHomeRecommendInfo(){//首页热门推荐
  162. this.CommonService.GetHomeRecommendInfo({identity:this.identity}).then(response =>{
  163. this.RecommendList = response.data
  164. this.GetProductPrice()
  165. })
  166. },
  167. GetProductPrice(){//获取商品或者活动价格
  168. let productIdArr = [];
  169. let productIds ='';
  170. this.RecommendList.map(item=>{// 0公开价格 1不公开价格 2仅对会员机构公开
  171. productIdArr.push(item.id)
  172. })
  173. productIds = productIdArr.join(",");
  174. this.ProductService.querySearchProductPrice({userId: this.userID,productIds:productIds}).then(response =>{
  175. this.RecommendList = this.ReturnNewProducts(this.RecommendList,response.data);
  176. this.skeletonShow = false;
  177. this.isRequest = true
  178. }).catch(error =>{
  179. this.$util.msg(error.msg,2000)
  180. })
  181. },
  182. ReturnNewProducts(Array,list){
  183. let NewArray = []
  184. Array.map(item=>{
  185. for (let i = 0; i < list.length; i++) {
  186. if( item.id == list[i].productId ){
  187. NewArray.push(Object.assign(item,list[i]))
  188. }
  189. }
  190. });
  191. return NewArray
  192. },
  193. PromotionsFormat(promo){//促销活动类型数据处理
  194. if(promo!=null){
  195. if(promo.type == 1 && promo.mode == 1){
  196. return true
  197. }else{
  198. return false
  199. }
  200. }
  201. return false
  202. },
  203. //轮播图切换修改背景色
  204. swiperChange(e) {
  205. const index = e.detail.current;
  206. this.current = index;
  207. },
  208. formatMoney(num){
  209. return num.toString().replace(/\d+/, function (n) { // 先提取整数部分
  210. return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { // 对整数部分添加分隔符
  211. return $1 + ",";
  212. });
  213. });
  214. },
  215. handleBannerActivity(item,index){
  216. switch(index){
  217. case 0:
  218. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  219. break;
  220. }
  221. },
  222. handleClick(data){
  223. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  224. this.$store.commit('setActivity',data)
  225. },
  226. handleCancelClick(data){
  227. this.$store.commit('setActivity',data)
  228. },
  229. navToListPage(nav){//三个分类模块跳转
  230. let self = this;
  231. uni.setStorage({
  232. key: 'commodity_id',
  233. data: nav.id,
  234. success: function () {
  235. self.$api.navToListPage({type:'0',value:nav.classifyName,id:nav.id});
  236. }
  237. })
  238. },
  239. navigateToGoods(nav){//分类导航跳转
  240. let self = this;
  241. uni.setStorage({
  242. key: 'commodity_id',
  243. data: nav.id,
  244. success: function () {
  245. self.$api.navigateToGoods({type:'0',value:nav.classifyName,id:nav.id});
  246. }
  247. })
  248. },
  249. navToDetailPage(id) {//跳转商品详情页
  250. this.modallayer = true;
  251. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  252. },
  253. handleContact(e){
  254. console.log(e.detail.path)
  255. console.log(e.detail.query)
  256. },
  257. navto(url){
  258. this.$api.navigateTo(url)
  259. },
  260. swiperNavtopage(link){
  261. this.$api.navigateTo(`/h5/pages/activity/activity?productID=4204&path=${link}`)
  262. },
  263. telPhoneTo(){
  264. let self = this;
  265. this.$api.get('/home/afterSale',{organizeID:this.userOrganizeID},
  266. response => {
  267. console.log(response.data.contactNumber)
  268. uni.makePhoneCall({
  269. phoneNumber:response.data.contactNumber //仅为示例
  270. });
  271. }
  272. )
  273. }
  274. },
  275. onPageScroll(e){//实时获取到滚动的值
  276. if(e.scrollTop>50){
  277. this.inputActive = 'fixed'
  278. }else{
  279. this.inputActive = 'float'
  280. }
  281. if(e.scrollTop>400){
  282. this.isScrollTop = true
  283. }else{
  284. this.isScrollTop = false
  285. }
  286. },
  287. onPullDownRefresh() {//下拉刷新
  288. this.getHomeInformation()
  289. uni.stopPullDownRefresh()
  290. },
  291. onShareAppMessage(res){//分享转发
  292. if (res.from === 'button') {
  293. // 来自页面内转发按钮
  294. }
  295. return {
  296. title: '采美采购商城-生美/医美采购服务平台',
  297. path: 'pages/tabBar/home/index',
  298. imageUrl:'https://img.caimei365.com/group1/M00/03/8C/Cmis215XHXSAWWkhAAXDP4-6m_c397.png'
  299. }
  300. },
  301. onShow(){
  302. this.modallayer = false
  303. authorize.getSetting().then(res =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  304. if(res == 1){
  305. this.getWxAuthorize()
  306. }else{
  307. this.$api.getComStorage('userInfo').then((resolve) =>{
  308. this.userID = resolve.userID ? resolve.userID :0;
  309. this.getHomeInformation()
  310. }).catch(error =>{
  311. this.getHomeInformation()
  312. })
  313. }
  314. })
  315. }
  316. }
  317. </script>
  318. <style lang="scss">
  319. page{
  320. background-color: #FFFFFF;
  321. }
  322. .container-section{
  323. width: 100%;
  324. height: auto;
  325. background-color: #F7F7F7;
  326. }
  327. </style>