<template>
  <div>
    <basic-container v-show="isShow" class="page-crad">
      <avue-crud
        ref="crud"
        :option="option"
        :data="dataList"
        :before-open="beforeOpen"
        :page.sync="page"
        :search.sync="search"
        @search-change="searchChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
        @on-load="onLoad"
        :table-loading="loading"
        @saveColumn="saveColumn"
        @resetColumn="resetColumn"
        :cell-style="cellStyle"
      >
        <template slot="corpIdSearch">
          <crop-select v-model="search.corpId" corpType="KH"></crop-select>
        </template>
        <template slot="businesDateSearch">
          <el-date-picker
            v-model="search.businesDate"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
        </template>
        <!-- <template slot-scope="{ row }" slot="corpId">
          <span>{{ row.corpsName }}</span>
        </template> -->
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { getList } from "@/api/statisticAnalysis/salesProfit";
export default {
  name: "index",
  data() {
    return {
      form: {},
      search: {},
      dataList: [],
      loading: false,
      isShow: true,
      detailData: {},
      page: {
        pageSize: 10,
        currentPage: 1
      },
      option: {
        searchShow: true,
        searchMenuSpan: 24,
        align: "center",
        searchSpan: 8,
        border: true,
        index: true,
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        menuWidth: 120,
        searchLabelWidth: 100,
        searchIcon: true,
        searchIndex: 2,
        menu: false,
        column: [
          {
            label: "合同号",
            prop: "orderNo",
            overHidden: true,
            width: 100,
            search: true
          },
          {
            label: "客户名称",
            prop: "corpId",
            overHidden: true,
            width: 100,
            search: true,
            formatter: row => {
              return row.corpsName;
            }
          },
          {
            label: "合同日期",
            prop: "businesDate",
            type: "date",
            format: "yyyy-MM-dd",
            overHidden: true,
            search: true,
            width: 100
          },
          {
            label: "起运港",
            prop: "portOfLoad",
            overHidden: true,
            width: 100
          },
          {
            label: "目的港",
            prop: "portOfDestination",
            overHidden: true,
            width: 100
          },
          {
            label: "运输条款",
            prop: "transport",
            overHidden: true,
            width: 100
          },
          {
            label: "采购报价",
            prop: "purchasePrice",
            overHidden: true,
            width: 100
          },
          {
            label: "销售金额",
            prop: "amount",
            overHidden: true,
            width: 100
          },
          {
            label: "产品毛利",
            prop: "grossProfit",
            overHidden: true,
            width: 100
          },
          {
            label: "产品利率",
            prop: "grossProfitRate",
            overHidden: true,
            width: 100
          },
          {
            label: "单票利润",
            prop: "singleTicketMargin",
            overHidden: true,
            width: 100
          }
        ]
      }
    };
  },
  methods: {
    cellStyle() {
      return "padding:0;height:40px;";
    },
    //点击搜索按钮触发
    searchChange(params, done) {
      if (params.businesDate) {
        params.contractStartDate = params.businesDate[0];
        params.contractEndDate = params.businesDate[1];
      }
      delete params.businesDate;
      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) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, params)
        .then(res => {
          this.dataList = res.data.data.records ? res.data.data.records : [];
          this.page.total = res.data.data.total;
          if (this.page.total) {
            this.option.height = window.innerHeight - 260;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    //新增跳转页面
    beforeOpen() {
      this.isShow = false;
    },
    editOpen(row, status) {
      this.detailData = {
        id: row.id,
        status: status
      };
      this.isShow = false;
    },
    goBack() {
      this.detailData = this.$options.data().detailData;
      this.isShow = true;
    }
  }
};
</script>

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