define([ 'vue', 'store/index', 'text!./index.html', 'css!./index.css' ], function (Vue, store, html) { const asyncGetComponent = new Promise((resolve) => { require(['components/kefu/index'], (Kefu) => { resolve(Kefu); }); }); return { props: { publicData: { type: Object, default: function () { return {}; } }, userInfo: { type: Object, default: () => { } } }, data: function () { return { year: new Date().getFullYear(), code_url: '', sidebarHeight: 0, serviceActive: false, isKefuActive: false }; }, mounted: function () { this.$nextTick(function () { if (code_url) { this.code_url = code_url; } }); }, updated: function () { this.$nextTick(function () { this.sidebarHeight = this.$refs.sidebar.clientHeight; this.$emit('action', this.$refs.sidebar.clientHeight); }); }, methods: { openKefuPage() { if (this.userInfo && this.userInfo.uid) { if (this.isKefuActive) return; this.isKefuActive = true; asyncGetComponent.then(Kefu => { const instance = new Vue({ ...Kefu, propsData: { code_url: this.code_url } }).$mount(); document.body.appendChild(instance.$el) instance.$forceClose = () => { instance.$destroy(true); instance.$el.remove(); this.isKefuActive = false; } }); } else { store.setLoginAction(true); } }, goPage: function () { var vm = this; if (this.publicData.sitePhone) { this.$alert('客服电话:' + this.publicData.sitePhone.site_service_phone, {}); } else { if (this.publicData.customer_service === '2') { this.serviceActive = true; window.addEventListener('message', function () { vm.serviceActive = false; }); } } } }, template: html }; });