index.vue 12 KB

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