<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">
      <parentTable
        v-loading="listLoading"
        :data="pageData.records"
        slot="table"
        style="width: 100%;"
      >
        <el-table-column label="项目名称" align="center" width="250">
          <template slot-scope="{row}">
            <span>{{ row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="事业部流水号" align="center" width="135">
          <template slot-scope="{row}">
            <span>{{ row.businessNo }}</span>
          </template>
        </el-table-column>
        <el-table-column label="项目编号" align="center" width="180">
          <template slot-scope="{row}">
            <span>{{row.belongTo}}{{ row.oaNo }}</span>
          </template>
        </el-table-column>
        <el-table-column label="项目类型" align="center" width="130">
          <template slot-scope="{row}">
            <span>{{ row.cateName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="业务来源" align="center" width="130">
          <template slot-scope="{row}">
            <span>{{ row.businessSourceName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="委托单位" align="center" width="130">
          <template slot-scope="{row}">
            <span>{{ row.clientUnit}}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户名字" align="center" width="130">
          <template slot-scope="{row}">
            <span>{{ row.clientName}}</span>
          </template>
        </el-table-column>
        <el-table-column label="合同金额(元)" align="center" width="110">
          <template slot-scope="{row}">
            <span>{{ row.amount}}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户经理" align="center" width="100">
          <template slot-scope="{row}">
            <span>{{ row.clientManager}}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户经理提成金额(元)" align="center" width="160">
          <template slot-scope="{row}">
            <span>{{ row.marketerBrokerageAmount}}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户经理提成率" align="center" width="150">
          <template slot-scope="{row}">
            <span>{{ row.brokerageRate}}%</span>
          </template>
        </el-table-column>
        <el-table-column label="是否预提" align="center" width="180" fixed="right">
          <template slot-scope="{row}">
            <el-switch
              style="display: block;height: 40px;padding-top: 8px"
              v-model= row.marketerAdvanceBrokerageAble
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-text="可预提"
              inactive-text="不可预提"
              @change="updateAble(row)"
            >
            </el-switch>
          </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: 'ViewsBrokerageAhead',
    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: {
      updateAble(row){
        this.$api.itemBrokerageGeneral.marketerStatus({id:row.id, marketerStatus:row.marketerAdvanceBrokerageAble}).then(res=>{
          if (res.code === 200){
            this.$notify({
              title: '成功',
              message: '修改成功',
              type: 'success',
              duration: 2000
            });
            this.getList();
          }
        })
      },
      getList() {
        const that = this;
        this.listLoading = true;
        const key = {};
        this.$api.itemBrokerageGeneral.list(Object.assign({marketerAdvanceBrokerageAble:true}, that.listQuery, key)).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>
