<template>
  <div>
    <basic-container class="page-crad">
      <avue-crud ref="crud" :option="option" :data="dataList" :page.sync="page" :search.sync="search"
        :cell-style="cellStyle" @search-change="searchChange" @current-change="currentChange" @size-change="sizeChange"
        @refresh-change="refreshChange" @on-load="onLoad" :table-loading="loading" @saveColumn="saveColumn"
        @resetColumn="resetColumn" @search-criteria-switch="searchCriteriaSwitch">
        <template slot="menuLeft">
          <el-button type="info" size="small" @click="outExport">导出
          </el-button>
        </template>
        <template slot="statusSearch">
          <el-radio v-model="search.status" label="1">是</el-radio>
          <el-radio v-model="search.status" label="0">否</el-radio>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { getToken } from "@/util/auth";
import { getList } from "@/api/statisticAnalysis/AmtAmount"
import { defaultDate4 } from "@/util/date";
export default {
  name: "index",
  data() {
    return {
      UConfiguration: {
        multipleChoices: false,
        multiple: false,
        disabled: false,
        searchShow: true,
        collapseTags: false,
        placeholder: '请点击右边按钮选择',
        dicData: []
      },
      form: {},
      search: {
        year: defaultDate4(),
        status: "0"
      },
      dataList: [],
      loading: false,
      detailData: {},
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0,
        pageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
      },
      option: {},
      optionBack: {
        searchShow: true,
        align: "center",
        searchMenuPosition: "right",
        searchSpan: 8,
        searchMenuSpan: 24,
        searchLabelWidth: 100,
        border: true,
        index: true,
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        searchIcon: true,
        menu: false,
        summaryText: "合计",
        showSummary: true,
        sumColumnList: [
          {
            name: "quantity1",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount1",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity2",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount2",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity3",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount3",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity4",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount4",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity5",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount5",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity6",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount6",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity7",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount7",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity8",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount8",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity9",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount9",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity10",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount10",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity11",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount11",
            type: "sum",
            decimals: 2
          },
          {
            name: "quantity12",
            type: "sum",
            decimals: 0
          },
          {
            name: "amount12",
            type: "sum",
            decimals: 2
          }
        ],
        column: [
          {
            label: "品牌",
            prop: "brand",
            filterable: true,
            multiple: true,
            type: "select",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            dicData: [],
            dataType: "string",
            overHidden: true,
            search: true
          },
          {
            label: "年份",
            prop: "year",
            type: "year",
            format: "yyyy",
            valueFormat: "yyyy",
            searchValue:defaultDate4(),
            overHidden: true,
            hide: true,
            showColumn: false,
            search: true
          },
          {
            label: "含未发货订单",
            prop: "status",
            searchValue:"0",
            overHidden: true,
            hide: true,
            showColumn: false,
            search: true
          },
          {
            label: '月份',
            children: [
              {
                label: "1月数量",
                prop: "quantity1",
                overHidden: true,
                width: 100
              },
              {
                label: "1月金额",
                prop: "amount1",
                overHidden: true,
                width: 100
              },
              {
                label: "2月数量",
                prop: "quantity2",
                overHidden: true,
                width: 100
              },
              {
                label: "2月金额",
                prop: "amount2",
                overHidden: true,
                width: 100
              },
              {
                label: "3月数量",
                prop: "quantity3",
                overHidden: true,
                width: 100
              },
              {
                label: "3月金额",
                prop: "amount3",
                overHidden: true,
                width: 100
              },
              {
                label: "4月数量",
                prop: "quantity4",
                overHidden: true,
                width: 100
              },
              {
                label: "4月金额",
                prop: "amount4",
                overHidden: true,
                width: 100
              },
              {
                label: "5月数量",
                prop: "quantity5",
                overHidden: true,
                width: 100
              },
              {
                label: "5月金额",
                prop: "amount5",
                overHidden: true,
                width: 100
              },
              {
                label: "6月数量",
                prop: "quantity6",
                overHidden: true,
                width: 100
              },
              {
                label: "6月金额",
                prop: "amount6",
                overHidden: true,
                width: 100
              },
              {
                label: "7月数量",
                prop: "quantity7",
                overHidden: true,
                width: 100
              },
              {
                label: "7月金额",
                prop: "amount7",
                overHidden: true,
                width: 100
              },
              {
                label: "8月数量",
                prop: "quantity8",
                overHidden: true,
                width: 100
              },
              {
                label: "8月金额",
                prop: "amount8",
                overHidden: true,
                width: 100
              },
              {
                label: "9月数量",
                prop: "quantity9",
                overHidden: true,
                width: 100
              },
              {
                label: "9月金额",
                prop: "amount9",
                overHidden: true,
                width: 100
              },
              {
                label: "10月数量",
                prop: "quantity10",
                overHidden: true,
                width: 100
              },
              {
                label: "10月金额",
                prop: "amount10",
                overHidden: true,
                width: 100
              },
              {
                label: "11月数量",
                prop: "quantity11",
                overHidden: true,
                width: 100
              },
              {
                label: "11月金额",
                prop: "amount11",
                overHidden: true,
                width: 100
              },
              {
                label: "12月数量",
                prop: "quantity12",
                overHidden: true,
                width: 100
              },
              {
                label: "12月金额",
                prop: "amount12",
                overHidden: true,
                width: 100
              }
            ]
          },
        ]
      }
    };
  },
  async created() {
    this.option = await this.getColumnData(this.getColumnName(225), this.optionBack);
    this.getAllWorkDicts()
  },
  activated() {
    this.$nextTick(() => {
      this.$refs.crud.refreshTable();
    });
  },
  methods: {
    getAllWorkDicts() {
      this.option.height = window.innerHeight - 210;
      this.getWorkDicts('brand').then(res => {
        this.findObject(this.option.column, "brand").dicData =
          res.data.data;
      })
    },
    cellStyle() {
      return "padding:0;height:40px;";
    },
    searchCriteriaSwitch(type) {
      if (type) {
        this.option.height = this.option.height - 46;
      } else {
        this.option.height = this.option.height + 46;
      }
      this.$refs.crud.getTableHeight();
    },
    //点击搜索按钮触发
    searchChange(params, done) {
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    refreshChange() {
      this.onLoad(this.page, this.search);
    },
    currentChange(val) {
      this.page.currentPage = val;
    },
    sizeChange(val) {
      this.page.currentPage = 1;
      this.page.pageSize = val;
    },
    onLoad(page, params = {}) {
      let data = this.deepClone(Object.assign({}, params, this.search));
      this.loading = true;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(data)
      ).then(res => {
        this.dataList = res.data.data.records ? res.data.data.records : [];
        this.page.total = res.data.data.total;
      }).finally(() => {
        this.loading = false;
      });
    },

    //列保存触发
    async saveColumn() {
      const inSave = await this.saveColumnData(this.getColumnName(225), this.option);
      if (inSave) {
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.crud.$refs.dialogColumn.columnBox = false;
      }
    },
    async resetColumn() {
      this.option = this.optionBack;
      const inSave = await this.delColumnData(this.getColumnName(225), this.optionBack);
      this.getAllWorkDicts()
      if (inSave) {
        this.$message.success("重置成功");
        this.$refs.crud.$refs.dialogColumn.columnBox = false;
      }
    },
    outExport() {
      let params = { ...this.search }
      window.open(
        `/api/blade-purchase-sales/exportOrder/totalSummaryExport?${this.website.tokenHeader
        }=${getToken()}&year=${params.year ? params.year : ''}&brand=${params.brand ? params.brand : ''}&status=${params.status ? params.status : ''}`
      );
    }
  }
};
</script>

<style scoped>
.page-crad ::v-deep .basic-container__card {
  height: 94.2vh;
}

::v-deep .el-table__expanded-cell[class*="cell"] {
  padding: 0px;
}

.itemTable ::v-deep .el-table {
  width: 100%;
}
</style>
