index.vue 13 KB

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