<template>
  <div>
    <div class="customer-head">
      <div class="customer-back">
        <el-button type="danger" style="border: none;background: none;color: red" icon="el-icon-arrow-left"
                   @click="backToList">返回列表
        </el-button>
      </div>
    </div>
    <basic-container class="page-crad" style="margin-top: 30px">
      <avue-crud
        ref="crud"
        :option="option"
        :data="dataList"
        :table-loading="loading"
        :cell-style="cellStyle"
        :key="crudIndex"
      >
        <template slot="menuLeft">
          <el-button type="info" size="small" @click="outExport" icon="el-icon-download">导出</el-button>
        </template>
        <template slot="accSysNo" slot-scope="scope">
          <span style="color: #409EFF;cursor: pointer" @click.stop="jumpPage(scope.row,scope.index)">{{ scope.row.accSysNo }}</span>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import {detail} from "@/api/statisticAnalysis/profitLedger";
import { getToken } from "@/util/auth";

export default {
  name: "detail",
  props: {
    detailData: {
      type: Object
    },
    tradeType: {
      type: [Number, String]
    }
  },
  data() {
    return {
      crudIndex: 0,
      dataList: [],
      loading: false,
      option: {
        searchShow: true,
        align: "center",
        searchSpan: 8,
        border: true,
        index: true,
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        cellBtn: false,
        cancelBtn: false,
        refreshBtn: false,
        showSummary: true,
        summaryText: '合计',
        sumColumnList: [
          {
            name: 'amount',
            type: 'sum'
          },
          {
            name: 'settlementAmount',
            type: 'sum'
          },
          {
            name: 'outstandingAmount',
            type: 'sum'
          },
        ],
        searchIcon: true,
        searchIndex: 2,
        menu: false,
        column: [
          {
            label: "单据来源",
            prop: "billType",
            overHidden: true,
          },
          {
            label: "结算单位",
            prop: "corpName",
            overHidden: true,
          },
          {
            label: "订单号",
            prop: "accSysNo",
            overHidden: true,
          },
          {
            label: "费用名称",
            prop: "itemName",
            overHidden: true,
          },
          {
            label: "单价",
            prop: "price",
            overHidden: true,
          },
          {
            label: "账单金额",
            prop: "amount",
            overHidden: true,
          },
          {
            label: "结算金额",
            prop: "settlementAmount",
            overHidden: true,
          },
          {
            label: "币别",
            prop: "currency",
            overHidden: true,
          },
          {
            label: "汇率",
            prop: "exchangeRate",
            overHidden: true,
          },
        ],
      },
    }
  },
  created() {
    if (this.detailData.id) {
      this.queryData(this.detailData.id);
    }
  },
  methods: {
    cellStyle() {
      return "padding:0;height:40px;";
    },
    queryData(id) {
      this.loading = true;
      detail(id, this.tradeType).then(res => {
        this.dataList = res.data.data.records;
      }).finally(() => {
        this.loading = false;
        this.option.height = window.innerHeight - 180;
        this.crudIndex++;
      })
    },
    backToList() {
      this.$emit("goBack");
    },
    //导出
    outExport() {
      this.$confirm('是否导出应付总账详情信息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        window.open(
          `/api/trade-finance/profit/exportItem?${
            this.website.tokenHeader
          }=${getToken()}&$tradeType=${this.tradeType}&corpId=${this.detailData.id}`
        );
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消' //
        });
      })
    },
    // 跳转页面
    jumpPage(row, index) {
      if (row.billType == '申请') {
        if (this.tradeType == '' || this.tradeType == 'JXS') {
          this.$router.$avueRouter.closeTag("/dealer/purchase/index");
          this.$router.push({
            path: "/dealer/purchase/index",
            query: {
              params: row.srcParentId
            },
          });
        }
      } else if (row.billType == '收费') {
        if (this.tradeType == '' || this.tradeType == 'JXS') {
          this.$router.$avueRouter.closeTag("/dealer/sales/index");
          this.$router.push({
            path: "/dealer/sales/index",
            query: {
              params: row.srcParentId
            },
          });
        }
      }
    },
  },
}
</script>

<style scoped>

</style>
