<template>
  <div>
    <div class="reatmen">
      <el-form :model="form" :inline="true" :label-width="formLabelwidth"  @submit.native.prevent>
        <el-form-item label="手机号码:">
          <div class="form-width-ms flex">
            <el-input style="padding-left:0px;min-width:123px;height:100%" ref="" oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" maxlength="11" v-model="form.mobilePhone" @change.enter.native="query">
              <el-button size="mini" slot="append" icon="el-icon-search" @click="openMember"></el-button>
            </el-input>
            <el-button icon="el-icon-circle-plus-outline" type="text" @click="openAddMember"></el-button>
          </div>
        </el-form-item>
        <el-form-item label="会员名字:">
          <div class="form-width-ms">
            <span>{{ form.memberName }} <i v-if="form.sex==1" class="el-icon-male text-blue"></i>
              <i v-if="form.sex==0" class="el-icon-female text-pink"></i></span>
              <el-button size="mini" type="text" v-if="form.memberName" @click="routePush">详情</el-button>
          </div>
        </el-form-item>
        <el-form-item label="业务时间:" v-if="isAddition==1">
          <div class="form-width-ms">
            <el-date-picker ref="recDate" v-model="form.additionDate" :picker-options="pickerOptions" format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择日期">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item v-if="sessionStorageData.allowdebt&&debtMoneys&&isAddition==0" label="以往欠款:">
          <div class="form-width-ms">
            <span>{{ debtMoneys }}</span>
            <el-button size="mini" type="text" @click="openMoney()">去还款</el-button>
          </div>
        </el-form-item>
        <el-form-item v-if="form.mobilePhone" label="成交额">
          <div class="form-width-ms"><span class="text-price text-red">{{ amountType(1) }}</span></div>
        </el-form-item>
        <el-form-item v-if="form.mobilePhone" label="卡付">
          <div class="form-width-ms"><span class="text-price text-red">{{ amountType(2) }}</span></div>
        </el-form-item>
        <el-form-item v-if="form.mobilePhone" label="现付">
          <div class="form-width-ms"><span class="text-price text-red">{{ amountType(3) }}</span></div>
        </el-form-item>
        <el-form-item v-if="form.mobilePhone" label="欠款">
          <div class="form-width-ms"><span class="text-price text-red">{{ amountType(4) }}</span></div>
        </el-form-item>
        <br /></el-form>
      <el-table 
        :data="list"           
        :header-cell-style="{
        background: 'linear-gradient(#6cb3ff, #1873d4)',
          color: '#eeeeee'
        }" 
        max-height="650"
        stripe
        ref="list">
        <el-table-column width="100" align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                icon="el-icon-delete"
                circle
                size="mini"
                type="primary"
                @click.stop="handleDel(scope.$index)"
              ></el-button>
            </template>
          </el-table-column>
        <el-table-column align="center" prop="projectNum" label="疗程编码" show-overflow-tooltip  min-width="180">
          <template slot-scope="scope">
            <div class="form-width-ms flex">
              <el-input placeholder="输入疗程编码" v-model="scope.row.projectNum" @change="proBlur(scope.row.projectNum,scope.$index)">
                <el-button size="mini" slot="append" icon="el-icon-search" @click="openPro(scope.$index)"></el-button>
              </el-input>
            </div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip min-width="120" align="center" prop="projectName" label="疗程名称"></el-table-column>
        <el-table-column align="center" prop="priceMember" label="单次标价" min-width="120">
          <template slot-scope="scope">
            <div class="form-width-xs pointer"><span class="text-price text-red">{{scope.row.priceMember?scope.row.priceMember:0}}</span></div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="salesPrice" label="成交单价" min-width="120">
         <template slot-scope="scope">
          <div class="form-width-xs pointer"><span class="text-price text-red">{{scope.row.salesPrice?scope.row.salesPrice:0}}</span></div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" prop="minumumTimes" label="最少购买(次)" min-width="90">
          <template slot-scope="scope">
            {{scope.row.minumumTimes?scope.row.minumumTimes:0}}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" prop="numberTimes" label="购买次数" min-width="120">
          <template slot-scope="scope">
            <div class="form-width-xs pointer">
              <div v-if="!scope.row.buysShow" @click="handleBuysShow(scope.row)">
                <span class="text-cyan">{{ scope.row.numberTimes?scope.row.numberTimes:0 }}</span>
                <i v-if="scope.row.numberTimes" class="el-icon-edit text-cyan"></i>
              </div>
              <el-input class="form-input-wdith"  v-focus v-else size="samll" oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" v-model="scope.row.numberTimes" @change="(val)=>numbertimes(val,scope.$index)" @blur="(val)=>numbertimes(val,scope.$index)"  ref="buyinput"></el-input>
            </div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" prop="amount" label="成交金额" min-width="120">
          <template slot-scope="scope">
            <div class="form-width-xl" v-if="!scope.row.menberShow" @click="handleMenberShow(scope.row)">
            <span class="text-price text-red">{{ scope.row.amount?scope.row.amount:0 }}</span>
            <i v-if="scope.row.amount" class="el-icon-edit text-cyan"></i>
          </div>
           <el-input class="form-input-wdith"  v-on:input="scope.row.amount = scope.row.amount.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')" v-focus v-else size="samll" v-model="scope.row.amount" @change="(val)=>changeDeal(val,scope.$index)" @blur="(val)=>changeDeal(val,scope.$index)" ref="priceinput"></el-input>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="充值卡付" min-width="120" v-if="sessionStorageData.refillCard">
          <template slot-scope="scope">
            <el-popover
              placement="bottom"
              width="700"
              @show="openRec(scope.row)"
              trigger="click">
              <el-table :data="scope.row.rechargeAccountList" :summary-method="getSummaries" max-height="300" :header-cell-style="{
                background: 'linear-gradient(#6cb3ff, #1873d4)',
                  color: '#eeeeee'
                }" >
                <el-table-column align="center" prop="rechargeTypeName" label="名称" show-overflow-tooltip min-width="120"></el-table-column>
                <el-table-column show-overflow-tooltip min-width="70" align="center" prop="cardRestMoney" label="剩余金额"></el-table-column>
                <el-table-column align="center" prop="cardOver" label="可用金额" width="70"></el-table-column>
                <el-table-column align="center" prop="spendMoney" label="本次支付" width="90">
                  <template slot-scope="scopes">
                    <div v-if="!scopes.row.isShow" @click="openCard(scopes.row, scope.$index)" class="form-input-width">
                      {{ scopes.row.spendMoney }}
                      <i class="el-icon-edit text-cyan"></i>
                    </div>
                    <el-input v-focus οninput="value=value.replace(/^0[0-9]+/,val=>val[1]).replace(/^(\.)+/,'').replace(/[^\d.]/g,'').replace(/\.+/,'.').replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
                      class="form-input-width-xs" @change="endEditCard(scopes.row,scope.$index)" @blur="endEditCard(scopes.row,scope.$index)" v-else v-model.lazy="scopes.row.spendMoney" precision="2"></el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="cardOvers" label="可用余额" width="70"></el-table-column>
                <el-table-column show-overflow-tooltip align="center" prop="storeName" label="所属门店" width="120"></el-table-column>
              </el-table>
              <el-button slot="reference" type="primary">充值卡</el-button>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="卡付金额" min-width="100">
          <template slot-scope="scope">
            {{ selectTabAmount(scope.row.rechargeAccountList,2)?selectTabAmount(scope.row.rechargeAccountList,2):0 }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="现付金额" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.nowAmount.toFixed(2)*1 }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" prop="debtMoney" label="欠款金额" min-width="100">
          <template slot-scope="scope">
            {{scope.row.debtMoney?scope.row.debtMoney.toFixed(2)*1:0}}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="实付金额" min-width="100">
          <template slot-scope="scope">
            {{ selectTabAmount(scope.row.rechargeAccountList,2) + scope.row.nowAmount.toFixed(2)*1 }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip align="center" prop="storeName" label="说明" min-width="250">
          <template slot-scope="scope">
            <el-input style="width: 180px" v-model="scope.row.description" placeholder="请输入说明"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <div class="reat">
        <div class="margin-bottom-xs marginAuto">
          <span  style="flex:1">员工/门店管理层/高管业绩</span>
          <div style="display: flex">
            <staffsles ref="staffsles" @staffslesData="staffslesData"></staffsles>
            <admin ref="admin" @adminData="adminData"></admin>
            <manager ref="manager" @managerData="managerData"></manager>
          </div>
        </div>
        <div class="tab">
          <el-table :data="payLists" :summary-method="getSummaries" show-summary row-key="payId" :header-cell-style="{
            background: 'linear-gradient(#6cb3ff, #1873d4)',
              color: '#eeeeee'
            }" >
            <el-table-column align="center" prop="collectionTypeName" label="支付方式" min-width="100"></el-table-column>
              <el-table-column align="center" prop="payMoney" fixed="right" label="本次支付 ( ¥ )" width="120">
                <template slot-scope="scope">
                  <div class="form-input-width" v-if="!scope.row.isShow" @click="openpay(scope.row)">{{ scope.row.payMoney }}<i class="el-icon-edit text-cyan"></i></div>
                  <el-input v-focus type="number" class="form-input-width-xs"  @blur="endEdit(scope.row)" v-else v-model.lazy="scope.row.payMoney" v-on:input="scope.row.payMoney = scope.row.payMoney.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')"></el-input>
                </template>
              </el-table-column>
          </el-table>     
        </div>
        <div style="width:100px">
            <el-button size="mini" type="primary"  :loading="saveloading" style="width:100%;height:35px;margin:10px 10px" @click="addList">添加</el-button>
            <el-button size="mini" type="info" plain @click="empty" style="width:100%;height:35px;margin:10px 10px">清空</el-button>
            <el-button size="mini" v-if="isAddition==0" type="primary" @click="isAddition = 1" v-role="5004005" style="width:100%;height:35px;;margin:10px 10px">补单</el-button> 
            <el-button size="mini" v-else type="success" @click="isAddition = 0" style="width:100%;height:35px;;margin:10px 10px">疗程</el-button>
            <el-button size="mini" type="primary" plain @click="getList" v-role="5004001" style="width:100%;height:35px;;margin:10px 10px">列表</el-button>
            <el-button size="mini" type="primary" @click="save((saveloading = true))" :loading="saveloading" v-role="5004002" style="width:100%;height:35px;;margin:10px 10px">提交</el-button>
          </div>
        </div>
      <div class="reatmen">
        <!-- 保存列表弹窗 -->
        <el-dialog :close-on-click-modal="false" v-dialogDrag title="疗程" :visible.sync="listDialogVisible" width="90%" :close="close">
          <div class="flex justify-between  padding-bottom-xs">
            <div>
              <el-date-picker @change="getList" style="width: 200px" v-model="selectDate"  type="month" placeholder="选择日期"></el-date-picker>
              <selec v-if="headOffice==1" ref="selec" @selecData="selecData"></selec>

            </div>
            <div class="flex">
              <div class="form-width-m padding-right-xs">
                <el-input size="medium" v-model="queryForm.courseReatmentNum" placeholder="输入单据号" clearable @change="getList"></el-input>
              </div>
              <div class="form-width-m padding-right-xs">
                <el-input size="medium" v-model="queryForm.memberName" placeholder="输入会员名字" clearable  @change="getList"></el-input>
              </div>
              <div class="form-width-m padding-right-xs">
                <el-input size="medium" maxlength="11" v-model="queryForm.mobilePhone" placeholder="输入会员手机号" oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" clearable  @change="getList"></el-input>
              </div>
              <el-button size="mini" type="primary" @click="getList">搜索</el-button>
            </div>
          </div>
          <el-table :data="pageInfo.formList" max-height="500" :header-cell-style="{
              background: 'linear-gradient(#6cb3ff, #1873d4)',
              color: '#eeeeee'
            }" ref="formList" border>
            <el-table-column align="center" prop="storeName" label="门店" min-width="80"></el-table-column>
            <el-table-column align="center" show-overflow-tooltip prop="courseReatmentNum" label="单号" min-width="140"></el-table-column>
            <el-table-column align="center" show-overflow-tooltip prop="date" label="日期" min-width="140"></el-table-column>
            <el-table-column align="center" prop="isAddition" show-overflow-tooltip label="补单" min-width="50">
              <template slot-scope="scope"><span class="text-red" v-show="scope.row.isAddition == 0">否</span><span class="text-green" v-show="scope.row.isAddition == 1">是</span></template>
            </el-table-column>
            <el-table-column align="center" prop="mobilePhone" label="手机号码" min-width="100">
              <template slot-scope="scope">
                {{ scope.row.mobilePhone | query }}
              </template>
            </el-table-column>
            <el-table-column align="center" prop="memberName" label="会员名称" min-width="80"></el-table-column>
            <el-table-column align="center" prop="projectName" :show-overflow-tooltip="true" label="疗程" min-width="120"></el-table-column>
            <el-table-column align="center" prop="salesPrice" label="成交单价" min-width="70"></el-table-column>
            <el-table-column align="center" prop="numberTimes" label="购买次数" min-width="70"></el-table-column>
            <el-table-column align="center" prop="collectionRechargeAmount" label="卡付金额" min-width="80"> </el-table-column>
            <el-table-column align="center" label="现付金额" min-width="80" prop="collectionCashAmount"></el-table-column>
            <el-table-column align="center" prop="amount" label="成交金额" min-width="70"></el-table-column>
            <el-table-column align="center" prop="courseReatmentAmount" label="实付金额" min-width="70">
              <template slot-scope="scope">
                {{ scope.row.collectionCashAmount + scope.row.collectionRechargeAmount }}
              </template>
            </el-table-column>
            <el-table-column align="center" prop="debtMoney" label="欠款" min-width="70"></el-table-column>
            <el-table-column align="center" prop="storeName" label="所属门店" show-overflow-tooltip min-width="100"></el-table-column>
            <el-table-column align="center" prop="inputBy" label="录单人" min-width="70"></el-table-column>
            <el-table-column align="center" prop="tag" label="状态" min-width="75" fixed="right">
              <template slot-scope="scope">
                <el-tag :type="scope.row.isCancel == 1 ? 'primary' : 'success'">{{ scope.row.isCancel==0?'正常':'作废' }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column align="center" fixed="right" label="明细" width="76">
              <template slot-scope="scope">
                <el-button size="mini" type="primary" @click="detail(scope.row)" plain>明细</el-button>
              </template>
            </el-table-column>
            <el-table-column align="center" fixed="right" label="作废" width="76">
              <template slot-scope="scope">
                <el-button @click.stop="abolish(scope.row)" size="mini" :disabled="scope.row.isCancel === 1" type="primary" v-role="5004003">作废</el-button>
              </template>
            </el-table-column>
            <el-table-column align="center" fixed="right" label="打印" width="76">
              <template slot-scope="scope">
                <el-button @click.stop="print(scope.row, (printDialogVisible = true))" :disabled="scope.row.isCancel === 1" size="mini" type="success" v-role="5004004">打印
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="block" style="margin-top: 10px">
            <!-- 分页组件 -->
            <el-pagination align="left" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryForm.pageNum" :page-sizes="[10, 20, 30, 40, 50]" :page-size="queryForm.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button size="mini" type="primary" @click="exportachis()" v-if="headOffice" :loading="exportloading">导 出</el-button>
            <el-button size="mini" @click="close">关 闭</el-button>
          </span>
        </el-dialog>
        <div>
          <el-dialog :close-on-click-modal="false" v-dialogDrag title="账户明细" :visible.sync="postponeDialog" width="60%">
            <el-form :model="postponeForm">
              <el-form-item label="会员名称" label-width="150px">
                <div style="wdith: 120px">{{ postponeForm.memberName }}</div>
              </el-form-item>
              <el-form-item label="疗程账户名称" label-width="150px">
                <div style="wdith: 120px">
                  {{ postponeForm.courseProjectName }}
                </div>
              </el-form-item>
              <el-form-item label="可用次数" label-width="150px">
                <div style="wdith: 120px">
                  {{ postponeForm.courseConsumeCount }}
                </div>
              </el-form-item>
              <el-form-item label="到期日期" label-width="150px">
                <div class="spanrs">
                  <span v-show="!recDateShow" @click="openDate((recDateShow = true))">{{ postponeForm.endTime }}
                    <el-button class="el-icon-edit" type="text" size="mini">修改</el-button>
                  </span>
                  <el-date-picker size="mini" @blur="recDateShow = false" v-show="recDateShow" ref="recDate" v-model="postponeForm.endTime" format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择日期">
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
              <el-button size="mini" type="primary" plain @click="postponeDialog = false">取消</el-button>
              <el-button size="mini" type="primary" @click="endPostpone((postponeDialog = false))">确定</el-button>
            </span>
          </el-dialog>
          <el-dialog :close-on-click-modal="false" v-dialogDrag title="打印" :visible.sync="printDialogVisible" width="60%">
            <div id="printTest" class="printDiv">
              <div class="text-center padding-xs">
                开卡
              </div>
              <br />
              <hr />
              <br />
              <el-form :model="printForm">
                <!-- <el-form-item label="门店:">
                  <div>
                    {{ printForm.storeName }}
                  </div>
                </el-form-item><br />
                <el-form-item label="时间:">
                  {{ printForm.date }}
                </el-form-item><br />
                <el-form-item label="单号:">
                  {{ printForm.courseReatmentNum }}
                </el-form-item><br />
                <el-form-item label="会员:">
                  <div>
                    {{ printForm.memberName }}/{{ printForm.mobilePhone ? (printForm.mobilePhone.substring(3, 0)) + '****' + (printForm.mobilePhone.substring(7)) : '******'}}
                  </div>
                </el-form-item><br />
                <el-form-item label="录单:">
                  <div>
                    {{ printForm.inputBy }}
                  </div>
                </el-form-item><br />
                <el-form-item label="疗程:">
                  <div style="min-width: 64px; display: inline-block">
                    {{ printForm.projectName }} <span class="text-cyan"></span>
                  </div>
                </el-form-item><br /> -->
                <!-- <el-table :data="printForm.courseLists" style="width: 200px;" show-summary>
                  <el-table-column align="center" prop="projectName" label="项目" min-width="100px"></el-table-column>
                  <el-table-column align="center" prop="courseReatmentAmount" label="实付金额" min-width="60">
                    <template slot-scope="scope">
                      {{ scope.row.amount - scope.row.debtMoney }}
                    </template>  
                  </el-table-column>
                  <el-table-column align="center" prop="numberTimes" label="次数" min-width="40px"> </el-table-column>
                </el-table>
                <hr />
                <el-table :data="printForm.rechargeConsumeList" style="width: 200px;" show-summary>
                  <el-table-column align="left" prop="rechargeTypeName" label="充值卡" min-width="100px"></el-table-column>
                  <el-table-column align="center" prop="spendMoney" label="支付" min-width="50px"></el-table-column>
                  <el-table-column align="center" prop="cardConsumeMoney" label="剩余" min-width="50px"></el-table-column>
                </el-table>
                <hr />
                <el-table :data="payTypeLists" style="width: 200px;">
                  <el-table-column align="left" prop="payName" label="付款方式" ></el-table-column>
                  <el-table-column align="center" prop="payMoney" label="支付" width="80"></el-table-column>
                </el-table> -->
                <div class="box1">
                  <p class="font-w">日 期：</p> <span>{{ printForm.date }}</span>
                </div>
                <div class="box1">
                  <p class="font-w">交易号：</p><span>{{ printForm.courseReatmentNum }}</span>
                </div>
                <div class="box1">
                  <p class="font-w">门 店：</p><span>{{ printForm.storeName }}</span> 
                </div>
                <div class="box1">
                  <p class="font-w">收银员：</p> <span>{{ printForm.inputNum }}</span> 
                </div>
                <div class="box1">
                  <p class="font-w">姓 名：</p><span>{{ printForm.memberName }}</span> 
                </div>
                <div class="box1">
                  <p class="font-w">手机号：</p><span>{{ printForm.mobilePhone }}</span> 
                </div>
                <hr style="margin-top:10px"/>
                <div class="print-project">
                  <ul>
                    <li class="project-top">
                      <p>项目</p>
                      <p>金额</p>
                      <p>次数</p>
                    </li>
                    <li v-for="(item,index) in courseProjectLists" :key="index" class="project-top-del">
                      <p>{{ item.projectName }}</p>
                      <p> {{ item.amount - item.debtMoney }}</p>
                      <p>{{ item.numberTimes }}</p>
                    </li>
                  </ul>
                </div>
                <hr style="margin-top:10px"/>
                <div class="print-project">
                  <ul>
                    <li class="project-top">
                      <p>付款方式</p>
                      <p>金额</p>
                    </li>
                    <li v-for="(item,index) in payTypeLists" :key="index" class="project-top-del">
                      <p>{{ item.payName }}</p>
                      <p> {{ item.payMoney }}</p>
                    </li>
                  </ul>
                </div>
                <div style="height:50px"></div>
                <el-form-item label="签名:">
                </el-form-item><br />
                <el-form-item label="服务热线:">
                  {{ printForm.telephone }} </el-form-item><br />
                <div>{{ printForm.printDate | dateFormat }}</div>
                <br /><br />
              </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
              <el-button size="mini" type="primary" plain @click="printDialogVisible = false">取消
              </el-button>
              <el-button size="mini" type="primary" v-print="'#printTest'">打印</el-button>
            </span>
          </el-dialog>
        </div>
        <el-dialog :close-on-click-modal="false" v-dialogDrag title="提示" :visible.sync="paymentcodeDialog" width="400px">
          <span style="font-size: 14px; margin-left: 10px; color: #999">本次支付需要验证支付密码</span>
          <el-form :model="paymentform">
            <el-form-item label="支付密码 : ">
              <el-input style="width: 150px" size="mini" type="password" v-model="paymentform.cashPassword" placeholder="会员的支付密码"></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button size="mini" type="primary" plain @click="paymentcodeDialog = false">取 消</el-button>
            <el-button size="mini" type="primary" @click="payment((paymentcodeDialog = false))">确 定</el-button>
          </span>
        </el-dialog>
      </div>
    </div>
    <staff ref="staff" @staffData="staffData"></staff>
    <addmember ref="addmember" @addUserConfirm="addUserConfirm"></addmember>
    <member ref="member" @memberData="memberData"></member>
    <repayment ref="repayment" @repaymentData="query"></repayment>
    <project ref="project" @projectData="proConfirm"></project>
    <detail ref="detail" @detailData="detailData"></detail>
    <trading ref="trading" :mobilePhone='form.mobilePhone'/>
    <record-details ref="recordDetails" />
    <record-detail ref="recordDetail"/>
  </div>
</template>
<script>
import {
  storeMemberOne,
  couAccountOne,
  recAccountList,
  checkCashWord,
  coursecancel,
  coursepage,
  addcourse,
  ctlist,
  editCouAccount,
  selectCourseOne,
  exportachis
} from "@/api/eashier.js";
import { propage } from "@/api/storeManage";
import repayment from "@/components/repayment/index.vue";
import staff from "@/components/staff/index";
import addmember from "@/components/member/edit/index";
import project from "@/components/project/index";
import member from "@/components/member/index";
import detail from "./components/detail";
import admin from "@/components/staffList/admin/index";
import manager from "@/components/staffList/manager/index";
import staffsles from "@/components/staffList/staff/index";
import selec from "@/components/store/select/index";
import recordDetails from './components/record-details.vue'
import recordDetail from './detail.vue'
export default {
  name:"reatment",
  components: {
    staffsles,
    manager,
    admin,
    member,
    repayment,
    staff,
    addmember,
    project,
    detail,
    selec,
    recordDetails,
    recordDetail
  },
  data() {
    return {
      exportloading:false,
      courseProjectLists:[],
      payTypeLists:[],
      courseLists:[],
      isShow:false,
      list:[],
      selectIndex:0,
      input: null,
      printDialogVisible: false, //打印弹窗开关
      listDialogVisible: false,
      paymentcodeDialog: false,
      postponeDialog: false,
      detailDialog: false,
      saveloading: false,
      recDateShow: false,
      refreshtext: false, //搜索判断字符
      menberShow: false,
      infoDialog: false, //上传文件弹窗开关
      buysShow: false,
      moneyRatio: 100,
      isAddition: 0,
      total: 0, //分页总条数
      queryForm: {
        //查询对象
        pageNum: 1, // 当前页码
        pageSize: 10, // 每页的数据条数,
      },
      selectDate: new Date(),
      payMoney: "",
      payLists: [], //现付列表
      proForm: {},
      manageList: [],
      staffList: [],
      detailForm: {
        rechargeConsumeList: [],
        payLists: [], //现付列表
      },
      postponeForm: {},
      pageInfos: {
        reatmentList: [],
        total: 0, //分页总条数
        pageSize: 10,
        pageNum: 1,
      },
      activeName: ["现付"],
      openCollNumber: 0,
      radioEditStaff: "",
      editStaffTable: [],
      sessionStorageData: {}, //门店参数集合
      editStaffRatioRow: "",
      radioEditStaffList: {},
      formLabelwidth: "70px",
      rechargeAccountList: [], //卡付列表
      collectionCashAmount: "",
      editStaffDailogtitle: "",
      collectionRechargeAmounts: 0,
      debtMoneys: 0,
      paymentform: {
        cashPassword: null,
      },

      printForm: {
        date: "",
        number: null,
        storeId: "",
        projectName: "",
        memberName: "",
        mobilePhone: null,
        num: null,
        money: null,
        payMoney: null,
        cardMoney: null,
        numMoney: null,
        numPayMoney: null,
        tel: "",
        printDate: new Date(),
      },
      form: {
        mobilePhone: null,
        memberName: "",
        sex: "",
        integralCheckbox: false,
        description: "",
        salesPrice: "",
        numberTimes: "",
        menberShow: false,
        courseReatmentAmount: 0,
        isDebt: false,
        collectionRechargeAmount: 0,
        collectionCashAmount: 0,
        collectionIntegralAmount: 0,
        integral: 0,
        integralMoney: 0,
        consumeIntegral: 0,
        debtMoney: 0,
        amount:0
      },
      headOffice: sessionStorage.getItem("headOffice") * 1,
      pageInfo: {
        total: 0, //分页总条数 // 总条数
        formList: [],
      },
      addForm: {
        sex: 1,
        memberName: "",
        mobilePhone: null,
        label: null,
        skinType: null,
        hairLong: null,
        cashPassword: null,
        checkPass: null,
      },
      vip: {}, //会员信息
      staffLists: [{ ratio: 100 }], //员工占比初始化
      managerLists: [{ ratio: 100 }], //员工占比初始化
      adminList: [{ ratio: 100 }], //员工占比初始化
      date: [],
      openStaffText: "",
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
    };
  },
  computed:{
    amountType(){
      return function(type){
        // 1成交额 2卡付 3现付 4欠款
        let num =  type==1?
        eval(this.list.map(item=>{return item.amount?item.amount*1:0}).join("+")):(type==2?
        eval(this.list.map(item=>{return this.selectTabAmount(item.rechargeAccountList,2)?this.selectTabAmount(item.rechargeAccountList,2):0}).join("+")):(type==3?
        eval(this.payLists.map(item=>{return item.payMoney*1}).join("+")):eval(this.list.map(item=>{return item.debtMoney?item.debtMoney*1:0}).join("+"))))
        return num?num.toFixed(2)*1:0
      }
    },
    // 现付金额
    selectTabAmount(){
      return function(val,type){
        let num = type ==1? eval(val.map(item=>{return item.payMoney?item.payMoney*1:0}).join("+")):eval(val.map(item=>{return item.spendMoney?item.spendMoney*1:0}).join("+"))
        return num?num.toFixed(2)*1:0
      }
    },
    // 待付金额
    treatAmount(){
      // 需要转换类型(字符串拼接需要转数值)
      let cardAmount = 0 //卡付金额
      let cashAmount = 0 //现金金额
      if(this.rechargeAccountList.length){
        // 允许卡付，金额累加
        cardAmount = this.rechargeAccountList.reduce((pre,item)=>{
          if(item.spendMoney){
            return pre + Number(item.spendMoney)
          }else return pre
        },0)
      }
      if(this.payLists.length){
        // 允许现金付
        cashAmount = this.payLists.reduce((pre,item)=>{
        if(item.payMoney){
          return pre + Number(item.payMoney)
        }else{
          return pre
        }
      },0)
      }
      // 比成交金额低,返回待付金额,大于成交金额,返回超出
      let num = Number(cardAmount + cashAmount)
      let amount = Number(this.form.amount)
      if(!amount){
        // 初始化金额为0
        return 0
      }
      if(amount>=num){
        return (amount - num).toFixed(2)
      }else{
        return '超出'+( (num -  amount).toFixed(2) ) + '元'
      }
    },
    // 实付金额
    paidAmount(){
      // 需要转换类型(字符串拼接需要转数值)
      let cardAmount = 0 //卡付金额
      let cashAmount = 0 //现金金额
      if(this.rechargeAccountList.length){
        // 允许卡付，金额累加
        cardAmount = this.rechargeAccountList.reduce((pre,item)=>{
          if(item.spendMoney){
            return pre + Number(item.spendMoney)
          }else return pre
        },0)
      }
      if(this.payLists.length){
        // 允许现金付
        cashAmount = this.payLists.reduce((pre,item)=>{
        if(item.payMoney){
          return pre + Number(item.payMoney)
        }else{
          return pre
        }
      },0)
      }
      return (Number(cardAmount+cashAmount)).toFixed(2)
    }
  },
  methods: {
    exportachis(){
      this.exportloading = true
      let params = {
        date:this.formatTime(this.selectDate, "YYYY-MM-DD hh:mm:ss")
      }
      exportachis(params).then(res=>{
        this.exportloading = false
        let blob = new Blob([res]);
        var a = document.createElement("a");
        var url = window.URL.createObjectURL(blob);
        console.log(url);
        a.href = url;
        a.download = "疗程导出表.xlsx";
        a.click();
        window.URL.revokeObjectURL(url);
      })
    },
    addUserConfirm(phone){
      this.form.mobilePhone = phone
      this.query()
    },
    handleMenberShow(row){
      // let num = eval(this.payLists.map(item=>{return item.payMoney*1}).join("+")) 
      // let cardNum = this.selectTabAmount(row.rechargeAccountList,2)
      // if(num ||cardNum){
      //   this.$message.error({
      //       message: "当前项目存在卡付或者现付！请先清空再进行操作",
      //     });
      // }else{
        row.menberShow = true
      // }
    },
    handleBuysShow(row){
      // let num = eval(this.payLists.map(item=>{return item.payMoney*1}).join("+")) 
      // let cardNum = this.selectTabAmount(row.rechargeAccountList,2)
      // if(num ||cardNum){
      //   this.$message.error({
      //       message: "当前项目存在卡付或者现付！请先清空再进行操作",
      //     });
      // }else{
        row.buysShow = true
      // }
    },
    updataNowAmount(){
      // 重置list
      this.list.forEach(item=>{
        // 清空现付,重置待付,欠款
        item.nowAmount = 0
        item.debtMoney = item.amount - this.selectTabAmount(item.rechargeAccountList,2)
        let cardCashSum = item.nowAmount*1 + (this.selectTabAmount(item.rechargeAccountList,2)?this.selectTabAmount(item.rechargeAccountList,2):0)
        item.debtAmount = ((item.amount * this.sessionStorageData.debtRatio * 1) /100 ).toFixed(2) *1 
        if(cardCashSum>item.debtAmount){
          item.debtAmount = 0
        }else{
          item.debtAmount -= cardCashSum.toFixed(2)*1
        }
      })
      let num = eval(this.payLists.map(item=>{return item.payMoney*1}).join("+")) //现金总和
      this.list.forEach(item=>{
        if(item.debtMoney){ //待付金额存在
          if(num){
            if(num>item.debtMoney){ //够付,不存在欠款
              item.nowAmount = item.debtMoney
              num -= item.nowAmount*1
              item.debtMoney = 0
              item.debtAmount = 0
            }else{ //不够付
              item.nowAmount = num
              item.debtMoney = (item.debtMoney-num).toFixed(2)*1
              num = 0
              item.debtAmount = ((item.amount * this.sessionStorageData.debtRatio * 1) /100 ).toFixed(2) *1 
              let cardCashSum = (item.nowAmount*1 + (this.selectTabAmount(item.rechargeAccountList,2)?this.selectTabAmount(item.rechargeAccountList,2):0))
              if(cardCashSum>item.debtAmount){
                item.debtAmount = 0
              }else{
                item.debtAmount -= cardCashSum
              }
            }
          }
        }
      })
    },
    openRec(row){
      row = this.handleData(row)
    },
    handleData(row){
        if(row){
            row.rechargeAccountList.forEach(firstItem=>{
                let list = []
                this.list.forEach(secondItem=>{
                    secondItem.rechargeAccountList.forEach(thirdItem=>{
                        if(thirdItem.id === firstItem.id){
                            thirdItem.spendMoney = thirdItem.spendMoney?thirdItem.spendMoney*1:0
                            list.push(thirdItem)
                        }
                    })
                })
                // // 本单使用总和
                this.$set(firstItem,'cardSum',eval(list.map(item=>item.spendMoney*1).join("+")))
                this.$set(firstItem,'cardOvers',firstItem.cardOver-firstItem.cardSum)
                firstItem.cardOvers = (firstItem.cardOvers).toFixed(2)*1
                // // 可用余额
            })
        }
        return row
    },
    handleDel(index){
      this.list.splice(index,1)
      this.resetAmount()
      this.updataNowAmount()
    },
    addList(){
      this.list.push({
        rechargeAccountList:JSON.parse(JSON.stringify(this.rechargeAccountList)),
        payLists:JSON.parse(JSON.stringify(this.payLists)),
        menberShow:false,
        buysShow:false,
        numberTimes:0,
        amount:0,
        integralCheckbox:false,
        debtAmount:0,
        nowAmount:0
        })
    },
    routePush(){
      this.$refs.trading.dialogFormVisible = true
    },
    changeDeal(val,index){
      if(typeof(val)=='object')return this.list[index].menberShow = false
      this.list[index].numberTimes?this.list[index].numberTimes*1:0 //购买次数转化
      this.list[index].amount = val*1
      if((val>(this.list[index].numberTimes*this.list[index].topPriceMember))||(val<(this.list[index].minumumPriceMember*this.list[index].numberTimes))){ //金额大于最大支付或者小于最大支付
        this.$message.warning({
          message:
            "成交金额不能低于" +
           ( this.list[index].minumumPriceMember*this.list[index].numberTimes).toFixed(2)*1 +
            "高于" +
          (this.list[index].numberTimes*this.list[index].topPriceMember).toFixed(2)*1,
        });
        this.list[index].amount = (this.list[index].salesPrice*this.list[index].numberTimes).toFixed(2)*1
        this.list[index].salesPrice = (this.list[index].amount/this.list[index].numberTimes).toFixed(2)*1
      }else{
        this.list[index].salesPrice = (this.list[index].amount/this.list[index].numberTimes).toFixed(2)*1
        this.list[index].rechargeAccountList = JSON.parse(JSON.stringify(this.rechargeAccountList))
        this.resetAmount()
        this.list[index].debtMoney = (val - (this.selectTabAmount(this.list[index].rechargeAccountList,2) + this.selectTabAmount(this.list[index].payLists,1) )).toFixed(2)*1
        this.updataNowAmount()
      }
      this.list[index].menberShow = false
    },
    close() {
      this.listDialogVisible = false;
      this.openCollNumber = 0;
    },

    setStaffRatio() {
      this.openCollNumber = 0;
      var that = this;
      this.$nextTick(() => {
        that.$refs.staffsles.show(that.staffLists);
        that.$refs.manager.show(that.managerLists);
        that.$refs.admin.show(that.adminList);
      });
    },

    //员工占比返回方法
    staffslesData(v) {
      this.staffLists = [...v];
    },
    //高管占比返回方法
    managerData(v) {
      this.managerLists = [...v];
    },
    //管理员占比返回方法
    adminData(v) {
      this.adminList = [...v];
    },
    openMoney() {
      this.$refs.repayment.show(this.vip);
    },
    //打开选择会员弹窗
    openMember() {
      this.$refs.member.show();
    },
    //选中会员返回方法
    memberData(v) {
      this.form.mobilePhone = v.mobilePhone;
      this.query();
    },
    //选中员工返回方法
    staffData(v) {
      let form = { ...this.form };
      if (this.openStaffText == "manage") {
        form.manageStaffName = v.manageStaffName;
        form.manageStaffId = v.manageStaffId;
        form.manageIdentityCard = v.manageIdentityCard;
        form.manageBrandNumber = v.manageBrandNumber;
      }
      this.form = {};
      this.form = form;
    },
    openPostpone(row) {
      let ids = {
        id: row.courseAccountId,
      };
      couAccountOne(ids).then((res) => {
        if (res.code == "000000") {
          this.postponeForm = res.data;
          //console.log(this.postponeForm);
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    endPostpone() {
      let form = {
        id: this.postponeForm.id,
        endTime: this.postponeForm.endTime,
      };
      editCouAccount(form).then((res) => {
        if (res.code == "000000") {
          this.$message.success({
            message: res.message,
          });
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    ratioChange(v, index) {
      this.staffList.forEach((item) => {
        if (item.id == v) {
          item.ratio = this.staffLists[index].ratio;
          item.staffNames = item.brandNumber + "--" + item.staffName;
          this.staffLists.splice(index, 1, item);
        }
      });
    },
    ratioChangeEdit(v, index) {
      this.staffList.forEach((item) => {
        if (item.id == v) {
          item.ratio = this.detailForm.entities[index].ratio;
          item.staffNames = item.brandNumber + "--" + item.staffName;
          this.detailForm.entities.splice(index, 1, item);
        }
      });
    },

    payment() {
      this.paymentform.id = this.form.memberId;
      checkCashWord(this.paymentform).then((res) => {
        if (res.data == true) {
          addcourse(this.form).then((res) => {
            if (res.code == "000000") {
              this.empty();
              this.$message.success({
                message: "疗程购买 ," + res.message,
              });
            } else {
              this.empty();
              this.$message.error({
                message: "疗程购买 , " + res.message,
              });
            }
          });
        } else {
          this.$message.error({
            message: "密码错误",
          });
        }
      });
    },

    changeIntegralCheckbox(row) {
      if (this.form.amount != undefined) {
        if (row == true) {
          this.form.debtMoney =
            this.form.amount -
            this.form.collectionRechargeAmount -
            this.form.collectionCashAmount;

          let list = JSON.parse(
            sessionStorage.getItem("sessionStorageData")
          ).excIntegralByMoney.split(":");
          if (this.form.integralMoney >= this.form.debtMoney) {
            this.form.integralMoney = this.form.debtMoney;
            this.form.consumeIntegral =
              this.form.debtMoney * (list[0] / list[1]);
            this.form.collectionIntegralAmount = this.form.integralMoney;
            this.form.debtMoney = 0;
          } else {
            this.form.debtMoney =
              (
                this.form.amount -
                this.form.integralMoney -
                this.collectionRechargeAmounts -
                this.collectionCashAmount
              ).toFixed(2) * 1;
            this.form.collectionIntegralAmount = 0;
          }
          if (this.form.debtMoney < 0) {
            this.form.debtMoney = 0;
          }
          this.form.courseReatmentAmount =
            this.form.collectionCashAmount +
            this.collectionRechargeAmounts +
            this.form.collectionIntegralAmount;
        } else {
          this.form.debtMoney =
            this.form.amount -
            (
              this.collectionRechargeAmounts - this.form.collectionCashAmount
            ).toFixed(2) *
              1;
          this.form.courseReatmentAmount =
            this.form.collectionCashAmount + this.collectionRechargeAmounts;
        }
      }
    },
    detail(row) {
      this.$refs.detail.show(row);
    },
    editStaff(row) {
      this.editStaffRatioRow = row;
    },
    radioEditStaffRow(row) {
      this.radioEditStaff = row.brandNumber;
      this.radioEditStaffList = row;
    },
    endRadioEditStaff() {
      var show = true;
      if (this.editStaffDailogtitle == "修改") {
        this.detailForm.entities.forEach((item) => {
          // console.log(this.radioEditStaffList);
          if (item.saleStaffId == this.radioEditStaffList.id) {
            this.$message.warning({
              message: "员工已存在",
            });
            show = false;
          }
        });
        if (show) {
          this.editStaffRatioRow.brandNumber =
            this.radioEditStaffList.brandNumber;
          this.editStaffRatioRow.saleStaffName =
            this.radioEditStaffList.saleStaffName;
          this.editStaffRatioRow.saleStaffId = this.radioEditStaffList.id;
          this.editStaffRatioRow.saleIdentityCard =
            this.radioEditStaffList.identityCard;
        }
      } else if (this.editStaffDailogtitle == "添加") {
        this.detailForm.entities.forEach((item) => {
          if (item.saleStaffId == this.radioEditStaffList.id) {
            this.$message.warning({
              message: "员工已存在",
            });
            show = false;
          }
        });
        if (show) {
          this.radioEditStaffList.saleRatio = 0;
          this.radioEditStaffList.editStaffRatioShow = false;
          this.detailForm.entities.push(this.radioEditStaffList);
        }
      }
    },

    //检查手机号是否是平台会员
    query() {
      var mobilePhone = this.form.mobilePhone;
      this.empty();
      // var number = partten.phoneNum;
      // if (!number.test(mobilePhone)) {
      //   this.$message.info({
      //     message: "请输入正确的手机号 ! ",
      //   });
      // } else {
        storeMemberOne({
          mobilePhone: mobilePhone,
          storeId: sessionStorage.getItem("parentId"),
        }).then((res) => {
          this.form.mobilePhone = mobilePhone;
          if (res.code == "000000") {
            this.vip = res.data;
            this.form.memberName = res.data.memberName;
            this.form.minumumTimes = res.data.minumumTimes;
            this.debtMoneys = res.data.debtMoney;
            this.form.memberId = res.data.id;
            this.form.sex = res.data.sex;
            if (this.sessionStorageData.course == true) {
              this.form.integral = res.data.integral;
              this.form.consumeIntegral = res.data.consumeIntegral;
              this.form.integralMoney = res.data.integralMoney;
            } else {
              this.form.integral = 0;
              this.form.consumeIntegral = 0;
              this.form.integralMoney = 0;
            }
            var ids = {
              // storeId: res.data.storeId,
              memberId: res.data.id,
            };
            var num = 0;
            recAccountList(ids).then((res) => {
              if (res.code == "000000") {
                var rechargeAccountList = [];
                res.rows.forEach((item) => {
                  item.isShow = false;
                  item.isShows = false;
                  item.spendMoney = 0.0;
                  item.discoutMoney = 0.0;
                  item.cardOver = item.cardConsumeMoney;
                  item.cardOvers = item.cardConsumeMoney;
                  if (this.sessionStorageData.buycourse == true) {
                    if (item.type == 1) {
                      item.offsetMoney =
                        item.cardConsumeMoney / (item.discount / 100);
                      item.offsetMoney =
                        Math.floor(item.offsetMoney * 100) / 100;
                      item.offsetMoney = this.getDecimal(item.offsetMoney);
                    } else {
                      item.offsetMoney = item.cardConsumeMoney;
                    }
                  } else {
                    item.offsetMoney = item.cardConsumeMoney;
                  }
                  rechargeAccountList.push(item);
                });
                rechargeAccountList.forEach(items=>items.giftConsumeMoney = null)
                this.rechargeAccountList = rechargeAccountList;
                this.addList()
              } else {
                this.$alert("查询会员充值卡: " + res.message, "提示", {
                  confirmButtonText: "确定",
                  confirmButtonClass: "confirmbtnFalses",
                  type: "warning",
                  center: true,
                  callback: (action) => {},
                });
              }
            });
          } else {
            this.empty();
            if (res.code == "200004") {
              this.$confirm(res.message + ",请先注册!", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                cancelButtonClass: "cancelbtnFalses",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
              }).then(() => {
                this.openAddMember();
              });
            } else {
              this.$message.warning({
                message: res.message,
              });
            }
          }
        });
      // }
    },
    openAddMember() {
      this.$refs.addmember.show("添加");
    },
    //修改单价
    changesales() {
      if (this.sessionStorageData.minimum == true) {
        this.form.salesPrice = this.form.salesPrice*1
        if (
          this.form.salesPrice > this.form.topPriceMember ||
          this.form.salesPrice < this.form.minumumPriceMember
        ) {
          this.form.salesPrice = this.form.priceMember;
          this.$message.warning({
            message:
              "成交价不能低于" +
              this.form.minumumPriceMember +
              "高于" +
              this.form.topPriceMember,
          });
        } else {
          this.menberShow = false;
        }
      } else {
        this.menberShow = false;
      }
      this.form.amount =
        ((this.form.salesPrice * 100 * this.form.numberTimes) / 100).toFixed(
          2
        ) * 1;
      this.form.debtMoney = this.form.amount;
      this.form.debtMoney = this.form.debtMoney.toFixed(2) * 1;
      this.moneyRatio =
        (this.form.salesPrice / this.proForm.priceMember).toFixed(2) * 100;
      this.resetAmount()
    },
    //重新计算支付
    resetAmount(){
      this.payLists.forEach(item=>{
        item.payMoney = 0
      })
      this.rechargeAccountList.forEach(item=>{
        item.spendMoney = 0
      })
    },
    //修改购买次数
    numbertimes(val,index) {
      // debtMoney
      if (this.list[index].numberTimes < this.list[index].minumumTimes) {
        this.$message.info({
          message: "最低购买不能少于" + this.list[index].minumumTimes + "次",
        });
        this.list[index].numberTimes = this.list[index].minumumTimes;
        this.list[index].buysShow = false;
      } else {
        this.list[index].buysShow = false;
        this.list[index].rechargeAccountList = JSON.parse(JSON.stringify(this.rechargeAccountList))
        this.resetAmount()
        this.list[index].amount = (this.list[index].numberTimes*this.list[index].salesPrice).toFixed(2)*1
        this.list[index].debtMoney = (this.list[index].amount*1 -(this.selectTabAmount(this.list[index].rechargeAccountList,2) + this.selectTabAmount(this.list[index].payLists,1))).toFixed(2)*1;
        this.updataNowAmount()
      }
    },
    //选择金额.
    openpay(row) {
      if (this.form.memberName&&this.list.length) {
        if(row.payMoney*1){
          row.payMoney = 0
          this.updataNowAmount()
        }else{
          let num = eval(this.list.map(item=>item.debtMoney?item.debtMoney*1:0).join("+")) //待付金额总和
          row.payMoney = num.toFixed(2)*1
        }
        row.isShow = true;
      } else {
        this.$message.info({
          message: "请先选择疗程 !",
        });
      }
    },
    updataDebtAmount(index){
      let num = ( this.selectTabAmount(this.list[index].rechargeAccountList,2) + this.list[index].nowAmount*1 ) //实付金额
      let maxdebt= ((this.list[index].amount * this.sessionStorageData.debtRatio * 1) /100 ).toFixed(2) *1 //最大欠款
      if(num>maxdebt){ //不存在欠款
        this.list[index].debtAmount = 0
      }else{ //还需最少支付
        this.list[index].debtAmount = (maxdebt - num).toFixed(2)*1
      }
    },
    endEdit(row) {
      row.payMoney = row.payMoney*1
      // let cashNum = eval(this.payLists.map(item=>{return item.payMoney*1}).join("+")) //现金总和
      let cardNum = eval(this.list.map(item=>{return item.debtMoney*1}).join("+")) //待付总和
      if(row.payMoney>cardNum){
        this.$message.info({
          message: "超出需支付金额 !请重新选择",
        });
        row.payMoney = 0
      }else{
        this.updataNowAmount(row)
      }
      row.isShow = false;
      this.list.push({})
      this.list.pop()
    },

    //返回当前行的下标
    tableRowClassName({ row, rowIndex }) {
      row.index = rowIndex;
    },
    proBlur(projectNum,index) {
      this.form.projectNum;
      let form = {
        pageSize: 999,
        projectNum,
        state: 1,
        directConsumption: 0,
      };
      this.selectIndex = index
      propage(form).then((res) => {
        if (res.code == "000000") {
          if (res.pageInfo.total == 1) {
            this.proConfirm(res.pageInfo.list[0]);
          } else {
            this.$message.info({ message: "请输入正确的项目编码!" });
          }
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    // proChange(v) {
    //   console.log(v);
    //   this.pageInfos.reatmentList.forEach((item) => {
    //     if (item.id == v) {
    //       this.proForm = item;
    //     }
    //   });
    //   this.proConfirm(this.proForm);
    // },
    //打开选择会员充值卡包弹窗
    openPro(index) {
      this.selectIndex = index
      this.$refs.project.show(0);
    },
    //购买类型确定
    proConfirm(pros) {
      this.proForm = pros;
      if (this.form.memberId) {
        this.list[this.selectIndex].projectName = this.proForm.projectName;
        this.list[this.selectIndex].projectNum = this.proForm.projectNum;
        this.list[this.selectIndex].projctId = this.proForm.id;
        this.list[this.selectIndex].price = this.proForm.price;
        this.list[this.selectIndex].topPrice = this.proForm.topPrice;  
        this.list[this.selectIndex].topPriceMember = this.proForm.topPriceMember;
        this.list[this.selectIndex].priceMember = this.proForm.priceMember;
        this.list[this.selectIndex].minumumPriceMember = this.proForm.minumumPriceMember;
        this.list[this.selectIndex].salesPrice = this.proForm.priceMember;
        this.list[this.selectIndex].minumumPrice = this.proForm.minumumPrice;
        this.list[this.selectIndex].salesAchievement = this.proForm.salesAchievement;
        this.list[this.selectIndex].salesCommission = this.proForm.salesCommission;
        this.list[this.selectIndex].cardSalesAchievement = this.proForm.cardSalesAchievement;
        this.list[this.selectIndex].cardSalesCommission = this.proForm.cardSalesCommission;
        this.list[this.selectIndex].minumumTimes = this.proForm.minumumTimes;
        this.list[this.selectIndex].numberTimes = this.proForm.minumumTimes;
        this.list[this.selectIndex].amount =
          ((this.list[this.selectIndex].salesPrice * 100 * this.list[this.selectIndex].numberTimes) / 100).toFixed(
            2
          ) * 1;
        this.list[this.selectIndex].debtMoney = this.list[this.selectIndex].amount;
        this.list[this.selectIndex].debtAmount= (this.list[this.selectIndex].amount * this.sessionStorageData.debtRatio * 1/100).toFixed(2)*1;
        if (this.list[this.selectIndex].integralCheckbox == true) {
          if (
            JSON.parse(sessionStorage.getItem("sessionStorageData"))
              .excIntegralByMoney
          ) {
            let list = JSON.parse(
              sessionStorage.getItem("sessionStorageData")
            ).excIntegralByMoney.split(":");
          }
          if (this.list[this.selectIndex].integralMoney >= this.list[this.selectIndex].debtMoney) {
            this.list[this.selectIndex].integralMoney = this.list[this.selectIndex].debtMoney;
            this.list[this.selectIndex].consumeIntegral =
              this.list[this.selectIndex].debtMoney * (list[0] / list[1]);
            this.list[this.selectIndex].debtMoney = 0;
          } else {
            this.list[this.selectIndex].debtMoney = this.list[this.selectIndex].amount - this.list[this.selectIndex].integralMoney;
          }
          this.list[this.selectIndex].collectionIntegralAmount = this.list[this.selectIndex].integralMoney;
        } else {
          this.list[this.selectIndex].debtMoney = this.list[this.selectIndex].amount;
          this.list[this.selectIndex].collectionIntegralAmount = 0;
        }
        this.list[this.selectIndex].collectionCashAmount = 0;
        this.list[this.selectIndex].collectionRechargeAmount = 0;
        this.list[this.selectIndex].courseReatmentAmount =
          this.list[this.selectIndex].collectionCashAmount +
          this.collectionRechargeAmounts +
          this.list[this.selectIndex].collectionIntegralAmount;
        this.list.push({})
        this.list.pop()
        let index = this.list.findIndex(item=>!item.projctId)
        // 有空行，index存在 ,没有空行,index = -1
        if(index == -1)this.addList()
      }
    },
    openCard(row, $index) {
      if (this.list[$index].salesPrice != "") {
          row.isShow = true;
      } else {
        return this.$message.info({
          message: "请先选择疗程!",
        });
      }
      if(row.spendMoney*1!=0){
        row.cardOvers = (row.spendMoney*1+row.cardOvers).toFixed(0)*1
      }
      if (this.sessionStorageData.buycourse == true) {
        if (this.list[$index].debtMoney * 1 > 0) {
          if (
            row.cardOvers >=
            ((row.discoutMoney * row.discount) / 100).toFixed(2) * 1
          ) {
            row.discoutMoney = this.list[$index].debtMoney * 1;
            row.spendMoney =
              ((row.discoutMoney * row.discount) / 100).toFixed(2) * 1;
          } else {
            row.discoutMoney =
              (row.cardOvers / (row.discount / 100).toFixed(2)) * 1;
            row.spendMoney = row.cardOvers;
          }
        } else {
          row.spendMoney = 0;
        }
      } else {
        if (this.list[$index].debtMoney * 1 > 0) {
          if (row.cardOvers < this.list[$index].debtMoney * 1) {
            row.spendMoney = row.cardOvers;
            row.discoutMoney = row.cardOvers;
          } else {
            row.discoutMoney = this.list[$index].debtMoney * 1;
            row.spendMoney = this.list[$index].debtMoney * 1;
          }
        } else {
          row.spendMoney = 0;
        }
      }
    },
    endEditCard(row,index) {
      row.spendMoney = (row.spendMoney * 1).toFixed(2) * 1;
      if (row.spendMoney == "") {
        row.spendMoney = 0;
      }
      if (row.spendMoney * 1 > row.cardOvers * 1) {
        this.$message.info({
          message: "支付金额不能大于可用金额!",
        });
        row.spendMoney = 0;
        row.isShow = false;
      } else {
        row.isShow = false;
        if (this.sessionStorageData.buycourse == true) {
          if (row.spendMoney * 1 > 0) {
            row.discoutMoney =
              (row.spendMoney / (row.discount / 100)).toFixed(2) * 1;
            row.cardOvers =
              (row.cardOvers * 1 - row.spendMoney * 1).toFixed(2) * 1;
          } else {
            row.discoutMoney = 0;
            row.cardOvers =
              (row.cardOvers * 1 - row.spendMoney * 1).toFixed(2) * 1;
          }
        } else {
          if (row.spendMoney * 1 > 0) {
            row.discoutMoney = row.spendMoney.toFixed(2) * 1;
            row.cardOvers =
              (row.cardOvers * 1 - row.spendMoney * 1).toFixed(2) * 1;
          } else {
            row.discoutMoney = 0;
            row.cardOvers =
              (row.cardOvers * 1 - row.spendMoney * 1).toFixed(2) * 1;
          }
        }
      }
      this.cardnum(index);
      this.updataDebtAmount(index)
    },
    disedit(row, $index) {
      if (this.form.salesPrice != "") {
        row.isShows = true;
        this.$nextTick(() => {
          this.$refs["indexs" + $index].focus();
          this.$refs["indexs" + $index].select();
        });
      } else {
        this.$message.info({
          message: "请先选择疗程!",
        });
      }
    },
    endEditCards(row) {
      if (row.discoutMoney == "") {
        row.discoutMoney = 0;
      }
      if (row.discoutMoney * 1 > row.offsetMoney * 1) {
        this.$message.info({
          message: "抵用支付金额不能大于可抵扣额!",
        });
      } else {
        row.isShows = false;
        this.cardnum();
        row.cardOvers = row.cardOver - row.spendMoney;

        row.spendMoney = Math.round((row.discoutMoney * row.discount) / 100);
        this.form.courseReatmentAmount =
          (this.form.collectionCashAmount * 100 +
            this.collectionRechargeAmounts * 100) /
          100;
        this.form.debtMoney =
          this.form.amount -
          this.form.collectionCashAmount -
          this.collectionRechargeAmounts -
          this.form.integralMoney;
        this.form.debtMoney = this.form.debtMoney.toFixed(2) * 1;
      }
    },
    empty() {
      Object.assign(this.$data, this.$options.data.call(this));
      this.setPage();
    },
    //保存确定方法
    save() {
      this.list.forEach(item=>{
        item.debtMoney = item.debtMoney?item.debtMoney.toFixed(2)*1:0
      })
      var staffLists = [];
      this.staffLists.forEach((item) => {
        delete item.ratioShow;
        if (item.id) {
          item.ratio = item.ratio?item.ratio.toFixed(2)*1:0
          staffLists.push(item);
        }
      });
      let salesmens = [];
      this.managerLists.forEach((item) => {
        if (item.id) {
          item.staffType = 0;

          salesmens.push(item);
        }
      });
      this.adminList.forEach((item) => {
        if (item.id) {
          item.staffType = 1;
          salesmens.push(item);
        }
      });
      var that = this;
      let form = {salesmens,staffLists}
      if (staffLists.length == 0) {
        this.$confirm("没有选择员工是否保存?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          cancelButtonClass: "cancelbtnFalses",
          confirmButtonClass: "confirmbtnFalses",
          type: "warning",
        }).then(() => {
          that.addCourse(form);
        }).catch(()=>{
          this.saveloading = false
        });
      } else {
        that.addCourse(form);
        that.loading = false;
      }
      setTimeout(() => {
        this.loading = false;
      }, 3000);
    },
    addCourse(val) {
      setTimeout(() => {
        this.loading = false;
      }, 3000);
      let sessionStorageData = JSON.parse(sessionStorage.getItem('sessionStorageData')) //疗程最大欠款比例
      this.list = this.list.filter(item=>item.projectNum)
      let courseLists = this.list.map(item=>{
        return {
          ...item,
          amount:item.amount.toFixed(2)*1,
          mobilePhone:this.form.mobilePhone,
          memberName:this.form.memberName,
          memberId:this.form.memberId,
          sex:this.form.sex,
          isDebt:item.debtMoney?1:0,
          isAddition:this.isAddition,
          collectionCashAmount:item.nowAmount.toFixed(2)*1,
          debtAmount:((item.amount * (sessionStorageData.debtRatio*1))/100).toFixed(2)*1
        }
      })
      var payLists = [];
      // 用作删除数组
      const auxiliaryArr = ['isShow','state','collectionType','id','collectionTypeName']
      for (let i =0;i<this.payLists.length;i++) {
        let params = {...this.payLists[i]}
        params.payId = this.payLists[i].id;
        params.payName = this.payLists[i].collectionTypeName;
        auxiliaryArr.forEach(item=>{
          delete params[item]
        })
        if (this.payLists[i].payMoney * 1 > 0) {
          payLists.push(params);
        }
      }
      let form = {
        ...val,
        payLists,
        courseLists
      }
      this.$confirm('是否发送短信?', '短信', {
          distinguishCancelAndClose: true,
          confirmButtonText: '是',
          cancelButtonText: '否'
        }).then(()=>{
          form.isSendSms = 1
          addcourse(form).then((res) => {
            this.loading = false;
            if (res.code == "000000") {
              this.empty();
              this.$message.success({
                message: res.message,
              });
              this.$refs.recordDetail.init()
            } else {
              this.$alert(res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {
                  this.saveloading = false;
                },
              });
              this.payLists.forEach(item=>{
                item.spendMoney = 0
              })
            }
            this.saveloading = false;
          });
        }).catch(()=>{
          form.isSendSms = 0
          addcourse(form).then((res) => {
            this.loading = false;
            if (res.code == "000000") {
              this.empty();
              this.$message.success({
                message: res.message,
              });
              this.$refs.recordDetail.init()
            } else {
              this.$alert(res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {
                  this.saveloading = false;
                },
              });
              this.payLists.forEach(item=>{
                item.spendMoney = 0
              })
            }
            this.saveloading = false;
          });
        })
    },
    //明细返回方法
    detailData(v) {
      this.getList();
    },
    selecData(v) {
      this.queryForm.storeList = v;
      this.getList();
    },
    //列表
    getList() {
      this.listDialogVisible = true;
      if (this.headOffice == 1) {
        this.$nextTick(() => {
          this.$refs.selec.show();
        });
      }
      this.queryForm.selectDate = this.formatTime(this.selectDate, "YYYY-MM");
      coursepage(this.queryForm).then((res) => {
        if (res.code == "000000") {
          res.pageInfo.list.forEach((item) => {
            item.rechargeConsumeList.forEach((items) => {
              items.cardOver = items.cardConsumeMoney + items.spendMoney;
              // items.giftConsumeMoney +
              items.cardOvers = items.cardConsumeMoney;
              //  + items.giftConsumeMoney;
            });
            item.entities.forEach((items) => {
              items.editStaffRatioShow = false;
            });
          });
          res.pageInfo.formList = res.pageInfo.list;
          this.pageInfo = res.pageInfo;
          this.total = res.pageInfo.total;
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    editStaff(row) {
      this.editStaffRatioRow = row;
    },

    //作废
    abolish(row) {
      this.$confirm("此操作将作废这张单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        cancelButtonClass: "cancelbtnFalses",
        confirmButtonClass: "confirmbtnFalses",
        type: "warning",
      })
        .then(() => {
          row.isCancel = 1;
          row.rechargeAccountList = row.rechargeConsumeList;
          delete row.payLists;
          delete row.entities;
          delete row.rechargeConsumeList;
          delete row.tag;
          row.rechargeAccountList.forEach((item) => {
            delete item.cardOver;
            delete item.cardOvers;
          });

          coursecancel(row).then((res) => {
            //console.log(res);
            if (row.code == "000000") {
              this.$message.success({
                message: res.message,
              });
              this.getList();
            } else {
              this.$message.success({
                message: res.message,
              });
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    //打印
    // 打印方法
    print(row) {
      row.telephone = JSON.parse(sessionStorage.getItem("storeInfo")).telephone;
      row.printDate = new Date();
      this.printForm = row;
      this.getDetail()
    },
    getDetail(){
        let params = {
          docId:this.printForm.courseReatmentNum,
          date:this.printForm.date
        }
        selectCourseOne(params).then(res=>{
            if(res.code == '000000'){
                this.printForm.rechargeConsumeList = res.data.rechargeConsumeList
                this.courseProjectLists = res.data.courseLists
                let list = []
                res.data.rechargeConsumeList.forEach(item=>{
                    let index = list.findIndex( items=>items.rechargeTypeName == item.rechargeTypeName  )
                    if( index == -1 ){
                        list.push(item)
                    }else{
                        list[index].spendMoney += item.spendMoney
                    }
                })
                list = list.filter(item=>item.spendMoney)
                this.payTypeLists = res.data.payLists.concat(list.map(item=>{return {payName:item.rechargeTypeName,payMoney:item.spendMoney }}))
            }
        })
       },
    propage() {
      var page = {
        pageNum: this.pageInfos.pageNum,
        pageSize: this.pageInfos.pageSize,
        state: 1,
        directConsumption: 0,
        // storeIds: JSON.parse(sessionStorage.getItem("storeIdLists")),
      };
      propage(page).then((res) => {
        if (res.code == "000000") {
          res.pageInfo.reatmentList = res.pageInfo.list;
          this.pageInfos = res.pageInfo;
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    //求和
    num(index) {
      var num = 0;
      this.list[index].payLists.forEach((item) => {
        num += item.payMoney * 1;
      });
      let cardNum = eval(this.list[index].rechargeAccountList.map(item=>{return item.spendMoney*1}).join("+")) //卡付总和
      this.list[index].collectionCashAmount = num.toFixed(2) * 1; //现金总和
      console.log(this.list[index].collectionCashAmount,this.list[index].debtMoney,this.list[index].integralCheckbox)
      if (this.list[index].integralCheckbox == true) {
        this.list[index].debtMoney =
          (
            this.list[index].amount * 1 -
            this.collectionRechargeAmounts * 1 -
            this.list[index].collectionCashAmount * 1 -
            this.list[index].collectionIntegralAmount * 1
          ).toFixed(2) * 1;
        this.list[index].courseReatmentAmount =
          (
            this.list[index].collectionCashAmount * 1 +
            this.collectionRechargeAmounts * 1 +
            this.list[index].collectionIntegralAmount * 1
          ).toFixed(2) * 1;

        this.list[index].debtMoney = this.list[index].debtMoney.toFixed(2) * 1;
      } else {
        this.list[index].debtMoney =
          (
            this.list[index].amount * 1 -
            cardNum * 1 -
            this.list[index].collectionCashAmount * 1
          ).toFixed(2) * 1;
        this.list[index].courseReatmentAmount =
          (
            this.list[index].collectionCashAmount * 1 +
            this.collectionRechargeAmounts * 1
          ).toFixed(2) * 1;
        this.list[index].debtMoney = this.list[index].debtMoney.toFixed(2) * 1;
      }
      if (
        this.list[index].debtMoney * 1 >
        (
          (this.list[index].amount * this.sessionStorageData.debtRatio * 1) /
          100
        ).toFixed(2) *
          1
      ) {
        this.$message.warning({
          message:
            "本次支付金额最多可以欠款 : " +
            (
              (this.list[index].amount * this.sessionStorageData.debtRatio * 1) /
              100
            ).toFixed(2) *
              1,
        });
      }
      this.list.push({})
      this.list.pop()
    },
    cardnum(index) {
      let spendMoney = 0;
      let discoutMoney = 0;
      this.list[index].rechargeAccountList.forEach((item) => {
        spendMoney += item.spendMoney * 1; //实付金额
        discoutMoney += item.discoutMoney * 1; //抵扣
      });
      if (this.sessionStorageData.buycourse == true) {
        this.list[index].collectionRechargeAmount = spendMoney;
        this.list[index].collectionRechargeAmounts = discoutMoney;
      } else {
        this.list[index].collectionRechargeAmount = spendMoney;
        this.list[index].collectionRechargeAmounts = spendMoney;
      }

      if (this.list[index].integralCheckbox == true) {
        this.list[index].courseReatmentAmount =
          (
            this.list[index].collectionCashAmount * 1 +
            this.list[index].collectionRechargeAmounts * 1 +
            this.list[index].collectionIntegralAmount * 1
          ).toFixed(2) * 1;
          this.list[index].debtMoney =
          (
            this.list[index].amount * 1 -
            this.list[index].collectionRechargeAmounts * 1 -
            this.list[index].collectionCashAmount * 1 -
            this.list[index].collectionIntegralAmount * 1
          ).toFixed(2) * 1;
      } else {
        this.list[index].courseReatmentAmount =
          (
            this.list[index].collectionCashAmount * 1 +
            this.list[index].collectionRechargeAmounts * 1
          ).toFixed(2) * 1;
          // this.list[index].debtMoney =
          // (
          //   this.list[index].amount * 1 -
          //   this.list[index].collectionRechargeAmounts * 1 -
          //   this.list[index].collectionCashAmount * 1
          // ).toFixed(2) * 1;
          this.list[index].debtMoney = this.list[index].amount * 1 -(this.selectTabAmount(this.list[index].rechargeAccountList,2) + this.list[index].nowAmount.toFixed(2)*1)
      }
      if (
        this.list[index].debtMoney * 1 >
        (
          (this.list[index].amount * this.sessionStorageData.debtRatio * 1) /
          100
        ).toFixed(2) *
          1
      ) {
        this.$message.warning({
          message:
            "本次支付金额最多可以欠款 : " +
            (
              (this.list[index].amount * this.sessionStorageData.debtRatio * 1) /
              100
            ).toFixed(2) *
              1,
        });
      }
      this.list.push({})
      this.list.pop()
    },

    ctlist() {
      var page = {
        pageNum: 1,
        pageSize: 50,
      };
      ctlist(page).then((res) => {
        var money = res.rows;
        money.forEach((item) => {
          item.payMoney = 0;
          item.isShow = false;
        });
        this.payLists = res.rows;
        this.propage();
      });
      var that = this;
      setTimeout(() => {
        that.$refs.staffsles.show(that.staffLists);
      }, 1000);
    },

    // 保留两位小数
    getDecimal(num) {
      //console.log(123);
      //判断是否有小数点
      var s = num.toString().indexOf(".");
      if (s == -1) {
        //是整数
        return (
          (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, "$1,") + ".00"
        );
      } else {
        //是小数
        var arr = num.toString().split(".");
        if (arr.length > 1 && arr[1].length < 2) {
          //一位小数
          return (
            (arr[0] || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, "$1,") +
            "." +
            arr[1] +
            "0"
          );
        } else {
          //两位小数
          return (
            (arr[0] || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, "$1,") +
            "." +
            arr[1]
          );
        }
      }
    },

    //分页方法
    handleSizeChange(val) {
      //   //console.log(`每页 ${val} 条`);

      this.queryForm.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      //   //console.log(`当前页: ${val}`);
      this.queryForm.pageNum = val;
      this.getList();
    },

    //指定列求和
    //数组按对应字段合计返回方法
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        if (column.property == "spendMoney") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              sums[index] = "--";
            }
          }, 0).toFixed(2);
          sums[index] += " ";
        } else if (column.property == "payMoney") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              sums[index] = "--";
            }
          }, 0);
          sums[index] += " ";
        } else {
          sums[index] = "--";
        }
      });
      return sums;
    },
    setPage() {
      this.ctlist();
      this.setStaffRatio();
      try{
        this.sessionStorageData = JSON.parse(
          sessionStorage.getItem("sessionStorageData")
        );
      }catch(err){
        this.sessionStorageData = {}
      }
    },
  },
  created() {
    this.setPage();
  },
};
</script>
<style scoped>
.print-project{
  width:100%
}
.project-top-del p:nth-child(1){
  width:110px;
}
.project-top-del p{
  display:inline-block;
  width:45px
}
.project-top p{
  display:inline-block;
  width:45px
}
.project-top p:nth-child(1){
  width:110px;
}
.font-w{
  display:inline-block;
}
.form-width-ms{
  width: 0.8rem !important;
  z-index: 999999999 !important;
}
.reatmen {
  background: white;
  overflow: hidden;
  padding-bottom: 50px;
  padding: 10px;
  padding: 10px;
  margin-left: 25px;
}

.reatmen .el-form-item {
  height: 40px;
}

.reatmen span {
  font-weight: 500;
}

.reatmen .spanr {
  width: 100px;
  display: inline-block;
}

.reatmen .sapns {
  width: 138px;
}

.reatmens .el-radio__label {
  display: none;
}

.jisuan {
  height: 38px;
  width: 100%;
  border-bottom: 1px solid #999999;
  position: relative;
  font-size: 14px;
  line-height: 35px;
  padding-left: 50px;
}

.jisuan span:nth-child(2) {
  margin-left: 180px;
}

.reatmen .el-table__row {
  height: 50px;
}

.reatmen .el-radio__label {
  display: none;
}

.propor {
  width: 350px;
  border-bottom: 1px solid #d8d8d8;
  padding-bottom: 10px;
}

.reatmen .numberinput .el-input__inner {
  width: 60px;
  height: 30px;
  padding: 0;
  border-color: #ff7788;
  display: inline-block;
}

.reatmen .el-dialog__body {
  padding: 20px 20px;
}
.reat{
  margin-top: 20px;
  display: flex;
  justify-content: space-around;
  overflow:auto
}
.right{
  margin-top: 15px;
  padding: 0 40px 10px 0;
  font-size: 12px;
  box-sizing: border-box;
  border: 1px solid #ccc;
  background: white;
  border-radius: 10px;
  width: 200px;
  margin-left: 35px;
  display: flex;
}
.spanrs {
  width: 160px;
}

.spanrs .el-date-editor {
  width: 150px;
}

.printDiv .el-form-item {
  margin-bottom: 0px;
}

.printDiv .el-form-item__label,
.el-form-item__content {
  font-size: 12px;
  color: black;
  font-family: "宋体";
  padding: 0 5px 0 0;
}
.printDiv {
  width: 280px;
  margin: 0 auto;
  /* font-size:12px; */
  /* font-family: "宋体"; */
  color:#000000
  /* color: black; */
}
.marginAuto{
  margin-right: 10px;
  width: 54%;
}
/deep/ .reatmen .el-form-item{
  height: 25% !important;
}
.tab{
  min-width: 20%;
}
</style>
