export default {
  name: 'StatsCompanyReportDetail',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    options: {
      type: Object,
      default: {
        month: null,
        type: null,
        company_id: null,
        package_id: null,
        unit_price: null
      }
    },
    list: {
      type: Object,
      default: null
    }
  },
  watch: {
    show(bool) {
      this.my_show = bool;
    },
    list(obj) {
      this.list_data = obj;
    }
  },
  data() {
    return {
      my_show: false,
      list_data: null,
      columns: [
        {
          title: 'SIM',
          key: 'sim',
          width: 150
        },
        {
          title: '运营商',
          key: 'carrier_operator_name',
          width: 120
        },
        {
          title: '企业名称',
          key: 'company_name',
          width: 300
        },
        {
          title: '套餐名称',
          key: 'package_name'
        },
        {
          title: '数量',
          key: 'counts',
          width: 75
        },
        {
          title: '套餐单价(元/月)',
          key: 'month_price',
          width: 150
        }
      ]
    };
  },
  methods: {
    visibleChange(bool) {
      this.$emit('update:show', bool);
    },
    /**
     * [index 列表]
     * @param  {Number} page [description]
     * @return {[type]}      [description]
     */
    index(page) {
      this.isShowLoading(true);
      let params = this.options;
      params.page = page;

      service.get('api/stats/company-report/detail', { params }).then(res => {
        this.isShowLoading(false);
        if (res.code == 0) {
          this.list_data = res.data;
        }
      }).catch(() => {
        this.isShowLoading(false);
      });
    },
    exportExcel() {
      this.isShowLoading(true);
      let params = this.options;

      service.get('api/stats/company-report/detail/export', { params }).then((res) => {
        if (res.code === 0) {
          if (res.data) {
            this.downloadFile(res.data);
          } else {
            this.$Modal.success({
              title: '提示',
              content: '当前导出数据量大，已进入后台队列导出模式，请稍后至导出列表查看下载。'
            });
          }
        }

        this.isShowLoading(false);
      }).catch(() => {
        this.isShowLoading(false);
      });
    }
  }
};
