<template>
  <div class="app-container">
      <div class="bj-divider">
          <div class="left"> 
                <span class="default-text">档期信息</span>
            </div>
             <div class="right"> 
                <el-button type="mini" @click="goBack()">返 回</el-button>
                <span class="tips"></span>
            </div>
      </div>
      
     <el-form ref="form" :model="form" :rules="rules" label-width="90px" style="margin-bottom:50px">
       <el-form-item label="所属档期" prop="scheduleId">
            <el-select disabled style="width: 500px" 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-row>
            <el-col :span="12">
                    <el-form-item label="总进线" label-width="90px" prop="totalNum">  
                       <el-input :disabled="form.id>0" v-model="form.totalNum"  onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))" type="number" placeholder="请输入总进线" />  
                    </el-form-item>
            </el-col>
            <el-col :span="12">
                    <el-form-item label="注册数" label-width="90px" prop="registerNum">
                        <el-input :disabled="form.id>0" v-model="form.registerNum" onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))" type="number" placeholder="请输入注册数" />  
                    </el-form-item>
            </el-col>
         </el-row>
        <el-row>
           <el-col :span="12">
                <el-form-item label="上线数" label-width="90px" prop="onlineNum">
                    <el-input :disabled="form.id>0" v-model="form.onlineNum" onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))" type="number" placeholder="请输入上线数" />
                </el-form-item>
           </el-col>
            <el-col :span="12">
                <el-form-item label="完课数" label-width="90px" prop="finishNum">
                    <el-input :disabled="form.id>0" v-model="form.finishNum"  onkeyup="value=(value.replace(/\D/g,'')==''?'':parseInt(value))" type="number" placeholder="请输入完课数" />
                </el-form-item>
           </el-col>
        </el-row>
      
         <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.onlineRate!='0'">
                    <el-form-item label-width="80px" label="完课率" prop="onlineRate">
                           {{(form.finishRate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
         </el-row>   

        <div class="bj-divider">
            <div class="left"> 
                    <span class="default-text">轮次业绩</span>
             </div>
        </div>
        
         <el-row v-for="(item, index) in roundArr" :key="index">
              <el-col :span="7">
                    <el-form-item :label="item+'业绩'"  label-width="90px" :prop="'round'+(index+1)+'Money'">  
                        <el-input-number  v-model="form['round'+(index+1)+'Money']" :step="10" :precision="2"  :min="0.00" :placeholder="'请输入'+item+'业绩'" />
                    </el-form-item>
              </el-col>
               <el-col :span="7">
                    <el-form-item :label="item+'单数'"  label-width="90px" :prop="'round'+(index+1)+'Order'">
                        <el-input-number  v-model="form['round'+(index+1)+'Order']" :min="0"  :step="1" :placeholder="'请输入'+item+'单数'"/>
                    </el-form-item>
              </el-col>  

              <el-col :span="5">
                    <el-form-item :label="item+'转化率:'" label-width="90px" :prop="'round'+(index+1)+'Rate'"> 
                       <b class="span">{{  renderRate(index) }}</b>  
                    </el-form-item>
              </el-col>
               <el-col :span="5">
                    <el-form-item :label="item+'客单价(元):'"  label-width="110px" :prop="'round'+(index+1)+'Unit'">
                        <b class="span">{{form['round'+(index+1)+'Unit']}}</b>  
                    </el-form-item>
              </el-col>
         </el-row>

         <el-row>
                <el-col :span="7">  
                <el-form-item label="累计总业绩" label-width="90px" prop="totalMoney">
                    <el-input-number  disabled v-model="form.totalMoney" :step="10" :precision="2"  :min="0.00" placeholder="请输入累计总业绩" />
                </el-form-item>
            </el-col>
            <el-col :span="7">
                <el-form-item label="累计总单" label-width="90px" prop="totalOrder">
                    <el-input-number disabled v-model="form.totalOrder" :min="0"  :step="1"  placeholder="请输入累计总单" />
                </el-form-item>
            </el-col>
            <el-col :span="6">
                <el-form-item label="目标业绩" label-width="90px" prop="targetMoney">
                    <el-input-number  v-model="form.targetMoney" :step="10" :precision="2"  :min="0.00" placeholder="请输入目标业绩" />
                </el-form-item>
            </el-col>
            <el-col :span="4">
                <el-form-item label="目标完成率"  label-width="90px" prop="targetRate">
                    <b class="span">{{ (form.targetRate*100).toFixed(2)+"%"}}</b>  
                </el-form-item>
            </el-col>

         </el-row>

         <!-- <el-row>
              <el-col :span="7">
                    <el-form-item label="二轮业绩"  label-width="90px" prop="round2Money">
                        <el-input-number v-model="form.round2Money" :precision="2"  :min="0.00" placeholder="请输入二轮业绩" />
                    </el-form-item>
              </el-col>
               <el-col :span="7">
                    <el-form-item label="二轮单数"  label-width="90px" prop="round2Order">
                        <el-input-number v-model="form.round2Order" :min="0" :step="1" placeholder="请输入二轮单数" />
                    </el-form-item>
              </el-col>  
              <el-col :span="5">
                    <el-form-item label="二轮转化率" label-width="90px"  prop="round2Rate">
                        {{(form.round2Rate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
               <el-col :span="5">
                    <el-form-item label="二轮客单价(元):" label-width="110px"  prop="round2Unit">
                        {{form.round2Unit}}
                    </el-form-item>
              </el-col>
         </el-row>

         <el-row>
              <el-col :span="7">
                    <el-form-item label="三轮业绩"  label-width="90px" prop="round3Money">
                        <el-input-number v-model="form.round3Money" :precision="2"  :min="0.00" placeholder="请输入三轮业绩" />
                    </el-form-item>
              </el-col>
               <el-col :span="7">
                    <el-form-item label="三轮单数"  label-width="90px" prop="round3Order">
                        <el-input-number v-model="form.round3Order" :min="0" :step="1" placeholder="请输入三轮单数" />
                    </el-form-item>
              </el-col>  
              <el-col :span="5">
                    <el-form-item label="三轮转化率" label-width="90px"  prop="round3Rate">
                        {{(form.round3Rate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
               <el-col :span="5">
                    <el-form-item label="三轮客单价(元):" label-width="110px"  prop="round3Unit">
                        {{form.round3Unit}}
                    </el-form-item>
              </el-col>
         </el-row>

         <el-row>
              <el-col :span="7">
                    <el-form-item label="四轮业绩"  label-width="90px" prop="round4Money">
                        <el-input-number v-model="form.round4Money" :precision="2"  :min="0.00" placeholder="请输入四轮业绩" />
                    </el-form-item>
              </el-col>
               <el-col :span="7">
                    <el-form-item label="四轮单数"  label-width="90px" prop="round4Order">
                        <el-input-number v-model="form.round4Order" :min="0" :step="1" placeholder="请输入四轮单数" />
                    </el-form-item>
              </el-col>  
              <el-col :span="5">
                    <el-form-item label="四轮转化率" label-width="90px"  prop="round4Rate">
                        {{(form.round4Rate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
               <el-col :span="5">
                     <el-form-item label="四轮客单价(元):" label-width="110px"  prop="round4Unit">
                        {{form.round4Unit}}
                    </el-form-item>
              </el-col>
         </el-row>
         
         <el-row>
              <el-col :span="7">
                    <el-form-item label="五轮业绩"  label-width="90px" prop="round5Money">
                        <el-input-number v-model="form.round5Money" :precision="2"  :min="0.00" placeholder="请输入五轮业绩" />
                    </el-form-item>
              </el-col>
               <el-col :span="7">
                    <el-form-item label="五轮单数"  label-width="90px" prop="round5Order">
                        <el-input-number v-model="form.round5Order" :min="0" :step="1" placeholder="请输入五轮单数" />
                    </el-form-item>
              </el-col>  
              <el-col :span="5">
                    <el-form-item label="五轮转化率" label-width="90px"  prop="round5Rate">
                        {{(form.round5Rate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
               <el-col :span="5">
                     <el-form-item label="五轮客单价(元):" label-width="110px"  prop="round5Unit">
                        {{form.round5Unit}}
                    </el-form-item>
              </el-col>
         </el-row>
         
         <el-row>
              <el-col :span="7">
                    <el-form-item label="六轮业绩"  label-width="90px" prop="round6Money">
                        <el-input-number v-model="form.round6Money" :precision="2"  :min="0.00" placeholder="请输入六轮业绩" />
                    </el-form-item>
              </el-col>
               <el-col :span="7">
                    <el-form-item label="六轮单数"  label-width="90px" prop="round6Order">
                        <el-input-number v-model="form.round6Order" :min="0" :step="1" placeholder="请输入六轮单数" />
                    </el-form-item>
              </el-col>  
              <el-col :span="5">
                    <el-form-item label="六轮转化率" label-width="90px"  prop="round6Rate">
                        {{(form.round6Rate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
               <el-col :span="5">
                    <el-form-item label="六轮客单价(元):" label-width="110px"  prop="round6Unit">
                        {{form.round6Unit}}
                    </el-form-item>
              </el-col>
         </el-row>
         
         <el-row>
              <el-col :span="7">
                    <el-form-item label="七轮业绩"  label-width="90px" prop="round7Money">
                        <el-input-number v-model="form.round7Money" :precision="2"  :min="0.00" placeholder="请输入七轮业绩" />
                    </el-form-item>
              </el-col>
               <el-col :span="7">
                    <el-form-item label="七轮单数"  label-width="90px" prop="round7Order">
                        <el-input-number v-model="form.round7Order" :min="0" :step="1" placeholder="请输入七轮单数" />
                    </el-form-item>
              </el-col>  
              <el-col :span="5">
                    <el-form-item label="七轮转化率" label-width="90px"  prop="round7Rate">
                        {{(form.round7Rate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
                <el-col :span="5">
                    <el-form-item label="七轮客单价(元):" label-width="110px"  prop="round7Unit">
                        {{form.round7Unit}}
                    </el-form-item>
              </el-col>
         </el-row>
         
         <el-row>
              <el-col :span="7">
                    <el-form-item label="八轮业绩"  label-width="90px" prop="round8Money">
                        <el-input-number v-model="form.round8Money" :precision="2"  :min="0.00" placeholder="请输入八轮业绩" />
                    </el-form-item>
              </el-col>
               <el-col :span="7">
                    <el-form-item label="八轮单数"  label-width="90px" prop="round8Order">
                        <el-input-number v-model="form.round8Order" :min="0" :step="1" placeholder="请输入八轮单数" />
                    </el-form-item>
              </el-col>  
              <el-col :span="5">
                    <el-form-item label="八轮转化率" label-width="90px"  prop="round8Rate">
                        {{(form.round8Rate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
               <el-col :span="5">
                    <el-form-item label="八轮客单价(元):" label-width="110px"  prop="round8Unit">
                        {{form.round8Unit}}
                    </el-form-item>
              </el-col>
         </el-row>
         
         <el-row>
              <el-col :span="7">
                    <el-form-item label="九轮业绩"  label-width="90px" prop="round9Money">
                        <el-input-number v-model="form.round9Money" :precision="2"  :min="0.00" placeholder="请输入九轮业绩" />
                    </el-form-item>
              </el-col>
               <el-col :span="7">
                    <el-form-item label="九轮单数"  label-width="90px" prop="round9Order">
                        <el-input-number v-model="form.round9Order" :min="0" :step="1" placeholder="请输入九轮单数" />
                    </el-form-item>
              </el-col>  
              <el-col :span="5">
                    <el-form-item label="九轮转化率" label-width="90px"  prop="round9Rate">
                        {{(form.round9Rate*100).toFixed(2)+"%"}}
                    </el-form-item>
              </el-col>
               <el-col :span="5">
                    <el-form-item label="九轮客单价(元):" label-width="110px"  prop="round9Unit">
                        {{form.round9Unit}}
                    </el-form-item>
              </el-col>
         </el-row>
          -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :disabled="scheduleItem.status==0" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
  </div>
</template>

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

export default {
  name: "TcmScheduleAdd",
  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()
        }
    };
    const roundOrderRule = (rule, value, callback) => {
        console.log('round1Order rule'+JSON.stringify(rule)+' value:'+value);
        var orderNum=0;
        for (let index = 0; index < 9; index++) {
            if(!!this.form['round'+index+'Order']){
                orderNum+=this.form['round'+index+'Order'];
            }
        }
        console.log('qxj orderNum:'+orderNum);
        var roundRate=rule.field.replace('Order','Rate');
        if (Number(value) > this.form.totalNum) {
            this.form[roundRate]=0;
            //callback(new Error('当前轮次单数不能大于总进线'))
        }else if(orderNum>this.form.totalNum){
             this.form[roundRate]=0;
            //callback(new Error('所有轮次单数不能大于总进线'))
        }
        callback();
    };
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 中医档期业绩报表表格数据
      tcmScheduleReportList: [],
      scheduleList:[],
      scheduleId:null,
      scheduleItem:{status:1},
      reportId:null,
      roundArr:["一轮","二轮","三轮","四轮","五轮","六轮","七轮","八轮","九轮"],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRange: [],
      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" }
          ],
          round1Order: [
            { required: false, validator: roundOrderRule, trigger: "blur" }
          ],
          round2Order: [
            { required: false, validator: roundOrderRule, trigger: "blur" }
          ],
          round3Order: [
            { required: false, validator: roundOrderRule, trigger: "blur" }
          ],
          round4Order: [
            { required: false, validator: roundOrderRule, trigger: "blur" }
          ],
          round5Order: [
            { required: false, validator: roundOrderRule, trigger: "blur" }
          ],
          round6Order: [
            { required: false, validator: roundOrderRule, trigger: "blur" }
          ],
          round7Order: [
            { required: false, validator: roundOrderRule, trigger: "blur" }
          ],
          round8Order: [
            { required: false, validator: roundOrderRule, trigger: "blur" }
          ],
          round9Order: [
            { required: false, validator: roundOrderRule, 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.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); 
        }
    },  
     'form.round1Money':function(newVal,oldVal){   
        console.log("qxj newVal:"+newVal+",is:"+!!newVal);
        if(newVal!=undefined){
            if(this.form.round1Order>0){
                this.form.round1Unit=(newVal/this.form.round1Order*1.0).toFixed(2); 
            }
            this.calcTotalMoney();
        }
    },
     'form.round1Order':function(newVal,oldVal){
        if(newVal!=undefined){
           this.form.round1Rate=(newVal/this.form.totalNum*1.0).toFixed(2); 
           this.form.round1Unit=0.0;
           if(newVal>0)
           this.form.round1Unit=(this.form.round1Money/newVal*1.0).toFixed(2); 
           this.calcTotalOrder();
        }
    },
     'form.round2Money':function(newVal,oldVal){   
        if(newVal!=undefined){
            if(this.form.round2Order>0){
                this.form.round2Unit=(newVal/this.form.round2Order*1.0).toFixed(2); 
            }
            this.calcTotalMoney();
        }
    },
     'form.round2Order':function(newVal,oldVal){
         if(newVal!=undefined){
           this.form.round2Rate=(newVal/this.form.totalNum*1.0).toFixed(2); 
           this.form.round2Unit=0.0;
           if(newVal>0)
           this.form.round2Unit=(this.form.round2Money/newVal*1.0).toFixed(2); 
           this.calcTotalOrder();
        }
    },
    'form.round3Money':function(newVal,oldVal){   
        if(newVal!=undefined){
            if(this.form.round3Order>0){
                this.form.round3Unit=(newVal/this.form.round3Order*1.0).toFixed(2); 
            }
            this.calcTotalMoney();
        }
    },
     'form.round3Order':function(newVal,oldVal){
        if(newVal!=undefined){
           this.form.round3Rate=(newVal/this.form.totalNum*1.0).toFixed(2); 
           this.form.round3Unit=0.0;
           if(newVal>0)
           this.form.round3Unit=(this.form.round3Money/newVal*1.0).toFixed(2); 
           this.calcTotalOrder();
        }
    },
    'form.round4Money':function(newVal,oldVal){   
         if(newVal!=undefined){
            if(this.form.round4Order>0){
                this.form.round4Unit=(newVal/this.form.round4Order*1.0).toFixed(2); 
            }
            this.calcTotalMoney();
        }
    },
     'form.round4Order':function(newVal,oldVal){
        if(newVal!=undefined){
           this.form.round4Rate=(newVal/this.form.totalNum*1.0).toFixed(2); 
           this.form.round4Unit=0.0;
           if(newVal>0)
           this.form.round4Unit=(this.form.round4Money/newVal*1.0).toFixed(2); 
           this.calcTotalOrder();
        }
    },
    'form.round5Money':function(newVal,oldVal){   
        if(newVal!=undefined){
            if(this.form.round5Order>0){
                this.form.round5Unit=(newVal/this.form.round5Order*1.0).toFixed(2); 
            }
            this.calcTotalMoney();
        }
    },
     'form.round5Order':function(newVal,oldVal){
         if(newVal!=undefined){
           this.form.round5Rate=(newVal/this.form.totalNum*1.0).toFixed(2); 
           this.form.round5Unit=0.0;
           if(newVal>0)
           this.form.round5Unit=(this.form.round5Money/newVal*1.0).toFixed(2); 
           this.calcTotalOrder();
        }
    },
    'form.round6Money':function(newVal,oldVal){   
        if(newVal!=undefined){
            if(this.form.round6Order>0){
                this.form.round6Unit=(newVal/this.form.round6Order*1.0).toFixed(2); 
            }
            this.calcTotalMoney();
        }
    },
     'form.round6Order':function(newVal,oldVal){
         if(newVal!=undefined){
           this.form.round6Rate=(newVal/this.form.totalNum*1.0).toFixed(2); 
           this.form.round6Unit=0.0;
           if(newVal>0)
           this.form.round6Unit=(this.form.round6Money/newVal*1.0).toFixed(2); 
           this.calcTotalOrder();
        }
    },
    'form.round7Money':function(newVal,oldVal){   
        if(newVal!=undefined){
            if(this.form.round7Order>0){
                this.form.round7Unit=(newVal/this.form.round7Order*1.0).toFixed(2); 
            }
            this.calcTotalMoney();
        }
    },
     'form.round7Order':function(newVal,oldVal){
         if(newVal!=undefined){
           this.form.round7Rate=(newVal/this.form.totalNum*1.0).toFixed(2); 
           this.form.round7Unit=0.0;
           if(newVal>0)
           this.form.round7Unit=(this.form.round7Money/newVal*1.0).toFixed(2); 
           this.calcTotalOrder();
        }
    },
    'form.round8Money':function(newVal,oldVal){   
        if(newVal!=undefined){
            if(this.form.round8Order>0){
                this.form.round8Unit=(newVal/this.form.round8Order*1.0).toFixed(2); 
            }
            this.calcTotalMoney();
        }
    },
     'form.round8Order':function(newVal,oldVal){
        if(newVal!=undefined){
           this.form.round8Rate=(newVal/this.form.totalNum*1.0).toFixed(2); 
           this.form.round8Unit=0.0;
           if(newVal>0)
           this.form.round8Unit=(this.form.round8Money/newVal*1.0).toFixed(2); 
           this.calcTotalOrder();
        }
    },
    'form.round9Money':function(newVal,oldVal){   
         if(newVal!=undefined){
            if(this.form.round9Order>0){
                this.form.round9Unit=(newVal/this.form.round9Order*1.0).toFixed(2); 
            }
            this.calcTotalMoney();
        }
    },
     'form.round9Order':function(newVal,oldVal){
            if(newVal!=undefined){
                this.form.round9Rate=(newVal/this.form.totalNum*1.0).toFixed(2); 
                this.form.round9Unit=0.0;
                if(newVal>0)
                this.form.round9Unit=(this.form.round9Money/newVal*1.0).toFixed(2); 
                this.calcTotalOrder();
            }
      },
     'form.targetMoney':function(newVal,oldVal){
         if(newVal!=undefined){
              this.form.targetRate=(this.form.totalMoney/newVal*1.0).toFixed(5); 
         }
      },
  },
  created() {
    this.scheduleId=this.$route.query.scheduleId;
    this.reportId=this.$route.query.reportId;
    this.reset();
    this.getListSchedule();
    this.getTreeselect();
    this.requestData();
  },
  methods: {
    getTreeselect() {
        treeselect().then((response) => {
          this.deptOptions = response.data;
        });
    },
    getListSchedule() {
        this.loading = true;
        listAllSchedule().then(response => {
            this.scheduleList = response.rows;
            var listTemp = this.scheduleList.filter(item => item.id==this.scheduleId);
            console.log("qxj listTemp:"+JSON.stringify(listTemp));
            if(listTemp.length>0){
                this.scheduleItem=listTemp[0];
            }
        });
    },
    /** 查询中医档期业绩报表详情 */
    requestData() {  
      this.reset();
      this.loading = true;
      getTcmScheduleReport(this.reportId).then(response => {
        this.form = response.data;
        console.log("qxj reportData:"+ JSON.stringify(response.data));
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.goBack();
    },
    // 表单重置
    reset() {
      this.form = {   //totalMoney  totalOrder  targetMoney  targetRate
        id: null,
        scheduleId: null,
        companyUserId: null,
        companyId: null,
        totalNum: null,
        registerNum: null,
        onlineNum: null,
        finishNum: null,
        registerRate: null,
        onlineRate: null,
        finishRate: null,
        totalMoney: 0,
        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,
        createUserId:null,
        updateUserId:null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    goBack(){
        this.$router.go(-1);
    },
    calcTotalMoney(){
        var totalMoney=0;
        for (let index = 1; index <= 9; index++) {
            if(!!this.form['round'+index+'Money']){
                totalMoney+=this.form['round'+index+'Money'];
            }
        }
        console.log("qxj totalMoney:"+totalMoney);
        this.form.totalMoney=totalMoney.toFixed(2);
    },
    calcTotalOrder(){
        var totalOrder=0;
        for (let index = 1; index <= 9; index++) {
            if(!!this.form['round'+index+'Order']){
                totalOrder+=this.form['round'+index+'Order'];
            }
        }
        console.log("qxj totalOrder:"+totalOrder);
        this.form.totalOrder=totalOrder;
    },
    renderRate(index){
        var val="0.00%";
        if((this.form['round'+(index+1)+'Rate'])!=Infinity){
             val=(this.form['round'+(index+1)+'Rate']*100).toFixed(2)+"%";
        }
        return val;
    },


    /** 提交按钮 */
    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.goBack();
              }
            });
          } else {
            addTcmScheduleReport(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.goBack();
              }
            });
          }

        }
      });
    },
    toDecimal2(x) {  
        var f = x;  
        if (isNaN(f)) {  
            return 0;  
        }  
        // var f = Math.round(x*100)/100;  
        // var s = f.toString();  
        // var rs = s.indexOf('.');  
        // if (rs < 0) {  
        //     rs = s.length;  
        //     s += '.';  
        // }  
        // while (s.length <= rs + 2) {  
        //     s += '0';  
        // }  
        return x.toFixed(2);  
    }
  }
};
</script>

<style lang="scss" scoped> 
 .app-main{
   background-color: #fff !important;
}
.app-container{
  margin: 0;
}

.bj-divider {
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    margin-bottom: 16px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
    width: 100%
}
.bj-divider.small {
    font-size: 14px;
    padding: 8px 0;
    margin-bottom: 8px
}
.bj-divider.noPadding {
    padding: 0
}
.bj-divider .left {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center
}
.bj-divider .button {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    background: #ffffff;
    border: 1px solid #fefefe;
}
.bj-divider .default-text {
    border-left: 4px #13c2c2 solid;
    padding-left: 16px;
    font-size: 18px
}


.bj-divider.small .default-text {
    font-size: 14px
}


.bj-divider .xs {
    font-size: 12px;
    padding: 0 8px
}
.bj-divider .tips {
    line-height: 20px;
    margin-left: 16px
}
.bj-divider .right {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center
}


.bj-divider .el-button {
    margin-left: 16px
}
.bj-divider .fixed {
    position: fixed;
    top: 55px;
    z-index: 9;
    right: 20px
}

.bj-divider .right .el-form-item--small.el-form-item {
    margin-bottom: 0
}

.dialog-footer{
    text-align: right;
    position: fixed;
    right: 0px;
    bottom: 0px;
    width: 90%;
    margin-right: 0px;
    padding:10px 20px;
    z-index: 9;
    background: #ffffff;
    height: 65px;
}

.span{
  font-size: 15px;
  font-weight:normal;
}


</style>