<template>
  <div class="app-container">
    <div class="title-container">
      <breadcrumb id="breadcrumb-container" class="breadcrumb-container"/>
    </div>
    <y-page-list-layout :page-list="pageData" :page-para="listQuery" :get-page-list="getList">
      <template slot="left">
        <el-input
          v-model="listQuery.itemName"
          placeholder="项目名称"
          clearable
          style="margin-left: 20px;width: 320px;float: left;"
        >
        </el-input>
        <el-input
          v-model="listQuery.userName"
          placeholder="人员名称"
          clearable
          style="margin-left: 20px;width: 320px;float: left;"
        >
        </el-input>
        <el-select
          v-model="listQuery.brokerageCate"
          placeholder="结算类型"
          clearable
          filterable
          style="margin-left: 20px;width: 150px;float: left;"
          class="filter-item"
        >
          <el-option label="结算" value="SETTLE"/>
          <el-option label="预提" value="AHEAD"/>
          <el-option label="回款结算" value="PAYMENT_SETTLE"/>
          <el-option label="补偿结算" value="COMPENSATION"/>
        </el-select>
        <el-select
          v-model="listQuery.year"
          placeholder="结算年份"
          clearable
          filterable
          style="margin-left: 20px;width: 100px;float: left;"
          class="filter-item"
        >
          <el-option label="2022" value="2022"/>
          <el-option label="2023" value="2023"/>
          <el-option label="2024" value="2024"/>
          <el-option label="2025" value="2025"/>
          <el-option label="2026" value="2026"/>
          <el-option label="2027" value="2027"/>
          <el-option label="2028" value="2028"/>
          <el-option label="2029" value="2029"/>
          <el-option label="2030" value="2030"/>
        </el-select>
        <el-select
          v-model="listQuery.month"
          placeholder="结算月份"
          clearable
          filterable
          style="margin-left: 20px;width: 100px;float: left;"
          class="filter-item"
        >
          <el-option label="1" value="1"/>
          <el-option label="2" value="2"/>
          <el-option label="3" value="3"/>
          <el-option label="4" value="4"/>
          <el-option label="5" value="5"/>
          <el-option label="6" value="6"/>
          <el-option label="7" value="7"/>
          <el-option label="8" value="8"/>
          <el-option label="9" value="9"/>
          <el-option label="10" value="10"/>
          <el-option label="11" value="11"/>
          <el-option label="12" value="12"/>
        </el-select>
        <el-button
          class="filter-item"
          style="margin-left: 10px;float: left;"
          type="primary"
          @click="getList"
          round
        >搜索
        </el-button>
        <el-button
          class="filter-item"
          style="float: left;"
          round
          type="warning"
          @click="resetSearch()"
        >重置
        </el-button>
      </template>
      <template slot="right">
        <PermissionButton
          menu-code="_views_settle_detail_export"
          class-name="filter-item"
          round
          type="primary"
          name="导出"
          @click="settleDetailExport"
        >
        </PermissionButton>
      </template>
      <parentTable
        v-loading="listLoading"
        :data="pageData.records"
        slot="table"
        style="width: 100%;"
      >
        <el-table-column label="项目名称" align="center">
          <template slot-scope="{row}">
            <span>{{ row.itemName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="阶段名称" align="center" width="250">
          <template slot-scope="{row}">
            <span>{{ row.stageName===null?'-':row.stageName}}</span>
          </template>
        </el-table-column>
        <el-table-column label="结算年份" align="center">
          <template slot-scope="{row}">
            <span>{{row.year}}</span>
          </template>
        </el-table-column>
        <el-table-column label="结算月份" align="center">
          <template slot-scope="{row}">
            <span>{{row.month}}</span>
          </template>
        </el-table-column>
        <el-table-column label="回款名称" align="center">
          <template slot-scope="{row}">
            <span>{{ row.paymentName===null?'-':row.paymentName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="回款金额" align="center">
          <template slot-scope="{row}">
            <span>{{ row.paymentAmount===null?'-':row.paymentAmount }}</span>
          </template>
        </el-table-column>
        <el-table-column label="人员名称" align="center" width="160">
          <template slot-scope="{row}">
            <span>{{ row.userName}}</span>
          </template>
        </el-table-column>
<!--        <el-table-column label="预计提成金额(元)" align="center" width="160">-->
<!--          <template slot-scope="{row}">-->
<!--            <span>{{ row.predictAmount}}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column label="结算金额(元)" align="center" width="120">
          <template slot-scope="{row}">
            <span>{{ row.brokerageAmount}}</span>
          </template>
        </el-table-column>
        <el-table-column label="结算类型" align="center" width="120">
          <template slot-scope="{row}">
            <span>{{ settleCate(row.brokerageCate)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="提成规则" align="center" width="150">
          <template slot-scope="{row}">
            <el-tag type="success">{{brokerageRule(row.brokerageRule)}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="提成方式" align="center" width="150">
          <template slot-scope="{row}">
            <el-tag type="success">{{brokerageMode(row.brokerageMode)}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="结算时间" align="center" width="180">
          <template slot-scope="{row}">
            <span>{{ row.created}}</span>
          </template>
        </el-table-column>
<!--        <el-table-column label="操作" align="center" width="100"  fixed="right">-->
<!--          <template slot-scope="{row}">-->
<!--            <el-button-->
<!--              class-name="filter-item"-->
<!--              type="primary"-->
<!--              @click="goDetail(row.id)"-->
<!--              round-->
<!--            >提成明细</el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
      </parentTable>
    </y-page-list-layout>
  </div>
</template>
<script>
  import YPageListLayout from '@/components/YPageListLayout'
  import Breadcrumb from '@/components/Breadcrumb'
  import PermissionButton from '@/components/PermissionButton/PermissionButton'
  import { fileDown } from '../../utils/file'

  export default {
    name: 'ViewsBrokerageSequenceDetail',
    components: {
      Breadcrumb,
      YPageListLayout,
    },
    filters: {
      statusFilter(status) {
        const statusMap = {
          published: 'success',
          draft: 'info',
          deleted: 'danger',
        }
        return statusMap[status]
      },
    },
    data() {
      return {
        isDisable:false,
        tableKey: 0,
        pageData: { records: [] },
        total: 20,
        listLoading: true,
        listQuery: {
          page: 1,
          size: 10,
          descs: 'id',
          state:null
        },
        listQueryKey: 'keyword',
        importLoading: false,
      }
    },
    created() {
      this.getList()
    },
    methods: {
      settleDetailExport(){
        this.$utils.exportUtil(
          "/itemBrokerageSequenceDetail/export", this.listQuery,
          "导出"
        );
      },
      settleCate(val){
        if (val === 'AHEAD'){
          return '预提';
        }
        if (val === 'SETTLE'){
          return '结算';
        }
        if (val === 'PAYMENT_SETTLE'){
          return '回款结算';
        }
        if (val === 'COMPENSATION'){
          return '补偿结算';
        }
      },
      brokerageRule(val){
        if (val === 'LAND_OTHER_RULE'){
          return '参与人员规则';
        }
        if (val === 'LAND_MARKETER_RULE'){
          return '市场人员规则';
        }
        if (val === 'LAND_SUPERVISOR_RULE'){
          return '营销主管规则';
        }
        if (val === 'LAND_MANAGER_RULE'){
          return '营销经理规则';
        }
      },
      brokerageMode(val){
        if (val === 'PERSONAL'){
          return '个人提成';
        }
        if (val === 'TEAM_SHARE'){
          return '团队提成';
        }
      },
      resetSearch() {
        this.listQuery = {
          current: 1,
          size: 10,
          descs: 'id',
        };
        this.getList()
      },
      getList() {
        const that = this;
        this.listLoading = true;
        this.$api.itemBrokerageSequenceDetail.list(Object.assign({}, that.listQuery)).then((res) => {
          that.pageData = res.data;
          setTimeout(() => {
            that.listLoading = false
          }, 200)
        })
          .catch(() => {
            that.listLoading = false
          })
      },
    }
  }
</script>
<style lang="scss" scoped>
  .right {
    flex: 1;

    .title {
      font-size: 16px;
      font-weight: 500;
      color: rgba(51, 51, 51, 1);
      line-height: 35px;
      margin-bottom: 8px;
    }

    .menu-2-box {
      display: flex;
      flex-wrap: wrap;
      width: 100%;
    }

    .menu-2-item {
      display: flex;
      align-items: center;
      color: #656565;
      font-size: 12px;
      width: 230px;
      height: 101px;
      background: rgb(255, 185, 129);
      border-radius: 3px;
      padding-left: 20px;
      margin-right: 10px;
      margin-bottom: 10px;
      cursor: pointer;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);

      .text {
        margin-left: 16px;
      }
    }
  }
</style>
