<template>
  <div>
    <div class="reatmen">
      <el-form :model="form" :inline="true" :label-width="formLabelwidth">
        <el-form-item label="手机号码:">
          <div class="form-width-ms">
            <el-input style="padding-left:0px;" ref="" oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" maxlength="11" v-model="form.mobilePhone" @blur="phone" @change="phone">
              <el-button size="mini" slot="append" icon="el-icon-search" @click="openMember"></el-button>
            </el-input>
          </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-else class="el-icon-female text-pink"></i></span>
            <span class="text-cyan pointer">
              <el-button size="mini" type="text" @click="openAddMember">添加会员</el-button>
            </span>
          </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" 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>
        <br />
        <el-form-item label="疗程编码:">
          <div class="form-width-ms flex ">
            <el-input placeholder="输入疗程编码" v-model="form.projectNum" @blur="proBlur" @change="proBlur">
              <el-button size="mini" slot="append" icon="el-icon-search" @click="openPro"></el-button>
            </el-input>
          </div>
        </el-form-item>
        <el-form-item label="疗程名称:">
          <div class="form-width-ms text-cut">
            <span>{{ form.projectName }}</span>
          </div>
        </el-form-item>
        <el-form-item label="单次标价:">
          <div class="form-width-xs">
            <span>{{ form.priceMember }}</span>
          </div>
        </el-form-item>
        <el-form-item label="成交单价:">
          <div class="form-width-ms pointer flex">
            <div v-if="!menberShow" @click="((menberShow = true))">
              {{ form.salesPrice }}
              <i class="el-icon-edit text-cyan"></i>
            </div>
            <el-input v-focus class="form-width-sm form-input-wdith-xs" v-else type="number" size="samll" oninput="this.value=this.value.replace(/\D*(\d*)(\.?)(\d{0,2})\d*/,'$1$2$3')" pattern="[0-9]*\.?[0-9]{0,2}" v-model="form.salesPrice" @change="changesales" @blur="changesales" ref="priceinput"></el-input>
            <span v-if="moneyRatio!=100" class="text-red padding-left-xs text-bold">{{moneyRatio}}%</span>
          </div>
        </el-form-item>
        <br />
        <el-form-item label="最少购买:">
          <div class="form-width-xs">
            <span>{{ form.minumumTimes }} (次)</span>
          </div>
        </el-form-item>
        <el-form-item label="购买次数:">
          <div class="form-width-xs pointer">
            <div v-if="!buysShow" @click="((buysShow = true))">
              {{ form.numberTimes }}
              <i class="el-icon-edit text-cyan"></i>
            </div>
            <el-input v-focus class="form-input-wdith" v-else size="samll" type="number" oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" v-model="form.numberTimes" @change="numbertimes" @blur="numbertimes" ref="buyinput"></el-input>
          </div>
        </el-form-item>
        <el-form-item label="成交金额:">
          <div class="form-width-xl">
            <span>{{ form.amount }}</span>
          </div>
        </el-form-item>
        <el-form-item label="待付金额:">
          <div class="form-width-xl padding-rigth-xs">
            <span>{{
              form.debtMoney >= 0
                ? form.debtMoney
                : "超出" + form.debtMoney * -1
            }}</span>
          </div>
        </el-form-item>
        <el-form-item label="实付金额:">
          <div class="text-red text-price">
            {{ form.courseReatmentAmount }}
          </div>
        </el-form-item><br />
        <el-form-item label v-show="sessionStorageData.course">
          <div style="width: 542px;padding-left:28px;">
            <el-checkbox style="display: inline-block" @change="changeIntegralCheckbox" v-model="form.integralCheckbox">
              使用积分| 总积分:{{ form.integral }}
            </el-checkbox>
            <div v-show="form.integralCheckbox" style="color: red; display: inline-block">
              | 可用积分:
              <span>{{ form.consumeIntegral }}</span>
              | 可兑换金额:<span class="text-price">{{ form.integralMoney }}</span>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="说明:" v-show="sessionStorageData.course">
        </el-form-item>
        <el-input v-show="sessionStorageData.course" style="width: 450px" v-model="form.description" type="textarea" placeholder="请输入说明" maxlength="200" :autosize="{ minRows: 1.5, maxRows: 2 }" show-word-limit></el-input>
        <el-form-item label="说明:" v-show="!sessionStorageData.course">
        </el-form-item>
        <el-input v-show="!sessionStorageData.course" class="border-radius-10" style="width: 845px" v-model="form.description" type="textarea" placeholder="请输入说明" maxlength="200" :autosize="{ minRows: 1.5, maxRows: 2 }" show-word-limit></el-input>
      </el-form>
      <div class="reat">
        <div class="margin-bottom-xs">
          <span class="margin-left padding-left" v-if="sessionStorageData.refillCard">卡付/</span><span>现付</span>
          <div class="flex justify-start align-start flex-wrap padding-top-xs margin-left padding-left">
            <div style="width:590px" class="border-radius-10 border margin-right-xs  bg-white padding-xs" v-if="sessionStorageData.refillCard">
              <el-table :data="rechargeAccountList" :summary-method="getSummaries" show-summary max-height="300">
                <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="offsetMoney" label="可抵扣额" width="90">
                  </el-table-column> -->
                <el-table-column align="center" prop="spendMoney" label="本次支付" width="90">
                  <template slot-scope="scope">
                    <div v-if="!scope.row.isShow" @click="openCard(scope.row, scope.$index)" class="form-input-width">
                      {{ scope.row.spendMoney }}
                      <i class="el-icon-edit text-cyan"></i>
                    </div>
                    <el-input v-focus type="number" class="form-input-width-xs" oninput="this.value=this.value.replace(/\D*(\d*)(\.?)(\d{0,2})\d*/,'$1$2$3')" pattern="[0-9]*\.?[0-9]{0,2}" @change="endEditCard(scope.row)" @blur="endEditCard(scope.row)" v-else v-model.lazy="scope.row.spendMoney" precision="2"></el-input>
                  </template>
                </el-table-column>
                <!-- <el-table-column align="center" prop="discoutMoney" label="抵扣支付" width="90">
                    <template slot-scope="scope">
											<div v-show="!scope.row.isShows" @click="disedit(scope.row,scope.$index)"
												style="padding:0 0px;cursor: pointer;width:80px">
												{{scope.row.discoutMoney}}
											</div>
											<input :ref="'indexs'+scope.$index"
												onkeyup="value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
												@blur="endEditCards(scope.row)" @keydown.enter="endEditCards(scope.row)"
												@change="endEditCards(scope.row)" v-show="scope.row.isShows"
												v-model="scope.row.discoutMoney" type="text"
												style="height:28px;width:60px" />
										</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>
              <div class="jisuan" v-show="false">
                <span>小计 :</span>
                <span style="padding-left: 60px">¥{{ form.collectionRechargeAmount }}</span>
                <span v-show="false">{{ collectionRechargeAmounts }}</span>
              </div>
            </div>
            <div style="width:280px" class="border-radius-10 border margin-right-xs  bg-white padding-xs">
              <el-table :data="payLists" :summary-method="getSummaries" show-summary>
                <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.$index)">{{ scope.row.payMoney }}<i class="el-icon-edit text-cyan"></i></div>
                    <el-input v-focus type="number" class="form-input-width-xs" oninput="this.value=this.value.replace(/\D*(\d*)(\.?)(\d{0,2})\d*/,'$1$2$3')" pattern="[0-9]*\.?[0-9]{0,2}" @change="endEdit(scope.row)" @blur="endEdit(scope.row)" v-else v-model.lazy="scope.row.payMoney" precision="2"></el-input>
                  </template>
                </el-table-column>
              </el-table>
              <div class="jisuan" v-show="false">
                <span>小计 :</span>
                <span style="padding-left: 60px">¥{{ form.collectionCashAmount }}</span>
              </div>
            </div>
          </div>
        </div>
        <span class="margin-left padding-left ">员工/门店管理层/高管业绩</span>
        <div class="flex justify-start align-start flex-wrap padding-top-xs margin-left padding-left">
          <staffsles ref="staffsles" @staffslesData="staffslesData"></staffsles>
          <admin ref="admin" @adminData="adminData"></admin>
          <manager ref="manager" @managerData="managerData"></manager>
        </div>
      </div>
      <div class="text-center padding-top" style="width:940px">
        <el-button size="mini" type="info" plain @click="empty">清空</el-button>
        <el-button size="mini" v-if="isAddition==0" type="primary" @click="isAddition = 1" v-role="5003002">补单</el-button>
        <el-button size="mini" v-else type="success" @click="isAddition = 0">疗程</el-button>
        <el-button size="mini" type="primary" plain @click="getList" v-role="5004001">列表</el-button>
        <el-button size="mini" type="primary" @click="save((saveloading = true))" :loading="saveloading" v-role="5004002">提交</el-button>
      </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" format="yyyy年 MM月" type="month" placeholder="选择日期"></el-date-picker>
            </div>
            <div class="flex">
              <div class="form-width-m padding-right-xs">
                <el-input size="medium" v-model="queryForm.courseReatmentNum" placeholder="输入单据号" clearable></el-input>
              </div>
              <div class="form-width-m padding-right-xs">
                <el-input size="medium" v-model="queryForm.memberName" placeholder="输入会员名字" clearable></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></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="tag" label="状态" min-width="65">
              <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" show-overflow-tooltip prop="courseReatmentNum" label="单号" min-width="120"></el-table-column>
            <el-table-column align="center" show-overflow-tooltip prop="date" label="日期" min-width="105"></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 | phone }}
              </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="50"></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"></el-table-column>
            <el-table-column align="center" prop="debtMoney" label="欠款" min-width="70"></el-table-column>
            <el-table-column align="center" prop="inputBy" label="录单人" min-width="70"></el-table-column>
            <!--<el-table-column align="center" fixed="right" label="账户操作" width="100" v-if="sessionStorageData.allowValid == 1">
              <template slot-scope="scope">
                <el-button @click.stop="openPostpone(scope.row, (postponeDialog = true))" :disabled="scope.row.isCancel === 1" size="mini" type="success">账户延期</el-button>
              </template>
            </el-table-column> -->
            <el-table-column align="center" fixed="right" label="操作" width="220">
              <template slot-scope="scope" fixed="right">
                <el-button size="mini" type="primary" @click="detail(scope.row)" plain>明细</el-button>
                <el-button @click.stop="abolish(scope.row)" size="mini" :disabled="scope.row.isCancel === 1" type="primary" v-role="5004003">作废</el-button>
                <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="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>
              <hr />
              <el-form :model="printForm" :inline="true">
                <el-form-item label="门店:">
                  <div>
                    {{ printForm.storeName }}
                  </div>
                </el-form-item>
                <el-form-item label="时间:">
                  {{ printForm.date }}
                </el-form-item>
                <el-form-item label="单号:">
                  {{ printForm.courseReatmentNum }}
                </el-form-item>
                <el-form-item label="会员:">
                  <div>
                    {{ printForm.memberName }}/{{ printForm.mobilePhone }}
                  </div>
                </el-form-item>
                <el-form-item label="疗程:">
                  <div style="min-width: 64px; display: inline-block">
                    {{ printForm.projectName }} <span class="text-cyan"></span>
                  </div>
                </el-form-item>
                <el-form-item label="成交:">
                  <div>{{ printForm.salesPrice }} * {{ printForm.numberTimes }} = {{ printForm.amount }}</div>
                </el-form-item>
                <el-form-item label="欠款:">
                  <div class="text-price">{{ printForm.debtMoney }}</div>
                </el-form-item>
                <br />
                <el-table v-if="printForm.collectionRechargeAmount!=0" :data="printForm.rechargeConsumeList" style="width: 180px;">
                  <el-table-column align="left" prop="rechargeTypeName" label="充值卡" min-width="100"></el-table-column>
                  <el-table-column align="center" prop="spendMoney" label="支付" width="40"></el-table-column>
                  <el-table-column align="center" prop="cardConsumeMoney" label="剩余" width="40"></el-table-column>
                </el-table>
                <el-table v-if="printForm.collectionCashAmount!=0" :data="printForm.payLists" style="width: 180px;">
                  <el-table-column align="left" prop="payName" label="付款方式" width="100"></el-table-column>
                  <el-table-column align="center" prop="payMoney" label="支付" width="80"></el-table-column>
                </el-table>
                <br />
                <!-- <el-form-item label="实付金额:">
                  <div>{{ printForm.collectionAmount }}</div>
                </el-form-item> -->
                <br />
                <br />
                <el-form-item label="签名:">
                  <!-- <div style="height:30px;width:150px;border-bottom:1px solid #333"> </div> -->
                </el-form-item><br />
                <el-form-item label="服务热线:">
                  {{ printForm.telephone }} </el-form-item><br />
                <el-form-item label="打印时间:">
                  {{ printForm.printDate | dateFormat }}
                </el-form-item>
                <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"></addmember>
    <member ref="member" @memberData="memberData"></member>
    <repayment ref="repayment" @repaymentData="phone"></repayment>
    <project ref="project" @projectData="proConfirm"></project>
    <detail ref="detail" @detailData="detailData"></detail>
  </div>
</template>
<script>
import {
  courseEditStaff,
  storeMemberOne,
  couAccountOne,
  recAccountList,
  checkCashWord,
  coursecancel,
  selectOne,
  coursepage,
  addcourse,
  ctlist,
  editCouAccount,
} from "@/api/eashier.js";
import { propage } from "@/api/storeManage";
import { partten } from "../../../../partten/index.js";
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";
export default {
  components: {
    staffsles,
    manager,
    admin,
    member,
    repayment,
    staff,
    addmember,
    project,
    detail,
  },
  inject: ["reload"],
  data() {
    return {
      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: "80px",
      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,
      },
      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: {
        //组件限制方法
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  methods: {
    close() {
      this.listDialogVisible = false;
      this.openCollNumber = 0;
    },

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

    //员工占比返回方法
    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.phone();
    },
    //选中员工返回方法
    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);
        }
      }
    },

    //检查手机号是否是平台会员
    phone() {
      var number = partten.phoneNum;
      if (!number.test(this.form.mobilePhone)) {
        this.$message.info({
          message: "请输入正确的手机号 ! ",
        });
      } else {
        storeMemberOne({
          mobilePhone: this.form.mobilePhone,
          storeId: sessionStorage.getItem("parentId"),
        }).then((res) => {
          //console.log(res);
          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.giftConsumeMoney;
                  item.cardOvers = item.cardConsumeMoney;
                  //  + item.giftConsumeMoney;
                  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;
                      // item.giftConsumeMoney +
                    }
                  } else {
                    item.offsetMoney = item.cardConsumeMoney;
                    // item.giftConsumeMoney +
                  }
                  rechargeAccountList.push(item);
                });
                this.rechargeAccountList = rechargeAccountList;
              } 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) {
        console.log(this.form);
        if (
          this.form.salesPric > 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;
          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;
        }
      } else {
        this.menberShow = false;
      }
    },
    //修改购买次数
    numbertimes() {
      if (this.form.numberTimes < this.proForm.minumumTimes) {
        this.$message.info({
          message: "最低购买不能少于" + this.proForm.minumumTimes + "次",
        });
        this.form.numberTimes = this.proForm.minumumTimes;
        this.buysShow = false;
      } else {
        this.buysShow = false;
        this.form.amount =
          ((this.form.salesPrice * 100 * this.form.numberTimes) / 100).toFixed(
            2
          ) * 1;
        this.form.debtMoney = this.form.amount;
      }
    },
    //选择金额.
    openpay(row, $index) {
      if (this.form.salesPrice != "") {
        //console.log(this.form);
        if (this.form.integralCheckbox == true) {
          row.payMoney =
            (
              this.form.amount -
              this.form.collectionCashAmount -
              this.collectionRechargeAmounts -
              this.form.integralMoney
            ).toFixed(2) * 1;
        } else {
          row.payMoney =
            (
              this.form.amount -
              this.form.collectionCashAmount -
              this.collectionRechargeAmounts
            ).toFixed(2) * 1;
        }
        if (row.payMoney < 0) {
          row.payMoney = 0;
        }
        row.payMoney = row.payMoney.toFixed(2) * 1;
        row.isShow = true;
      } else {
        this.$message.info({
          message: "请先选择疗程 !",
        });
      }
    },

    endEdit(row) {
      //console.log(row);
      row.payMoney = (row.payMoney * 1).toFixed(2) * 1;
      row.isShow = false;
      this.num();
      if (this.form.integralCheckbox == true) {
        this.form.courseReatmentAmount =
          (
            this.form.collectionCashAmount * 1 +
            this.collectionRechargeAmounts * 1 +
            this.form.integralMoney * 1
          ).toFixed(2) * 1;
      } else {
        this.form.courseReatmentAmount =
          (
            this.form.collectionCashAmount * 1 +
            this.collectionRechargeAmounts * 1
          ).toFixed(2) * 1;
      }
    },

    //返回当前行的下标
    tableRowClassName({ row, rowIndex }) {
      row.index = rowIndex;
    },
    proBlur() {
      this.form.projectNum;
      let form = {
        pageSize: 999,
        projectNum: this.form.projectNum,
        state: 1,
        directConsumption: 0,
      };
      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() {
      this.$refs.project.show(0);
    },
    //购买类型确定
    proConfirm(pros) {
      console.log(pros);
      this.proForm = pros;
      if (this.form.memberId) {
        this.form.projectName = this.proForm.projectName;
        this.form.projectNum = this.proForm.projectNum;
        this.form.projctId = this.proForm.id;
        this.form.price = this.proForm.price;
        this.form.topPrice = this.proForm.topPrice;
        this.form.topPriceMember = this.proForm.topPriceMember;
        this.form.priceMember = this.proForm.priceMember;
        this.form.minumumPriceMember = this.proForm.minumumPriceMember;
        this.form.salesPrice = this.proForm.priceMember;
        this.form.minumumPrice = this.proForm.minumumPrice;
        this.form.salesAchievement = this.proForm.salesAchievement;
        this.form.salesCommission = this.proForm.salesCommission;
        this.form.cardSalesAchievement = this.proForm.cardSalesAchievement;
        this.form.cardSalesCommission = this.proForm.cardSalesCommission;
        this.form.minumumTimes = this.proForm.minumumTimes;
        this.form.numberTimes = this.proForm.minumumTimes;
        this.form.amount =
          ((this.form.salesPrice * 100 * this.form.numberTimes) / 100).toFixed(
            2
          ) * 1;
        this.form.debtMoney = this.form.amount;
        if (this.form.integralCheckbox == true) {
          if (
            JSON.parse(sessionStorage.getItem("sessionStorageData"))
              .excIntegralByMoney
          ) {
            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.debtMoney = 0;
          } else {
            this.form.debtMoney = this.form.amount - this.form.integralMoney;
          }
          this.form.collectionIntegralAmount = this.form.integralMoney;
        } else {
          this.form.debtMoney = this.form.amount;
          this.form.collectionIntegralAmount = 0;
        }
        this.form.collectionCashAmount = 0;
        this.form.collectionRechargeAmount = 0;
        this.form.courseReatmentAmount =
          this.form.collectionCashAmount +
          this.collectionRechargeAmounts +
          this.form.collectionIntegralAmount;
      }
    },
    openCard(row, $index) {
      if (this.sessionStorageData.buycourse == true) {
        if (this.form.debtMoney * 1 > 0) {
          if (
            row.cardOver >=
            ((row.discoutMoney * row.discount) / 100).toFixed(2) * 1
          ) {
            row.discoutMoney = this.form.debtMoney * 1;
            row.spendMoney =
              ((row.discoutMoney * row.discount) / 100).toFixed(2) * 1;
          } else {
            row.discoutMoney =
              (row.cardOver / (row.discount / 100).toFixed(2)) * 1;
            row.spendMoney = row.cardOver;
          }
        } else {
          row.spendMoney = 0;
        }
      } else {
        if (this.form.debtMoney * 1 > 0) {
          if (row.cardOver < this.form.debtMoney * 1) {
            row.spendMoney = row.cardOver;
            row.discoutMoney = row.cardOver;
          } else {
            row.discoutMoney = this.form.debtMoney * 1;
            row.spendMoney = this.form.debtMoney * 1;
          }
        } else {
          row.spendMoney = 0;
        }
      }
      if (this.form.salesPrice != "") {
        row.isShow = true;
      } else {
        this.$message.info({
          message: "请先选择疗程!",
        });
      }
    },
    endEditCard(row) {
      row.spendMoney = (row.spendMoney * 1).toFixed(2) * 1;
      if (row.spendMoney == "") {
        row.spendMoney = 0;
      }
      if (row.spendMoney * 1 > row.cardOver * 1) {
        this.$message.info({
          message: "支付金额不能大于可用金额!",
        });
      } 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.cardOver * 1 - row.spendMoney * 1).toFixed(2) * 1;
          } else {
            row.discoutMoney = 0;
            row.cardOvers =
              (row.cardOver * 1 - row.spendMoney * 1).toFixed(2) * 1;
          }
        } else {
          if (row.spendMoney * 1 > 0) {
            row.discoutMoney = row.spendMoney.toFixed(2) * 1;
            row.cardOvers =
              (row.cardOver * 1 - row.spendMoney * 1).toFixed(2) * 1;
          } else {
            row.discoutMoney = 0;
            row.cardOvers =
              (row.cardOver * 1 - row.spendMoney * 1).toFixed(2) * 1;
          }
        }
      }
      this.cardnum();
    },
    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) {
      //console.log(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.form.isAddition = this.isAddition;
      var staffLists = [];
      this.staffLists.forEach((item) => {
        delete item.ratioShow;
        if (item.id) {
          staffLists.push(item);
        }
      });

      var payLists = [];
      var rechargeAccountList = [];
      for (let i in this.payLists) {
        this.payLists[i].payId = this.payLists[i].id;
        this.payLists[i].payName = this.payLists[i].collectionTypeName;
        delete this.payLists[i].isShow;
        delete this.payLists[i].state;
        delete this.payLists[i].collectionType;
        delete this.payLists[i].id;
        delete this.payLists[i].collectionTypeName;
        if (this.payLists[i].payMoney * 1 > 0) {
          payLists.push(this.payLists[i]);
        }
      }
      for (let i in this.rechargeAccountList) {
        if (this.rechargeAccountList[i].spendMoney * 1 > 0) {
          delete this.rechargeAccountList[i].cardOver;
          delete this.rechargeAccountList[i].isShow;
          delete this.rechargeAccountList[i].isShows;
          delete this.rechargeAccountList[i].cardOvers;
          delete this.rechargeAccountList[i].offsetMoney;
          delete this.rechargeAccountList[i].card;
          rechargeAccountList.push(this.rechargeAccountList[i]);
        }
      }

      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);
        }
      });
      this.form.salesmens = salesmens;
      this.form.payLists = payLists;
      this.form.staffLists = staffLists;
      this.form.rechargeAccountList = rechargeAccountList;
      if (this.sessionStorageData.buycourse == true) {
        if (this.form.payLists.length == 0) {
          if (
            this.form.debtMoney >=
            this.sessionStorageData.balance * 1 + 0.01
          ) {
            this.form.isDebt = 1;
          } else {
            this.form.isDebt = 0;
            this.form.debtMoney = 0;
          }
        } else {
          if (this.form.debtMoney > 0) {
            this.form.isDebt = 1;
          } else {
            this.form.isDebt = 0;
          }
        }
      } else {
        if (this.form.debtMoney > 0) {
          this.form.isDebt = 1;
        } else {
          this.form.isDebt = 0;
        }
      }
      if (this.form.debtMoney < 0) {
        this.form.debtMoney = 0;
      }
      if (this.form.integralCheckbox == false) {
        this.form.integral = 0;
        this.form.collectionIntegralAmount = 0;
      } else {
        this.form.integral = this.form.consumeIntegral;
        this.form.collectionIntegralAmount = this.form.integralMoney;
      }
      this.form.courseReatmentAmount =
        (
          this.form.collectionCashAmount +
          this.collectionRechargeAmounts +
          this.form.collectionIntegralAmount
        ).toFixed(2) * 1;

      this.form.courseReatmentAmount = this.form.courseReatmentAmount * 1;
      this.form.numberTimes = this.form.numberTimes * 1;
      var that = this;
      if (staffLists.length == 0) {
        this.$confirm("没有选择员工是否保存?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          cancelButtonClass: "cancelbtnFalses",
          confirmButtonClass: "confirmbtnFalses",
          type: "warning",
        }).then(() => {
          that.addCourse();
        });
      } else {
        that.addCourse();
        that.loading = false;
      }
      setTimeout(() => {
        this.loading = false;
      }, 3000);
    },
    addCourse() {
      setTimeout(() => {
        this.loading = false;
      }, 3000);
      addcourse(this.form).then((res) => {
        this.loading = false;
        if (res.code == "000000") {
          this.empty();
          this.$message.success({
            message: res.message,
          });
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {
              this.saveloading = false;
            },
          });
        }
        this.saveloading = false;
      });
    },
    //明细返回方法
    detailData(v) {
      this.getList();
    },
    //列表
    getList() {
      this.queryForm.selectDate = this.formatTime(this.selectDate, "YYYYMM");
      this.listDialogVisible = true;
      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;
    },
    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() {
      var num = 0;
      this.payLists.forEach((item) => {
        num += item.payMoney * 100;
      });
      this.form.collectionCashAmount = (num / 100).toFixed(2) * 1;
      if (this.form.integralCheckbox == true) {
        this.form.debtMoney =
          (
            this.form.amount * 1 -
            this.collectionRechargeAmounts * 1 -
            this.form.collectionCashAmount * 1 -
            this.form.collectionIntegralAmount * 1
          ).toFixed(2) * 1;
        this.form.courseReatmentAmount =
          (
            this.form.collectionCashAmount * 1 +
            this.collectionRechargeAmounts * 1 +
            this.form.collectionIntegralAmount * 1
          ).toFixed(2) * 1;

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

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

    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);
          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();
      this.sessionStorageData = JSON.parse(
        sessionStorage.getItem("sessionStorageData")
      );
    },
  },
  created() {
    this.setPage();
  },
};
</script>
<style scoped>
.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;
}

.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: 180px;
  margin: 0 auto;
}
</style>
