index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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="isRequest"></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"></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. }
  123. },
  124. onLoad() {
  125. },
  126. computed: {
  127. ...mapState(['hasLogin','userInfo','isActivity'])
  128. },
  129. methods: {
  130. ...mapMutations(['login','logout']),
  131. getWxAuthorize(){
  132. authorize.getCode('weixin').then(wechatcode =>{// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  133. authorize.getUserInfo('weixin').then(wxResponse =>{
  134. userInfoLogin({code:wechatcode,encryptedData:wxResponse.encryptedData,iv:wxResponse.iv}).then(response =>{
  135. this.isLogin = true;
  136. this.userID = response.data.userID;
  137. this.userIdentity = response.data.userIdentity;
  138. this.clubStatus = response.data.clubStatus;
  139. this.$store.commit('updateStatus',response.data)
  140. this.login(response.data);
  141. uni.setStorageSync('token',response.data.token)
  142. uni.removeStorageSync('sessionid')
  143. uni.setStorageSync('sessionid','JSESSIONID='+response.data.sessionId)
  144. if(response.data.userIdentity ==1){
  145. this.$api.navigateTo('/seller/pages/index/index')
  146. }else if(response.data.userIdentity === 3){
  147. this.$api.navigateTo('/supplier/pages/index/index')
  148. }
  149. this.getHomeInformation()
  150. }).catch(error =>{
  151. this.isLogin = false;
  152. this.logout()
  153. uni.removeStorageSync('sessionid')
  154. uni.setStorageSync('sessionid','JSESSIONID='+error.data)
  155. this.$store.commit('updateStatus',error.data)
  156. this.getHomeInformation()
  157. })
  158. })
  159. })
  160. },
  161. GetHomeInit(){//金刚区分类
  162. this.CommonService.GetHomeInit({}).then(response =>{
  163. let data = response.data
  164. this.navBarsList = data.topMenuList
  165. }).catch(error =>{
  166. this.$util.msg(error.msg,2000)
  167. })
  168. },
  169. GetHomeFloorInfo(){//初始化首页楼层数据
  170. this.CommonService.GetHomeFloorInfo({}).then(response =>{
  171. let data = response.data
  172. this.flootData = data
  173. data.forEach((item,index) => {
  174. switch(item.type){
  175. case 3:
  176. this.supplierList = item.floorData
  177. break;
  178. case 4:
  179. this.specialList = item.floorData
  180. break;
  181. case 5:
  182. this.specialProList = item.floorData
  183. break;
  184. case 6:
  185. this.pagesList = item.subFloors
  186. break;
  187. }
  188. })
  189. }).catch(error =>{
  190. this.$util.msg(error.msg,2000)
  191. })
  192. },
  193. getHomeInformation(){//初始化首页数据
  194. this.CommonService.GetHomeModulesDataInfo({ userId:this.userID }).then(res =>{
  195. let data = res.data;
  196. this.bannerImageList = data.bannerImageList
  197. this.mallPageModules = data.mallPageModules
  198. this.firstModulesName= data.firstModulesName
  199. this.secondModulesName= data.secondModulesName
  200. this.firstModulesImage= data.firstModulesImage
  201. this.secondModulesImage= data.secondModulesImage
  202. this.thirdModulesName= data.thirdModulesName
  203. this.productsClassifyList = data.productsClassifyList
  204. this.$store.commit('updateAllNum',data.shoppingCartCount)
  205. this.GetHomeInit();
  206. this.GetHomeRecommendInfo()
  207. this.GetHomeFloorInfo()
  208. }).catch(error =>{
  209. this.$util.msg(error.msg,2000)
  210. })
  211. },
  212. GetHomeRecommendInfo(){//首页热门推荐
  213. this.CommonService.GetHomeRecommendInfo().then(response =>{
  214. this.RecommendList = response.data
  215. this.GetProductPrice()
  216. })
  217. },
  218. GetProductPrice(){//获取商品或者活动价格
  219. let productIdArr = [];
  220. let productIds ='';
  221. this.RecommendList.map(item=>{// 0公开价格 1不公开价格 2仅对会员机构公开
  222. productIdArr.push(item.id)
  223. })
  224. productIds = productIdArr.join(",");
  225. this.ProductService.querySearchProductPrice({userId: this.userID,productIds:productIds}).then(response =>{
  226. this.RecommendList = this.ReturnNewProducts(this.RecommendList,response.data);
  227. this.skeletonShow = false;
  228. this.isRequest = true
  229. }).catch(error =>{
  230. this.$util.msg(error.msg,2000)
  231. })
  232. },
  233. ReturnNewProducts(Array,list){
  234. let NewArray = []
  235. Array.map(item=>{
  236. for (let i = 0; i < list.length; i++) {
  237. if( item.id == list[i].productId ){
  238. NewArray.push(Object.assign(item,list[i]))
  239. }
  240. }
  241. });
  242. return NewArray
  243. },
  244. PromotionsFormat(promo){//促销活动类型数据处理
  245. if(promo!=null){
  246. if(promo.type == 1 && promo.mode == 1){
  247. return true
  248. }else{
  249. return false
  250. }
  251. }
  252. return false
  253. },
  254. //轮播图切换修改背景色
  255. swiperChange(e) {
  256. const index = e.detail.current;
  257. this.current = index;
  258. },
  259. formatMoney(num){
  260. return num.toString().replace(/\d+/, function (n) { // 先提取整数部分
  261. return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { // 对整数部分添加分隔符
  262. return $1 + ",";
  263. });
  264. });
  265. },
  266. handleBannerActivity(item,index){
  267. switch(index){
  268. case 0:
  269. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  270. break;
  271. }
  272. },
  273. handleClick(data){
  274. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  275. this.$store.commit('setActivity',data)
  276. },
  277. handleCancelClick(data){
  278. this.$store.commit('setActivity',data)
  279. },
  280. navToListPage(nav){//三个分类模块跳转
  281. let self = this;
  282. uni.setStorage({
  283. key: 'commodity_id',
  284. data: nav.id,
  285. success: function () {
  286. self.$api.navToListPage({type:'0',value:nav.classifyName,id:nav.id});
  287. }
  288. })
  289. },
  290. navigateToGoods(nav){//分类导航跳转
  291. let self = this;
  292. uni.setStorage({
  293. key: 'commodity_id',
  294. data: nav.id,
  295. success: function () {
  296. self.$api.navigateToGoods({type:'0',value:nav.classifyName,id:nav.id});
  297. }
  298. })
  299. },
  300. navToDetailPage(id) {//跳转商品详情页
  301. this.modallayer = true;
  302. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  303. },
  304. handleContact(e){
  305. console.log(e.detail.path)
  306. console.log(e.detail.query)
  307. },
  308. showTost(){
  309. this.$util.msg("功能开发中,敬请期待~",2000)
  310. // this.$api.navigateTo(`/seller/pages/login/login`)
  311. // uni.navigateToMiniProgram({
  312. // appId: 'wx5a5cda32926f55ac',
  313. // path: '/pages/tabBar/home/index',
  314. // extraData: {
  315. // 'data1': 'test'
  316. // },
  317. // envVersion: 'develop',
  318. // success(res) {
  319. // console.log(res)
  320. // // 打开成功
  321. // }
  322. // })
  323. },
  324. navto(url){
  325. this.$api.navigateTo(url)
  326. },
  327. swiperNavtopage(link){
  328. this.$api.navigateTo(`/h5/pages/activity/activity?productID=4204&path=${link}`)
  329. },
  330. telPhoneTo(){
  331. let self = this;
  332. this.$api.get('/home/afterSale',{organizeID:this.userOrganizeID},
  333. response => {
  334. console.log(response.data.contactNumber)
  335. uni.makePhoneCall({
  336. phoneNumber:response.data.contactNumber //仅为示例
  337. });
  338. }
  339. )
  340. }
  341. },
  342. onPageScroll(e){//实时获取到滚动的值
  343. if(e.scrollTop>50){
  344. this.inputActive = 'fixed'
  345. }else{
  346. this.inputActive = 'float'
  347. }
  348. if(e.scrollTop>400){
  349. this.isScrollTop = true
  350. }else{
  351. this.isScrollTop = false
  352. }
  353. },
  354. onPullDownRefresh() {//下拉刷新
  355. this.getHomeInformation()
  356. uni.stopPullDownRefresh()
  357. },
  358. onShareAppMessage(res){//分享转发
  359. if (res.from === 'button') {
  360. // 来自页面内转发按钮
  361. }
  362. return {
  363. title: '采美采购商城-生美/医美采购服务平台',
  364. path: 'pages/tabBar/home/home',
  365. imageUrl:'https://img.caimei365.com/group1/M00/03/8C/Cmis215XHXSAWWkhAAXDP4-6m_c397.png'
  366. }
  367. },
  368. onShow(){
  369. this.modallayer = false;
  370. authorize.getSetting().then(res =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  371. if(res == 1){
  372. this.getWxAuthorize()
  373. }else{
  374. this.$api.getComStorage('userInfo').then((resolve) =>{
  375. this.userID = resolve.userID ? resolve.userID :0;
  376. this.getHomeInformation()
  377. }).catch(error =>{
  378. this.getHomeInformation()
  379. })
  380. }
  381. })
  382. }
  383. }
  384. </script>
  385. <style lang="scss">
  386. page{
  387. background-color: #FFFFFF;
  388. }
  389. .container-section{
  390. width: 100%;
  391. height: auto;
  392. background-color: #F7F7F7;
  393. }
  394. </style>