<template>
  <div class="setImport">
    <div class="header_flex">
      <div>
        <el-button size="small" type="primary" @click="dialogFormVisible= true,listIndex=-1" v-role='50010002'>添加</el-button>
      </div>
      <div>
        <!-- 	<el-input size="medium" style="width:180px;" placeholder="当前页搜索" v-model="input">
					<i slot="prefix" class="el-input__icon el-icon-search"></i>
				</el-input> -->
        <el-button size="small" type="primary" @click="(searchDialog=true)" :disabled="activeName*1==2">条件搜索</el-button>
        <el-button size="small" type="info" plain @click='memberInitPage(searchTrue=false)'>刷新</el-button>
        <el-button size="small" type="primary" v-role='50010007' @click="download()">下载模板</el-button>
        <el-button size="small" type="warning" v-role='50010008' @click="infoDialog=true">导入</el-button>
        <el-button size="small" type="success" v-role='50010009' @click="exit()">导出</el-button>
        <el-button size="small" type="primary" v-role='50010005' :disabled="!(activeName==1||activeName==2)" @click='checks'>校验</el-button>
        <el-button size="small" type="success" v-role='50010006' :disabled="activeName!=3" @click='inits'>初始化</el-button>
      </div>
    </div>
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <!-- 0:封存删除1:插入2:异常3:正常4:已初始化 -->
      <el-tab-pane label="新添加" name=1></el-tab-pane>
      <el-tab-pane label="异常单" name=2></el-tab-pane>
      <el-tab-pane label="已校验" name=3></el-tab-pane>
      <el-tab-pane label="已导入" name=4></el-tab-pane>
      <el-tab-pane label="已删除" name=0></el-tab-pane>
    </el-tabs>
    <el-table :data="pageInfo.importList" :row-class-name="tableRowClassName" :header-cell-style="{background: 'linear-gradient(#6cb3ff, #1873d4)',color:'#eeeeee'}">
      <el-table-column label="状态" align="center" width="70" prop="initState">
        <template slot-scope="scope">
          <el-tooltip effect="dark" :content="activeName==2?scope.row.unusualReason:scope.row.initState==1?'新创建':scope.row.initState==2?'异常单':scope.row.initState==3?'已校验':scope.row.initState==4?'已导入':'已删除'" placement="right">
            <el-tag :type="scope.row.initState==1?'info':scope.row.initState==2?'warning':scope.row.initState==3?'':scope.row.initState==4?'success':'danger'" effect="dark">
              <span>{{scope.row.initState==1?'新创建':scope.row.initState==2?'异常单':scope.row.initState==3?'已校验':scope.row.initState==4?'已导入':'已删除'}}</span>
            </el-tag>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="所属门店" min-width="110" show-overflow-tooltip prop="storeName"></el-table-column>
      <el-table-column label="日期" min-width="110" show-overflow-tooltip prop="modifyDate"></el-table-column>
      <el-table-column label="单据号" align="center" min-width="110" show-overflow-tooltip prop="initNum">
        <template slot-scope="scope">
          <div style="cursor: pointer;">{{scope.row.initNum}}</div>
        </template>
      </el-table-column>
      <el-table-column label="手机号码" align="center" min-width="110" show-overflow-tooltip prop="mobilePhone">
        <!-- <template slot-scope="scope">
          <el-input size="small" maxlength="11" v-model="scope.row.mobilePhone" @focus="listIndex = scope.$index" @blur="memberOne()" v-show="!rowIndex"></el-input>
          <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.mobilePhone}}</div>
        </template> -->
      </el-table-column>
      <el-table-column label="会员名称" align="center" min-width="80" show-overflow-tooltip prop="memberName">
        <template slot-scope="scope">
          {{scope.row.memberName}}
          <!-- <el-input size="small" v-model="scope.row.memberName" v-show="!rowIndex"></el-input>
					<div style="cursor: pointer;" v-show="rowIndex">{{scope.row.memberName}}</div> -->
        </template>
      </el-table-column>
      <el-table-column label="单据类型" align="center" min-width="80" prop="type">
        <template slot-scope="scope">
          <!-- <el-select size="small" v-model="scope.row.cardType" @change="cardTypeChange" @focus="listIndex = scope.$index" :placeholder="scope.row.cardType==0?'充值账户':'疗程账户'" v-show="!rowIndex">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select> -->
          <div style="cursor: pointer;">
            {{scope.row.cardType==0?'充值账户':'疗程账户'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="账户名称" align="center" min-width="120" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <div v-show="!rowIndex" @click="openEditTpe(scope.row,scope.$index)">
            {{scope.row.tradeName}} <i class="el-icon-edit"></i>
          </div>
          <div style="cursor: pointer;" v-show="rowIndex">
            {{scope.row.tradeName}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="标准金额" align="center" min-width="80" prop="standardMoney">
        <template slot-scope="scope">
          <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.standardMoney" v-show="!rowIndex"></el-input>
          <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.standardMoney}}</div>
        </template>
      </el-table-column>
      <el-table-column label="标准次数" align="center" min-width="80" prop="standardCount">
        <template slot-scope="scope">
          <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.standardCount" v-show="!rowIndex&&scope.row.cardType==1"></el-input>
          <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.standardCount}}</div>
        </template>
      </el-table-column>
      <el-table-column label="剩余次数" align="center" min-width="80" prop="restCount"> <template slot-scope="scope">
          <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.restCount" v-show="!rowIndex&&scope.row.cardType==1"></el-input>
          <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.restCount}}</div>
        </template></el-table-column>
      <el-table-column label="可用次数" align="center" min-width="80" prop="courseConsumeCount"> <template slot-scope="scope">
          <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.courseConsumeCount" v-show="!rowIndex&&scope.row.cardType==1">
          </el-input>
          <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.courseConsumeCount}}</div>
        </template></el-table-column>
      <el-table-column label="剩余金额" align="center" min-width="80" prop="restMoney">
        <template slot-scope="scope">
          <div v-if="scope.row.cardType==0">
            <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.restMoney" v-show="!rowIndex"></el-input>
            <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.restMoney}}</div>
          </div>
          <div v-else>
            <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.courseConsumePrice" v-show="!rowIndex"></el-input>
            <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.courseConsumePrice}}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="可用金额" align="center" min-width="80" prop="cardConsumeMoney">
        <template slot-scope="scope">
          <div v-if="scope.row.cardType==0">
            <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.cardConsumeMoney" v-show="!rowIndex"></el-input>
            <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.cardConsumeMoney}}</div>
          </div>
          <div v-else>
            <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.courseConsumePrice" v-show="!rowIndex"></el-input>
            <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.courseConsumePrice}}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="赠送剩余金额" align="center" min-width="120" prop="cardGiftMoney"> <template slot-scope="scope">
          <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.cardGiftMoney" v-show="!rowIndex&&scope.row.cardType==0"></el-input>
          <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.cardGiftMoney}}</div>
        </template></el-table-column>
      <el-table-column label="赠送可用金额" align="center" min-width="120" prop="giftConsumeMoney"> <template slot-scope="scope">
          <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.giftConsumeMoney" v-show="!rowIndex&&scope.row.cardType==0"></el-input>
          <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.giftConsumeMoney}}</div>
        </template></el-table-column>
      <el-table-column label="欠款金额" align="center" min-width="80" prop="debtMoney">
        <template slot-scope="scope">
          <el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.debtMoney" v-show="!rowIndex"></el-input>
          <div style="cursor: pointer;" v-show="rowIndex">{{scope.row.debtMoney}}</div>
        </template>
      </el-table-column>

      <el-table-column label="到期日期" show-overflow-tooltip align="center" min-width="105" prop="endTime"> <template slot-scope="scope">
          {{scope.row.endTime}}
          <!-- 	<el-input @focus="listIndex = scope.$index" size="small" v-model="scope.row.validTime" v-show="!rowIndex"></el-input>
					<div style="cursor: pointer;" v-show="rowIndex">{{scope.row.validTime}}</div> -->
        </template></el-table-column>
      <el-table-column label="备注" align="center" min-width="100" prop="remark"></el-table-column>

      <el-table-column label="操作" align="center" fixed="right" width="160" v-if="!(activeName==3||activeName==4||activeName==0)">
        <template slot-scope="scope">
          <el-button type="success" v-role='50010003' size="mini" @click="openEdit(scope.row,scope.$index,rowIndex=0) " v-show="rowIndex">修改</el-button>
          <el-button type="success" size="mini" @click="endEdit(scope.row,scope.$index,rowIndex = -1)" v-show="!rowIndex">保存</el-button>
          <el-button type="success" v-role='50010004' size="mini" @click="rowIndex = -1" plain="" v-show="!rowIndex">取消
          </el-button>
          <el-button type="primary" icon="el-icon-delete" size="mini" v-show="rowIndex" @click='delRow(scope.row)'></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :close-on-click-modal="false" v-dialogDrag title="新增" width="900px" :visible.sync="dialogFormVisible" :before-close="handleClose">
      <div style="height:55vh;overflow: auto;padding-left:80px">
        <el-form :model="addForm" inline ref="form">
          <el-form-item :label-width="labelWidth" label="手机号码" prop="memberName">
            <div class="addex">
              <el-input style="padding-left:0px;" ref="" oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" maxlength="11" v-model="addForm.mobilePhone" @change="memberOne" @blur="memberOne">
                <el-button size="mini" slot="append" icon="el-icon-search" @click="openMember"></el-button>
              </el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.memberName!=null" :label-width="labelWidth" label="会员名字" prop="memberName">
            <div class="addex">
              <span>{{addForm.memberName}} -</span>
              <span :class="addForm.sex==1?'text-blue':'text-red'">{{addForm.sex==1?'男':'女'}}</span>
            </div>
          </el-form-item>
          <br>
          <el-form-item :label-width="labelWidth" label="选择类型">
            <div class="addex">
              <el-radio-group v-model="addForm.cardType" @change='change'>
                <el-radio :label='1'>项目疗程</el-radio>
                <el-radio :label='0'>充值类别</el-radio>
              </el-radio-group>
            </div>
          </el-form-item>
          <el-form-item :label-width="labelWidth" label="类型名称" prop="rechargeTypeName">
            <div class="addex text-cyan">
              <el-button :disabled="addForm.cardType==null" size="mini" type="primary" v-show="addForm.projectName==null&&addForm.rechargeTypeName==null" @click="electDialogFormVisible=true">选择</el-button>
              <div @click="electDialogFormVisible=true" v-show="addForm.projectName!=null||addForm.rechargeTypeName!=null" style="display:flex;align-items: center;">
                <div>{{addForm.projectName}}</div>
                <div>{{addForm.rechargeTypeName}}</div>
                <i class="el-icon-edit"></i>
              </div>
            </div>
          </el-form-item>
          <el-form-item :label-width="labelWidth" label="原帐户编码" prop="oldProjectNum">
            <div class="addex">
              <el-input v-model="addForm.oldProjectNum"></el-input>
            </div>
          </el-form-item>
          <el-form-item :label-width="labelWidth" label="原帐户名称" prop="oldProjectName">
            <div class="addex">
              <el-input v-model="addForm.oldProjectName"></el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.projectName!=null" :label-width="labelWidth" label="标准金额" prop="standardMoney">
            <div class="addex">
              <el-input v-model="addForm.standardMoney"></el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.projectName!=null" :label-width="labelWidth" label="标准次数" prop="standardCount">
            <div class="addex">
              <el-input v-model="addForm.standardCount"></el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.projectName!=null" :label-width="labelWidth" label="剩余金额" prop="courseRestPrice">
            <div class="addex">
              <el-input v-model="addForm.courseRestPrice"></el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.projectName!=null" :label-width="labelWidth" label="可用金额" prop="courseConsumePrice">
            <div class="addex">
              <el-input v-model="addForm.courseConsumePrice"></el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.rechargeTypeName!=null" :label-width="labelWidth" label="剩余金额" prop="rechargeTypeName">
            <div class="addex">
              <el-input v-model="addForm.restMoney"></el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.rechargeTypeName!=null" :label-width="labelWidth" label="可用金额" prop="rechargeTypeName">
            <div class="addex">
              <el-input v-model="addForm.cardConsumeMoney"></el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.rechargeTypeName!=null" :label-width="labelWidth" label="赠送剩余金额" prop="rechargeTypeName">
            <div class="addex">
              <el-input v-model="addForm.cardGiftMoney"></el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.rechargeTypeName!=null" :label-width="labelWidth" label="赠送可用金额" prop="rechargeTypeName">
            <div class="addex">
              <el-input v-model="addForm.giftConsumeMoney"></el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.projectName!=null" :label-width="labelWidth" label="剩余次数" prop="rechargeTypeName">
            <div class="addex">
              <el-input v-model="addForm.restCount"></el-input>
            </div>
          </el-form-item>
          <el-form-item v-show="addForm.projectName!=null" :label-width="labelWidth" label="可用次数" prop="rechargeTypeName">
            <div class="addex">
              <el-input v-model="addForm.courseConsumeCount"></el-input>
            </div>
          </el-form-item>
          <el-form-item :label-width="labelWidth" v-show="addForm.projectName!=null||addForm.rechargeTypeName!=null" label="欠款金额" prop="rechargeTypeName">
            <div class="addex">
              <el-input v-model="addForm.debtMoney"></el-input>
            </div>
          </el-form-item>
          <el-form-item :label-width="labelWidth" label="备注" prop="remark">
            <div class="addex">
              <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="addForm.remark"></el-input>
            </div>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" plain @click="handleClose">取 消</el-button>
        <el-button size="small" type="primary" @click="confirm(dialogFormVisible=false)">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" v-dialogDrag :title="addForm.cardType==0?'选择充值类别':'选择项目'" :visible.sync="electDialogFormVisible" :append-to-body="true">
      <div class="electform">
      <!-- 模糊查询 -->
        <div style="display:flex;align-items:center">
          <el-input v-model="typeParams.name" placeholder="请输入名称" style="width:120px;margin-right:20px"></el-input>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" size='mini' @click="searchClick">确认</el-button>
          </div>
        </div>
        <el-table :data="projectList"  @row-click='radioRow' v-if="addForm.cardType==1" max-height="550" @row-dblclick="electConfirm(electDialogFormVisible=false)">
          <el-table-column label="选择" width="80">
            <template slot-scope="scope">
              <el-radio v-model="tableRadio" :label="scope.row.tradeId" @change.native="(scope.row)">{{''}}</el-radio>
            </template>
          </el-table-column>
          <el-table-column width="1"></el-table-column>

          <el-table-column align="center" min-width="100" label="项目名称" prop="projectName" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column align="center" min-width="80" label="散客标价" prop="price"></el-table-column>
          <el-table-column align="center" min-width="80" label="散客最低价" prop="minumumPrice"></el-table-column>
          <el-table-column align="center" min-width="80" label="会员标价" prop="priceMember"></el-table-column>
          <el-table-column align="center" min-width="80" label="会员最低价" prop="minumumPriceMember"></el-table-column>
          <el-table-column align="center" min-width="80" label="最少销售次数" prop="minumumTimes">
          </el-table-column>
        </el-table>
        <el-table :data="rechargeTypeList" @row-click='radioRow' v-if="addForm.cardType==0" max-height="550" @row-dblclick="electConfirm(electDialogFormVisible=false)">
          <el-table-column label="选择" width="80">
            <template slot-scope="scope">
              <el-radio v-model="tableRadio" :label="scope.row.tradeId" @change.native="(scope.row)">
                {{''}}
              </el-radio>
            </template>
          </el-table-column>
          <el-table-column align="center" min-width="80" label="充值类别" prop="type">
            <template slot-scope="scope">
              <div v-if="addForm.cardType==0">{{scope.row.type==0?'赠送卡':'折扣卡'}}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" min-width="120" label="充值名称" prop="rechargeTypeName" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column align="center" min-width="80" label="享受折扣(%)" prop="discount"></el-table-column>
          <el-table-column align="center" min-width="80" label="续充金额" prop="rechargeMoney"></el-table-column>
          <el-table-column align="center" min-width="80" label="赠送金额" prop="giftMoney"></el-table-column>
        </el-table>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" plain @click="(electDialogFormVisible = false)">取 消</el-button>
        <el-button size="mini" type="primary" @click="electConfirm()">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" v-dialogDrag title="导入列表" :visible.sync="editDialogFormVisible" width="80%">
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" plain="" @click="editDialogFormVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="submit(editDialogFormVisible=false)">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="导入表格" :visible.sync="infoDialog" :close-on-click-modal='false'>
      <excel @fileData='fileDatas' @infoDialogV='infoDialogV'></excel>
    </el-dialog>
    <el-dialog title="搜索" :visible.sync="searchDialog">
      <el-form :model="searchForm">
        <el-form-item label="会员名字搜索:" label-width="120px">
          <div class="searchDiv">
            <el-input v-model="searchForm.memberName" placeholder="输入要查询的会员名字" clearable>
            </el-input>
          </div>
        </el-form-item>
        <el-form-item label="账户搜索:" label-width="120px">
          <div class="searchDiv">
            <el-input maxlength="11" v-model="searchForm.tradeName" placeholder="输入要交易账户名称" oninput="this.value=this.value.replace(/\D/g,'')" pattern="[0-9]*" clearable></el-input>
          </div>
        </el-form-item>
         <el-form-item label="日期查询:" label-width="120px">
          <div class="searchDiv">
            <el-date-picker
              style="width:200px"
              v-model="searchForm.modifyDate"
              type="daterange"
              format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择日期">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item label="门店查询" label-width="120px">
          <div class="serachDiv">
            <storesSelect style="width:200px" ref="storesSelect" @selecData='selecData'/>
          </div>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" plain @click="searchDialog = false"> 取 消</el-button>
        <el-button type="primary" size="mini" @click="search(searchDialog = false) ">确 定</el-button>
      </span>
    </el-dialog>
    <div class="block" style="margin-top:15px;">
      <!-- 分页组件 -->
      <el-pagination align="left" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-sizes="[5,10,20,30,40,50]" :page-size="pageInfo.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageInfo.total"></el-pagination>
    </div>
    <member ref="member" @memberData="memberData"></member>
  </div>
</template>
<script>
import storesSelect from '@/components/store/select'
import { partten } from "../../../../partten/index.js";
import excel from "@/components/excel";
import { propageNew, recTypePage } from "@/api/storeManage";
import member from "@/components/member/index";
import {
  memberInitAdd,
  memberInitDownload,
  memberInitExport,
  memberInitImport,
  memberInitUpdate,
  memberInitDelete,
  memberInitCheck,
  memberInitInit,
  storeMemberOne,
  memberInitPage,
} from "@/api/eashier";
export default {
  components: {
    excel,
    member,
    storesSelect
  },
  data() {
    return {
      typeParams:{},
      searchDialog: false, //搜索弹窗开关
      searchForm: {
        //搜索表单
      },
      searchTrue: false, //搜索判断
      pageInfo: {
        total: 0, //分页总条数
        pageNum: 1,
        pageSize: 10,
        importList: [],
      },
      rowIndex: -1,
      options: [
        {
          value: 0,
          label: "充值账户",
        },
        {
          value: 1,
          label: "疗程账户",
        },
      ],
      labelWidth: "100px",
      addForm: {
        projectName: null,
        sex: null,
        rechargeTypeName: null,
        cardType: null,
        memberState: 1,
        cardState: 1,
        memberNum: null,
        memberName: null,
      },
      tableRadio: null,
      tableRadioList: {},
      searchDialog: false, //搜索弹窗开关
      dialogFormVisible: false, //弹窗开关
      editDialogFormVisible: false,
      electDialogFormVisible: false,
      input: null,
      selectIndex: -1,
      activeName: "1",
      searchTrue: false, //搜索判断
      infoDialog: false, //上传文件弹窗开关
      projectList:[],
      rechargeTypeList:[]

    };
  },
  watch:{
    'typeParams.name':{
      handler(val){
        if(val == ''){
          this.pages()
        }
      },
      immediate:true
    }
  },
  methods: {
    searchClick(){
      this.pages()
    },
    //关闭弹窗前的回调方法
    handleClose() {
      this.addForm = {};
      this.dialogFormVisible = false;
      this.$refs.form.clearValidate();
      this.typeParams = {}
    },
    // 门店回调
    selecData(ids){
      this.searchForm.storeIds = ids
    },
    //搜索方法
    search() {
      this.searchForm.initState = this.activeName * 1;
      this.searchForm.pageNum = this.pageInfo.pageNum;
      this.searchForm.pageSize = this.pageInfo.pageSize;
      let params = { ...this.searchForm }
      try{
        // null.length会报错，所以try catch
        if(params.modifyDate.length){
          params['startDate'] = params['modifyDate'][0] + ' 00:00:00'
          params['sendDate'] = params['modifyDate'][1] + ' 23:59:59'
          delete params['modifyDate']
        }
      }catch(err){
        delete params['modifyDate']
      }
      memberInitPage(params).then((res) => {
        if (res.code == "000000") {
          if (res.pageInfo.total == 0) {
            this.$message.warning({
              message: "没有找到符合条件的数据",
            });
          }
          // 确认清空选项
          this.searchForm = {}
          this.$refs.storesSelect.storeIds = []
          res.pageInfo.importList = res.pageInfo.list;
          this.pageInfo = res.pageInfo;
          this.searchTrue = true;
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    //打开选择会员弹窗
    openMember() {
      this.$refs.member.show(this.vip);
    },
    //选中会员返回方法
    memberData(v) {
      this.addForm.mobilePhone = v.mobilePhone;
      this.memberOne();
    },
    //查询会员信息
    memberOne() {
      var page = { storeId: sessionStorage.getItem("parentId") };
      if (this.listIndex != -1) {
        page.mobilePhone = this.pageInfo.importList[this.listIndex].mobilePhone;
      } else {
        page.mobilePhone = this.addForm.mobilePhone;
      }
      if (partten.phoneNum.test(page.mobilePhone)) {
        storeMemberOne(page).then((res) => {
          if (res.code == "000000") {
            res.data.debtMoney = 0;
            if (this.listIndex != -1) {
              delete res.data.id;
              let form = Object.assign(
                this.pageInfo.importList[this.listIndex],
                res.data
              );
              this.pageInfo.importList.splice(this.listIndex, 1, form);
            } else {
              res.data.memberId = res.data.id;
              this.addForm = Object.assign(this.addForm, res.data);
            }
          } else {
            this.$message.warning({
              message: res.message,
            });
          }
        });
      } else {
        this.$message.warning({
          message: "请输入正确的手机号",
        });
      }
    },
    //下载模板方法
    download() {
      memberInitDownload().then((res) => {
        let blob = new Blob([res]);
        console.log(blob);
        var a = document.createElement("a");
        var url = window.URL.createObjectURL(blob);
        console.log(url);
        a.href = url;
        a.download = "单据账户初始化模板.xlsx";
        a.click();
        window.URL.revokeObjectURL(url);
      });
    },

    //导出方法
    exit() {
      this.searchForm.initState = this.activeName * 1;
      this.searchForm.pageNum = this.pageInfo.pageNum;
      this.searchForm.pageSize = this.pageInfo.pageSize;
      if (this.searchForm.projectTypeName == "") {
        delete this.searchForm.projectTypeName;
      }
      console.log(this.searchForm);
      memberInitExport(this.searchForm).then((res) => {
        let blob = new Blob([res]);
        var a = document.createElement("a");
        var url = window.URL.createObjectURL(blob);
        console.log(url);
        a.href = url;
        a.download = "单据账户导出表.xlsx";
        a.click();
        window.URL.revokeObjectURL(url);
      });
    },

    checks() {
      var page = {
        pageNum: this.pageInfo.pageNum,
        pageSize: this.pageInfo.pageSize,
        initState: this.activeName,
      };
      memberInitCheck(page).then((res) => {
        if (res.code == "000000") {
          if (this.activeName * 1 == 2) {
            res.pageInfo.importList = res.pageInfo.list;
            this.pageInfo = res.pageInfo;
          } else {
            this.memberInitPage();
          }
          this.$message.success({
            message: res.message,
          });
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    inits() {
      memberInitInit({
        initState: 3,
      }).then((res) => {
        if (res.code == "000000") {
          this.$message.success({
            message: res.message,
          });
          this.memberInitPage();
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    fileDatas(v) {
      var fileData = new FormData();
      if (v == null) {
        this.$alert("请选择需要上传的文件", "提示", {
          confirmButtonText: "确定",
          confirmButtonClass: "confirmbtnFalses",
          type: "warning",
          center: true,
          callback: (action) => {},
        });
      } else {
        fileData.append("multipartFile", v);
        memberInitImport(fileData).then((res) => {
          if (res.code == "000000") {
            this.$message.success({
              message: res.message,
            });
            this.memberInitPage();
          } else {
            this.$alert(res.message, "提示", {
              confirmButtonText: "确定",
              confirmButtonClass: "confirmbtnFalses",
              type: "warning",
              center: true,
              callback: (action) => {},
            });
          }
        });
      }
    },
    //返回上传文件弹窗状态
    infoDialogV(v) {
      this.infoDialog = v;
    },
    openEdit(row, index) {
      // let show = true
      // this.pageInfo.importList.forEach((item, indexs) => {
      // 	if (indexs != index && item.showInput == true) {
      // 		console.log(123);
      // 		item.showInput = false
      // 		show = false
      // 	}
      // })
    },
    openEditTpe(row, index) {
      this.addForm.cardType = row.cardType;
      this.selectIndex = index;
      this.electDialogFormVisible = true;
      console.log(row);
    },
    endEdit(row, index) {
      if (row.debtMoney == undefined || row.debtMoney == null) {
        row.debtMoney = 0;
      }
      if (row.cardGiftMoney == undefined || row.cardGiftMoney == null) {
        row.cardGiftMoney = 0;
      }
      if (row.giftConsumeMoney == undefined || row.giftConsumeMoney == null) {
        row.giftConsumeMoney = 0;
      }
      if (
        this.addForm.cardState == undefined ||
        this.addForm.cardState == null
      ) {
        this.addForm.cardState = 1;
      }
      if (
        this.addForm.memberState == undefined ||
        this.addForm.memberState == null
      ) {
        this.addForm.memberState = 1;
      }
      memberInitUpdate(this.pageInfo.importList).then((res) => {
        if (res.code == "000000") {
          this.$message.success({
            message: res.message,
          });
          this.memberInitPage();
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },

    delRow(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          memberInitDelete({
            id: row.id,
          }).then((res) => {
            if (res.code == "000000") {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.memberInitPage();
            } else {
              this.$alert(res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {},
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //返回当前行的下标
    tableRowClassName({ row, rowIndex }) {
      row.index = rowIndex;
      // row.showInput = false
    },
    //提交信息
    submit() {},
    change(row) {
      console.log(row);
      this.typeParams = {}
      let form = {
        cardState: this.cardState,
        memberName: this.addForm.memberName,
        sex: this.addForm.sex,
        mobilePhone: this.addForm.mobilePhone,
        memberNum: this.addForm.memberNum,
        cardType: this.addForm.cardType,
        memberState: this.addForm.memberState,
        memberId: this.addForm.memberId,
      };
      this.addForm = form;
    },

    cardTypeChange() {
      let form = {
        cardState: this.pageInfo.importList[this.listIndex].cardState,
        memberName: this.pageInfo.importList[this.listIndex].memberName,
        sex: this.pageInfo.importList[this.listIndex].sex,
        mobilePhone: this.pageInfo.importList[this.listIndex].mobilePhone,
        memberNum: this.pageInfo.importList[this.listIndex].memberNum,
        cardType: this.pageInfo.importList[this.listIndex].cardType,
        memberState: this.pageInfo.importList[this.listIndex].memberState,
        // tradeName: this.pageInfo.importList[this.listIndex].tradeName,
        showInput: this.pageInfo.importList[this.listIndex].showInput,
        initState: this.pageInfo.importList[this.listIndex].initState,
        id: this.pageInfo.importList[this.listIndex].id,
      };
      this.pageInfo.importList.splice(this.listIndex, 1, form);
    },
    //确定返回方法
    confirm() {
      if (
        this.addForm.debtMoney == undefined ||
        this.addForm.debtMoney == null ||
        this.addForm.debtMoney == ""
      ) {
        this.addForm.debtMoney = 0;
      }
      if (
        this.addForm.cardGiftMoney == undefined ||
        this.addForm.cardGiftMoney == null ||
        this.addForm.cardGiftMoney == ""
      ) {
        this.addForm.cardGiftMoney = 0;
      }
      if (
        this.addForm.giftConsumeMoney == undefined ||
        this.addForm.giftConsumeMoney == null ||
        this.addForm.giftConsumeMoney == ""
      ) {
        this.addForm.giftConsumeMoney = 0;
      }
      if (
        this.addForm.cardState == undefined ||
        this.addForm.cardState == null
      ) {
        this.addForm.cardState = 1;
      }
      if (
        this.addForm.memberState == undefined ||
        this.addForm.memberState == null
      ) {
        this.addForm.memberState = 1;
      }
      if (this.addForm.cardType == 0) {
        this.addForm.standardMoney = this.addForm.rechargeMoney;
      }
      console.log(this.addForm);
      memberInitAdd(this.addForm).then((res) => {
        if (res.code == "000000") {
          this.$message.success({
            message: res.message,
          });
          this.activeName = "1";
          this.memberInitPage();
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    electConfirm() {
      if (this.selectIndex != -1) {
        let form = Object.assign(
          this.pageInfo.importList[this.selectIndex],
          this.tableRadioList
        );
        this.pageInfo.importList.splice(this.selectIndex, 1, form);
      } else {
        this.addForm = Object.assign(this.addForm, this.tableRadioList);
      }
      this.electDialogFormVisible = false;
    },
    radioRow(row) {
      this.tableRadio = row.tradeId;
      this.tableRadioList = row;
    },
    //切换标签页
    handleClick(tab, event) {
      console.log(tab.name, event);
      if (tab.name * 1 == 2) {
        this.checks();
        this.searchTrue = false;
      } else {
        this.memberInitPage();
      }
    },
    pages() {
      let page1 = {
        pageNum: 1,
        pageSize: 1000,
        state: 1,
        directConsumption: 0,
      };
      let page2 = {
        pageNum: 1,
        pageSize: 1000,
        state: 1,
      };
      this.addForm.cardType?(this.typeParams.name?page1.projectName=this.typeParams.name:""):(this.typeParams.name?page2.rechargeTypeName=this.typeParams.name:"")
      propageNew(page1).then((res) => {
        if (res.code == "000000") {
          res.pageInfo.list.forEach((item) => {
            item.tradeName = item.projectName;
            item.tradeId = item.id;
            delete item.id;
          });
          this.projectList = res.pageInfo.list;
          console.log(this.projectList)
        } else {
        }
      });
      recTypePage(page2).then((res) => {
        if (res.code == "000000") {
          res.pageInfo.list.forEach((item) => {
            item.tradeName = item.rechargeTypeName;
            item.tradeId = item.id;
            delete item.id;
          });
          this.rechargeTypeList = res.pageInfo.list;
        } else {
        }
      });
    },
    memberInitInit() {
      let page = {
        id: "",
      };
      memberInitInit(page).then((res) => {
        console.log(res);
      });
    },
    handleSizeChange(val) {
      //   //console.log(`每页 ${val} 条`);
      this.pageInfo.pageSize = val;

      if (this.searchTrue == true) {
        this.search();
      } else {
        if (this.activeName * 1 == 2) {
          this.checks();
        } else {
          this.memberInitPage();
        }
      }
    },
    handleCurrentChange(val) {
      //   //console.log(`当前页: ${val}`);
      this.pageInfo.pageNum = val;
      if (this.searchTrue == true) {
        this.search();
      } else {
        if (this.activeName * 1 == 2) {
          this.checks();
        } else {
          this.memberInitPage();
        }
      }
    },
    memberInitPage() {
      let page = {
        pageNum: this.pageInfo.pageNum,
        pageSize: this.pageInfo.pageSize,
        initState: this.activeName,
      };

      memberInitPage(page).then((res) => {
        if (res.code == "000000") {
          res.pageInfo.list.forEach((item) => {
            item.showInput = false;
          });
          this.pageInfo.importList = res.pageInfo.list;
          this.pageInfo.total = res.pageInfo.total;
        } else {
        }
      });
    },
  },
  created() {
    let list = JSON.parse(sessionStorage.getItem("list"));
    list.forEach((item) => {
      if (item.id == 50010001) {
        this.memberInitPage();
        this.pages();
      }
    });
  },
};
</script>
<style scoped>
.electform .el-radio__label {
  display: none;
}

.addex {
  width: 200px;
}

.setImport .el-tabs .el-tabs__content {
  display: none;
}
</style>
