index.vue 11 KB

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