<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
       <el-form-item label="所属部门" prop="deptId">
          <treeselect style="width:205.4px" v-model="queryParams.deptId" :options="deptOptions" :show-count="true" placeholder="请选择所属部门" />
      </el-form-item>
       <el-form-item label="员工姓名" prop="userNickName">
        <el-input
          v-model="queryParams.userNickName"
          placeholder="请输入员工姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="所属档期" prop="scheduleId">
            <el-select filterable multiple style="width:205.4px" v-model="scheduleIdArr" placeholder="请选择档期" clearable size="small" >
                  <el-option
                      v-for="item in scheduleList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
            </el-select>
        </el-form-item>

       <!-- <el-form-item label="档期名称" prop="scheduleName">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入档期名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

    <!-- <el-form-item label="档期状态" prop="scheduleStatus">
        <el-select v-model="queryParams.status" placeholder="请选择档期状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item> -->

      <el-form-item label="创建时间" prop="createTime">
            <el-date-picker
              style="width:225.4px"
              clearable size="small"
              v-model="dateRange"
              type="daterange"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
       </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['company:tcmScheduleReport:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['company:tcmScheduleReport:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['company:tcmScheduleReport:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['company:tcmScheduleReport:export']"
        >导出</el-button>
      </el-col>
	    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tcmScheduleReportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id"  width="50" align="center" prop="id" />
      <el-table-column label="档期" align="center" prop="scheduleName" />
      <!-- <el-table-column label="公司名称" align="center" prop="companyName" /> -->
      <el-table-column label="所在部门" align="center" prop="deptName" />
      <el-table-column label="员工姓名" align="center" prop="userNickName" />
     
      <el-table-column label="总进线" align="center" prop="totalNum" />
      <el-table-column label="注册数" align="center" prop="registerNum" />
      <el-table-column label="上线数" align="center" prop="onlineNum" />
      <el-table-column label="完课数" align="center" prop="finishNum" />

      <el-table-column  label="注册率" align="center" prop="registerRate"   >
        <template slot-scope="scope">
          {{ renderTotalVal(scope.row,0) }}
        </template>
    </el-table-column>()
     <el-table-column  label="进线上线率" align="center" prop="onlineRate"   >
        <template slot-scope="scope">
           {{ renderTotalVal(scope.row,1) }}
        </template>
    </el-table-column>
     <el-table-column  label="进线完课率" align="center" prop="finishRate"   >
        <template slot-scope="scope">
             {{ renderTotalVal(scope.row,2) }}
        </template>
    </el-table-column>
     <el-table-column  label="累计总业绩" width="90" align="center" prop="totalMoney"   >
        <template slot-scope="scope">
          {{!scope.row.totalMoney?0:(scope.row.totalMoney).toFixed(2)}}
        </template>
    </el-table-column>
     <el-table-column  label="累计总单" align="center" prop="totalOrder"   >
        <template slot-scope="scope">
          {{!scope.row.totalOrder?0:scope.row.totalOrder}}
        </template>
    </el-table-column>
   <el-table-column  label="目标业绩"  align="center" prop="targetMoney"   >
        <template slot-scope="scope">
          {{!scope.row.targetMoney?0:(scope.row.targetMoney).toFixed(2)}}
        </template>
    </el-table-column>
    <el-table-column  label="目标完成率"  width="90" align="center" prop="targetRate"   >
        <template slot-scope="scope">
           {{ scope.row.targetMoney>0?(scope.row.totalMoney/scope.row.targetMoney*100.0).toFixed(3)+"%":"0%"}}
        </template>
    </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>

     <el-table-column label="更新时间" align="center" prop="updateTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>

<!-- 
      <el-table-column label="一轮业绩" align="center" prop="round1Money" />
      <el-table-column label="一轮单数" align="center" prop="round1Order" />
      <el-table-column label="一轮转化率" align="center" prop="round1Rate" />
      <el-table-column label="一轮客单价" align="center" prop="round1Unit" />
      <el-table-column label="二轮业绩" align="center" prop="round2Money" />
      <el-table-column label="二轮单数" align="center" prop="round2Order" />
      <el-table-column label="二轮转化率" align="center" prop="round2Rate" />
      <el-table-column label="二轮客单价" align="center" prop="round2Unit" />
      <el-table-column label="二轮业绩" align="center" prop="round3Money" />
      <el-table-column label="三轮单数" align="center" prop="round3Order" />
      <el-table-column label="三轮转化率" align="center" prop="round3Rate" />
      <el-table-column label="三轮客单" align="center" prop="round3Unit" />
      <el-table-column label="四轮业绩" align="center" prop="round4Money" />
      <el-table-column label="四轮单数" align="center" prop="round4Order" />
      <el-table-column label="四轮转化率" align="center" prop="round4Rate" />
      <el-table-column label="四轮客单价" align="center" prop="round4Unit" />
      <el-table-column label="五轮业绩" align="center" prop="round5Money" />
      <el-table-column label="五轮单数" align="center" prop="round5Order" />
      <el-table-column label="五轮转化率" align="center" prop="round5Rate" />
      <el-table-column label="五轮客单价" align="center" prop="round5Unit" />
      <el-table-column label="六轮业绩" align="center" prop="round6Money" />
      <el-table-column label="六一轮单" align="center" prop="round6Order" />
      <el-table-column label="六轮转率" align="center" prop="round6Rate" />
      <el-table-column label="六轮客单价" align="center" prop="round6Unit" />
      <el-table-column label="七轮业绩" align="center" prop="round7Money" />
      <el-table-column label="七轮单数" align="center" prop="round7Order" />
      <el-table-column label="七轮转化率" align="center" prop="round7Rate" />
      <el-table-column label="七轮客单价" align="center" prop="round7Unit" />
      <el-table-column label="八轮业绩" align="center" prop="round8Money" />
      <el-table-column label="八轮单数" align="center" prop="round8Order" />
      <el-table-column label="八轮转化率" align="center" prop="round8Rate" />
      <el-table-column label="八轮客单价" align="center" prop="round8Unit" />
      <el-table-column label="九轮业绩" align="center" prop="round9Money" />
      <el-table-column label="九轮单数" align="center" prop="round9Order" />
      <el-table-column label="九轮转化率" align="center" prop="round9Rate" />
      <el-table-column label="九轮客单价" align="center" prop="round9Unit" /> -->

      <el-table-column fixed="right" label="操作" width="150px" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDetails(scope.row)"
            v-hasPermi="['company:tcmScheduleReport:query']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['company:tcmScheduleReport:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['company:tcmScheduleReport:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改中医档期业绩报表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

       <el-form-item label="所属档期" prop="scheduleId">
            <el-select filterable style="width: 200px" v-model="form.scheduleId" placeholder="请选择档期" clearable size="small" >
              <el-option 
                      v-for="item in scheduleList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
            </el-select>
        </el-form-item>

        <el-form-item label="总进线" prop="totalNum">  
          <el-input v-model="form.totalNum"  onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))" type="number" placeholder="请输入总进线" />  
        </el-form-item>
        <el-form-item label="注册数" prop="registerNum">
          <el-input v-model="form.registerNum" onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))" type="number" placeholder="请输入注册数" />  
        </el-form-item>
        <el-form-item label="上线数" prop="onlineNum">
          <el-input v-model="form.onlineNum" onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))" type="number" placeholder="请输入上线数" />
        </el-form-item>
        <el-form-item label="完课数" prop="finishNum">
          <el-input v-model="form.finishNum"  onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))" type="number" placeholder="请输入完课数" />
        </el-form-item>

         <el-row>
              <el-col :span="8" v-if="form.registerRate!='0'">
                    <el-form-item label-width="80px" label="注册率" prop="registerRate">
                           {{(form.registerRate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
               <el-col :span="8" v-if="form.onlineRate!='0'">
                   <el-form-item label-width="80px" label="上线率" prop="onlineRate" style="margin-right:10px">
                          {{(form.onlineRate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>  
              <el-col :span="8" v-if="form.finishRate!='0'">
                    <el-form-item label-width="80px" label="完课率" prop="finishRate">
                         {{(form.finishRate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
         </el-row>

  
        <!-- <el-form-item label="累计总业绩" prop="totalMoney">
          <el-input v-model="form.totalMoney" placeholder="请输入累计总业绩" />
        </el-form-item>
        <el-form-item label="累计总单" prop="totalOrder">
          <el-input v-model="form.totalOrder" placeholder="请输入累计总单" />
        </el-form-item>
        <el-form-item label="目标业绩" prop="targetMoney">
          <el-input v-model="form.targetMoney" placeholder="请输入目标业绩" />
        </el-form-item>
        <el-form-item label="目标完成率" prop="targetRate">
          <el-input v-model="form.targetRate" placeholder="请输入目标完成率" />
        </el-form-item> -->

        <!-- <el-form-item label="一轮业绩" prop="round1Money">
          <el-input v-model="form.round1Money" placeholder="请输入一轮业绩" />
        </el-form-item>
        <el-form-item label="一轮单数" prop="round1Order">
          <el-input v-model="form.round1Order" placeholder="请输入一轮单数" />
        </el-form-item>
        <el-form-item label="一轮转化率" prop="round1Rate">
          <el-input v-model="form.round1Rate" placeholder="请输入一轮转化率" />
        </el-form-item>
        <el-form-item label="一轮客单价" prop="round1Unit">
          <el-input v-model="form.round1Unit" placeholder="请输入一轮客单价" />
        </el-form-item>
        <el-form-item label="二轮业绩" prop="round2Money">
          <el-input v-model="form.round2Money" placeholder="请输入二轮业绩" />
        </el-form-item>
        <el-form-item label="二轮单数" prop="round2Order">
          <el-input v-model="form.round2Order" placeholder="请输入二轮单数" />
        </el-form-item>
        <el-form-item label="二轮转化率" prop="round2Rate">
          <el-input v-model="form.round2Rate" placeholder="请输入二轮转化率" />
        </el-form-item>
        <el-form-item label="二轮客单价" prop="round2Unit">
          <el-input v-model="form.round2Unit" placeholder="请输入二轮客单价" />
        </el-form-item>
        <el-form-item label="二轮业绩" prop="round3Money">
          <el-input v-model="form.round3Money" placeholder="请输入二轮业绩" />
        </el-form-item>
        <el-form-item label="三轮单数" prop="round3Order">
          <el-input v-model="form.round3Order" placeholder="请输入三轮单数" />
        </el-form-item>
        <el-form-item label="三轮转化率" prop="round3Rate">
          <el-input v-model="form.round3Rate" placeholder="请输入三轮转化率" />
        </el-form-item>
        <el-form-item label="三轮客单" prop="round3Unit">
          <el-input v-model="form.round3Unit" placeholder="请输入三轮客单" />
        </el-form-item>
        <el-form-item label="四轮业绩" prop="round4Money">
          <el-input v-model="form.round4Money" placeholder="请输入四轮业绩" />
        </el-form-item>
        <el-form-item label="四轮单数" prop="round4Order">
          <el-input v-model="form.round4Order" placeholder="请输入四轮单数" />
        </el-form-item>
        <el-form-item label="四轮转化率" prop="round4Rate">
          <el-input v-model="form.round4Rate" placeholder="请输入四轮转化率" />
        </el-form-item>
        <el-form-item label="四轮客单价" prop="round4Unit">
          <el-input v-model="form.round4Unit" placeholder="请输入四轮客单价" />
        </el-form-item>
        <el-form-item label="五轮业绩" prop="round5Money">
          <el-input v-model="form.round5Money" placeholder="请输入五轮业绩" />
        </el-form-item>
        <el-form-item label="五轮单数" prop="round5Order">
          <el-input v-model="form.round5Order" placeholder="请输入五轮单数" />
        </el-form-item>
        <el-form-item label="五轮转化率" prop="round5Rate">
          <el-input v-model="form.round5Rate" placeholder="请输入五轮转化率" />
        </el-form-item>
        <el-form-item label="五轮客单价" prop="round5Unit">
          <el-input v-model="form.round5Unit" placeholder="请输入五轮客单价" />
        </el-form-item>
        <el-form-item label="六轮业绩" prop="round6Money">
          <el-input v-model="form.round6Money" placeholder="请输入六轮业绩" />
        </el-form-item>
        <el-form-item label="六一轮单" prop="round6Order">
          <el-input v-model="form.round6Order" placeholder="请输入六一轮单" />
        </el-form-item>
        <el-form-item label="六轮转率" prop="round6Rate">
          <el-input v-model="form.round6Rate" placeholder="请输入六轮转率" />
        </el-form-item>
        <el-form-item label="六轮客单价" prop="round6Unit">
          <el-input v-model="form.round6Unit" placeholder="请输入六轮客单价" />
        </el-form-item>
        <el-form-item label="七轮业绩" prop="round7Money">
          <el-input v-model="form.round7Money" placeholder="请输入七轮业绩" />
        </el-form-item>
        <el-form-item label="七轮单数" prop="round7Order">
          <el-input v-model="form.round7Order" placeholder="请输入七轮单数" />
        </el-form-item>
        <el-form-item label="七轮转化率" prop="round7Rate">
          <el-input v-model="form.round7Rate" placeholder="请输入七轮转化率" />
        </el-form-item>
        <el-form-item label="七轮客单价" prop="round7Unit">
          <el-input v-model="form.round7Unit" placeholder="请输入七轮客单价" />
        </el-form-item>
        <el-form-item label="八轮业绩" prop="round8Money">
          <el-input v-model="form.round8Money" placeholder="请输入八轮业绩" />
        </el-form-item>
        <el-form-item label="八轮单数" prop="round8Order">
          <el-input v-model="form.round8Order" placeholder="请输入八轮单数" />
        </el-form-item>
        <el-form-item label="八轮转化率" prop="round8Rate">
          <el-input v-model="form.round8Rate" placeholder="请输入八轮转化率" />
        </el-form-item>
        <el-form-item label="八轮客单价" prop="round8Unit">
          <el-input v-model="form.round8Unit" placeholder="请输入八轮客单价" />
        </el-form-item>
        <el-form-item label="九轮业绩" prop="round9Money">
          <el-input v-model="form.round9Money" placeholder="请输入九轮业绩" />
        </el-form-item>
        <el-form-item label="九轮单数" prop="round9Order">
          <el-input v-model="form.round9Order" placeholder="请输入九轮单数" />
        </el-form-item>
        <el-form-item label="九轮转化率" prop="round9Rate">
          <el-input v-model="form.round9Rate" placeholder="请输入九轮转化率" />
        </el-form-item>
        <el-form-item label="九轮客单价" prop="round9Unit">
          <el-input v-model="form.round9Unit" placeholder="请输入九轮客单价" />
        </el-form-item> -->

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { treeselect } from "@/api/company/companyDept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listTcmScheduleReport, getTcmScheduleReport, delTcmScheduleReport, addTcmScheduleReport, updateTcmScheduleReport, exportTcmScheduleReport,listAllSchedule } from "@/api/company/tcmScheduleReport";

export default {
  name: "TcmScheduleReport",
  components: { Treeselect },
  data() {
     const registerNumRule = (rule, value, callback) => {
        console.log('registerNumVal->',value)
        if (Number(value) > this.form.totalNum) {
            callback(new Error('注册数不能大于总进线'))
        } else {
            callback()
        }
    };
    const onlineNumRule = (rule, value, callback) => {
        console.log('onlineNumVal->',value)
        if (Number(value) > this.form.registerNum) {
            callback(new Error('上线数不能大于注册数'))
        } else {
            callback()
        }
    };
    const finishNumRule = (rule, value, callback) => {
        console.log('finishNumVal->',value)
        if (Number(value) > this.form.registerNum) {
            callback(new Error('完课数不能大于注册数'))
        } else {
            callback()
        }
    };
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 中医档期业绩报表表格数据
      tcmScheduleReportList: [],
      scheduleList:[],
      scheduleIdArr:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        scheduleId: null,
        deptId:null,
        userId: null,
        companyId: null,
        totalNum: null,
        registerNum: null,
        onlineNum: null,
        finishNum: null,
        registerRate: null,
        onlineRate: null,
        finishRate: null,
        totalMoney: null,
        
      },
      users:[],
      // 部门树选项
      deptOptions: [],
      // 部门名称
      deptName: undefined,
      // 表单参数
      form: {},
      // 表单校验
      rules: { 
          scheduleId: [    
            { required: true, message: "请选择档期", trigger: "blur" }
          ],
          totalNum: [    
            { required: true, message: "总进线不能为空", trigger: "blur" }
          ],
          registerNum: [
            { required:  true, message: "注册数不能为空", trigger: "blur" },
            { required: true, validator: registerNumRule, trigger: "blur" },
            // { pattern: /^[1-9]\d*$/, message: '只能输入整数'}
          ],
          onlineNum: [
            { required: true, message: "上线数不能为空", trigger: "blur" },
            { required: true, validator: onlineNumRule, trigger: "blur" }
          ],
          finishNum: [
            { required: true, message: "完课数不能为空", trigger: "blur" },
            { required: true, validator: finishNumRule, trigger: "blur" }
          ],
      }
    };
  },
  watch:{
    'form.registerNum':function(newVal,oldVal){
        console.log('newVal->',newVal)
        console.log('oldVal->',oldVal)
        this.form.registerRate=0;
        if(!!newVal && Number(newVal)<=this.form.totalNum && this.form.totalNum!=0 ){
           this.form.registerRate=(newVal/this.form.totalNum*1.0).toFixed(2);
        }
    },
    'form.onlineNum':function(newVal,oldVal){
        console.log('newVal->',newVal)
        console.log('oldVal->',oldVal)
        this.form.onlineRate=0;
        if(!!newVal  && this.form.registerNum!=0){
           this.form.onlineRate=(newVal/this.form.registerNum*1.0).toFixed(2);
        }
        
    },
    'form.finishNum':function(newVal,oldVal){
        console.log('newVal->',newVal)
        console.log('oldVal->',oldVal)
        this.form.finishRate=0;
        if(!!newVal   && this.form.registerNum!=0){
           this.form.finishRate=(newVal/this.form.registerNum*1.0).toFixed(2); 
        }
        
    }
  },
  created() {
    this.getTreeselect();
    this.getListSchedule();
    this.getList();
  },
  methods: {

    calcRegister(){
        
    },
    calcOnline(){

    },
    calcFinish(){

    },
    getTreeselect() {
        treeselect().then((response) => {
           this.deptOptions = response.data;
        });
    },
    getListSchedule() {
        this.loading = true;
        listAllSchedule().then(response => {
            this.scheduleList = response.rows;
        });
    },
    /** 查询中医档期业绩报表列表 */
    getList() {
      if(this.scheduleIdArr.length>0){
          this.queryParams.scheduleId=this.scheduleIdArr.toString();
      }
      this.loading = true;
      listTcmScheduleReport(this.addDateRange(this.queryParams,this.dateRange)).then(response => {
          this.tcmScheduleReportList = response.rows;
          this.total = response.total;
          this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        scheduleId: null,
        userId: null,
        companyId: null,
        totalNum: null,
        registerNum: null,
        onlineNum: null,
        finishNum: null,
        registerRate: null,
        onlineRate: null,
        finishRate: null,
        totalMoney: null,
        totalOrder: null,
        targetMoney: null,
        targetRate: null,
        round1Money: null,
        round1Order: null,
        round1Rate: null,
        round1Unit: null,
        round2Money: null,
        round2Order: null,
        round2Rate: null,
        round2Unit: null,
        round3Money: null,
        round3Order: null,
        round3Rate: null,
        round3Unit: null,
        round4Money: null,
        round4Order: null,
        round4Rate: null,
        round4Unit: null,
        round5Money: null,
        round5Order: null,
        round5Rate: null,
        round5Unit: null,
        round6Money: null,
        round6Order: null,
        round6Rate: null,
        round6Unit: null,
        round7Money: null,
        round7Order: null,
        round7Rate: null,
        round7Unit: null,
        round8Money: null,
        round8Order: null,
        round8Rate: null,
        round8Unit: null,
        round9Money: null,
        round9Order: null,
        round9Rate: null,
        round9Unit: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加中医档期业绩报表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTcmScheduleReport(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改中医档期业绩报表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTcmScheduleReport(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            let that=this;
            addTcmScheduleReport(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
                setTimeout(() => {
                    that.handleDetails(response.data);
                }, 1800);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除中医档期业绩报表编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTcmScheduleReport(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    handleDetails(row){
        this.$router.push({path:'/schedule/report/add',query:{"scheduleId":row.scheduleId,"reportId":row.id}});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出员工业绩报表数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTcmScheduleReport(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    renderTotalVal(row,index){
       var value="0%";
        if(index==0){   //注册率=注册数/总进线
             if(row.totalNum>0){
                 value=(row.registerNum/row.totalNum*100.0).toFixed(3)+"%";
             }
        }
        else if(index==1){   //进线上线率=上线数/总进线
            if(row.totalNum>0){
                  value=(row.onlineNum/row.totalNum*100.0).toFixed(3)+"%"; 
             }
        }
        else if(index==2){   //进线完课率=完课数/总进线
             if(row.totalNum>0){
                  value=(row.finishNum/row.totalNum*100.0).toFixed(3)+"%";
             }
        }
        return value;
    }
  }
};
</script>
