index.vue 13 KB

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