<template>
  <div class="achievements page-body">
    <q-tabs style="margin-bottom:20px;" v-model="msg.Q_IsComfirm" @input="tabChange()" narrow-indicator dense
      align="left" class="text-primary">
      <q-tab :ripple="false" name="1" label="已发放绩效" />
      <q-tab :ripple="false" name="2" label="可发放绩效" />
    </q-tabs>
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
        <div class="col-3">
          <q-select @input="resetSearch" standout="bg-primary text-white" option-value="SId" option-label="SName"
            v-model="msg.School_Id" :options="schoolList" emit-value map-options label="所属校区" />
        </div>
        <div class="col-3">
          <q-input @input="resetSearch" clearable standout="bg-primary text-white" v-model="msg.ClassName" label="班级名称"
            maxlength="20" @clear="resetSearch" />
        </div>
        <div class="col-3">
          <q-input @input="resetSearch" clearable standout="bg-primary text-white" v-model="msg.TeacherName"
            label="教师名称" maxlength="20" @clear="resetSearch" />
        </div>
        <div class="col-3" v-if="msg.Q_IsComfirm==1">
          <q-select @input="resetSearch" standout="bg-primary text-white" option-value="Id" option-label="Name"
            v-model="msg.Q_IsCreateFinance" :options="StateList" emit-value map-options label="状态" />
        </div>
        <div class="col-3" v-if="msg.Q_IsComfirm==2">
          <q-select @input="resetSearch" standout="bg-primary text-white" option-value="Id" option-label="Name"
            v-model="msg.PerfState" :options="StateList2" emit-value map-options label="状态" />
        </div>
        <div class="col-3 Sysuser_Date" v-if="msg.Q_IsComfirm==1">
          <q-field filled>
             <template v-slot:control>
              <el-date-picker v-model="dateList2" @change="resetSearch()" value-format="yyyy-MM-dd" type="daterange" style="border:none;"
                 range-separator="至"  start-placeholder="操作开始时间"  end-placeholder="操作结束时间">
                  </el-date-picker>       
            </template>
          </q-field>
        </div>
        <div class="col-3 Sysuser_Date" v-if="msg.Q_IsComfirm==2">
          <q-field filled class="col-6">
             <template v-slot:control>
              <el-date-picker v-model="dateList" @change="resetSearch()" value-format="yyyy-MM-dd" type="daterange" style="border:none;"
                 range-separator="至"  start-placeholder="结课开始时间"  end-placeholder="结课结束时间">
                  </el-date-picker>       
            </template>
          </q-field>
        </div>
      </div>
    </div>
    <div class="productQueryList" v-loading='loading'>
      <ul v-if="data.length!=0">
        <li v-for="(item,index) in data" :key="index">
          <div class="dline">
            <div class="d1 row">
              <q-avatar square size="102px">
                <img :src="item.TeacherIcon">
              </q-avatar>
              <div style="margin-left: 20px">
                <div class="List-title">{{item.TeacherName}}</div>
                <div class="row d-div"><span class="d2-n">原有课时费</span>{{item.BaseHourFee}}元</div>
                <div class="row d-div" style="color:#F28C1D;"><span class="d2-n">课时费奖励</span>{{item.AddHourFee}}元</div>
                <div class="row d-div"><span class="d2-n">带班人数</span>{{item.BaseStuNum}} <span style="color:#F28C1D;"
                    v-if="item.AddStuNum>0">{{'+'+item.AddStuNum}}</span> </div>
              </div>
            </div>
            <div class="d2">
              <div class="List-title">招生信息</div>
              <div class="row d-div"><span class="d2-n">班级名称</span>{{item.ClassName}}</div>
              <div class="row d-div"><span class="d2-n">班级人数</span>{{item.ClassPeopelNum}}</div>
              <div class="row d-div"><span class="d2-n">结课日期</span>{{item.EndDate.split('T')[0]}}</div>
            </div>
            <div class="d3">
              <div class="List-title">KPI指标</div>
              <div class="row d-div"><span class="d2-n">班级满班率</span>{{item.FullClassRate}}%</div>
              <div class="row d-div"><span class="d2-n">平均上课率</span>{{item.AvgCheckRate}}%</div>
              <div class="row d-div"><span class="d2-n" >累计总课时</span>{{item.ClassHours}}课时</div>
            </div>
            <div class="d4">
              <div class="List-title">绩效奖励</div>
              <div class="row d-div" style="align-items: flex-end;color: #F72E52;line-height: 14px">
                ￥<span
                  style="font-size: 30px;line-height: 30px;font-weight: bold;font-family: perfectFont">{{item.Money.toFixed(2).split('.')[0]}}.</span>
                {{item.Money.toFixed(2).split('.')[1]}}
              </div>
              <div class="row d-div"><span class="d2-n" style="width: 60px">明细</span> <span
                  style="color:#2961FE;text-decoration:underline;cursor: pointer">
                  {{item.UnitPrice}}元
                  <q-popup-proxy>
                    <q-banner>
                      <div style="margin-top:20px;" class="achievements-proxy">
                        <table class="socialTable">
                          <tr>
                            <td style="width:100px;" v-if="item.JJList&&item.JJList.length>0"
                              :rowspan="item.JJList.length+2">平均上课率</td>
                            <td :colspan="item.JJFullRate.length+2">满班率</td>
                          </tr>
                          <tr>
                            <td></td>
                            <td v-for="(x,j) in item.JJFullRate" style="width:100px;">
                              <div class="Classdel_Div">{{x.StartValue}}%-{{x.EndValue}}%</div>
                            </td>
                          </tr>
                          <tr v-for="(x,j) in item.JJList">
                            <td style="width:100px;">
                              <div class="div_RowList">
                                {{x.StartValue}}<span v-if="x.StartValue>=0">%</span><span
                                  v-if="x.StartValue>=0&&x.EndValue>=0">-</span>{{x.EndValue}}<span
                                  v-if="x.EndValue>=0">%</span>
                              </div>
                            </td>
                            <td v-for="(subItem,subIndex) in x.FullClassList">
                              {{subItem.ClassMoney}}
                            </td>
                          </tr>
                        </table>
                      </div>
                    </q-banner>
                  </q-popup-proxy>
                </span> *{{item.ClassHours}}课时</div>
            </div>
            <div class="d5" v-if="msg.Q_IsComfirm==1" style="width: 12%;">
              <div class="List-title">财务单据</div>
              <div style="width: 100%;" class="row wrap">
                <div class="d5-item" style="cursor: pointer" v-if="item.FinanceId && item.FinanceId>0" @click="goUrl('FinancialDocumentsDetail',item.FinanceId)">
                  {{item.FinanceId}}
                </div>
                <div v-else style="color:#999999;">
                  暂无
                </div>
              </div>
            </div>
            <div class="d5" v-if="msg.Q_IsComfirm==2">
              <div class="List-title">课时奖励</div>
              <div class="row d-div"><span class="d2-n" style="width: 110px;">预计课时费调涨</span> <span
                  style="cursor: pointer;text-decoration:underline;">{{item.AddHourFee}}元</span>
                <q-popup-proxy>
                  <q-banner>
                    <div style="margin-top:20px;" class="achievements-proxy">
                      <table class="socialTable">
                        <tr>
                          <th :colspan="item.KSFullRate.length+3">
                            社会课时费调账规则
                          </th>
                        </tr>
                        <tr>
                          <td style="width:100px;" v-if="item.KSList&&item.KSList.length>0"
                            :rowspan="(item.KSList.length*2)+3">平均上课率</td>
                          <td :colspan="item.KSFullRate.length+3">满班率</td>
                        </tr>
                        <tr>
                          <td colspan="2"></td>
                          <td v-for="(x,j) in item.KSFullRate">
                            <div class="Classdel_Div">{{x.StartValue}}%-{{x.EndValue}}%</div>
                          </td>
                        </tr>
                        <template v-for="(x,j) in item.KSList">
                          <tr>
                            <td @click="getDataItem(x,index)" rowspan="2" style="width:150px;">
                              <div class="div_RowList">
                                {{x.StartValue}}<span v-if="x.StartValue>=0">%</span><span
                                  v-if="x.StartValue>=0&&x.EndValue>=0">-</span>{{x.EndValue}}<span
                                  v-if="x.EndValue>=0">%</span>
                              </div>
                            </td>
                            <td style="width:150px;">奖励课时费</td>
                            <td v-for="(subItem,subIndex) in x.FullClassList" style="width:100px;">
                              {{subItem.ClassMoney}}
                            </td>
                          </tr>
                          <tr>
                            <td>增加带班人数</td>
                            <td v-for="(subItem,subIndex) in x.FullClassList" style="width:100px;">
                              {{subItem.PeopelNum}}
                            </td>
                          </tr>
                        </template>
                      </table>
                    </div>
                  </q-banner>
                </q-popup-proxy>
              </div>
              <div class="row d-div"><span class="d2-n" style="width: 110px">预计带班人数调涨</span>{{item.AddStuNum}}人</div>
            </div>
            <div class="d7">
              <div class="row" style="align-items: center;color: #3FC4FF;cursor: pointer"
                v-if="item.PerfState==2 && item.FinanceId==0" @click="systemShan(item)">
                <img src="../../assets/images/course/zhidan.png" alt=""
                  style="width: 16px;height: 12px;margin-right: 5px;">
                生成单据
              </div>
              <div class="row" style="align-items: center;color: #2961FE;cursor: pointer" v-if="item.PerfState==2">
                <img src="../../assets/images/course/xiaoxi.png" alt=""
                  style="width: 16px;height: 12px;margin-right: 5px;">
                账单信息
              </div>
              <div class="row" style="align-items: center;color: #02C499;cursor: pointer"
                @click="IsShowRemarkDialog=true,RemarkMsg.PerfId=item.Id">
                <img src="../../assets/images/course/addreamke.png" alt=""
                  style="width: 16px;height: 12px;margin-right: 5px;">
                添加备注
                <q-popup-proxy>
                  <q-banner v-if="IsShowRemarkDialog==true">
                    <div style="width:250px;">
                      <div style="margin:10px 0 15px 0;">添加备注</div>
                      <q-input filled stack-label maxlength="500" :dense="false" v-model="RemarkMsg.Remark" class="col-12"
                               type="textarea" label="备注" />
                      <q-card-actions align="right" class="bg-white">
                        <q-btn label="取消" flat color="grey-10" size="sm"  @click="IsShowRemarkDialog=false"
                               style="font-weight:400 !important" />
                        <q-btn label="确认" color="accent q-px-md" size="sm" style="font-weight:400 !important"
                               @click="saveRemark()" />
                      </q-card-actions>
                    </div>
                  </q-banner>
                </q-popup-proxy>
              </div>
              <div class="row" style="align-items: center;color: #8175FB;cursor: pointer" @click="gostudent(item,1)"
                v-if="item.PerfState==1">
                <img src="../../assets/images/course/queren.png" alt=""
                  style="width: 16px;height: 12px;margin-right: 5px;">
                确认订单
              </div>
              <div class="row" style="align-items: center;color: #F72E52;cursor: pointer" @click="gostudent(item,2)"
                v-if="item.PerfState==1">
                <img src="../../assets/images/course/nofang.png" alt=""
                  style="width: 16px;height: 12px;margin-right: 5px;">
                不发放绩效
              </div>
              <div class="row" style="align-items: center;color: #02B4C4;cursor: pointer" @click="gostudent(item,3)"
                v-if="item.PerfState==3">
                <img src="../../assets/images/course/huifu.png" alt=""
                  style="width: 16px;height: 12px;margin-right: 5px;">
                恢复绩效
              </div>
              <div class="row" style="align-items: center;color: #F28C1D;cursor: pointer" @click="gostudent(item,4)"
                v-if="item.PerfState==2 && item.FinanceId==0">
                <img src="../../assets/images/course/chehui.png" alt=""
                  style="width: 16px;height: 12px;margin-right: 5px;">
                撤销奖励
              </div>
            </div>
          </div>
          <div class="d6 row">
            <span style="color:#2D2D2D;">教师备注：</span>
            <div class="row wrap Remark-l" v-if="item.RemarkList.length>0">
              {{item.RemarkList[0].Content}}
              <span class="iconfont icon-xiangxia"
                style="color: #2961FE;font-size: 10px;position: absolute;right: 0;top:10px">
                <q-popup-proxy>
                  <q-banner>
                    <div style="width: 700px;">
                      <div>教师备注:</div>
                      <div v-for="(xq,jq) in item.RemarkList" :key="jq"
                        style=" margin-top: 10px;background: #e6e6e6;padding: 5px;font-size: 12px">
                        <div>{{xq.Content}}</div>
                        <div style="text-align: right">{{xq.CreateBy}} {{xq.CreateTime}}</div>
                      </div>
                    </div>
                  </q-banner>
                </q-popup-proxy>
              </span>
            </div>
            <div v-else class="row wrap Remark-l">
              暂无
            </div>
          </div>
        </li>
        <li style="border: none;display: flex;justify-content: flex-end;background: white;padding: 5px 20px">
          <q-pagination v-model="msg.PageIndex" :max="pageCount" @input="changePage" class="full-width justify-end"
            color="primary" :input="true">
          </q-pagination>
        </li>
      </ul>
      <div v-else style="width: 100%;color: #999999;text-align: center;font-size: 20px">暂无数据</div>
    </div>

    <!--    一键制单-->
    <q-dialog v-model="ISsystem" persistent>
      <q-card style="width: 400px;max-width:500px;">
        <q-card-section>
          <div class="text-h6">一键制单</div>
        </q-card-section>
        <q-card-section class="q-pt-none scroll" style="max-height: 70vh">
          <div class="col">
            <q-radio v-model="FinanceMsg.IsPublic" val="0" label="私账" />
            <q-radio v-model="FinanceMsg.IsPublic" val="1" label="公账" />
          </div>
          <div class="col" style="margin-top: 20px">
            <q-select standout="bg-primary text-white" option-value="ID" option-label="Name"
              v-model="FinanceMsg.CurrencyId" :options="coinGetList" emit-value map-options label="币种" />
          </div>
        </q-card-section>
        <q-separator />
        <q-card-actions align="right" class="bg-white">
          <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important"
            @click="ISsystem=false,Resetsystem()" v-if="!Floading" />
          <q-btn label="立即制单" color="accent" class="q-px-md" style="font-weight:400 !important" :loading="Floading"
            @click="savesystem()" />
        </q-card-actions>
      </q-card>
    </q-dialog>
  </div>
</template>

<script>
  import {
    getSchoolDropdown,
  } from '../../api/school/index'
  import {
    getBonusStateEnumList, //教师奖励状态 枚举
    getTeachingPerfPageList,
    setTeachingPerfRemark,
    setTeachingPerfState,
    setTeachingPerfFinance
  } from '../../api/course/class'
  export default {
    meta: {
      title: "教师业绩奖励"
    },
    name: "achievements",
    data() {
      return {
        msg: {
          PageIndex: 1,
          PageSize: 8,
          School_Id: 0,
          ClassId: 0,
          ClassName: '', //班级名称
          TeacherId: 0,
          TeacherName: '',
          Q_IsCreateFinance: 0, //是否制单 1是 2否
          Q_IsComfirm: '1', //是否已确认 1是 2否
          PerfState: 0, //状态 枚举
          StartTime: '',
          EndTime: '',
          OPStartTime: '',
          OPEndTime: '',
        },
        schoolList: [],
        StateList: [{
          Id: 0,
          Name: "不限"
        }, {
          Id: 1,
          Name: "已制单"
        }, {
          Id: 2,
          Name: "未制单"
        }, ],
        StateList2: [{
          Id: 0,
          Name: "不限"
        }, {
          Id: 1,
          Name: "待处理"
        }, {
          Id: 3,
          Name: "不发放绩效"
        }, ],
        dateList: [],
        dateList2: [],
        data: [],
        loading: false,
        IsShowRemarkDialog: false,
        pageCount: 0,
        RemarkMsg: {
          Remark: '',
          PerfId: '',
        },
        Dloading: false,
        ISsystem: false,
        Floading: false,
        FinanceMsg: {
          PerfId: 0,
          IsPublic: '0',
          CurrencyId: '',
        },
        coinGetList: [], //币种数组
      }
    },
    created() {
      this.getList()
      this.getSchool()
      this.financeinfo_post_GetList()
    },
    methods: {
      financeinfo_post_GetList() { // 获取币种
        this.apipost('financeinfo_post_GetList', {
          Name: '',
          TCID: 0
        }, res => {
          if (res.data.resultCode == 1) {
            this.coinGetList = res.data.data;
            this.FinanceMsg.CurrencyId = this.coinGetList[0].ID
          }
        }, err => {})
      },
      resetSearch() {
        this.msg.PageIndex = 1
        this.getList()
      },
      getList() {
        if (this.dateList && this.dateList.length > 0) {
          this.msg.StartTime = this.dateList[0];
          this.msg.EndTime = this.dateList[1];
        } else {
          this.msg.StartTime = '';
          this.msg.EndTime = '';
        }
        if (this.dateList2 && this.dateList2.length > 0) {
          this.msg.OPStartTime = this.dateList2[0];
          this.msg.OPEndTime = this.dateList2[1];
        } else {
          this.msg.OPStartTime = '';
          this.msg.OPEndTime = '';
        }
        this.loading = true;
        getTeachingPerfPageList(this.msg).then(res => {
          this.loading = false
          this.data = res.Data.PageData
          this.pageCount = res.Data.PageCount;

          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      },
      getSchool() {
        getSchoolDropdown({}).then(res => {
          this.schoolList = res.Data
          this.schoolList.unshift({
            SId: 0,
            SName: "不限"
          })
        })
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getList()
      },

      tabChange() { //切换tab
        this.resetSearch()
      },
      saveRemark() {
        if (this.RemarkMsg.Remark == '') {
          this.$q.notify({
            type: 'warning',
            position: 'top',
            timeout: 1500,
            message: `请选择输入备注`
          })
          return
        }
        this.Dloading = true
        setTeachingPerfRemark(this.RemarkMsg).then(res => {
          this.Dloading = false
          if (res.Code == 1) {
            this.$q.notify({
              icon: 'iconfont icon-chenggong',
              color: 'accent',
              timeout: 2000,
              message: '保存成功！',
              position: 'top'
            })
            this.getList()
            this.IsShowRemarkDialog = false
          }
        })
      },
      systemShan(item) { //一键制单
        this.FinanceMsg.PerfId = item.Id
        this.ISsystem = true;
      },
      Resetsystem() {
        this.FinanceMsg = {
          PerfId: 0,
          IsPublic: '0',
          CurrencyId: '',
        }
      },
      savesystem() {
        if (this.FinanceMsg.CurrencyId == '') {
          this.$q.notify({
            type: 'warning',
            position: 'top',
            timeout: 1500,
            message: `请选择币种`
          })
          return
        }
        let that = this
        that.Floading = true
        setTeachingPerfFinance(this.FinanceMsg).then(res => {
          if (res.Code == 1) {
            that.$q.notify({
              icon: 'iconfont icon-chenggong',
              color: 'accent',
              timeout: 2000,
              message: '制单成功',
              position: 'top'
            })
            that.getList()
            that.Resetsystem()
            that.Floading = false
            that.ISsystem = false;
            that.$forceUpdate()
          }
        }).catch(() => {
          this.Floading = false
        })
      },
      gostudent(item, type) { //确认
        let that = this
        let text = '';
        if (type == 1) {
          text = '确认绩效'
        } else if (type == 2) {
          text = '不发放绩效'
        } else if (type == 3) {
          text = '恢复绩效'
        } else if (type == 4) {
          text = '撤销绩效'
        }
        this.$q.dialog({
          title: '提示信息',
          message: text,
          cancel: true,
          persistent: true,
          html: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          setTeachingPerfState({
            PerfId: item.Id,
            Type: type
          }).then(res => {
            if (res.Code == 1) {
              that.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '操作成功',
                position: 'top'
              })
              that.getList()
            }
          })
        }).onCancel(() => {
        });
      },
      goUrl(path, rowData, ) {
        this.$router.push({
          path: '/financial/financalDocument/' + path,
          query: {
            "id": rowData,
            blank: 'y',
            tab: '单据详情'
          }
        })
      },
    }
  }
</script>

<style>
  .achievements ul {
    padding: 0px
  }

  .achievements ul li {
    background: rgba(221, 222, 224, 0.2);
    border-radius: 4px;
    margin-top: 15px;
    list-style-type: none
  }

  .achievements li .List-title {
    font-size: 16px;
    color: #111111;
    font-weight: bold;
    font-family: perfectFont;
    margin-bottom: 10px
  }

  .achievements li .d-div {
    margin-top: 5px;
    align-items: center;
    font-size: 14px
  }

  .achievements li .dline {
    display: table;
    width: 100%;
    display: flex;
    flex-direction: row
  }

  .achievements li .d1 {
    flex: 1;
    width: 1px;
    padding: 20px 13px 10px;
  }

  .achievements li .d2,
  .achievements li .d3,
  .achievements li .d4,
  .achievements li .d5 {
    width: 16.5%;
    padding: 20px 13px 10px;
  }

  .achievements li .d7 {
    width: 11%;
    padding: 20px 13px 10px;
  }

  .achievements li .d7 div {
    margin-bottom: 5px
  }

  .achievements li .d1 .di-title {
    font-size: 16px;
    color: #111111;
  }

  .achievements li .d1 .di-c {
    font-size: 14px;
    display: flex;
    align-items: center;
    line-height: 28px;
    color: #111111
  }

  .achievements li .d6 {
    padding: 20px;
    width: 100%;
    height: inherit;
    position: relative;
    border-top: 1px solid #DDDEE0
  }

  .achievements li .d2-n {
    font-size: 12px;
    color: #999999;
    display: inline-block;
    width: 70px
  }

  .achievements li .d3 .d3-s {
    color: var(--q-color-negative);
    font-weight: bold;
    font-family: perfectFont
  }

  .achievements .d5-item {
    padding: 3px 10px;
    background: #EEEEEF;
    color: #111111;
    align-items: center;
    justify-content: center;
    border-radius: 4px
  }

  .achievements .price-popup {
    border-radius: 4px;
  }

  .achievements .Remark-l {
    flex: 1;
    padding: 10px 15px 10px 10px;
    background: #E1EAF5;
    border-radius: 4px;
    font-size: 14px;
    color: #F28C1D;
    position: relative
  }

  .achievements-proxy tr th {
    background: #fff;
    height: 40px;
    font-size: 14px;
    color: #333;
    border: 1px solid #E6E6E6
  }

  .achievements-proxy tr {
    background: #fff;
    text-align: center;
    height: 40px;
  }

  .achievements-proxy tr td {
    font-size: 12px;
    border: 1px solid #E5E5E5;
  }

  .Sysuser_Date .el-range-editor .el-range-input {
    background-color: transparent;
  }

  .Sysuser_Date .el-range-editor.el-input__inner {
    background-color: transparent;
  }

</style>
