index.vue 12 KB

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