<template>
    <div class="payroll-box">
        <div class="tools">
            <!-- <h1>订单管理</h1> -->
            <div class="rightmenu">
                <!-- <el-button size="mini" type="primary" @click="downLoadExcel">导出</el-button> -->
            </div>
        </div>
        <div class="query-box">
            <el-row :gutter="20">
                <el-col :xs="7" :sm="6" :md="5" :lg="4" :xl="3">
                    <span class="font-size-12" style="padding-right: 10px;flex-shrink: 0;">期数：</span>
                    <el-select size="mini" width="200" v-model="msg.PeriodsId" placeholder="请选择"
                        @change="getList">
                        <el-option label="不限" :value="-1"></el-option>
                        <el-option v-for="item in PeroidsList" :key="item.Id" :label="item.Periods"
                            :value="item.Id"></el-option>
                    </el-select>
                </el-col>
            </el-row>
        </div>
        <div class="page-content">
            <el-table v-loading="loading" stripe ref="multipleTable" :data="dataList" tooltip-effect="dark"
                style="width: 100%" :height="dataList.length > 0 ? '600' : '660'" row-class-name="font-size-12">
                <el-table-column label="期数">
                    <template slot-scope="scope">
                    {{scope.row.Month}}
                    </template>
                </el-table-column>
                <el-table-column label="总利润">
                    <template slot-scope="scope">
                    {{scope.row.ProfitMoney}}
                    </template>
                </el-table-column>
                <el-table-column label="引流数量">
                    <template slot-scope="scope">
                    {{scope.row.EmpType == 1 ? '-' : scope.row.LureNum}}
                    </template>
                </el-table-column>
                <el-table-column label="成交单数">
                    <template slot-scope="scope">
                    {{scope.row.EmpType == 1 ? '-' : scope.row.OrderNum}}
                    </template>
                </el-table-column>
                <el-table-column label="工资规则">
                    <template slot-scope="scope">
                        <span :class="scope.row.WageType!=1?'cursor-p':''" @click="scope.row.WageType!=1?GenerateScale(scope.row):''">{{scope.row.WageType!=1?'上季度定档':'新员工比例'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="基本工资">
                    <template slot-scope="scope">
                    {{scope.row.WageMoney}}
                    </template>
                </el-table-column>
                <el-table-column label="本次提成比例">
                    <template slot-scope="scope">
                    {{scope.row.CommissionRate}}%
                    </template>
                </el-table-column>
                <el-table-column label="提成金额">
                    <template slot-scope="scope">
                    {{scope.row.Commission}}
                    </template>
                </el-table-column>
                <el-table-column label="本次年终比例">
                    <template slot-scope="scope">
                    {{scope.row.BonusRate}}%
                    </template>
                </el-table-column>
                <el-table-column label="当月年终奖励">
                    <template slot-scope="scope">
                    {{scope.row.BonusMoney}}
                    </template>
                </el-table-column>
                <el-table-column label="累计年终奖励">
                    <template slot-scope="scope">
                    {{scope.row.TotalBonus}}
                    </template>
                </el-table-column>
                
                <el-table-column label="备注" show-overflow-tooltip>
                    <template slot-scope="scope">
                    {{scope.row.Remark}}
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div v-if="total>0">
            <el-pagination class="Mypagination" background @current-change="handleCurrentChange"
                :page-sizes="[10, 30, 60, 90, 100]" :page-size="msg.pageSize" layout="total, sizes, prev, pager, next"
                @size-change="handleSizeChange" :total="total">
            </el-pagination>
        </div>
        <!-- 查看生成比例 -->
        <el-dialog custom-class='w1006' title="员工生成比例" :visible.sync="outerVisible" center>
            <template>
                <div
                  class="cm_content"
                  style="width: 100%;margin-bottom: 35px;margin-top: 30px;"
                >
                  
                <div class="ITUDWageMoney-box" style="margin-bottom: 20px;">
                    <span>姓名：{{EmName}}</span>
                </div>
                  <table
                    class="po_content singeRowTable"
                    style="border:1px solid #E6E6E6;"
                    cellspacing="0"
                    cellpadding="0"
                    v-loading="loading">
                    <tr>
                        <th>期数</th>
                        <th>类型</th>
                        <th>利润</th>
                        <th>引流数量</th>
                        <th>成交订单</th>
                        
                    </tr>
                    <tr v-for="(item,index) in commissionratioList.List"
                        :key="index">
                        <td>{{item.Month}}</td>
                        <td>{{item.EmpType!=1?'引流':'销售'}}</td>
                        <td>{{item.ProfitMoney}}</td>
                        <td>{{item.EmpType!=1?item.LureNum:'-'}}</td>
                        <td>{{item.EmpType!=1?item.OrderNum:'-'}}</td>
                    </tr>
                    <tr>
                        <td>平均</td>
                        <td>-</td>
                        <td>{{commissionratioList.AvgProfit}}</td>
                        <td>{{commissionratioList.AvgLureNum}}</td>
                        <td>{{commissionratioList.AvfOrderNum}}</td>
                    </tr>
                  </table>
                  
                  <div class="ITUDschedule-Box-box">
                    <div class="ITUDschedule-box">
                        <div class="ITUDWageMoney-box">
                            <span>工资：{{commissionratioList.WageMoney}}</span>
                        </div>
                        <div class="progress-box">
                            <div v-for="(item,index) in commissionratioList.WageRateList" :key="index" 
                            class="relative-position">
                            <el-progress :text-inside="true" :stroke-width="20"
                              :percentage="setItemProgress(item)"
                              :status="setItemStatus(item)"
                              :format="setItemTextW(item)"
                              :color="
                              commissionratioList.AvgLureNum>item.StartValue&&
                                commissionratioList.AvfOrderNum>item.EndValue?colorlists[Math.floor(Math.random()*10)]:colors[Math.floor(Math.random()*10)]">
                              </el-progress>
                              <div class="rate-box">
                                <div class="sanjiao" :style="{'border-bottom-color':commissionratioList.AvgLureNum>item.StartValue&&
                                commissionratioList.AvfOrderNum>item.EndValue?'#FF7262':'#CACACA'}"></div>
                                <div class="rate full-width" :class="{'active-rate':commissionratioList.AvgLureNum>item.StartValue&&
                                    commissionratioList.AvfOrderNum>item.EndValue}">
                                  <i class="el-icon-check" style="font-size:8px"></i> {{item.Rate}}
                                </div>
                              </div>
                            </div>
                        </div>
                    </div>
                    <div class="ITUDschedule-box" style="margin-left: 20px;">
                        <div class="ITUDWageMoney-box">
                            <span>提成比例：{{commissionratioList.CommissionRate}}%</span>
                        </div>
                        <div class="progress-box">
                            <div v-for="(item,index) in commissionratioList.CommissionRateList" :key="index" 
                            class="relative-position">
                              <el-progress :text-inside="true" :stroke-width="20"
                              :percentage="setItemProgress(item)"
                              :status="setItemStatus(item)"
                              :format="setItemText(item)"
                              :color="
                              commissionratioList.AvgLureNum>item.StartValue&&
                                commissionratioList.AvfOrderNum>item.EndValue?colorlists[Math.floor(Math.random()*10)]:colors[Math.floor(Math.random()*10)]">
                              </el-progress>
                              <div class="rate-box">
                                <div class="sanjiao" :style="{'border-bottom-color':commissionratioList.AvgLureNum>item.StartValue&&
                                commissionratioList.AvfOrderNum>item.EndValue?'#FF7262':'#CACACA'}"></div>
                                <div class="rate full-width" :class="{'active-rate':commissionratioList.AvgLureNum>item.StartValue&&
                                    commissionratioList.AvfOrderNum>item.EndValue}">
                                  <i class="el-icon-check" style="font-size:8px"></i> {{item.Rate}}%
                                </div>
                    
                              </div>
                            </div>
                        </div>
                    </div>
                    
                  </div>
                  
                </div>
                <div v-if="!commissionratioList"
                  style="width: 100%;border:1px solid #fff;display: flex;align-items: center;justify-content: center;height: 60px;margin-top: 30px;"
                >暂无数据</div>
               
              </template>
			<div slot="footer" class="dialog-footer">
				<el-button @click="outerVisible = false">取消</el-button>
				<el-button type="primary" @click="outerVisible = false">确定</el-button>
			</div>
            
		</el-dialog>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                commissionratioList:[],
                EmName:'',
                EmpType:'',
                outerVisible:false,
                loading:false,
                PeroidsList: [],
                titleList:[
                    {name:'不限',id:'-1'},
                    {name:'引流规则',id:'2'},
                    {name:'销售规则',id:'1'}
                ],
                dataList:[],
                total:0,
                msg: {
                    pageIndex: 1,
                    pageSize: 10,
                    PeriodsId: -1
                },
                colors: [
                    'rgba(42, 48, 54,.2)',
                    'rgba(138, 24, 48,.2)',
                    'rgba(200, 138, 131,.2)',
                    'rgba(84, 221, 226,.2)',
                    'rgba(178, 199, 168,.2)',
                    'rgba(16, 195, 195,.2)',
                    'rgba(0, 21, 68,.2)',
                    'rgba(226, 166, 198,.2)',
                    'rgba(278,17,66,.2)',
                    'rgba(153, 199, 235,.2)',
                    'rgba(34,184,221,.2)',
                    'rgba(221,72,34,.2)',
                    'rgba(204,51,204,.23)',
                    'rgba(255,204,0,.2)',
                    'rgba(77,179,179,.2)',
                    'rgba(196,60,141,.2)',
                    'rgba(195,90,141,.2)',
                ],
                colorlists: [
                    'rgba(42, 48, 54, 1)',
                    'rgba(138, 24, 48, 1)',
                    'rgba(200, 138, 131, 1)',
                    'rgba(84, 221, 226, 1)',
                    'rgba(178, 199, 168, 1)',
                    'rgba(16, 195, 195, 1)',
                    'rgba(0, 21, 68, 1)',
                    'rgba(226, 166, 198, 1)',
                    'rgba(278,17,66, 1)',
                    'rgba(153, 199, 235,1)',
                    'rgba(34,184,221,1)',
                    'rgba(221,72,34,1)',
                    'rgba(204,51,204,1)',
                    'rgba(255,204,0,1)',
                    'rgba(77,179,179,1)',
                    'rgba(196,60,141,1)',
                    'rgba(195,90,141,1)',
                ],
            }
        },
        mounted() {
            this.getList()
            this.GetCommissionPeroidsList()
        },
        methods: {
            // 自定义进度条文字
            setItemTextW(row) {
                return () => {
                    return row.StartValue + ' - ' + row.EndValue
                }
            },
            // 设置进度
            setItemProgress(data) {
                if(this.commissionratioList.AvgLureNum>=data.StartValue&&this.commissionratioList.AvfOrderNum>=data.EndValue){
                    return 100
                }else{
                    return 100
                }
            },
            // 自定义进度条文字
            setItemText(row) {
                this.formatProgress(row)
                return () => {
                    return row.StartValue + ' - ' + row.EndValue
                }
            },
            // 设置当前进度条状态，显示不同颜色
            setItemStatus(data) {
                if(this.commissionratioList.AvgLureNum>=data.StartValue&&this.commissionratioList.AvfOrderNum>=data.EndValue){
                    return 'exception'
                }
            },
            formatProgress(data){
                if (data.StartValue > 0) {
                    const s = data.StartValue.toString().slice(0, -4) ? data.StartValue.toString().slice(0, -4) : '0'
                    const e = data.StartValue.toString().slice(-4, -3)
                    data.StartValue = s + (e > 0 ? ('.' + e) : '') + 'w';
                } else if (data.StartValue == 0) {
                    data.StartValue = 0
                } else if (data.StartValue == -1) {
                   data.StartValue = '∞'
                }
                if (data.EndValue > 0) {
                    const s = data.EndValue.toString().slice(0, -4) ? data.EndValue.toString().slice(0, -4) : '0'
                    const e = data.EndValue.toString().slice(-4, -3)
                   data.EndValue = s + (e > 0 ? ('.' + e) : '') + 'w';
                } else if (data.EndValue == 0) {
                    data.EndValue = 0
                } else if (data.EndValue == -1) {
                    data.EndValue = '∞'
                }
            },
            // 获取员工生成比例
            GenerateScale(item){
                if(!item.WageReId){
                    return
                }
                this.EmName = item.EmName
                this.EmpType = item.EmpType
                let msg = {
                    WageReId:item.WageReId
                }
                this.apipost(
                    "/api/Commission/GetCommissionSource",msg,res => {
                        if (res.data.resultCode == 1) {
                            this.outerVisible = true
                            this.commissionratioList = res.data.data
                        } else {
                            this.Error(res.data.message);
                        }
                    }
                );
            },
            GetCommissionPeroidsList() { //期数下拉
                this.apipost(
                    "/api/Commission/GetCommissionPeroidsList",{},res => {
                    if (res.data.resultCode == 1) {
                        this.PeroidsList = res.data.data;
                    } else {
                        this.Error(res.data.message);
                    }
                    }
                );
            },
            // 获取订单列表
            getList() {
                this.loading = true;
                this.apipost(
                    "/api/Commission/GetMyCommissionPageList",
                    this.msg,
                    (res) => {
                        if (res.data.resultCode == 1) {
                            this.loading = false
                            this.dataList = res.data.data.pageData
                            this.total = res.data.data.count;
                        }else{
                            this.loading = false
                            this.$message.error(res.data.message);
                        }
                    })
            },
            handleSizeChange(val) {
                this.msg.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.msg.pageIndex = val;
                this.getList();
            },
        }
    }
</script>

<style scoped>
    .singeRowTable{
        width: 100%;
    }
    .singeRowTable tr th {
        background: #E6E6E6;
        height: 40px;
        font-size: 14px;
        color: #333;
    }
    .singeRowTable tr td{
        padding: 8px 5px !important;
    }
    
    .cursor-p{
        cursor: pointer;
    }
    .cursor-p:hover{
        color: #409EFF;
    }
    .ITUDWageMoney-box{
        margin-top: 20px;
        margin-bottom: 10px;
    }
    .ITUDschedule-Box-box{
        display: flex;
        flex-direction: row;
        justify-content: space-between;
    }
    .ITUDschedule-box{
        flex: 1;
        display: flex;
        flex-direction: column;
    }
    .ITUD-title{
        margin-top: 10px;
        margin-bottom: 10px;
    }
    .progress-box{
        flex: 1;
        display: flex;
        flex-direction: row;
        
    }
    .relative-position{
        flex: 1;
        margin-right: 0;
        position: relative;
    }
    /deep/.relative-position .el-progress-bar__outer{
        border-radius: 0 !important;
    }
    /deep/.relative-position .el-progress-bar__inner{
        border-radius: 0 !important;
    }
    .ITUD-text-box{
        position: relative;
    }
    .ITUD-text{
        position: absolute;
        z-index: 999;
        color: red;
    }
    .rate-box {
        position: absolute;
        top: 30px;
        left: 50%;
        transform: translateX(-50%);
        color: #000;
        z-index: 9;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        
    }
  .sanjiao {
      width: 0;
      height: 0;
      margin-left: 5%;
      border-right: 4px solid transparent;
      border-left: 4px solid transparent;
      border-bottom: 3px solid #CACACA;
    }
    .rate {
      min-width: 20px;
      padding: 2px 6px;
      background-color: #CACACA !important;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #666666;
      font-size: 0.62vw;
      font-family: PingFang SC;
      border-radius: 7px;
      line-height:12px;
      white-space:nowrap;
    }
    .active-rate{
      background-color: #FF7262 !important;
      color: #FFFFFF !important;
    }
    /deep/.el-table tr:first-child th:nth-child(6){
        background: #FFE082 !important;
    }
    /deep/.el-table tr:first-child th:nth-child(7){
        background: #FFE082 !important;
    }
    /deep/.el-table tr:first-child th:nth-child(8){
        background: #FFE082 !important;
    }
    /deep/.el-table tr:first-child th:nth-child(9){
        background: #E1BEE7 !important;
    }
    /deep/.el-table tr:first-child th:nth-child(10){
        background: #E1BEE7 !important;
    }
    /deep/.el-table tr:first-child th:nth-child(11){
        background: #E1BEE7 !important;
    }
    /deep/.el-table tr td:nth-child(6){
        background: #FFE082;
    }
    /deep/.el-table tr td:nth-child(7){
        background: #FFE082;
    }
    /deep/.el-table tr td:nth-child(8){
        background: #FFE082;
    }
    /deep/.el-table tr td:nth-child(9){
        background: #E1BEE7;
    }
    /deep/.el-table tr td:nth-child(10){
        background: #E1BEE7;
    }
    /deep/.el-table tr td:nth-child(11){
        background: #E1BEE7;
    }
</style>