<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="所属组织" prop="deptIdList">  
            <el-cascader v-model="queryParams.deptIdList"
            :options="deptOptions" :filterable="true" style="width: 240px" :show-all-levels="false"
            :props="{ 
                multiple: true,
                emitPath: false,// 若设置 false，则只返回该节点的值，只返回最后选择的id
                checkStrictly: false,//来设置父子节点取消选中关联，从而达到选择任意一级选项的目的
                value:'id',label:'label' 
            }" clearable collapse-tags >
            </el-cascader> 
        </el-form-item> 
        <el-form-item label="关键字" prop="searchValue">
            <el-input v-model="queryParams.searchValue" placeholder="请输入用户姓名，编号，手机号" maxlength="20" clearable style="width: 240px"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button 
            size="mini"
            @click="handleBatchEdit"
          >批量补扣</el-button>
        </el-col>
         
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row> 
      <el-table v-loading="loading" :data="tableListData" height="800">
        <el-table-column label="序号" align="center" width="80" type="index" fixed="left">
            <template scope="scope"> 
                <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index+1 }}</span>
            </template> 
        </el-table-column> 
        <el-table-column label="用户编号" align="center" prop="custNum" :show-overflow-tooltip="true" width="120" fixed="left"/>
        <el-table-column label="用户姓名" align="center" prop="custName" :show-overflow-tooltip="true" width="120" fixed="left"/>
        <el-table-column label="用户手机号" align="center" prop="mobile" :show-overflow-tooltip="true" width="120"/>
        <el-table-column label="所属组织" align="center" prop="orgFullName" :show-overflow-tooltip="true" width="120"/>
        <el-table-column label="用户类别" align="center" prop="psnTypeName" :show-overflow-tooltip="true" width="120"/>
        <el-table-column label="账户总余额" align="center" prop="accBalTotal" :show-overflow-tooltip="true" width="120">
          <template slot-scope="scope">
                <span>{{ (scope.row.accBalTotal/100).toFixed(2) }}</span>
            </template> 
        </el-table-column>
        <el-table-column label="可用总余额" align="center" prop="accAvailableBal" :show-overflow-tooltip="true" width="120">
          <template slot-scope="scope">
                <span>{{ (scope.row.accAvailableBal/100).toFixed(2) }}</span>
            </template> 
        </el-table-column>
        <el-table-column label="个人钱包余额" align="center" prop="walletBal" :show-overflow-tooltip="true" width="120">
          <template slot-scope="scope">
                <span>{{ (scope.row.walletBal/100).toFixed(2) }}</span>
            </template> 
        </el-table-column>
        <el-table-column label="补贴钱包余额" align="center" prop="subsidyBal" :show-overflow-tooltip="true" width="120">
          <template slot-scope="scope">
                <span>{{ (scope.row.subsidyBal/100).toFixed(2) }}</span>
            </template> 
        </el-table-column>
        <!-- <el-table-column label="红包余额" align="center" prop="redEnvelope" :show-overflow-tooltip="true" width="120">
          <template slot-scope="scope">
                <span>{{ (scope.row.redEnvelope/100).toFixed(2) }}</span>
            </template> 
        </el-table-column> -->
        <el-table-column label="冻结金额" align="center" prop="accFreezeBalTotal" :show-overflow-tooltip="true" width="120">
          <template slot-scope="scope">
                <span>{{ (scope.row.accFreezeBalTotal/100).toFixed(2) }}</span>
            </template> 
        </el-table-column>
        <el-table-column label="账户状态" align="center" prop="accountStatusName" :show-overflow-tooltip="true" width="120"/>
        <!-- <el-table-column label="账户有效期" align="center" prop="endDate" :show-overflow-tooltip="true" width="150"/> -->

        
        <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="scope"> 
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)" 
            >补扣</el-button>
          </template>
        </el-table-column>
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
      <!-- 补扣对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body> 
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-row> 
                <el-col :span="12">
                  <el-form-item label="所属区域" prop="areaId">
                    <el-cascader v-model="form.areaId"
                      :options="treeAreaOptions" :filterable="true" style="width: 100%;" :show-all-levels="false"
                      :props="{ 
                        emitPath: false,// 若设置 false，则只返回该节点的值，只返回最后选择的id
                        checkStrictly: false,//来设置父子节点取消选中关联，从而达到选择任意一级选项的目的
                        value:'id',label:'label'
                      }" clearable @change="handleAreaChange">
                    </el-cascader>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="所属食堂" prop="canteenId">
                    <el-select v-model="form.canteenId" placeholder="请选择所属食堂" clearable style="width: 100%;" @change="handleCanteenChange">
                        <el-option v-for="item in canteenOptions"
                            :key="item.canteenId"
                            :label="item.canteenName"
                            :value="item.canteenId"
                        ></el-option>
                    </el-select> 
                  </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                  <el-form-item label="所属档口" prop="stallId">
                    <el-select v-model="form.stallId" placeholder="请选择所属档口" clearable style="width: 100%;" @change="getPayDeviceList">
                        <el-option v-for="item in stallOptions"
                            :key="item.stallId"
                            :label="item.stallName"
                            :value="item.stallId"
                        ></el-option>
                    </el-select> 
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="订单来源" prop="ordWay">
                        <el-select v-model="form.ordWay" style="width: 100%;" clearable @change="getPayDeviceList">
                            <el-option label="移动端" value="1" />
                            <el-option label="设备" value="2" />
                        </el-select>  
                    </el-form-item>
                </el-col> 
            </el-row>
            <el-row>
                <el-col :span="12">
                  <el-form-item label="设备名称" prop="deviceId">
                    <el-select v-model="form.deviceId" placeholder="请选择设备名称" clearable style="width: 100%;" :disabled="form.ordWay==1">
                        <el-option v-for="item in devicesOptions"
                            :key="item.deviceId"
                            :label="item.deviceName"
                            :value="item.deviceId"
                        ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="订单日期" prop="ordDateTime">
                        <el-date-picker
                            v-model="form.ordDateTime" style="width: 100%;"
                            type="date" value-format="yyyy-MM-dd" clearable
                            placeholder="选择日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col> 
            </el-row>
            <el-row>
                <el-col :span="12">
                  <el-form-item label="餐次" prop="mealtimeType">
                    <el-select v-model="form.mealtimeType" style="width: 100%;" clearable>
                      <el-option label="早餐" value="1"></el-option>
                      <el-option label="午餐" value="2"></el-option>
                      <el-option label="下午茶" value="3"></el-option>
                      <el-option label="晚餐" value="4"></el-option>
                      <el-option label="夜宵" value="5"></el-option>
                    </el-select>  
                  </el-form-item>
                </el-col> 
                <el-col :span="12">
                  <el-form-item label="补扣原因" prop="remark">
                    <el-input v-model="form.remark" placeholder="请输入补扣原因" maxlength="30" clearable style="width: 100%;"/>
                  </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                  <el-form-item label="补扣金额" prop="amount">
                    <el-input v-model="form.amount" placeholder="请输入补扣金额" maxlength="6" clearable style="width: 100%;" @input="(v)=>(form.amount=v.replace(/[^\d.]/g,''))"/>
                  </el-form-item>
                </el-col>
                <el-col :span="12"> 
                    <el-form-item label="是否设置补扣顺序" prop="ifSetDeduction">
                        <el-radio-group v-model="form.ifSetDeduction">
                            <el-radio label="1">是</el-radio>
                            <el-radio label="2">否</el-radio> 
                        </el-radio-group>
                    </el-form-item>
                </el-col> 
            </el-row>
            <el-row v-if="form.ifSetDeduction==1"> 
                <el-col :span="12">
                    <el-form-item label="补扣顺序" prop="walletTypeList">
                        <el-select v-model="form.walletTypeList" multiple style="width: 100%;" clearable>
                            <el-option label="个人钱包" value="1"></el-option>
                            <el-option label="补贴钱包" value="2"></el-option>
                            <el-option label="红包" value="4"></el-option> 
                        </el-select> 
                    </el-form-item>  
                </el-col>
            </el-row> 
            
        </el-form> 
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
      <!-- 批量补扣 -->
      <el-dialog title="批量补扣" :visible.sync="openBatch" width="900px" append-to-body>
        <div style="width: 100%;height: 650px;overflow-y: auto;">
          <div style="height: 30px;padding-left: 10px;line-height: 30px;margin: 10px 0;font-size: 14px;color: #000;background: #e7f0fa;border-left: 3px solid #4b80fd;">第一步：选择用户</div>
            <el-form :model="dialogParams" ref="dialogParams" size="small" :inline="true" v-show="showSearch" label-width="68px">
              <el-form-item label="" prop="searchValue">
                  <el-input v-model="dialogParams.searchValue" placeholder="请输入用户姓名，编号，手机号" maxlength="20" clearable style="width: 240px"/>
              </el-form-item>
              <el-form-item label="" prop="deptIdList">  
                  <el-cascader v-model="dialogParams.deptIdList"
                  :options="deptOptions" :filterable="true" style="width: 240px" :show-all-levels="false"
                  placeholder="所属组织"
                  :props="{ 
                      multiple: true,
                      emitPath: false,// 若设置 false，则只返回该节点的值，只返回最后选择的id
                      checkStrictly: false,//来设置父子节点取消选中关联，从而达到选择任意一级选项的目的
                      value:'id',label:'label' 
                  }" clearable collapse-tags >
                  </el-cascader> 
              </el-form-item> 
              <el-form-item label="" prop="psnType">
                  <el-select v-model="dialogParams.psnType" placeholder="用户类别" style="width: 240px" clearable> 
                    <el-option
                        v-for="dict in dict.type.sys_user_type"
                        :key="dict.value"
                        :label="dict.label"
                        :value="Number(dict.value)"
                      />
                  </el-select>   
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleDialogQuery">搜索</el-button> 
              </el-form-item>
            </el-form> 
            <el-table :data="dialogTableData" height="300" ref="multipleTable" :row-key="(row)=>{return row.accountId}" @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="50" align="center" :reserve-selection="true"/>
              <el-table-column label="用户编号" align="center" prop="custNum" :show-overflow-tooltip="true"  />
              <el-table-column label="用户姓名" align="center" prop="custName" :show-overflow-tooltip="true" />
              <el-table-column label="用户手机号" align="center" prop="mobile" :show-overflow-tooltip="true" />
              <el-table-column label="所属组织" align="center" prop="orgFullName" :show-overflow-tooltip="true" />
              <el-table-column label="用户类别" align="center" prop="psnTypeName" :show-overflow-tooltip="true"/>
            </el-table>
            <pagination
              v-show="dialogTotal>0"
              :total="dialogTotal"
              :page.sync="dialogParams.pageNum"
              :limit.sync="dialogParams.pageSize"
              @pagination="getDialogList"
            />
            <div style="height: 30px;padding-left: 10px;line-height: 30px;margin: 20px 0;font-size: 14px;color: #000;background: #e7f0fa;border-left: 3px solid #4b80fd;">
                第二步：填写补扣金额
            </div>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px"> 
                <el-row> 
                <el-col :span="12">
                  <el-form-item label="所属区域" prop="areaId">
                    <el-cascader v-model="form.areaId"
                      :options="treeAreaOptions" :filterable="true" style="width: 100%;" :show-all-levels="false"
                      :props="{ 
                        emitPath: false,// 若设置 false，则只返回该节点的值，只返回最后选择的id
                        checkStrictly: false,//来设置父子节点取消选中关联，从而达到选择任意一级选项的目的
                        value:'id',label:'label'
                      }" clearable @change="handleAreaChange">
                    </el-cascader>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="所属食堂" prop="canteenId">
                    <el-select v-model="form.canteenId" placeholder="请选择所属食堂" clearable style="width: 100%;" @change="handleCanteenChange">
                        <el-option v-for="item in canteenOptions"
                            :key="item.canteenId"
                            :label="item.canteenName"
                            :value="item.canteenId"
                        ></el-option>
                    </el-select> 
                  </el-form-item>
                </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                    <el-form-item label="所属档口" prop="stallId">
                        <el-select v-model="form.stallId" placeholder="请选择所属档口" clearable style="width: 100%;" @change="getPayDeviceList">
                            <el-option v-for="item in stallOptions"
                                :key="item.stallId"
                                :label="item.stallName"
                                :value="item.stallId"
                            ></el-option>
                        </el-select> 
                    </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="订单来源" prop="ordWay">
                            <el-select v-model="form.ordWay" style="width: 100%;" clearable @change="getPayDeviceList">
                                <el-option label="移动端" value="1" />
                                <el-option label="设备" value="2" />
                            </el-select>  
                        </el-form-item>
                    </el-col> 
                </el-row>
                <el-row>
                    <el-col :span="12">
                    <el-form-item label="设备名称" prop="deviceId">
                        <el-select v-model="form.deviceId" placeholder="请选择设备名称" clearable style="width: 100%;" :disabled="form.ordWay==1">
                            <el-option v-for="item in devicesOptions"
                                :key="item.deviceId"
                                :label="item.deviceName"
                                :value="item.deviceId"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="订单日期" prop="ordDateTime">
                            <el-date-picker
                                v-model="form.ordDateTime" style="width: 100%;"
                                type="date" value-format="yyyy-MM-dd" clearable
                                placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                    </el-col> 
                </el-row>
                <el-row>
                    <el-col :span="12">
                    <el-form-item label="餐次" prop="mealtimeType">
                        <el-select v-model="form.mealtimeType" style="width: 100%;" clearable>
                        <el-option label="早餐" value="1"></el-option>
                        <el-option label="午餐" value="2"></el-option>
                        <el-option label="下午茶" value="3"></el-option>
                        <el-option label="晚餐" value="4"></el-option>
                        <el-option label="夜宵" value="5"></el-option>
                        </el-select>  
                    </el-form-item>
                    </el-col> 
                    <el-col :span="12">
                    <el-form-item label="补扣原因" prop="remark">
                        <el-input v-model="form.remark" placeholder="请输入补扣原因" maxlength="30" clearable style="width: 100%;"/>
                    </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="补扣金额" prop="amount">
                            <el-input v-model="form.amount" placeholder="请输入补扣金额" maxlength="9" clearable style="width: 100%;" @input="(v)=>(form.amount=v.replace(/[^\d.]/g,''))"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12"> 
                        <el-form-item label="是否设置补扣顺序" prop="ifSetDeduction">
                            <el-radio-group v-model="form.ifSetDeduction">
                                <el-radio label="1">是</el-radio>
                                <el-radio label="2">否</el-radio> 
                            </el-radio-group>
                        </el-form-item>
                    </el-col> 
                </el-row>
                <el-row v-if="form.ifSetDeduction==1"> 
                    <el-col :span="12">
                        <el-form-item label="补扣顺序" prop="walletTypeList">
                            <el-select v-model="form.walletTypeList" multiple style="width: 100%;" clearable>
                                <el-option label="个人钱包" value="1"></el-option>
                                <el-option label="补贴钱包" value="2"></el-option>
                                <el-option label="红包" value="4"></el-option> 
                            </el-select> 
                        </el-form-item>  
                    </el-col>
                </el-row> 
            </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="confirmBatchEdit">确 定</el-button>
          <el-button @click="openBatch=false">取 消</el-button>
        </div>
      </el-dialog>

      <el-dialog title="批量校验预览" :visible.sync="openResult" width="800px" append-to-body>
        <div>总人数： {{resultData.totalCount || '--' }} ， 补扣人数：{{resultData.sucCount || '--' }}， 补扣总额：{{resultData.sucTotalAmount || '--' }}， 无效人数：{{resultData.errCount || '--'}}</div>
        <el-table :data="resultData.errVOList" height="300">
            <el-table-column label="用户编号" align="center" prop="custNum" :show-overflow-tooltip="true"  />
            <el-table-column label="用户姓名" align="center" prop="custName" :show-overflow-tooltip="true" />
            <el-table-column label="用户手机号" align="center" prop="mobile" :show-overflow-tooltip="true" />
            <el-table-column label="所属组织" align="center" prop="orgFullName" :show-overflow-tooltip="true" />
            <el-table-column label="用户类别" align="center" prop="psnTypeName" :show-overflow-tooltip="true"/>
            <el-table-column label="金额" align="center" prop="amount" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <span>{{ (scope.row.amount/100).toFixed(2) }}</span>
                </template> 
            </el-table-column>
            <el-table-column label="失败原因" align="center" prop="errMsg" :show-overflow-tooltip="true"/>
        </el-table> 
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="openResult=false" v-if="resultData.sucVOList&&resultData.sucVOList.length==0">确 定</el-button>
          <el-button type="primary" @click="confirmBatchDeduct" v-else>继 续</el-button> 
          <el-button @click="openResult=false">取 消</el-button>
        </div>
      </el-dialog> 
    </div>
  </template>
  
  <script>
  import { deptTreeSelect } from '@/api/system/user'
  import { accInfoPageApi } from "@/api/accountCenter/manager";
  import { systemAreaTreeApi,getCanteenByAreaApi,getStallByCanteenApi } from "@/api/base/stall";
  import { getPayDeviceListApi,consumeDeductSingleApi,consumeBatchCheckApi,consumeDeductBatchApi } from "@/api/accountCenter/consume";
  
  
  export default {
    name: "",
    dicts: ['sys_user_type'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        //表格数据
        tableListData: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false, 
        //下拉选数据
        deptOptions:[], 
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10, 
          deptIdList:[],
          searchValue:null, 
        },
        cancelCount:0,
        expiredCount:0,
        treeAreaOptions:[],//区域树
        canteenOptions:[],//食堂下拉选
        stallOptions:[],//档口下拉选
        devicesOptions:[],
        // 表单参数
        form: {},
        rowData:{},
        pickerOptions:{                                 
            //禁用当前日期之前的日期
            disabledDate(time) {
            //Date.now()是javascript中的内置函数，它返回自1970年1月1日00:00:00 UTC以来经过的毫秒数。
               return time.getTime() < Date.now() - 8.64e7;
            }
        },
        // 表单校验
        rules: {
            //areaId canteenId  ordWay ordDateTime mealtimeType amount ifSetDeduction
            areaId: [
                { required: true, message: "所属区域不能为空", trigger: "blur" }
            ],
            canteenId: [
                { required: true, message: "所属食堂不能为空", trigger: "blur" }
            ],
            ordWay: [
                { required: true, message: "订单来源不能为空", trigger: "change" }
            ],
            ordDateTime: [
                { required: true, message: "订单日期不能为空", trigger: "blur" }
            ],
            mealtimeType: [
                { required: true, message: "餐次不能为空", trigger: "blur" }
            ],
            amount: [
                { required: true, message: "补扣金额不能为空", trigger: "blur" }
            ],
            ifSetDeduction: [
                { required: true, message: "是否设置补扣顺序不能为空", trigger: "blur" }
            ] 
        },
        openBatch:false,
        dialogParams: {
          pageNum: 1,
          pageSize: 10,
          accountStatusList:[],
          deptIdList:[],
          searchValue:null,
          psnType:null
        },
        dialogTableData:[],
        dialogTotal: 0, 
        batchIds:[],
        openResult:false,
        resultData:{}
      };
    },
    created() { 
        this.getDeptTree() 
        this.getAreaTreeData();
        this.getPayDeviceList(); 
        this.getList();
    },
    methods: {
        /** 查询部门下拉树结构 */
        getDeptTree() {
            deptTreeSelect().then((response) => {
                this.deptOptions = this.filterTree(response.data)
            })
        },
        filterTree(nodes) {
            return nodes
                .map((node) => {
                    if (node.children) {
                        node.children = this.filterTree(node.children)
                    }
                    return node
                })
                .filter((node) => node.status !== '1')
        },
        
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() { 
            this.resetForm("queryForm");
            this.handleQuery();
        },
        /** 查询列表 */
        getList() { 
            this.loading = true;
            let param = {
              "pageNum": this.queryParams.pageNum, 
              "pageSize": this.queryParams.pageSize, 
              "deptIdList": this.queryParams.deptIdList,
              "searchValue": this.queryParams.searchValue,
            }
            accInfoPageApi(param).then(response => {
                this.tableListData = response.rows;
                this.total = Number(response.total);
                this.loading = false;
            });
        },
        //区域树
        getAreaTreeData() {
            systemAreaTreeApi({}).then((response) => {
                this.treeAreaOptions = response.data; 
            });
        },
        handleAreaChange(e){ 
            let param= {
              "areaId":e,"canteenType": 1
            }
            getCanteenByAreaApi(param).then((response) => {
                this.canteenOptions=response.rows||[];
                this.form.canteenId=null
                this.stallOptions=[]
                this.form.stallId=null
                this.getPayDeviceList()
            });
        },
        handleCanteenChange(e){
            let param= {
                canteenId:e
            }
            getStallByCanteenApi(param).then((response) => {
                this.stallOptions=response.rows||[]; 
                this.form.stallId=null 
                this.getPayDeviceList()
            });
        }, 
        getPayDeviceList(){ 
            let param = {
                canteenId:this.form.canteenId,
                stallId:this.form.stallId
            }
            getPayDeviceListApi(param).then((response) => {
                this.devicesOptions=response||[]
                this.form.deviceId=null
            });
        },
        /** 补扣按钮操作 */
        handleUpdate(row) {
            this.reset();
            this.rowData = row
            this.open = true;
            this.title = "补扣";
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {};
            this.canteenOptions=[]
            this.stallOptions=[]
            this.$set(this.form,"ordWay","1")
            this.$set(this.form,"ifSetDeduction","2")
            this.resetForm("form");
        }, 
        /** 提交按钮 */
        submitForm: function() {
            this.$refs["form"].validate(valid => {
            if (valid) {
              let param = {
                ...this.rowData,
                ...this.form, 
              }
              param.amount=Number(this.form.amount*100);
              param.ordDateTime=this.form.ordDateTime+" 00:00:00";
              param.shopstallId=this.form.stallId;
              this.devicesOptions.forEach(item=>{
                if(item.deviceId == this.form.deviceId){
                    param.mchName = item.deviceName
                    param.mchNum = item.deviceNum
                    param.mchSn = item.deviceSn
                    param.mchType = item.deviceType
                }
              }) 
              consumeDeductSingleApi(param).then(response => {
                console.log("1",response)
                if(response.code==200){
                    this.$modal.msgSuccess("补扣成功");
                    this.open = false;
                    this.getList();
                }else{
                    this.$modal.msgError(response.msg);
                }  
              }).catch(() => {});
            }
            });
        },
        //批量补扣弹窗
        handleBatchEdit() {
          this.resetForm("dialogParams");
          this.getDialogList()
          this.batchIds = [] 
          this.form = {}
          this.canteenOptions=[]
          this.stallOptions=[]
          this.$set(this.form,"ordWay","1")
          this.$set(this.form,"ifSetDeduction","2")
          this.resetForm("form");
          this.openBatch = true;
          this.$nextTick(()=>{
            this.$refs.multipleTable.clearSelection() 
          },300)
        },
        //弹窗搜索
        handleDialogQuery(){
          this.dialogParams.pageNum = 1;
          this.getDialogList();
        },
        //批量弹窗表格查询
        getDialogList(){
          let param = {
              "pageNum": this.dialogParams.pageNum, 
              "pageSize": this.dialogParams.pageSize, 
              "deptIdList": this.dialogParams.deptIdList,
              "searchValue": this.dialogParams.searchValue,
              "psnType": this.dialogParams.psnType
            } 
            accInfoPageApi(param).then(response => {
                this.dialogTableData = response.rows;
                this.dialogTotal = Number(response.total); 
            });
        },
        //批量弹窗勾选
        handleSelectionChange(selection){
          this.batchIds = selection.map((item) => item.userId)  
        },
        //批量补扣提交
        confirmBatchEdit(){
          console.log(this.batchIds)
          console.log(this.form)
          if(this.batchIds.length>0){ 
            let param = { 
                ...this.form,
                custIdList:this.batchIds 
            }
            param.amount=Number(this.form.amount*100);
            param.ordDateTime=this.form.ordDateTime+" 00:00:00";
            param.shopstallId=this.form.stallId;
            this.devicesOptions.forEach(item=>{
                if(item.deviceId == this.form.deviceId){
                    param.mchName = item.deviceName
                    param.mchNum = item.deviceNum
                    param.mchSn = item.deviceSn
                    param.mchType = item.deviceType
                }
            }) 
            consumeBatchCheckApi(param).then(response => { 
                this.openBatch = false; 
                this.resultData = response.data
                this.openResult=true
            });
          }else{
            this.$modal.msgError("请先勾选账户！");
          } 
        },
        confirmBatchDeduct(){
          let param = { 
                ...this.resultData,
                custIdList:this.batchIds 
          } 
          consumeDeductBatchApi(param).then(response => {
              // this.$modal.msgSuccess("操作正在进行中，稍后可前往批量操作记录查看结果！");
              if(response.code==200){
                this.$modal.msgSuccess("操作成功！");
                this.getList();
                this.openResult=false
              }
          });
        }
        
    }
  };
  </script>
  