import { navLinkType } from '@/common/setting/constVarsHelper.js'; /** * 全局混入型 */ module.exports = { beforeCreate() { }, data() { return { /** * 页面加载 */ pageLoading: true } }, methods: { /** * //常用链接操作 */ //返回首页 goHome() { uni.switchTab({ url: '/pages/index/default/default' }); }, //返回上一页 goNavigateBack(el) { // let pages = getCurrentPages(); // 当前页页⾯实例 // if (pages.length > 1) { // uni.navigateBack(); // } else { // this.goHome() // } uni.navigateBack(); }, //路由跳转 goRoute(url) { // 无参数 this.$u.route(url); }, goRoute(url, params) { // 带参数,传递的对象形式的参数,如{name: 'lisa', age: 18} this.$u.route(url, params); }, //查看所在坐标地图位置 goShopMap() { var reshipCoordinate = this.$store.state.config.reshipCoordinate; if (reshipCoordinate && reshipCoordinate.indexOf(",") != -1) { var arr = reshipCoordinate.split(',') this.$u.route('/pages/map/map', { id: 1, latitude: arr[0], longitude: arr[1], }); } }, //查看所在坐标地图位置 goMapDetails(id, latitude, longitude) { this.$u.route('/pages/map/map', { id: id, latitude: latitude, longitude: longitude, }); }, goUserCenter() { this.$u.route({ url: '/pages/index/member/member', type: 'switchTab' }); }, goSearch() { this.$u.route({ url: '/pages/search/search', }); }, // 返回上一页 toBackBtn() { var pages = getCurrentPages(); if (pages.length > 1) { uni.navigateBack({ delta: 1 }); } else { this.$u.route({ type: 'switchTab', url: '/pages/index/default/default' }); } }, //返回操作处理 toOnBackPress(options) { if (options.from === 'navigateBack') { return false } let loginPages = ['/pages/index/cart/cart', '/pages/index/member/member'] let backPage = this.$store.state.redirectPage if (loginPages.indexOf(backPage) > -1) { this.$store.commit({ type: 'redirect', page: '' }) this.$u.route({ type: 'switchTab', url: '/pages/index/default/default' }) return true } }, //登录成功统一跳转处理 toLoginSuccessHandleBack() { let redirect = this.$store.state.redirectPage this.$store.commit({ type: 'redirect', page: '' }) let switchTabs = ['/pages/index/default/default', '/pages/index/member/member'] if (switchTabs.indexOf(redirect) > -1) { this.$u.route({ type: 'switchTab', url: redirect }) } else if (redirect) { this.$u.route({ type: 'switchTab', url: redirect }) } else { this.$u.route({ type: 'switchTab', url: '/pages/index/default/default' }) } }, // 购物车页面跳转 redirectCart() { this.$u.route({ type: 'switchTab', url: '/pages/index/cart/cart' }); }, /** * 订单接口信息 */ // 查看订单详情 goOrderDetail(orderId) { this.$u.route('/pages/member/order/detail/detail', { orderId: orderId }); }, // 取消订单 // 去支付 goToPay(orderId) { this.$u.route('/pages/payment/pay/pay', { orderId: orderId, type: 1 }); }, // 确认收货 // 去评价 toEvaluate(orderId) { this.$u.route('/pages/member/order/evaluate/evaluate', { orderId: orderId }); }, // 申请售后 // 查看物流信息 goShowExpress(code, no, address = '', mobile = '') { let params = encodeURIComponent( 'code=' + code + '&no=' + no + '&add=' + address + '&mobile=' + mobile ) this.$u.route('/pages/member/order/expressDelivery/expressDelivery', { params: params }); }, /** * 商品接口信息 */ // 查看商品详情 goGoodsDetail(goodsId) { this.$u.route('/pages/goods/goodDetails/goodDetails', { id: goodsId }); }, // 查看商品评论详情 goGoodComments(goodsId) { this.$u.route('/pages/goods/goodComments/goodComments', { id: goodsId }); }, // 跳转商品列表页 goGoodsList(obj = {}) { let url = '/pages/category/list/list' if (Object.keys(obj).length) { url = url + this.$u.queryParams(obj) } this.$u.route(url) }, // 秒杀详情 goSeckillDetail(id) { this.$u.route('/pages/activity/seckill/seckillDetails/seckillDetails', { id: id }); }, // 团购详情 goGroupBuyingDetail(id) { this.$u.route('/pages/activity/groupBuying/groupBuyingDetails/groupBuyingDetails', { id: id }); }, //拼团详情页 goPinTuanDetail(id, teamId) { if (teamId) { this.$u.route('/pages/activity/pinTuan/pinTuanDetails/pinTuanDetails', { id: id, teamId: teamId, }); } else { this.$u.route('/pages/activity/pinTuan/pinTuanDetails/pinTuanDetails', { id: id }); } }, // 查看团购列表 goGroupPurchase() { this.$u.route('/pages/activity/groupBuying/list/list') }, // 查看秒杀列表 goSeckillList() { this.$u.route('/pages/activity/seckill/list/list') }, // 查看拼团列表 goPinTuanList() { this.$u.route('/pages/activity/pinTuan/list/list') }, /** * 文章接口 */ // 查看文章分类 goArticleClassify(id) { this.$u.route('/pages/article/list/list', { id: id }); }, goArticleList() { this.$u.route('/pages/article/list/list') }, // 查看文章详情 goArticleDetail(id) { this.$u.route('/pages/article/details/details', { idType: 1, id: id }); }, /** * 公告接口 */ // 查看公告列表 goNoticeList() { this.$u.route('/pages/notice/list/list') }, // 查看公告详情 goNoticeDetail(id) { this.$u.route('/pages/notice/details/details', { id: id }); }, // 前往用户协议 goUserAgreementPage() { var id = this.$store.state.config.userAgreementId; this.$u.route('/pages/article/details/details', { idType: 1, id: id }); }, // 前往隐私协议 goUserPrivacyPolicy() { var id = this.$store.state.config.privacyPolicyId; this.$u.route('/pages/article/details/details', { idType: 1, id: id }); }, // 关于我们 goAboutUs() { let id = this.$store.state.config.aboutArticleId; this.$u.route('/pages/article/details/details', { idType: 1, id: id }); }, /** * 接龙接口信息 */ // 查看接龙详情 goSolitaireDetail(id) { this.$u.route('/pages/activity/solitaire/solitaireDetails/solitaireDetails', { id: id }); }, // 查看服务列表 goSolitaireList() { this.$u.route('/pages/activity/solitaire/list/list') }, //服务接口信息 goServicesDetail(serviceId) { this.$u.route('/pages/serviceGoods/details/details', { id: serviceId }); }, // 查看服务列表 goServicesList() { this.$u.route('/pages/serviceGoods/index/index') }, // 查看个人详情 goServicesUserDetail(serviceId) { this.$u.route('/pages/member/serviceOrder/details/details', { id: serviceId }); }, /** * 广告相关 */ // 广告点击查看详情 showSliderInfo(type, val) { if (!val) { return; } if (type == navLinkType.urlLink) { if (val.indexOf('http') != -1) { // #ifdef APP-PLUS || APP-PLUS-NVUE || MP this.$u.route('/pages/webview/webview', { src: val }); // #endif } else { // #ifdef APP-PLUS || APP-PLUS-NVUE || MP if (val == '/pages/index/default/default' || val == '/pages/category/index/index' || val == '/pages/index/cart/cart' || val == '/pages/index/member/member') { this.$u.route({ type: 'switchTab', url: val }); return; } else if (val.indexOf('/pages/coupon/coupon?id=') > -1) { var id = val.replace('/pages/coupon/coupon?id=', ""); this.receiveCoupon(id) } else { this.$u.route(val); return; } // #endif } } else if (type == navLinkType.shop) { // 商品详情 this.$u.route('/pages/goods/goodDetails/goodDetails', { id: val }); } else if (type == navLinkType.article) { // 文章详情 this.$u.route('/pages/article/details/details', { idType: 1, id: val }); } else if (type == navLinkType.articleCategory) { // 文章列表 //this.$u.route('/pages/article/list/list') this.$u.route('/pages/article/category/category', { id: val }); } else if (type == navLinkType.intelligentForms) { //自定义表单 this.$u.route('/pages/form/details/details', { id: val }); } else if (type == navLinkType.shopCategory) { //商品分类 this.$u.route('/pages/category/list/list', { id: val }); } else { this.$u.route(val); } }, // 用户领取优惠券 receiveCoupon(couponId) { uni.showLoading({ title: '加载中', mask: true }); let _this = this; let coreshopdata = { id: couponId } this.$u.api.getCoupon(coreshopdata).then(res => { if (res.status) { uni.hideLoading(); _this.$refs.uToast.show({ message: res.msg, type: 'success', back: false }) } else { uni.hideLoading(); _this.$u.toast(res.msg) } }) }, /** * 工具函数 */ doCopyData(data) { var _this = this; uni.setClipboardData({ data: data, success: function() { _this.$u.toast('复制成功') } }); }, doPhoneCall() { var phome = this.$store.state.config.shopMobile || 0; if (phome != 0) { uni.makePhoneCall({ phoneNumber: phome }); } }, goBack() { //处理兼容,如果没有上一级界面则返回首页 const pages = getCurrentPages(); if (pages.length === 2) { uni.navigateBack({ delta: 1 }); } else if (pages.length === 1) { uni.switchTab({ url: '/pages/index/default/default', }) } else { uni.navigateBack({ delta: 1 }); } }, } }