<style>
  @import "../css/cssReset.css";

  .baseSet_Title {
    width: 120px !important;
    padding: 18px 0 0 16px;
    text-align: right;
  }

  .salesRules .border-bottom {
    /* border-bottom: 1px dashed #EEE; */
    padding-bottom: 5px;
    margin-bottom: 5px;
  }

  .salesRules .text-bottom {
    height: 32px;
    line-height: 32px;
    margin-bottom: 10px;
  }

  .marketRules .border-bottom {
    padding-bottom: 5px;
    margin-bottom: 5px;
  }

  .marketRules .text-bottom {
    height: 32px;
    line-height: 32px;
    margin-bottom: 10px;
  }

  .marketRules .singeRowTable tr th {
    border: 1px solid #d2d2d2;
  }

  .border-bottom {
    border-bottom: 1px dashed #EEE;
    padding-bottom: 5px;
    margin-bottom: 5px;
  }
  .stulistNum {
    display: inline-block;
    width: 25px;
    height: 25px;
    text-align: center;
    line-height: 23px;
    border: 1px solid #2961FE;
    border-radius: 50%;
    cursor: pointer;
    color: #2961FE;
  }

</style>
<template>
  <div class="page-body marketRules">
    <div class="page-search row items-center">
      <div class="col row wrap q-col-gutter-md">
        <div class="col-3">
          <q-input @input="resetSearch" filled clearable v-model="msg.PlanName" label="名称" maxlength="20" />
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat
        class="sticky-column-table sticky-right-column-table" separator="none" :data="dataList" :columns="columns"
        row-key="name">
        <template v-slot:top>
          <div class="col-2 q-table__title">人头奖金配置</div>
          <q-space />
          <div class="page-option">
            <q-btn color="accent" size="sm" class="q-mr-md" icon="add" label="新增规则" @click="AddMsg(null)" />
          </div>
        </template>
        <template v-slot:body-cell-SaleList="props">
          <q-td>
            <template v-if="props.row.SaleList">
              <template v-if="props.row.SaleList.length==1">
                {{props.row.SaleList[0].SaleManName}}
              </template>
              <template v-if="props.row.SaleList.length>1">
                {{props.row.SaleList[0].SaleManName}}：
                <span class="stulistNum">
                  {{props.row.SaleList.length}}
                  <q-popup-proxy>
                    <q-banner>
                      <div style="width:400px;max-height:600px;overflow-y:auto;">
                        <el-tag size="mini" style="margin:0 10px 10px 0" v-for="(item,index) in props.row.SaleList" :key="index">{{item.SaleManName}}</el-tag>
                      </div>
                    </q-banner>
                  </q-popup-proxy>
                </span>
              </template>
              <template v-if="props.row.SaleList.length==0">
                无
              </template>
            </template>
          </q-td>
        </template>
        <template v-slot:body-cell-UseCourseList="props">
          <q-td>
            <div class="border-bottom" v-for="(item,index) in props.row.UseCourseList" :key="index">
              {{item.CourseName}}
            </div>
          </q-td>
        </template>
        <template v-slot:body-cell-NotUseCourseList="props">
          <q-td>
            <div class="border-bottom" v-for="(item,index) in props.row.NotUseCourseList" :key="index">
              {{item.CourseName}}
            </div>
          </q-td>
        </template>
        <template v-slot:body-cell-DetailList="props">
          <q-td>
            <div class="border-bottom" v-for="(item,index) in props.row.DetailList" :key="index">
              月报名人数:<span style="margin-left:10px;color:blue">{{item.StartNum}}-{{item.EndNum}}</span> 人,奖励<span
                style="margin-left:10px;color:red">{{item.Money}}</span>元
            </div>
          </q-td>
        </template>
        <template v-slot:body-cell-Id="props">
          <q-td :props="props">
            <div>
              <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="编辑"
                @click="AddMsg(props.row)" />
              <q-btn flat size="xs" icon="delete" color="negative" class="q-mr-xs" label="删除"
                @click="delConsult(props.row.Id)" />
            </div>
          </q-td>
        </template>
        <template v-slot:bottom>
          <q-pagination class="full-width justify-end" v-model="msg.pageIndex" color="primary" :max="pageCount"
            :input="true" @input="changePage" />
        </template>
      </q-table>
    </div>
    <consult-form v-if="isShowConsult" :save-obj="objOption" @close="closeSaveForm" @success="resetSearch">
    </consult-form>
  </div>
</template>
<script>
  import {
    GetBounsPlanPage,
    RemoveBonusPlan
  } from '../../../api/finance/index'
  import consultForm from '../../../components/finance/consult-form'
  export default {
    meta: {
      title: "人头奖金配置"
    },
    props: {},
    components: {
      consultForm
    },
    data() {
      return {
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          PlanName: ""
        },
        columns: [{
            name: "PlanName",
            label: "方案名称",
            field: "PlanName",
            align: "left"
          },
          {
            name: "PlanTypeStr",
            label: "类型",
            field: "PlanTypeStr",
            align: "left"
          },
          {
            name: "BasicSalary",
            label: "基本工资",
            field: "BasicSalary",
            align: "left"
          },
          {
            name: "OpenBonus",
            label: "开单奖金",
            field: "OpenBonus",
            align: "left"
          },
          {
            name: "WorkAgeSalary",
            required: true,
            label: "工龄工资",
            align: "left",
            field: 'WorkAgeSalary'
          },
          {
            name: "ClueNumSalary",
            required: true,
            label: "线索奖金",
            align: "left",
            field: 'ClueNumSalary'
          },
          {
            name: "SaleList",
            required: true,
            label: "适用人员",
            align: "left",
            field: 'SaleList'
          },
          {
            name: "UseCourseList",
            required: true,
            label: "适用课程",
            align: "left",
            field: 'UseCourseList'
          },
          {
            name: "NotUseCourseList",
            label: "不适用课程",
            field: "NotUseCourseIds",
            align: "left",
          },
          {
            name: "DetailList",
            label: "社会班招生人头达标奖金",
            field: "DetailList",
            align: "left"
          },
          {
            name: 'Id',
            label: '操作',
            field: 'Id'
          }
        ],
        pageCount: 0,
        loading: false,
        isShowConsult: false,
        dataList: [], //列表数据
        objOption: null
      }
    },
    created() {},
    mounted() {
      this.getList(); //获取规则
    },
    methods: {
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getList();
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getList()
      },
      getList() {
        this.loading = true;
        GetBounsPlanPage(this.msg).then(res => {
          if (res.Code == 1) {
            this.dataList = res.Data.PageData;
            this.pageCount = res.Data.PageCount;
          }
          this.loading = false
        })
      },
      AddMsg(obj) {
        if (obj) {
          this.objOption = obj;
        } else {
          this.objOption = null
        }
        this.isShowConsult = true
      },
      closeSaveForm() {
        this.isShowConsult = false;
      },
      delConsult(Id) {
        let delMsg = {
          Id: Id
        };
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定删除？',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          RemoveBonusPlan(delMsg).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '删除成功！',
                position: 'top'
              })
              this.getList();
            }
          })
        }).onCancel(() => {

        });
      }
    },
  }

</script>
<style lang="sass">
  @import url('~assets/css/table.sass')

</style>
