export default { props: { show: { type: Boolean, default: false } }, watch: { show(bool) { this.my_show = bool; if (bool) { this.current = 0; this.status = 'wait'; this.circle.percent = 0; this.circle.content = '未开始'; } } }, data() { return { my_show: false, loading: false, disabled: false, steps: [ { 'title': '同步集团', 'content': '所有卡源集团的数据', 'command': 'real:sync-bloc', 'max': 5 }, { 'title': '同步企业', 'content': '所有下级企业的数据', 'command': 'real:sync-company', 'max': 10 }, { 'title': '同步套餐', 'content': '所有套餐的数据', 'command': 'real:sync-package', 'max': 30 }, { 'title': '同步订单', 'content': '指定月份的销售订单数据', 'command': 'real:sync-order', 'max': 65 }, { 'title': '同步企业订单', 'content': '指定月份的续费及增值包数据', 'command': 'real:sync-added-order', 'max': 100 } ], current: 0, circle: { percent: 0, content: '未开始' }, status: 'wait', month: this.moment().subtract('2', 'months').startOf('month').format('YYYY-MM') }; }, methods: { call() { this.disabled = true; let params = {}; params.command = this.steps[this.current]['command']; if (!params.command) { return this.$Message.error('命令错误'); } if ([3, 4].indexOf(this.current) !== -1) { if (!this.month) { return this.$Message.error('请选择要同步的月份'); } params.parameters = { month: this.moment(this.month).format('YYYY-MM') }; } let max = this.steps[this.current]['max']; this.status = 'process'; this.circle.content = '正在' + this.steps[this.current]['title']; let interval = setInterval(() => { if (this.circle.percent < max) { this.circle.percent++; } }, 1000); console.log(this.current); service.post('/api/artisan/call', params).then(res => { if (res.code == 0) { this.circle.content = this.steps[this.current]['title'] + '完成'; this.circle.percent = max; this.status = (max == 100) ? 'finish' : 'wait'; this.current++; } else { this.circle.content = '同步失败'; this.circle.percent = this.steps[this.current - 1]['max']; this.status = 'error'; } this.disabled = false; console.log(this.circle); clearInterval(interval); }).catch((err) => { console.log(err); this.circle.content = '同步失败'; this.circle.percent = this.steps[this.current - 1]['max']; this.status = 'error'; this.disabled = false; clearInterval(interval); }); }, visibleChange(bool) { if (!bool) { this.$emit('update:show', false); } }, clear() { this.my_show = false; } } };