index.vue 13 KB

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