import {
  createElement
} from '@antv/f2';
import Chart from './chart';
import {
  jsx as _jsx
} from "@antv/f2/jsx-runtime";
const _Http = getApp().globalData.http;
Component({
  data: {
    onRenderChart: () => {},
    show: true,
    hidden: true
  },
  lifetimes: {
    attached: function () {
      // this.render()
    },
  },
  methods: {
    render() {
      console.log('render')
      _Http.basic({
        id: "20230729142603",
        "content": {
          "datatype": "订货额",
          date: Date.now()
        },
      }).then(res => {
        console.log("柱状图数据", res)
        if (res.msg != '成功' || res.data.length == 0) return;
        this.setData({
          hidden: false
        })
        let data = [];
        ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'].forEach(v => {
          let list2 = res.data.filter(s => s.month == v);
          let lastYear = list2[0].year > list2[1].year ? list2[1] : list2[0],
            thisYear = list2[0].year > list2[1].year ? list2[0] : list2[1];
          lastYear.name = 'London';
          thisYear.name = 'Berlin';
          data.push(lastYear)
          data.push(thisYear)
        })
        this.setData({
          onRenderChart: () => {
            return this.renderChart(data.map(v => {
              v.month = v.month
              return v
            }));
          }
        });

        setTimeout(() => {
          this.setData({
            show: false
          })
          setTimeout(() => {
            this.setData({
              show: true
            })
          }, 100);
        }, 100);
      })
    },
    renderChart(data) {
      return createElement(Chart, {
        data
      });
    },
  }
})