export default {
  name: "StatsOrderDetail",
  props: {
    show: {
      type: Boolean,
      default: false
    },
    options: {
      type: Object,
      default: {
        type: null,
        order_id: null,
        orderBy: "id",
        sortedBy: "asc"
      }
    },
    list: {
      type: Object,
      default: null
    }
  },
  watch: {
    show(bool) {
      this.my_show = bool;
    },
    list(obj) {
      this.list_data = obj;
    }
  },
  data() {
    var columns = [
      {
        title: "SIM",
        key: "sim",
        width: 150
      },
      {
        title: "企业名称",
        key: "company_name",
        width: 300
      },
      {
        title: "套餐名称",
        key: "package_name",
        width: 150
      },
      {
        title: "套餐周期",
        key: "service_months",
        width: 120
      },
      {
        title: "支付方式",
        key: "pay_channel_name",
        width: 120
      },
      {
        title: "价格",
        key: "unit_price",
        width: 120
      },
      {
        title: "数量",
        key: "counts",
        width: 75
      },
      {
        title: "订单时间",
        key: "order_at",
        width: 170
      }
    ];

    var columns2 = JSON.parse(JSON.stringify(columns));

    columns2.splice(2, 0, {
      title: "基本套餐",
      key: "base_package_name",
      width: 150
    });

    console.log(columns2);

    var data = {
      my_show: false,
      list_data: null,
      columns: columns,
      columns2: columns2
    };

    return data;
  },
  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/order/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/order/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);
        });
    }
  }
};
