<template>
  <div>
    <el-form inline lable-width="100px" :modal="memberForm">
      <el-form-item label="手机号码:">
        <div class="form-width text-cyan flex justify-start align-center">
          <el-input maxlength="11" v-model="memberForm.mobilePhone" @change="inputMember" @blur="inputMember">
            <el-button size="mini" slot="append" maxlength="11" 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="cashNumber == 1 ? '会员名字' : '散客名字'">
        <div class="form-width-sm text-cyan">
          <el-input v-model="memberForm.memberName">
            <el-button title="切换" size="mini" slot="append" icon="el-icon-sort" @click="changeMember()"></el-button>
          </el-input>
        </div>
      </el-form-item>
      <el-form-item label="性别">
        <div class="text-bold flex justify-start align-center text-xss">
          男: <el-input class="form-width-xss" v-model="memberForm.man" type="number"></el-input>
          女: <el-input class="form-width-xss" v-model="memberForm.woman" type="number"></el-input>
        </div>
      </el-form-item>
      <el-form-item label="会员积分" v-if="cashNumber == 1 && memberForm.integral > 0 && memberIntegral">
        <div class="text-cyan">
          {{ memberForm.integral }}
        </div>
      </el-form-item>
      <el-form-item label="以往欠款" v-if="cashNumber == 1 && memberForm.debtMoney > 0">
        <div class="form-width-sm text-red text-price ">
          {{ memberForm.debtMoney }}
          <el-button type="text" @click="goPayDebt">去还款</el-button>
        </div>
      </el-form-item>
      <el-popover placement="bottom" width="800" trigger="hover" v-if="cashNumber == 1">
        <reccard ref="reccard" @reccardData="reccardData"></reccard>
        <el-button slot="reference">充值卡</el-button>
      </el-popover>
      <el-popover placement="bottom" width="700" trigger="hover" v-if="cashNumber == 1">
        <course ref="course" @courseData="courseData"></course>
        <el-button slot="reference">项目包</el-button>
      </el-popover>
      <el-form-item label="补单日期:" v-if="isAddition == 1">
        <div class="activeFormDiv">
          <el-date-picker v-model="additionDate" type="date" :picker-options="pickerOptions" format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </div>
      </el-form-item>
    </el-form>
    <div class="flex justify-start align-start ">
      <div class="into-table-width">
        <el-table style="margin-top:3px;" :data="list" max-height="650" ref="list" @row-click="rowClick"
          :row-class-name="rowClassName" :row-key='getRowKeys' @expand-change="expandSelect" :expand-row-keys="expand"
          row-key="index" stripe
          :header-cell-style="{ background: 'linear-gradient(#6cb3ff, #1873d4)', color: '#eeeeee', }">
          <el-table-column type="expand">
            <template slot-scope="scope">
              <div class="flex justify-start align-center  flex-wrap ">
                <el-form inline class="margin-top-xs margin-left-xs">
                  <el-form-item label='美发师'>
                    <div class="flex align-center form-width-m">
                      <el-select filterable default-first-option clearable @clear="clear(scope.row, 'zhonggongList')"
                        v-model="scope.row.zhonggongLists" placeholder="请选择"
                        @change="handleChange($event, scope.row, 'zhonggongList')">
                        <el-option v-for="(item, index) in options" :key="index" :label="item.label" :value="item.id">
                        </el-option>
                      </el-select>
                      <!-- <div class="el-icon-circle-close text-xs text-cyan" @click.stop="scope.row.zhonggongLists=null,scope.row.zhonggongList.splice(0,1)"></div> -->
                      <div class="el-icon-edit-outline text-xs text-cyan"
                        @click.stop="openStaffRatio(scope.row, scope.$index, 'zhonggongList')"></div>
                    </div>
                  </el-form-item>
                  <el-form-item label='美容师'>
                    <div class="flex align-center form-width-m">
                      <el-select filterable default-first-option clearable @clear="clear(scope.row, 'largeList')"
                        v-model="scope.row.largeLists" placeholder="请选择"
                        @change="handleChange($event, scope.row, 'largeList')">
                        <el-option v-for="(item, index) in options" :key="index" :label="item.label" :value="item.id">
                        </el-option>
                      </el-select>
                      <!-- <div class="el-icon-circle-close text-xs text-cyan" @click.stop="scope.row.largeLists=null,scope.row.largeList.splice(0,1)"></div> -->
                      <div class="el-icon-edit-outline text-xs text-cyan"
                        @click.stop="openStaffRatio(scope.row, scope.$index, 'largeList')"></div>
                    </div>
                  </el-form-item>
                  <el-form-item label='技师'>
                    <div class="flex align-center form-width-m">
                      <el-select filterable default-first-option clearable @clear="clear(scope.row, 'technicianLists')"
                        v-model="scope.row.technicianLists" placeholder="请选择"
                        @change="handleChange($event, scope.row, 'technicianList')">
                        <el-option v-for="(item, index) in options" :key="index" :label="item.label" :value="item.id">
                        </el-option>
                      </el-select>
                      <!-- <div class="el-icon-circle-close text-xs text-cyan" @click.stop="scope.row.technicianLists=null,scope.row.technicianList.splice(0,1)"></div> -->
                      <div class="el-icon-edit-outline text-xs text-cyan"
                        @click.stop="openStaffRatio(scope.row, scope.$index, 'technicianList')"></div>
                    </div>
                  </el-form-item>
                  <el-form-item label='助理'>
                    <div class="flex align-center form-width-m">
                      <el-select filterable default-first-option clearable @clear="clear(scope.row, 'smallLists')"
                        v-model="scope.row.smallLists" placeholder="请选择"
                        @change="handleChange($event, scope.row, 'smallList')">
                        <el-option v-for="(item, index) in options" :key="index" :label="item.label" :value="item.id">
                        </el-option>
                      </el-select>
                      <!-- <div class="el-icon-circle-close text-xs text-cyan" @click.stop="scope.row.smallLists=null,scope.row.smallList.splice(0,1)"></div> -->
                      <div class="el-icon-edit-outline text-xs text-cyan"
                        @click.stop="openStaffRatio(scope.row, scope.$index, 'smallList')"></div>
                    </div>
                  </el-form-item>
                  <el-form-item label='高管'>
                    <div class="flex align-center form-width-m">
                      <el-select filterable default-first-option clearable @clear="clear(scope.row, 'managerLists')"
                        v-model="scope.row.managerLists" placeholder="请选择"
                        @change="handleChange($event, scope.row, 'managerList')">
                        <el-option v-for="(item, index) in managerOptions" :key="index" :label="item.label"
                          :value="item.id">
                        </el-option>
                      </el-select>
                      <!-- <div class="el-icon-circle-close text-xs text-cyan" @click.stop="scope.row.managerLists=null,scope.row.managerList.splice(0,1)"></div> -->
                      <div class="el-icon-edit-outline text-xs text-cyan"
                        @click.stop="openStaffRatio(scope.row, scope.$index, 'managerList')"></div>
                    </div>
                  </el-form-item>
                  <el-form-item label='管理层'>
                    <div class="flex align-center form-width-m">
                      <el-select filterable default-first-option clearable @clear="clear(scope.row, 'adminLists')"
                        v-model="scope.row.adminLists" placeholder="请选择"
                        @change="handleChange($event, scope.row, 'adminList')">
                        <el-option v-for="(item, index) in adminOptions" :key="index" :label="item.label"
                          :value="item.id">
                        </el-option>
                      </el-select>
                      <!-- <div class="el-icon-circle-close text-xs text-cyan" @click.stop="scope.row.adminLists=null,scope.row.adminList.splice(0,1)"></div> -->
                      <div class="el-icon-edit-outline text-xs text-cyan"
                        @click.stop="openStaffRatio(scope.row, scope.$index, 'adminList')"></div>
                    </div>
                  </el-form-item>
                  <br>
                </el-form>
              </div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="140" align="center" label="项目选项">
            <template slot-scope="scope">
              <div class="flex justify-between align-center" @click.stop="">
                <el-input v-model="scope.row.projectNum" placeholder="编码"
                  @blur="proBlur(scope.row, proIndex = scope.$index)"
                  @change="proBlur(scope.row, proIndex = scope.$index)">
                  <el-button title="门店项目" size="mini" slot="append" icon="el-icon-tickets"
                    @click.stop="openPro(proIndex = 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="noDiscount" label="卡付打折" width="50">
            <template slot-scope="scope">{{
                scope.row.noDiscount == 0 ? "是" : scope.row.noDiscount == 1 ? '否' : "未设"
            }}</template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="80" align="center" prop="transactionPrice" label="项目金额">
            <template slot-scope="scope">
              <div @click.stop="transactionPrice = scope.row.transactionPrice" v-if="scope.row.courseAccountId == null">
                <el-input @focus="transactionPrice = scope.row.transactionPrice" type="number"
                  v-model="scope.row.transactionPrice" @blur="endEditMoney(scope.row)" placeholder="¥"></el-input>
              </div>
              <div v-else>{{ scope.row.transactionPrice }}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="80" align="center" prop="" label="支付类型">
            <template slot-scope="scope">
              <div>{{ scope.row.courseAccountId != null ? '疗程付' : '卡付/现付' }}</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="120" align="center" prop="" label="充值卡付">
            <template slot-scope="props">
              <div @click.stop="" v-if="props.row.isCardPay == 0">
                <el-popover placement="bottom" width="900" @show="openRec(props.row)">
                  <div v-if="props.row.courseAccountId == null">
                    <el-table class=" border" v-if="props.row.cashNumber == 1" style="max-width:900px"
                      :data="rowRecList" :summary-method="getSummaries" show-summary max-height="400"
                      :header-cell-style="{ background: 'linear-gradient(#6cb3ff, #1873d4)', color: '#eeeeee' }">
                      <el-table-column align="center" prop="rechargeTypeName" show-overflow-tooltip label="卡付名称"
                        width="110"></el-table-column>
                      <el-table-column align="center" label="类别" width="60">
                        <template slot-scope="scope">
                          <span v-if="scope.row.type == 1">折扣卡</span>
                          <span v-if="scope.row.type == 0">赠送卡</span>
                          <span v-if="scope.row.type == 2">活动卡</span>
                        </template>
                      </el-table-column>
                      <el-table-column align="center" prop="cardOver" label="可用金额" width="70"></el-table-column>
                      <el-table-column show-overflow-tooltip min-width="70" align="center" prop="discount"
                        label="折扣(%)"></el-table-column>
                      <!-- <el-table-column align="center" prop="offsetMoney" label="可抵扣额" width="100"></el-table-column> -->
                      <el-table-column align="center" prop="spendMoney" label="本次支付" width="90">
                        <template slot-scope="scope">
                          <div class="form-input-width" v-if="recIndex != scope.$index"
                            @click="editcard(scope.row, scope.$index)">
                            {{ scope.row.spendMoney }}
                            <i class="text-cyan el-icon-edit"></i>
                          </div>
                          <el-input v-else v-focus type="number" size="samll" class="form-input-width"
                            @blur="endEditcard(scope.row, scope.$index)" v-model="scope.row.spendMoney"></el-input>
                        </template>
                      </el-table-column>
                      <!-- <el-table-column align="center" prop="discoutMoney" label="抵扣支付" width="100"></el-table-column> -->
                      <el-table-column align="center" prop="cardOvers" label="可用余额" width="70"></el-table-column>
                      <el-table-column align="center" prop="giftConsumeMoney" label="赠送可用" width="70"></el-table-column>
                      <el-table-column show-overflow-tooltip min-width="70" align="center" prop="discountFreeAmount"
                        label="折扣(%)"></el-table-column>
                      <el-table-column align="center" prop="giftSpendMoney" label="赠送支付" width="70"></el-table-column>
                      <el-table-column align="center" prop="cardGiftOvers" label="赠送剩余" width="70"></el-table-column>
                      <el-table-column align="center" prop="storeName" label="所属门店" width="110" show-overflow-tooltip>
                      </el-table-column>
                    </el-table>
                  </div>
                  <!-- <recash ref="recash" @recashData="recashData"></recash> -->
                  <el-button slot="reference" @click="selectindex(props.row)">充值卡</el-button>
                </el-popover>
              </div>
              <div v-else>不允许卡付</div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="collectionAmounts" label="卡付抵扣金额">
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="75" align="center" prop="collectionRechargeAmount"
            label="卡付金额"></el-table-column>
          <!-- <el-table-column show-overflow-tooltip min-width="75" align="center" prop="collectionCashAmount" label="现付金额">
          </el-table-column> -->
          <el-table-column show-overflow-tooltip width="75" align="center" prop="sex" label="性别">
            <template slot-scope="scope">
              <el-select v-model="scope.row.sex" placeholder="">
                <el-option label="男" :value="0"></el-option>
                <el-option label="女" :value="1"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="120" align="center" prop="remark" label="备注">
            <template slot-scope="scope">
              <div @click.stop="">
                <el-input v-model="scope.row.remark"></el-input>
              </div>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="120" align="center" prop="storeName" label="所属门店">
          </el-table-column>
          <el-table-column width="80" align="center" label="操作">
            <!-- fixed="right" -->
            <template slot-scope="scope">
              <el-button :disabled="scope.row.editNumber == 1" icon="el-icon-delete" circle size="mini" type="primary"
                @click.stop="delPro(scope.row)"></el-button>

            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="border-radius-10 border margin-left-xs  bg-white padding-xs" style="margin-right:2%">
        <div class="flex justify-center align-center text-bold padding-bottom-xs">
          <div class="form-width-m ">
            <span class=" ">总付金额:</span>
            <span class="text-red text-price">
              {{ form.cashAmount }}
            </span>
          </div>
          <div class="form-width-m">
            <span class=" ">现付金额:</span>
            <span class="text-red text-price">
              {{ form.collectionCashAmounts }}
            </span>
          </div>
        </div>
        <payment ref="payment" @paymentData="paymentData"></payment>
      </div>
    </div>
    <member ref="member" @memberData="memberData"></member>
    <staffratio ref="staffratio" @staffratioData="staffratioData"></staffratio>
    <passcode ref="passcode" @passcodeData="passcodeData"></passcode>
    <project ref="project" @projectData="projectData"></project>
    <div class="flex justify-start padding-right padding-top">
      <div class="into-table-width flex justify-center" style="height:45px">
        <el-button size="samll" icon="el-icon-add" type="primary" @click="addPro">添加项目</el-button>
        <el-button size="samll" type="primary" plain @click="openList">收银列表</el-button>
        <el-button size="samll" type="primary" plain @click="goBack">{{ isAddition == 1 ? '收银' : '补单' }}</el-button>
        <el-button size="samll" type="primary" plain @click="notData">清空页面</el-button>
        <div class="padding-left padding-right"></div>
        <el-button size="samll" type="primary" @click="confirm()">确认收银</el-button>
      </div>
      <div></div>
    </div>
    <repayment ref="repayment" @repaymentData="inputMember"></repayment>
    <addmember ref="addmember"></addmember>
    <orders ref="orders"></orders>
  </div>
</template>
<script>
import addmember from "@/components/member/edit/index";
import {
  selectList,
  selectListType,
  storeMemberOne,
  ctlist,
  cashdoCash,
  couAccountList,
  proOne,
  addCash,
  recAccountCashList,
  QuerCompetent,
} from "@/api/eashier.js";
import member from "@/components/member/index";
import project from "@/components/project/index";
import repayment from "@/components/repayment/index";
import reccard from "./reccard";
import course from "./course";
import payment from "./payment";
import staffratio from "./staffratio";
import passcode from "./passcode";
import { propage } from "@/api/storeManage.js";
import recash from "./recash";
import orders from "./detail/detail";
import { partten } from "@/utils/partten/index.js";
export default {
  components: {
    member,
    reccard,
    course,
    payment,
    staffratio,
    passcode,
    project,
    addmember,
    repayment,
    recash,
    orders,
  },
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      useRecharge:
        JSON.parse(sessionStorage.getItem("sessionStorageData")).useRecharge *
        1,
      balance:
        JSON.parse(sessionStorage.getItem("sessionStorageData")).balance * 1 +
        0.01,
      memberIntegral: JSON.parse(sessionStorage.getItem("sessionStorageData"))
        .memberIntegral,
      debtMoneys: 0,
      list: [], //主数组
      listCopy: [],
      rowList: [],
      form: {
        collectionCashAmount: 0,
        collectionCashAmounts: 0,
        cashAmount: 0,
        debtMoney: 0,
      },
      recListCopy: [], //当前会员的最初充值卡包
      recForm: {},
      projectList: [],
      memberForm: {}, //会员对象
      notMemberForm: {},
      expand: [],
      expandedRows: [],
      payLists: [], //现付列表
      rechargeAccountList: [], //卡付列表
      editIndex: -1,
      loading: false,
      formData: new FormData(),
      cashNumber: -1,
      rowIndex: -1,
      proIndex: -1,
      editProIndex: -1,
      isAddition: 0,
      additionDate: null,
      transactionPrice: null,
      options: [], //员工下拉选择列表
      adminOptions: [], //管理员下拉选择列表
      managerOptions: [], //高管下拉选择列表
      recIndex: -1,
      recGiftIndex: -1,
      rowRecList: [],
      copyPayList: [],
      routeNumber: null,
    };
  },
  methods: {
    selectindex(row) {
      console.log(row)
    },
    changeMember() {
      if (this.cashNumber == 1) {
        Object.assign(this.$data, this.$options.data.call(this));
        this.cashNumber = 0;
      } else {
        Object.assign(this.$data, this.$options.data.call(this));
        this.cashNumber = 1;
      }
    },
    openList() {
      this.$refs.orders.show();
    },

    clear(row, text) {
      //console.log(text);
      let form = { ...row };
      form[text] = [];
      //console.log(form);
      this.list.splice(row.index, 1, form);
    },
    //修改卡付金额
    editcard(row, index) {
      this.recIndex = index;
      console.log(index)
    },
    endEditcard(row, index) {
      console.log(index)
      let debtMoney =
        (this.recForm.amount * 1 - this.recForm.cashAmount * 1).toFixed(2) * 1;
        console.log(this.recForm)
      let form = { ...row };
      console.log(form)
      //console.log(debtMoney);//套餐价格
      if (debtMoney > 0) {
        if (form.type == 2 || form.type == 0) {
          if (this.useRecharge == 2) {
            //先用充值再用赠送
            if (this.recForm.noDiscount == 0) {
              if (form.offsetMoney > debtMoney) {
                form.spendMoney =
                  ((debtMoney * form.discount) / 100).toFixed(2) * 1;
              } else {
                form.spendMoney = form.cardOver;
                form.discoutMoney =
                  (form.cardOver * (form.discount / 100)).toFixed(2) * 1;

                form.giftSpendMoney =
                  (
                    (debtMoney - form.discoutMoney) *
                    (form.discountFreeAmount / 100)
                  ).toFixed(2) * 1;
                form.discoutGiftMoney =
                  (debtMoney - form.discoutMoney).toFixed(2) * 1;
              }
            } else {
              if (form.offsetMoney > debtMoney) {
                form.spendMoney = debtMoney;
              } else {
                form.spendMoney = form.cardOver;
                form.discoutMoney = form.cardOver.toFixed(2) * 1;
                form.giftSpendMoney =
                  (debtMoney - form.discoutMoney).toFixed(2) * 1;
                form.discoutGiftMoney =
                  (debtMoney - form.discoutMoney).toFixed(2) * 1;
              }
            }
          } else {
            //按比例使用
            let sunRatio =
              (form.cardRestMoney + form.cardGiftOvers).toFixed(2) * 1;///可用余额+赠送余额
            let recRatio = (form.cardRestMoney / sunRatio).toFixed(2) * 1;//可用余额比例
            let recGiftRatio = (form.cardGiftOvers / sunRatio).toFixed(2) * 1;//赠送余额比例
            if (form.offsetMoney > debtMoney * recRatio) {//
              if (this.recForm.noDiscount == 0) {
                form.discoutMoney =//充值卡支付的钱
                  ((form.spendMoney * 1) / (form.discount / 100)).toFixed(2) * 1;
                form.giftSpendMoney = ((form.spendMoney * 1) / recRatio * recGiftRatio).toFixed(2) * 1;
                console.log("这个是赠送金额" + form.giftSpendMoney)
                form.discoutGiftMoney =//赠送卡支付的钱
                  (form.giftSpendMoney / (form.discountFreeAmount / 100)).toFixed(2) * 1;
                //console.log(form.discoutGiftMoney)
              } else {
                //console.log(debtMoney);
                form.spendMoney = (debtMoney * recRatio).toFixed(2) * 1;
                form.discoutMoney = (debtMoney * recRatio).toFixed(2) * 1;
                form.giftSpendMoney = (debtMoney * recGiftRatio).toFixed(2) * 1;
                form.discoutGiftMoney =
                  (debtMoney * recGiftRatio).toFixed(2) * 1;
              }

            } else {
              form.spendMoney = form.cardOver;
              form.discoutMoney =
                ((form.spendMoney * 1) * (form.discount / 100)).toFixed(2) * 1;
              form.giftSpendMoney = ((form.spendMoney * 1) / recRatio * recGiftRatio).toFixed(2) * 1;
              console.log("这个是赠送金额" + form.giftSpendMoney)
              form.discoutGiftMoney =//赠送卡支付的钱
                (form.giftSpendMoney * (form.discount / 100)).toFixed(2) * 1;
            }
          }
          if (form.spendMoney == 0) {
            form.giftSpendMoney = 0;
            form.discoutMoney = 0;
            form.discoutGiftMoney = 0;
          }
        } else {
          if (this.recForm.noDiscount == 0) {
            // 可以打折
            
            form.discoutMoney =
              ((form.spendMoney * form.discount) / 100).toFixed(2) * 1;
          } else {
            不可以打折
           form.discoutMoney = form.spendMoney;
          }
          form.discoutGiftMoney=0
        }
        if (form.discoutGiftMoney + form.discoutMoney > this.list[this.editProIndex].amount) {
          this.$message.info({
            message: "卡付金额不能大于套餐金额",
          });
          form.spendMoney = 0
          form.discoutMoney = 0
          form.discoutGiftMoney = 0
          form.giftSpendMoney = 0
        }
      } else {
        form.spendMoney = 0;
        form.giftSpendMoney = 0;
        if (0 <= row.spendMoney * 1 > row.cardOver * 1) {
          this.$message.info({
            message: "支付金额不能大于可用金额!",
          });
        }
      }
      if (form.spendMoney > form.cardOver) {
        form.spendMoney = form.cardOver;
        form.giftSpendMoney = form.cardGiftOvers;
      }

      this.rowRecList.splice(index, 1, form);
      this.list[this.editProIndex].collectionCashAmounts = this.list[this.editProIndex].amount - (form.discoutMoney + form.discoutGiftMoney)
      //console.log(this.list)
      //console.log('这是index'+index)
      let num = 0;
      this.list.forEach((item) => {
        // //console.log("这个是"+item.collectionCashAmounts)
        num = num + item.collectionCashAmounts
      });
      //console.log(num)
      this.form.collectionCashAmounts = num;
      this.sumNum();
      // this.rowRecList.splice(index, 1, form);

      // ---------------------------------------------------------------------------------------------------------------
      // if (!row.spendMoney) {
      //   row.spendMoney = 0;
      // }
      // row.spendMoney = row.spendMoney * 1;

      // if (0 <= row.spendMoney * 1 > row.cardOver * 1) {
      //   this.$message.info({
      //     message: "支付金额不能大于可用金额!",
      //   });
      // } else {
      //   this.recIndex = -1;
      //   if (row.spendMoney * 1 < 0) {
      //   } else {
      //     if (this.recForm.noDiscount == 0) {
      //       row.discoutMoney =
      //         ((row.spendMoney * 1) / ((row.discount * 1) / 100)).toFixed(2) * 1;
      //     } else {
      //       row.discoutMoney = row.spendMoney;
      //     }
      //     row.cardOvers =
      //       (row.cardOver * 1 - row.spendMoney * 1).toFixed(2) * 1;
      //     row.cardGiftOvers =
      //       (row.giftConsumeMoney * 1 - row.giftSpendMoney * 1).toFixed(2) * 1;
      //   }
      //   if (row.spendMoney == 0) {
      //     row.discoutGiftMoney = 0;
      //   }
      // }
      // let res = { ...row };
      // this.rowRecList.splice(index, 1, res);
      // this.sumNum();
    },
    sumNum() {
      let spendMoney = 0;
      let spendNumber = 0;
      //console.log(this.rowRecList)
      this.rowRecList.forEach((item) => {
        spendMoney += (item.discoutMoney + item.discoutGiftMoney) * 1;
        spendNumber += (item.spendMoney * 1 + item.giftSpendMoney) * 1;
        //console.log(item.discoutMoney);
        //console.log(item.discoutGiftMoney);
      });
      //console.log(spendMoney);

      this.recForm.collectionRechargeAmount = spendNumber.toFixed(2) * 1;
      this.recForm.collRecAmonnt = spendMoney.toFixed(2) * 1;
      //console.log(this.recForm.collectionRechargeAmount)
      this.recForm.cashAmount =
        (
          this.recForm.collectionCashAmount +
          this.recForm.collRecAmonnt +
          this.recForm.collectionIntegralAmount
        ).toFixed(2) * 1;
      this.recForm.payLists = this.payLists;
      this.recForm.rechargeAccountList = JSON.parse(
        JSON.stringify(this.rowRecList)
      );
      this.recForm.collectionAmount =
        (
          spendNumber +
          this.recForm.collectionCashAmount +
          this.recForm.collectionIntegralAmount
        ).toFixed(2) * 1;
      this.recForm.collectionAmounts =
        (
          spendMoney
        ).toFixed(2) * 1;
      //console.log(this.recForm.collectionAmount)
      this.recForm.rechargeAmount = spendNumber;
      this.list.splice(this.recForm.index, 1, this.recForm);
      let rList = [];
      this.list.forEach((item) => {
        if (item.index == this.editProIndex) {
          let rechargeAccountList = JSON.parse(
            JSON.stringify(item.rechargeAccountList)
          );
          rechargeAccountList.forEach((item) => {
            //console.log(item);
            item.cardOver = item.cardOvers;
            item.giftConsumeMoney = item.cardGiftOvers;
            item.giftSpendMoney = 0;
            item.spendMoney = 0;
            rList.push(item);
          });
        }
      });

      this.recListCopy = JSON.parse(JSON.stringify(rList));

      this.list.forEach((item) => {
        if (item.index != this.editProIndex) {
          //console.log(this.setRecList(item));
          let recArr = this.setRecList(item);
          item.rechargeAccountList.forEach((item, index) => {
            if (item.spendMoney > 0) {
              this.sumAmont();
            } else {
              //console.log(item);
              item.cardOver = recArr[index].cardOvers;
              item.cardOvers = recArr[index].cardOvers;
              item.giftConsumeMoney = recArr[index].cardGiftOvers;
              item.cardGiftOvers = recArr[index].cardGiftOvers;
            }
          });
        }
      });
      //console.log(rList);
      //console.log(this.list);
      this.sumAmont();
    },
    openRec(row) {
      this.recForm = JSON.parse(JSON.stringify(row));
      this.rowRecList = JSON.parse(JSON.stringify(row.rechargeAccountList));
      this.editProIndex = row.index;
      console.log( this.editProIndex)
    },
    recashData(v) {
      this.list = v.list;
      let Vindex = v.form.index;
      let recList = v.form.rechargeAccountList;
      this.list.forEach((item, index) => {
        if (Vindex < index) {
          //console.log("大于当前, 卡包变");
          recList.forEach((rec, recIndex) => {
            if (rec.spendMoney > 0) {
              item.rechargeAccountList[recIndex].cardOver = rec.cardOvers;
              item.rechargeAccountList[recIndex].cardOvers = rec.cardOvers;
            }
          });
        }
      });
      this.sumAmont();
    },
    proBlur(row) {
      if (this.cashNumber == 1 && !this.memberForm.memberName) {
        this.$message.warning({ message: "请先选择会员 !" });
      } else {
        let form = {
          pageSize: 999,
          projectNum: row.projectNum,
          state: 1,
          directConsumption: 1,
        };
        propage(form).then((res) => {
          if (res.code == "000000") {
            if (res.pageInfo.total == 1) {
              if (!res.pageInfo.list[0].courseAccountId) {
                res.pageInfo.list[0].courseAccountId = null;
                res.pageInfo.list[0].courseProjectId = res.pageInfo.list[0].id;
                res.pageInfo.list[0].courseMoney = 0;
              } else {
                res.pageInfo.list[0].courseMoney =
                  res.pageInfo.list[0].courseConsumePrice;
              }
              this.setProOne(res.pageInfo.list[0]);
            } else {
              this.$message.info({ message: "请输入正确的项目编码!" });
            }
          } else {
            this.$alert(res.message, "提示", {
              confirmButtonText: "确定",
              confirmButtonClass: "confirmbtnFalses",
              type: "warning",
              center: true,
              callback: (action) => { },
            });
          }
        });
      }
    },

    openAddMember() {
      this.$refs.addmember.show("添加");
    },
    getRowKeys(row) {
      return row.index;
    },

    endEditMoney(row) {
      let form = { ...row };
      //console.log(row);
      if (this.cashNumber == 1) {
        if (
          form.topPriceMember < form.transactionPrice * 1 ||
          form.transactionPrice * 1 < form.minumumPriceMember
        ) {
          this.$message.error({
            message:
              "价格不能低于" +
              form.minumumPriceMember +
              "高于" +
              form.topPriceMember,
          });
          form.transactionPrice = this.transactionPrice;
        } else {
          form.amount = row.transactionPrice;
        }
      } else {
        if (
          form.topPrice < form.transactionPrice * 1 ||
          form.transactionPrice * 1 < form.minumumPrice
        ) {
          this.$message.error({
            message:
              "价格不能低于" + form.minumumPrice + "高于" + form.topPrice,
          });
          form.transactionPrice = this.transactionPrice;
        } else {
          form.amount = row.transactionPrice;
        }
      }
      this.list.splice(row.index, 1, form);
      this.sumAmont();
    },
    handleChange(data, row, text) {
      //console.log("行号", row.index);
      let form = { ...row };
      if (text == "managerList") {
        this.managerOptions.forEach((item, index) => {
          if (item.id == data) {
            item.ratio = 100;
            form[text] = [];
            form[text].push(item);
            form.texts = item.label;
          }
        });
      } else if (text == "adminList") {
        this.adminOptions.forEach((item, index) => {
          if (item.id == data) {
            item.ratio = 100;
            form[text] = [];
            form[text].push(item);
            form.texts = item.label;
          }
        });
      } else {
        this.options.forEach((item, index) => {
          if (item.id == data) {
            //console.log("返回数据:", item);
            item.ratio = 100;
            form[text] = [];
            form[text].push(item);
            form.texts = item.label;
          }
        });
      }
      this.list.splice(row.index, 1, form);
    },
    goPayDebt() {
      this.$refs.repayment.show(this.memberForm);
    },
    inputMember() {
      if (partten.phoneNum.test(this.memberForm.mobilePhone)) {
        storeMemberOne({
          mobilePhone: this.memberForm.mobilePhone,
          storeId: sessionStorage.getItem("parentId"),
        }).then((res) => {
          if (res.code == "000000") {
            this.memberForm = res.data;
            this.debtMoneys = res.data.debtMoneys;
            this.cashNumber = 1;
            this.list = [];
            var this_ = this;
            setTimeout(() => {
              this_.$refs.reccard.show(this_.memberForm);
              this_.$refs.course.show(this_.memberForm);
            }, 500);
            this.getRecCard();
          } else {
            if (this.cashNumber == 1) {
              this.$alert(res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => { },
              });
              this.cashNumber = 0;
            }
          }
        });
      } else {
        this.$message.warning({ message: "请输入正确的手机号" });
      }
    },
    passcodeData(v) {
      if (v != null) {
        console.log(v)
        this.formData.append("file", v);
      }
      this.addCashConfirm();
    },
    //打开选择会员充值卡包弹窗
    openPro() {
      if (this.cashNumber == 1 && !this.memberForm.memberName) {
        this.$message.warning({ message: "请先选择会员 !" });
      } else {
        this.$refs.project.show(1);
      }
    },
    openCrad() {
      this.$refs.project.show(this.memberForm);
    },
    projectData(v) {
      //console.log(v);
      if (!v.courseAccountId) {
        v.courseAccountId = null;
        v.courseProjectId = v.id;
        v.courseMoney = 0;
      } else {
        v.courseMoney = v.courseConsumePrice;
      }
      this.setProOne(v);
    },
    setProOne(row) {
      if (row.courseAccountId == null) {
        row.courseMoney = 0;
      } else {
        row.courseMoney = row.courseConsumePrice;
      }
      let form = {};
      proOne({
        id: row.courseProjectId,
      }).then((res) => {
        if (res.code == "000000") {
          form = {
            payLists: this.payLists,
            zhonggongList: [],
            largeList: [],
            smallList: [],
            technicianList: [],
            adminList: [],
            managerList: [],
            commissionZhonggong: res.data.commissionZhonggong,
            commissionTechnician: res.data.commissionTechnician,
            commissionSmall: res.data.commissionSmall,
            commissionLarge: res.data.commissionLarge,
            cardCommissionZhonggong: res.data.cardCommissionZhonggong,
            cardCommissionTechnician: res.data.cardCommissionTechnician,
            cardCommissionSmall: res.data.cardCommissionSmall,
            cardCommissionLarge: res.data.cardCommissionLarge,
            achievementLarge: res.data.achievementLarge,
            achievementSmall: res.data.achievementSmall,
            achievementTechnician: res.data.achievementTechnician,
            achievementZhonggong: res.data.achievementZhonggong,
            cardAchievementLarge: res.data.cardAchievementLarge,
            cardAchievementSmall: res.data.cardAchievementSmall,
            cardAchievementTechnician: res.data.cardAchievementTechnician,
            cardAchievementZhonggong: res.data.cardAchievementZhonggong,
            projectName: res.data.projectName,
            projectNum: res.data.projectNum,
            courseAccountId: row.courseAccountId,
            courseMoney: row.courseMoney,
            noDiscount: res.data.noDiscount,
            isCardPay: res.data.isCardPay,
            amount: res.data.transactionPrice,
            integral: 0,
            integralMoney: 0,
            collectionRechargeAmount: 0,
            collRecAmonnt: 0,
            collectionCashAmount: 0,
            collectionIntegralAmount: 0,
            collectionAmount: 0,
            projectId: res.data.id,
            // cashNum:  res.data.cashNum,
            storeId: res.data.storeId,
            storeName: res.data.storeName,
            price: res.data.price,
            topPrice: res.data.topPrice,
            topPriceMember: res.data.topPriceMember,
            priceMember: res.data.priceMember,
            minumumPrice: res.data.minumumPrice,
            minumumPriceMember: res.data.minumumPriceMember,
            cashNumber: this.cashNumber,
            numberTimes: 1,
            minumumTimes: res.data.minumumTimes,
          };
          //console.log(form);
          this.setRecList(form);
          if (this.cashNumber == 1) {
            if (row.courseAccountId == null) {
              form.transactionPrice = res.data.priceMember;
              form.amount = res.data.priceMember;
              if (res.data.priceMember == 0) {
                form.amount = res.data.price;
                form.transactionPrice = res.data.price;
              }
            } else {
              form.amount = row.price;
              form.transactionPrice = row.price;
            }
            form.memberId = this.memberForm.id;
            form.integral = this.memberForm.integral;
            form.rechargeAccountList = this.recListCopy;
          } else {
            form.amount = res.data.price;
            form.transactionPrice = res.data.price;
            form.rechargeAccountList = [];
          }
          form.memberName = this.memberForm.memberName;
          form.mobilePhone = this.memberForm.mobilePhone;

          if (form.courseAccountId == null) {
            form.cashAmount = 0;
            form.collectionAmount = 0;
          } else {
            form.cashAmount = form.amount;
            form.collectionAmount = form.cashAmount;
            //console.log("1")
          }
          if (this.list.length > 0) {
            //console.log(this.list.length);
            if (!this.list[0].projectName) {
              this.proIndex = 0;
            }
          }
          if (this.proIndex != -1) {
            if (this.list[this.proIndex].projectName) {
              this.czRecList(this.list[this.proIndex]);
            }
            form.index = this.proIndex;
            this.list.splice(this.proIndex, 1, form);
            this.expand.push(this.proIndex);
            this.expandedRows.push(this.list[this.proIndex]);
            this.proIndex = -1;
          } else {
            this.list.push(form);
            let i = this.list.length - 1;
            form.index = i;
            this.expand.push(i);
            this.expandedRows.push(this.list[i]);
          }
          this.openRec(form);
          this.sumAmont();
        } else {
          this.$alert(res.message, "查询项目明细", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => { },
          });
        }
      });
    },
    setRecList(form) {
      this.recListCopy.forEach((item) => {
        item.cardGiftOvers = 0;
        item.spendMoney = 0;
        item.giftSpendMoney = 0;
        item.discoutMoney = 0;
        item.discoutGiftMoney = 0;
        if (!item.cardOver) {
          item.cardOver = item.cardConsumeMoney;
          item.cardOvers = item.cardConsumeMoney;
        }
        if (!item.cardGiftOvers) {
          item.cardGiftOvers = item.giftConsumeMoney;
        }
        if (item.type == 0) {
          item.discountFreeAmount = 100;
        }
        if (item.type != 1 && form.noDiscount == 0) {
          item.offsetMoney =
            (item.cardConsumeMoney / (item.discount / 100)).toFixed(2) * 1;
          if (item.type == 2) {
            item.offsetGiftMoney = item.giftConsumeMoney;
          } else {
            item.offsetGiftMoney =
              (item.giftConsumeMoney / (item.discountFreeAmount / 100)).toFixed(
                2
              ) * 1;
          }
          //console.log(item);
        } else {
          item.offsetMoney = item.giftConsumeMoney + item.cardConsumeMoney;
          item.offsetGiftMoney = 0;
        }
      });
      return this.recListCopy;
    },
    //确定返回方法
    confirm() {
      let flag = true;
      if (this.list == []) {
        this.$alert("项目最少需要一个", "提示", {
          confirmButtonText: "确定",
          confirmButtonClass: "confirmbtnFalses",
          type: "warning",
          center: true,
          callback: (action) => { },
        });
        flag = false;
      }
      let sumMoney = 0;
      this.list.forEach((item, index) => {
        if (item.courseAccountId == null) {
          sumMoney +=
            (
              item.amount -
              item.collRecAmonnt -
              item.collectionIntegralAmount
            ).toFixed(2) * 1;
        }
        // if (!(item.sex == 0 || item.sex == 1)) {
        //   this.$alert("项目没有选择顾客性别", "提示", {
        //     confirmButtonText: "确定",
        //     confirmButtonClass: "confirmbtnFalses",
        //     type: "warning",
        //     center: true,
        //     callback: (action) => {},
        //   });
        //   flag = false;
        // }
      });

      if (
        this.balance <=
        (this.form.collectionCashAmounts - sumMoney).toFixed(2) * 1 ||
        (this.form.collectionCashAmounts - sumMoney).toFixed(2) * 1 < 0
      ) {
        flag = false;
        this.$alert("实付金额不等于项目金额", "提示", {
          confirmButtonText: "确定",
          confirmButtonClass: "confirmbtnFalses",
          type: "warning",
          center: true,
          callback: (action) => { },
        });
      }
      if (this.isAddition == 1 && !this.additionDate) {
        flag = false;
        this.$alert("请输入补单日期", "提示", {
          confirmButtonText: "确定",
          confirmButtonClass: "confirmbtnFalses",
          type: "warning",
          center: true,
          callback: (action) => { },
        });
      }
      if (flag) {
        let passShow = false;
        this.list.forEach((item, index) => {
          if (index == 0) {
            item.man = this.notMemberForm.man
              ? this.notMemberForm.man
              : this.memberForm.man;
            item.woman = this.notMemberForm.woman
              ? this.notMemberForm.woman
              : this.memberForm.woman;
          }
          if (item.courseAccountId != null) {
            passShow = true;
          }
          item.rechargeAccountList.forEach((items) => {
            if (items.spendMoney > 0) {
              passShow = true;
            }
          });
        });
        if (passShow) {
          this.$refs.passcode.show(this.memberForm);
        } else {
          this.addCashConfirm();
        }
      }
    },
    addCashConfirm() {
      let list = [];
      this.list.forEach((item) => {
        if (item.courseAccountId == null) {
          item.collectionCashAmount =
            (
              item.amount -
              item.collRecAmonnt -
              item.collectionIntegralAmount
            ).toFixed(2) * 1;
          item.cashAmount =
            (
              item.collRecAmonnt +
              item.collectionIntegralAmount +
              item.collectionCashAmount
            ).toFixed(2) * 1;
        }

        item.isAddition = this.isAddition;
        if (this.isAddition == 1) {
          item.additionDate = this.additionDate;
        }
        let salesmens = [];
        item.managerList.forEach((items) => {
          if (items.id) {
            items.staffType = 0;
            salesmens.push(items);
          }
        });
        item.adminList.forEach((items) => {
          if (items.id) {
            items.staffType = 1;
            salesmens.push(items);
          }
        });
        item.salesmens = salesmens;
        let payLists = [];
        let rechargeAccountList = [];
        this.payLists.forEach((item) => {
          if (item.payMoney > 0) {
            let items = {
              payMoney: item.payMoney,
              payId: item.payId,
              payName: item.payName,
            };
            payLists.push(items);
          }
        });
        item.payListsCopy = this.payLists;
        item.payLists = payLists;
        item.rechargeAccountList.forEach((item) => {
          if (item.spendMoney > 0) {
            rechargeAccountList.push(item);
          }
        });
        // item.rechargeAccountListCopy = item.rechargeAccountList;
        item.rechargeAccountList = rechargeAccountList;
        if (item.courseAccountId != null) {
          item.collectionAmount = item.amount;
          //console.log("2")
        }
        if (item.projectId) {
          list.push(item);
        }
      });
      console.log(list)

      list.forEach((item) => {
        item.collectionAmount = item.collectionAmounts

      })
      console.log(list)
      this.formData.append("cashListRequestList", JSON.stringify(list));
      addCash(this.formData).then((res) => {
        if (res.code == "000000") {
          this.$message.success({
            message: "验证成功 , 收银" + res.message,
          });
          this.formData = new FormData()
          this.notData();
        } else {
          this.payLists = this.payListsCopy;
          this.list.forEach((item) => {
            item.collectionCashAmount = 0;
          });
          this.$alert("收银" + res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => { },
          });
          this.formData = new FormData()
        }
      });
    },
    openStaffRatio(row, index, text) {
      this.editIndex = index;
      console.log(row)
      this.$refs.staffratio.show(row, text);
      this.$refs.staffratio.showdetele();
      localStorage.setItem("row",JSON.stringify(row))
      localStorage.setItem("text",text)
    },
    staffratioData(v) {
      console.log(v)
      let form = this.list[this.editIndex];
      let texts = v.text + "s";
      form[v.text] = v.list;
      form[texts] = v.list[0].label;
      this.list.splice(this.editIndex, 1, form);
    },
    addPro() {
      let list = {
        projectName: "",
        largeList: [],
        zhonggongList: [],
        smallList: [],
        technicianList: [],
        managerList: [],
        adminList: [],
        payLists: this.payLists,
        rechargeAccountList: [], //卡付列表
      };

      this.list.push(list);
    },
    delPro(row) {
      // this.czRecList(row);
      this.list.splice(row.index, 1);
      //console.log(row)
      this.form.cashAmount = this.form.cashAmount - row.amount + row.cashAmount
      this.form.collectionCashAmounts = this.form.cashAmount - row.amount + row.cashAmount
      this.form.collectionCashAmount = this.form.collectionCashAmounts
      this.payLists.forEach((item) => {
        item.payMoney = 0
      });
      this.sumAmont()
    },
    // czRecList(row) {
    //   let list = [];
    //   row.rechargeAccountList.forEach((item) => {
    //     if (item.spendMoney > 0) {
    //       list.push(item);
    //     }
    //   });
    //   this.recListCopy.forEach((item) => {
    //     list.forEach((items) => {
    //       if (item.id == items.id) {
    //         //console.log(item);
    //         //console.log(item.giftConsumeMoney);
    //         //console.log(item.giftSpendMoney);
    //         item.cardOver = (item.cardOver + items.spendMoney).toFixed(2) * 1;
    //         item.cardOvers = (item.cardOvers + items.spendMoney).toFixed(2) * 1;
    //         item.cardGiftOvers =
    //           (item.giftConsumeMoney + items.giftSpendMoney).toFixed(2) * 1;
    //         item.giftConsumeMoney =
    //           (item.giftConsumeMoney + items.giftSpendMoney).toFixed(2) * 1;
    //       }
    //     });
    //   });
    // },
    //打开选择会员弹窗
    openMember() {
      this.cashNumber = 1;
      this.$refs.member.show();
    },
    //选中会员返回方法
    memberData(v) {
      //console.log(v);
      this.memberForm.mobilePhone = v.mobilePhone;
      this.inputMember();
    },
    reccardData(v) { },
    courseData(v) {
      this.setProOne(v);
    },
    paymentData(v) {
      //console.log(v);
      this.form = v.form;
      this.payLists = v.list;
      this.sumAmont();
    },
    rowClassName({ row, rowIndex }) {
      row.index = rowIndex;
    },

    expandSelect: function (row, expandedRows) {
      var that = this;
      this.expandedRows = JSON.parse(JSON.stringify(expandedRows));
      // if (expandedRows.length) {
      //   that.expand = [];
      //   if (row) {
      //     that.expand.push(row.index);
      //   }
      // } else {
      //   that.expand = [];
      // }
    },
    //点击选中
    rowClick(row) {
      //console.log(row);
      this.$refs.list.toggleRowExpansion(row);
    },
    close() {
      this.form = {};
      this.rowList = [];
      this.list = [];
      this.memberForm = {};
    },
    //保存确定方法
    save() {
      this.close();
    },
    //获取数据
    async getData() {
      this.list.forEach((item) => {
        item.payLists = [...this.payLists];
        item.rechargeAccountList = [];
      });
      //判断是否是会员
      var itemForm = this.list[0];
      this.notMemberForm = itemForm;
      this.cashNumber = itemForm.cashNumber;
      if (itemForm.cashNumber == 1) {
        //会员
        storeMemberOne({
          mobilePhone: itemForm.mobilePhone,
          storeId: sessionStorage.getItem("parentId"),
        }).then((res) => {
          if (res.code == "000000") {
            this.memberForm = res.data;
            this.$refs.reccard.show(this.memberForm);
            this.$refs.course.show(this.memberForm);
            var memberIds = {
              memberId: itemForm.memberId,
            };
            recAccountCashList({
              memberId: this.memberForm.id,
            }).then((res) => {
              if (res.code == "000000") {
                this.rechargeAccountList = res.rows;
                this.list.forEach((item) => {
                  item.rechargeAccountList = this.rechargeAccountList;
                });
              } else {
                this.$alert(res.message, "查询会员卡包", {
                  confirmButtonText: "确定",
                  confirmButtonClass: "confirmbtnFalses",
                  type: "warning",
                  center: true,
                  callback: (action) => { },
                });
              }
              //查询当前会员下的所有项目疗程 如果有相对应的项目 就给courseAccountId赋值 没有的话 就是卡付现付
              couAccountList(memberIds).then((res) => {
                if (res.code == "000000") {
                  this.projectList = res.rows;
                  if (res.rows.length != 0) {
                    this.list.forEach((items1) => {
                      res.rows.forEach((items) => {
                        items.number = items.courseConsumeCount;
                        if (
                          items.courseProjectId == items1.projectId &&
                          items.number > 0
                        ) {
                          if (items1.courseAccountId == null) {
                            items1.courseAccountId = items.id;
                            items.number = items.number * 1 - 1;
                          }
                        }
                      });
                    });
                  }
                } else {
                  this.$alert(res.message, "查询会员疗程", {
                    confirmButtonText: "确定",
                    confirmButtonClass: "confirmbtnFalses",
                    type: "warning",
                    center: true,
                    callback: (action) => { },
                  });
                }

                let list = [];
                this.list.forEach((itemList, index) => {
                  var itemLists = {
                    index: index,
                    id: itemList.id,
                    largeList: itemList.largeList,
                    zhonggongList: itemList.zhonggongList,
                    smallList: itemList.smallList,
                    technicianList: itemList.technicianList,
                    adminList: [],
                    managerList: [],
                    projectName: itemList.projectName,
                    payLists: itemList.payLists,
                    rechargeAccountList: this.setRecList(itemList),
                    courseAccountId: itemList.courseAccountId,
                    amount: itemList.transactionPrice,
                    noDiscount: itemList.noDiscount,
                    integral: 0,
                    integralMoney: 0,
                    payMoneys: 0,
                    spendMoneys: 0,
                    collectionRechargeAmount: 0,
                    collRecAmonnt: 0,
                    collectionCashAmount: 0,
                    collectionIntegralAmount: 0,
                    collectionAmount: 0,
                    projectId: itemList.projectId,
                    projectName: itemList.projectName,
                    memberName: itemList.memberName,
                    memberId: itemList.memberId,
                    cashNum: itemList.cashNum,
                    isCardPay: itemList.isCardPay,
                    storeName: itemList.storeName,
                    price: itemList.price,
                    priceMember: itemList.priceMember,
                    minumumPrice: itemList.minumumPrice,
                    minumumPriceMember: itemList.minumumPriceMember,
                    topPrice: itemList.topPrice,
                    topPriceMember: itemList.topPriceMember,
                    storeId: itemList.storeId,
                    transactionPrice: itemList.transactionPrice,
                    cashNumber: itemList.cashNumber,
                    numberTimes: 1,
                    mobilePhone: itemList.mobilePhone,
                    minumumTimes: itemList.minumumTimes,
                    commissionZhonggong: itemList.commissionZhonggong,
                    commissionTechnician: itemList.commissionTechnician,
                    commissionSmall: itemList.commissionSmall,
                    commissionLarge: itemList.commissionLarge,
                    cardCommissionZhonggong: itemList.cardCommissionZhonggong,
                    cardCommissionTechnician: itemList.cardCommissionTechnician,
                    cardCommissionSmall: itemList.cardCommissionSmall,
                    cardCommissionLarge: itemList.cardCommissionLarge,
                    achievementLarge: itemList.achievementLarge,
                    achievementSmall: itemList.achievementSmall,
                    achievementTechnician: itemList.achievementTechnician,
                    achievementZhonggong: itemList.achievementZhonggong,
                    cardAchievementLarge: itemList.cardAchievementLarge,
                    cardAchievementSmall: itemList.cardAchievementSmall,
                    cardAchievementTechnician:
                      itemList.cardAchievementTechnician,
                    cardAchievementZhonggong: itemList.cardAchievementZhonggong,
                  };

                  if (itemLists.courseAccountId == null) {
                    itemLists.cashAmount = 0;
                    itemLists.collectionAmount = 0;
                    itemLists.courseMoney = 0;
                  } else {
                    itemLists.cashAmount = itemLists.amount;
                    itemLists.collectionAmount = itemLists.amount;
                    //console.log(3)
                    itemLists.courseMoney = itemLists.transactionPrice;
                  }
                  list.push(itemLists);
                });
                this.list = list;
                this.setList();
              });
            });
          }
        });
      } else {
        //不是会员
        let list = [];
        this.list.forEach((itemList, index) => {
          var itemLists = {
            index: index,
            id: itemList.id,
            largeList: itemList.largeList,
            zhonggongList: itemList.zhonggongList,
            smallList: itemList.smallList,
            technicianList: itemList.technicianList,
            adminList: [],
            managerList: [],
            projectName: itemList.projectName,
            payLists: itemList.payLists,
            rechargeAccountList: this.rechargeAccountList,
            courseAccountId: itemList.courseAccountId,
            amount: itemList.transactionPrice,
            integral: 0,
            integralMoney: 0,
            cashAmount: 0,
            payMoneys: 0,
            spendMoneys: 0,
            noDiscount: itemList.noDiscount,
            collectionRechargeAmount: 0,
            collRecAmonnt: 0,
            collectionCashAmount: 0,
            collectionAmount: 0,
            projectId: itemList.projectId,
            isCardPay: itemList.isCardPay,
            projectName: itemList.projectName,
            memberName: itemList.memberName,
            cashNum: itemList.cashNum,
            storeName: itemList.storeName,
            price: itemList.price,
            priceMember: itemList.priceMember,
            minumumPrice: itemList.minumumPrice,
            minumumPriceMember: itemList.minumumPriceMember,
            topPrice: itemList.topPrice,
            topPriceMember: itemList.topPriceMember,
            storeId: itemList.storeId,
            transactionPrice: itemList.transactionPrice,
            cashNumber: itemList.cashNumber,
            numberTimes: 1,
            mobilePhone: itemList.mobilePhone,
            minumumTimes: itemList.minumumTimes,
            commissionZhonggong: itemList.commissionZhonggong,
            commissionTechnician: itemList.commissionTechnician,
            commissionSmall: itemList.commissionSmall,
            commissionLarge: itemList.commissionLarge,
            cardCommissionZhonggong: itemList.cardCommissionZhonggong,
            cardCommissionTechnician: itemList.cardCommissionTechnician,
            cardCommissionSmall: itemList.cardCommissionSmall,
            cardCommissionLarge: itemList.cardCommissionLarge,
            achievementLarge: itemList.achievementLarge,
            achievementSmall: itemList.achievementSmall,
            achievementTechnician: itemList.achievementTechnician,
            achievementZhonggong: itemList.achievementZhonggong,
            cardAchievementLarge: itemList.cardAchievementLarge,
            cardAchievementSmall: itemList.cardAchievementSmall,
            cardAchievementTechnician: itemList.cardAchievementTechnician,
            cardAchievementZhonggong: itemList.cardAchievementZhonggong,
          };
          list.push(itemLists);
        });
        this.list = list;
        this.setList();
      }
    },
    setList() {
      this.list.forEach((item) => {
        item.editNumber = 1;
        if (item.largeList.length != 0) {
          item.largeLists =
            item.largeList[0].brandNumber + "-" + item.largeList[0].staffName;
          item.largeList[0].ratio = 100;
        } else {
          item.largeLists = "";
        }
        if (item.zhonggongList.length != 0) {
          item.zhonggongLists =
            item.zhonggongList[0].brandNumber +
            "-" +
            item.zhonggongList[0].staffName;
          item.zhonggongList[0].ratio = 100;
        } else {
          item.zhonggongLists = "";
        }
        if (item.smallList.length != 0) {
          item.smallLists =
            item.smallList[0].brandNumber + "-" + item.smallList[0].staffName;
          item.smallList[0].ratio = 100;
        } else {
          item.smallLists = "";
        }
        if (item.technicianList.length != 0) {
          item.technicianLists =
            item.technicianList[0].brandNumber +
            "-" +
            item.technicianList[0].staffName;
          item.technicianList[0].ratio = 100;
        } else {
          item.technicianLists = "";
        }
        if (item.adminList.length != 0) {
          item.adminLists =
            item.adminList[0].brandNumber + "-" + item.adminList[0].staffName;
          item.adminList[0].ratio = 100;
        } else {
          item.adminLists = "";
        }
        if (item.managerList.length != 0) {
          item.managerLists =
            item.managerList[0].brandNumber +
            "-" +
            item.managerList[0].staffName;
          item.managerList[0].ratio = 100;
        } else {
          item.managerLists = "";
        }
      });
    },

    goBack() {
      if (this.isAddition == 0) {
        this.orderNumber = 1;
        this.isAddition = 1;
        this.additionDate = this.formatTime(new Date(), "YYYY-MM-DD");
      } else {
        this.orderNumber = 0;
        this.isAddition = 0;
      }
    },
    getRecCard() {
      recAccountCashList({
        memberId: this.memberForm.id,
      }).then((res) => {
        if (res.code == "000000") {
          this.rechargeAccountList = res.rows;
          this.recListCopy = JSON.parse(JSON.stringify(res.rows));
          this.list.forEach((item) => {
            item.rechargeAccountList = this.rechargeAccountList;
          });
          this.addPro();
        } else {
          this.$alert(res.message, "查询会员卡包", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => { },
          });
        }
      });
      this.getCt();
    },
    getDetail() {
      selectListType({ type: 0 }).then((res) => {
        if (res.code == "000000") {
          res.rows.forEach((item) => {
            item.label = item.brandNumber + "-" + item.staffName;
            item.ratio = 100;
            delete item.state;
          });

          this.adminOptions = res.rows;
        } else {
          this.$alert(res.message, "加载员工提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => { },
          });
        }
      });
      QuerCompetent({ type: 0, pageSize: 999 }).then((res) => {
        if (res.code == "000000") {
          res.pageInfo.list.forEach((item) => {
            item.label = item.brandNumber + "-" + item.staffName;
            item.ratio = 100;
            delete item.state;
          });
          this.managerOptions = res.pageInfo.list;
        } else {
          this.$alert(res.message, "加载高管提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => { },
          });
        }
      });
      selectList({ id: "" }).then((res) => {
        if (res.code == "000000") {
          res.rows.forEach((item) => {
            item.label = item.brandNumber + "-" + item.staffName;
            delete item.state;
            item.ratio = 100;
          });
          this.options = Array.from(new Set(res.rows));
        } else {
          this.$alert(res.message, "加载员工列表", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => { },
          });
        }
      });
      this.getCt();
    },
    getCt() {
      ctlist({
        state: 1,
      }).then((res) => {
        if (res.code == "000000") {
          res.rows.forEach((item) => {
            item.payMoney = 0;
            item.payId = item.id;
            item.payName = item.collectionTypeName;
          });
          this.payLists = JSON.parse(JSON.stringify(res.rows));
          this.copyPayList = JSON.parse(JSON.stringify(res.rows));
          this.list.forEach((item) => {
            item.payLists = this.payLists;
            item.rechargeAccountList = [];
          });
          this.form = {
            collectionCashAmount: 0,
            cashAmount: 0,
          };
          this.sumAmont();
        } else {
          this.$alert(res.message, "加载现付列表", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => { },
          });
        }
      });
    },
    sumAmont() {
      let money = 0;
      var payMoneys = 0;
      this.payLists.forEach((item) => {
        payMoneys += item.payMoney;
      });
      if (this.form.collectionCashAmount <= 0) {
        this.list.forEach((item) => {
          item.collectionCashAmount = 0;
          if (item.rechargeAmount) {
            item.collectionAmount =
              (
                item.rechargeAmount +
                item.collectionIntegralAmount +
                item.collectionCashAmount
              ).toFixed(2) * 1;
            //console.log(4)
          } else {
            item.collectionAmount =
              (
                item.collectionIntegralAmount + item.collectionCashAmount
              ).toFixed(2) * 1;
          }
          //console.log(5)
        });
      }
      let collectionRechargeAmountg = 0;
      this.list.forEach((item) => {
        let debtMoney = 0;

        if (item.amount && item.courseAccountId == null) {

          debtMoney =
            (
              item.amount -
              item.collectionCashAmount -
              item.collRecAmonnt -
              item.collectionIntegralAmount
            ).toFixed(2) * 1;
          money += debtMoney;
        }
        collectionRechargeAmountg += (item.collectionRechargeAmount).toFixed(2) * 1;
      });

      this.form.cashAmount = (money.toFixed(2) * 1) + (collectionRechargeAmountg.toFixed(2) * 1)
      this.form.collectionCashAmounts = (money.toFixed(2) * 1)
      console.log(this.form.collectionCashAmounts)
      console.log(this.form.cashAmount)
      this.list.forEach((item) => {
        if (
          this.form.cashAmount == this.form.collectionCashAmount &&
          item.courseAccountId == null
        ) {
          item.collectionCashAmount =
            (
              item.amount -
              item.collRecAmonnt -
              item.collectionIntegralAmount
            ).toFixed(2) * 1;
        }
        if (item.rechargeAmount) {
          item.collectionAmount =
            (
              item.rechargeAmount +
              item.collectionIntegralAmount +
              item.collectionCashAmount
            ).toFixed(2) * 1;
          //console.log(6)
          //console.log( item.collectionAmount)

        } else {
          item.collectionAmount =
            (item.collectionIntegralAmount + item.collectionCashAmount).toFixed(
              2
            ) * 1;
          //console.log(7)
        }
      });
      this.form.debtMoney =
        (this.form.cashAmount - this.form.collectionCashAmount).toFixed(2) * 1;
      var that = this;
      setTimeout(() => {
        that.$nextTick(() => {
          console.log(that.form)
          that.$refs.payment.show(that.form, that.payLists);
        });
      }, 500);
    },
    //数组按对应字段合计返回方法
    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 == "discoutMoney") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return (prev + curr).toFixed(2) * 1;
            } else {
              sums[index] = "--";
            }
          }, 0);
          sums[index] += " ";
        } else if (column.property == "spendMoney") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return (prev + curr).toFixed(2) * 1;
            } else {
              sums[index] = "--";
            }
          }, 0);
          sums[index] += " ";
        } else {
          sums[index] = "--";
        }
      });
      return sums;
    },
    notData() {
      Object.assign(this.$data, this.$options.data.call(this));
      var that = this;
      setTimeout(() => {
        that.$nextTick(() => {
          that.$refs.payment.show(that.form, that.payLists);
          if (that.$refs.course) {
            that.$refs.course.show();
          }
          if (that.$refs.reccard) {
            that.$refs.reccard.show();
          }
        });
      }, 500);
      this.setPage();
    },
    setPage() {
      this.getDetail();
    },
  },
  activated() {
    this.setPage();
  },
  created() { },
};
</script>
 
<style scoped>
.el-icon-edit-outline {
  padding-left: 5px;
}

.imgss {
  width: 160px;
  height: 60px;
  border: 1px solid #333;
}

.esign {
  border: #333 1px solid;
}

.el-form-item {
  margin-bottom: 5px;
}
</style>