<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd(-1)"
          v-hasPermi="['cs:csPricingInventory:add']">新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['cs:csPricingInventory:edit']">修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['cs:csPricingInventory:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button plain size="mini" @click="handleSearch">高级搜索</el-button>
      </el-col>

      <el-col :span="1.5" :offset="8">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['cs:csPricingInventory:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-download" size="mini" @click="handleExportTemplate"
          v-hasPermi="['cs:csPricingInventory:export']">导出模板</el-button>
      </el-col>
      <el-col :span="6">
        <span style="padding-right: 10px;">表格设置</span>
        <el-select v-model="tableHeaderList" multiple collapse-tags placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div v-if="showSearch" ref="showSearch" class="searchForm">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="140px">
        <el-form-item label="关键词" prop="keyword">
          <el-input placeholder="请输入关键词" v-model="queryParams.keyword" />
        </el-form-item>
        <el-form-item label="用户VPN账号" prop="userAccount">
          <el-input v-model="queryParams.userAccount" placeholder="请输入用户VPN账号" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="用户姓名" prop="userName">
          <el-input v-model="queryParams.userName" placeholder="请输入用户姓名" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="中心经办人VPN账号" prop="centreAccount">
          <el-input v-model="queryParams.centreAccount" placeholder="请输入中心经办人VPN账号" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="用户单位" prop="userCompanyName">
          <el-input v-model="queryParams.userCompanyName" placeholder="请输入用户单位" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="资源类型" prop="resourceClassId">
          <el-select v-model="queryParams.resourceClassId" placeholder="请选择资源类型" clearable>
            <el-option label="HPC" :value="0" />
            <el-option label="商业软件" :value="1" />
            <el-option label="裸节点或云计算" :value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="使用状态" prop="useStatus">
          <el-select v-model="queryParams.useStatus" placeholder="请选择使用状态" clearable>
            <el-option label="进行中" :value="0" />
            <el-option label="已到期" :value="1" />
            <el-option label="结束" :value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="消费金额" prop="expendPrice">
          <el-input v-model="queryParams.expendPrice" placeholder="请输入消费金额" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="提交时间" prop="dateRange">
          <el-date-picker clearable v-model="queryParams.dateRange" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" placeholder="请选择创建时间">
          </el-date-picker>
        </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-button size="mini" @click="showSearch = false">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="loading" :data="csPricingInventoryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="sort">
        <template slot-scope="scope">
          {{ ((queryParams.pageNum - 1) * queryParams.pageSize) + (scope.$index + 1) }}
        </template>
      </el-table-column>
      <el-table-column label="清单编号" align="center" prop="inventoryNumber"
        v-if="tableHeaderList.indexOf('inventoryNumber') != -1" />
      <el-table-column label="制定时间" align="center" prop="createAt" v-if="tableHeaderList.indexOf('createAt') != -1"
        width="180" />
      <el-table-column label="经办人姓名" align="center" prop="operatorName"
        v-if="tableHeaderList.indexOf('operatorName') != -1" />
      <el-table-column label="用户姓名" align="center" prop="userName" v-if="tableHeaderList.indexOf('userName') != -1" />
      <el-table-column label="用户VPN账号" align="center" prop="userAccount"
        v-if="tableHeaderList.indexOf('userAccount') != -1" />
      <el-table-column label="用户单位" align="center" prop="userCompanyName"
        v-if="tableHeaderList.indexOf('userCompanyName') != -1" />
      <el-table-column label="中心经办人" align="center" prop="centreName"
        v-if="tableHeaderList.indexOf('centreName') != -1" />
      <el-table-column label="资源类型" align="center" prop="resourceClassId"
        v-if="tableHeaderList.indexOf('resourceClassId') != -1">
        <template slot-scope="scope">
          {{ scope.row.resourceClassId == 0 ? 'HPC' : scope.row.resourceClassId == 1 ? '商业软件' :
            scope.row.resourceClassId == 2 ? '裸节点' : ''
          }}
        </template>
      </el-table-column>
      <el-table-column label="消费金额" align="center" prop="expendPrice"
        v-if="tableHeaderList.indexOf('expendPrice') != -1" />
      <el-table-column label="资源计费说明" align="center" prop="resourceChargingList"
        v-if="tableHeaderList.indexOf('resourceChargingList') != -1">
        <template slot-scope="scope">
          <span style="cursor: pointer" @click="checkResourceChargingList(scope.row)">查看</span>
        </template>
      </el-table-column>
      <el-table-column label="资源回收策略" align="center" prop="recoveryStrategy"
        v-if="tableHeaderList.indexOf('recoveryStrategy') != -1" />
      <el-table-column label="使用状态" align="center" prop="useStatus" v-if="tableHeaderList.indexOf('useStatus') != -1">
        <template slot-scope="scope">
          <span style="color: #45b6af" v-if="scope.row.useStatus == 0">进行中</span>
          <span style="color: #dfba49" v-if="scope.row.useStatus == 1">已到期</span>
          <span style="color: #999999" v-if="scope.row.useStatus == 2">结束</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['cs:csPricingInventory:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['cs:csPricingInventory:remove']">删除</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="选择新增类型" :visible.sync="show" width="500px">
      <div class="addStyle">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd(0)"
          v-hasPermi="['cs:csPricingInventory:add']">新增HPC</el-button>
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd(1)"
          v-hasPermi="['cs:csPricingInventory:add']">新增商业软件</el-button>
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd(2)"
          v-hasPermi="['cs:csPricingInventory:add']">新增裸节点和云计算</el-button>
      </div>
    </el-dialog>
    <el-dialog title="资源计费说明" :visible.sync="showResourceChargingList">
      <el-table :data="resourceChargingList" :border="true" v-if="resourceClassId == 0">
        <el-table-column prop="sort" label="序号" width="90" align="center" fixed="left"></el-table-column>
        <el-table-column prop="resourceClass" label="资源类型">
          <template slot-scope="scope">
            <span>{{ scope.row.resourceClass }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="acAccount" label="AC账户名" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.acAccount }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="queueName" label="队列">
          <template slot-scope="scope">
            <span>{{ scope.row.queueName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="用户资源" align="center">
          <el-table-column prop="coreNum" label="核心数">
            <template slot-scope="scope">
              <span>{{ scope.row.coreNum }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="maxWorkNum" label="最大作业运行数">
            <template slot-scope="scope">
              <span>{{ scope.row.maxWorkNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column prop="cpuPrice" label="CPU单价(元)">
          <template slot-scope="scope">
            <span>{{ scope.row.cpuPrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="dcuPrice" label="DCU单价(元)">
          <template slot-scope="scope">
            <span>{{ scope.row.dcuPrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="storagePrice" label="存储单价(元/年*TB)">
          <template slot-scope="scope">
            <span>{{ scope.row.storagePrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="storageTotal" label="存储总量">
          <template slot-scope="scope">
            <span>{{ scope.row.storageTotal }}</span>
          </template>
        </el-table-column>
        <el-table-column label="赠送资源" align="center">
          <el-table-column prop="storageNum" label="存储量">
            <template slot-scope="scope">
              <span>{{ scope.row.storageNum }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="machinePrice" label="机时金额">
            <template slot-scope="scope">
              <span>{{ scope.row.machinePrice }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column prop="consumePrice" label="消费金额（元）">
          <template slot-scope="scope">
            <span>{{ scope.row.consumePrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="rechargePrice" label="账户充值金额（元）">
          <template slot-scope="scope">
            <span>{{ scope.row.rechargePrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注">
          <template slot-scope="scope">
            <span>{{ scope.row.remarks }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-table :data="resourceChargingList" :border="true" v-if="resourceClassId == 1">
        <el-table-column prop="sort" label="序号" width="90" align="center" fixed="left"></el-table-column>
        <el-table-column prop="resourceClass" label="资源类型">
          <template slot-scope="scope">
            <span>{{ scope.row.resourceClass }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="softwareName" label="软件名称" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.softwareName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="softwarePrice" label="软件单价（元/核/月）">
          <template slot-scope="scope">
            <span>{{ scope.row.softwarePrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="softwareCoreNum" label="软件使用核心权限（个）">
          <template slot-scope="scope">
            <span>{{ scope.row.softwareCoreNum }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="useDays" label="使用时长（天）">
          <template slot-scope="scope">
            <span>{{ scope.row.useDays }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="consumePrice" label="消费金额（元">
          <template slot-scope="scope">
            <span>{{ scope.row.consumePrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注">
          <template slot-scope="scope">
            <span>{{ scope.row.remarks }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-table :data="resourceChargingList" :border="true" v-if="resourceClassId == 2">
        <el-table-column prop="sort" label="序号" width="90" align="center" fixed="left"></el-table-column>
        <el-table-column prop="resourceClass" label="资源类型">
          <template slot-scope="scope">
            <span>{{ scope.row.resourceClass }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="contractName" label="合同名称">
          <template slot-scope="scope">
            <span>{{ scope.row.contractName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="annexUrl" label="附件">
          <template slot-scope="scope">
            <span>{{ scope.row.annexUrl }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="consumePrice" label="消费金额(元)">
          <template slot-scope="scope">
            <span>{{ scope.row.consumePrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注">
          <template slot-scope="scope">
            <span>{{ scope.row.remarks }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 添加或修改计价清单对话框 -->
    <el-dialog :visible.sync="open" append-to-body fullscreen>
      <div slot="title" style="font-size: 20px; font-weight: bold;">
        {{ title }}
      </div>
      <el-form ref="form" :model="form" inline style="padding-left: 10px">
        <el-form-item label="清单编号" prop="inventoryNumber">
          <el-input v-model="form.inventoryNumber" placeholder="请输入清单编号" />
        </el-form-item>
        <el-form-item label="制定时间" prop="createAt">
          <el-date-picker v-model="form.createAt" type="datetime" placeholder="请选择制定时间" value-format="yyyy-MM-dd HH:mm"
            format="yyyy-MM-dd HH:mm">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div class="module1">
        <div class="moduleTitle">用户基本信息</div>
        <el-form ref="form1" :model="form" inline>
          <el-form-item label="VPN账号" prop="userAccount">
            <el-input v-model="form.userAccount" placeholder="请输入VPN账号" />
          </el-form-item>
          <el-form-item label="用户姓名" prop="userName">
            <el-input v-model="form.userName" placeholder="请输入用户姓名" maxlength="10" />
          </el-form-item>
          <el-form-item label="用户单位" prop="userCompanyName">
            <el-input v-model="form.userCompanyName" placeholder="请输入用户单位" />
          </el-form-item>
          <el-form-item label="用户手机号" prop="userPhone" :rules="[
            // { required: true, message: '请输入手机号', trigger: 'blur' },
            { min: 11, max: 11, message: '手机号长度为11位', trigger: 'blur' },
            { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
          ]">
            <el-input v-model="form.userPhone" placeholder="请输入用户手机号" />
          </el-form-item>
          <el-form-item label="用户邮箱" prop="userEmail" :rules="[
            // { required: true, message: '请输入邮箱', trigger: 'blur' },
            { pattern: /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/, message: '邮箱格式有误', trigger: 'blur' },
          ]">
            <el-input v-model="form.userEmail" placeholder="请输入用户邮箱" />
          </el-form-item>
        </el-form>
      </div>
      <div class="module1">
        <div class="moduleTitle">经办人基本信息</div>
        <el-form ref="form2" :model="form" inline>
          <el-form-item label="VPN账号" prop="operatorAccount">
            <el-input v-model="form.operatorAccount" placeholder="请输入VPN账号" />
          </el-form-item>
          <el-form-item label="经办人姓名" prop="operatorName">
            <el-input v-model="form.operatorName" placeholder="请输入经办人姓名" maxlength="10" />
          </el-form-item>
          <el-form-item label="经办人单位" prop="operatorOmpanyName">
            <el-input v-model="form.operatorOmpanyName" placeholder="请输入经办人单位" />
          </el-form-item>
          <el-form-item label="经办人手机号" prop="operatorPhone" :rules="[
            // { required: true, message: '请输入手机号', trigger: 'blur' },
            { min: 11, max: 11, message: '手机号长度为11位', trigger: 'blur' },
            { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
          ]">
            <el-input v-model="form.operatorPhone" placeholder="请输入经办人手机号" />
          </el-form-item>
        </el-form>
      </div>
      <div class="module1" style="margin-bottom: 10px">
        <div class="moduleTitle">采购说明</div>
        <el-input type="textarea" v-model="form.procureExplain" placeholder="请输入采购说明" />
      </div>
      <div class="module1">
        <div class="moduleTitle">中心经办人信息</div>
        <el-form ref="form3" :model="form" inline>
          <el-form-item label="VPN账号" prop="centreAccount">
            <el-input v-model="form.centreAccount" placeholder="请输入VPN账号" />
          </el-form-item>
          <el-form-item label="中心经办人" prop="centreName">
            <el-input v-model="form.centreName" placeholder="请输入中心经办人姓名" maxlength="10" />
          </el-form-item>
          <el-form-item label="中心经办人手机号" prop="centrePhone" :rules="[
            // { required: true, message: '请输入手机号', trigger: 'blur' },
            { min: 11, max: 11, message: '手机号长度为11位', trigger: 'blur' },
            { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' },
          ]">
            <el-input v-model="form.centrePhone" placeholder="请输入中心经办人手机号" />
          </el-form-item>
          <el-form-item label="中心经办人邮箱" prop="centreEmail" :rules="[
            // { required: true, message: '请输入邮箱', trigger: 'blur' },
            { pattern: /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/, message: '邮箱格式有误', trigger: 'blur' },
          ]">
            <el-input v-model="form.centreEmail" placeholder="请输入中心经办人邮箱" />
          </el-form-item>
        </el-form>
      </div>
      <div class="module1">
        <div class="moduleTitle">资源计费说明</div>
        <div class="tableData">
          <div class="tableTitle" @click="addChildren(0)">添加计费信息</div>
          <el-table :data="form.resourceChargingList" :border="true" v-if="form.resourceClassId == 0">
            <el-table-column prop="sort" label="序号" width="90" align="center" fixed="left"></el-table-column>
            <el-table-column prop="resourceClass" label="资源类型">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.resourceClass }}</span>
                <el-input v-model="scope.row.resourceClass" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="acAccount" label="AC账户名" show-overflow-tooltip>
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.acAccount }}</span>
                <el-input v-model="scope.row.acAccount" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="queueName" label="队列">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.queueName }}</span>
                <el-input v-model="scope.row.queueName" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column label="用户资源" align="center">
              <el-table-column prop="coreNum" label="核心数">
                <template slot-scope="scope">
                  <span v-if="!scope.row.isEdit">{{ scope.row.coreNum }}</span>
                  <el-input v-model="scope.row.coreNum" v-if="scope.row.isEdit" />
                </template>
              </el-table-column>
              <el-table-column prop="maxWorkNum" label="最大作业运行数">
                <template slot-scope="scope">
                  <span v-if="!scope.row.isEdit">{{ scope.row.maxWorkNum }}</span>
                  <el-input v-model="scope.row.maxWorkNum" v-if="scope.row.isEdit" />
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column prop="cpuPrice" label="CPU单价(元)">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.cpuPrice }}</span>
                <el-input v-model="scope.row.cpuPrice" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="dcuPrice" label="DCU单价(元)">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.dcuPrice }}</span>
                <el-input v-model="scope.row.dcuPrice" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="storagePrice" label="存储单价(元/年*TB)">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.storagePrice }}</span>
                <el-input v-model="scope.row.storagePrice" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="storageTotal" label="存储总量">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.storageTotal }}</span>
                <el-input v-model="scope.row.storageTotal" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column label="赠送资源" align="center">
              <el-table-column prop="storageNum" label="存储量">
                <template slot-scope="scope">
                  <span v-if="!scope.row.isEdit">{{ scope.row.storageNum }}</span>
                  <el-input v-model="scope.row.storageNum" v-if="scope.row.isEdit" />
                </template>
              </el-table-column>
              <el-table-column prop="machinePrice" label="机时金额">
                <template slot-scope="scope">
                  <span v-if="!scope.row.isEdit">{{ scope.row.machinePrice }}</span>
                  <el-input v-model="scope.row.machinePrice" v-if="scope.row.isEdit" />
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column prop="consumePrice" label="消费金额（元）">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.consumePrice }}</span>
                <el-input v-model="scope.row.consumePrice" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="rechargePrice" label="账户充值金额（元）">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.rechargePrice }}</span>
                <el-input v-model="scope.row.rechargePrice" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="remarks" label="备注">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.remarks }}</span>
                <el-input v-model="scope.row.remarks" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right">
              <template slot-scope="scope">
                <el-button type="text" @click="edit(0, scope.row.sort)" v-if="!scope.row.isEdit">编辑</el-button>
                <el-button type="text" @click="save(0, scope.row.sort)" v-if="scope.row.isEdit">保存</el-button>
                <el-button type="text" @click="del(0, scope.$index)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-table :data="form.resourceChargingList" :border="true" v-if="form.resourceClassId == 1">
            <el-table-column prop="sort" label="序号" width="90" align="center" fixed="left"></el-table-column>
            <el-table-column prop="resourceClass" label="资源类型">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.resourceClass }}</span>
                <el-input v-model="scope.row.resourceClass" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="softwareName" label="软件名称" show-overflow-tooltip>
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.softwareName }}</span>
                <el-input v-model="scope.row.softwareName" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="softwarePrice" label="软件单价（元/核/月）">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.softwarePrice }}</span>
                <el-input v-model="scope.row.softwarePrice" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="softwareCoreNum" label="软件使用核心权限（个）">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.softwareCoreNum }}</span>
                <el-input v-model="scope.row.softwareCoreNum" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="useDays" label="使用时长（天）">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.useDays }}</span>
                <el-input v-model="scope.row.useDays" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="consumePrice" label="消费金额（元">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.consumePrice }}</span>
                <el-input v-model="scope.row.consumePrice" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="remarks" label="备注">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.remarks }}</span>
                <el-input v-model="scope.row.remarks" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right">
              <template slot-scope="scope">
                <el-button type="text" @click="edit(0, scope.row.sort)" v-if="!scope.row.isEdit">编辑</el-button>
                <el-button type="text" @click="save(0, scope.row.sort)" v-if="scope.row.isEdit">保存</el-button>
                <el-button type="text" @click="del(0, scope.$index)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-table :data="form.resourceChargingList" :border="true" v-if="form.resourceClassId == 2">
            <el-table-column prop="sort" label="序号" width="90" align="center" fixed="left"></el-table-column>
            <el-table-column prop="resourceClass" label="资源类型">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.resourceClass }}</span>
                <el-input v-model="scope.row.resourceClass" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="contractName" label="合同名称" show-overflow-tooltip>
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.contractName }}</span>
                <el-input v-model="scope.row.contractName" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="annexUrl" label="附件">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.annexUrl }}</span>
                <el-input v-model="scope.row.annexUrl" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="consumePrice" label="消费金额(元)">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.consumePrice }}</span>
                <el-input v-model="scope.row.consumePrice" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="remarks" label="备注">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.remarks }}</span>
                <el-input v-model="scope.row.remarks" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="100">
              <template slot-scope="scope">
                <el-button type="text" @click="edit(0, scope.row.sort)" v-if="!scope.row.isEdit">编辑</el-button>
                <el-button type="text" @click="save(0, scope.row.sort)" v-if="scope.row.isEdit">保存</el-button>
                <el-button type="text" @click="del(0, scope.$index)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div class="module1" style="margin-bottom: 10px">
        <div class="moduleTitle">使用状态</div>
        <el-radio-group v-model="form.useStatus">
          <el-radio label="0">进行中</el-radio>
          <el-radio label="1">已到期</el-radio>
          <el-radio label="2">结束</el-radio>
        </el-radio-group>
      </div>
      <div class="module1" style="margin-bottom: 10px">
        <div class="moduleTitle">资源回收策略</div>
        <el-input type="textarea" v-model="form.recoveryStrategy" placeholder="请输入资源回收策略" />
      </div>
      <div class="module1">
        <div class="moduleTitle">到期提醒</div>
        <div class="tableData">
          <div class="tableTitle" @click="addChildren(1)">添加提醒</div>
          <el-table :data="form.expireRemindList" :border="true">
            <el-table-column prop="sort" label="序号" width="90" align="center" fixed="left"></el-table-column>
            <el-table-column prop="remindTime" label="设置到期时间">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.remindTime }}</span>
                <el-date-picker v-model="scope.row.remindTime" type="datetime" placeholder="设置到期时间"
                  value-format="yyyy-MM-dd HH:mm" format="yyyy-MM-dd HH:mm" v-if="scope.row.isEdit">
                </el-date-picker>
              </template>
            </el-table-column>
            <el-table-column prop="remindRemarks" label="到期提醒备注">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.remindRemarks }}</span>
                <el-input v-model="scope.row.remindRemarks" v-if="scope.row.isEdit" />
              </template>
            </el-table-column>
            <el-table-column prop="isSync" label="是否同步到用户端">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.isSync == '0' ? '是' : '否' }}</span>
                <el-switch v-model="scope.row.isSync" active-value="0" inactive-value="1" active-text="是"
                  inactive-text="否" v-if="scope.row.isEdit">
                </el-switch>
              </template>
            </el-table-column>
            <el-table-column prop="status" label="状态">
              <template slot-scope="scope">
                <span v-if="!scope.row.isEdit">{{ scope.row.status == '0' ? '开启' : '关闭' }}</span>
                <el-switch v-model="scope.row.status" active-value="0" inactive-value="1" active-text="开启"
                  inactive-text="关闭" v-if="scope.row.isEdit">
                </el-switch>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button type="text" @click="edit(1, scope.row.sort)" v-if="!scope.row.isEdit">编辑</el-button>
                <el-button type="text" @click="save(1, scope.row.sort)" v-if="scope.row.isEdit">保存</el-button>
                <el-button type="text" @click="del(1, scope.$index)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {resourceCharging, listCsPricingInventory, getCsPricingInventory, delCsPricingInventory, addCsPricingInventory, updateCsPricingInventory } from "@/api/cs/csPricingInventory";
import { getInfo } from '@/api/login'
export default {
  name: "CsPricingInventory",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 计价清单表格数据
      csPricingInventoryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      show: false,
      showResourceChargingList: false,
      resourceChargingList: [],
      resourceClassId: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: '',
        resourceClassId: null,
        userAccount: null,
        userName: null,
        userCompanyName: null,
        centreAccount: null,
        expendPrice: null,
        useStatus: null,
        dateRange: [],
      },
      // 表单参数
      form: {
        resourceClassId: '',
        userAccount: '',
        userName: '',
        userCompanyName: '',
        userPhone: '',
        userEmail: '',
        operatorName: '',
        operatorOmpanyName: '',
        operatorPhone: '',
        procureExplain: '',
        centreAccount: '',
        centreName: '',
        centreEmail: '',
        centrePhone: '',
        useStatus: '0',
        recoveryStrategy: '',
        resourceChargingList: [],
        expireRemindList: [],
        createAt: ''
      },
      // 表单校验
      rules: {
      },
      options: [{
        value: 'inventoryNumber',
        label: '清单编号'
      }, {
        value: 'createAt',
        label: '日期'
      }, {
        value: 'operatorName',
        label: '经办人姓名'
      }, {
        value: 'userName',
        label: '用户姓名'
      }, {
        value: 'userAccount',
        label: '用户VPN账号'
      }, {
        value: 'userCompanyName',
        label: '用户单位'
      }, {
        value: 'centreName',
        label: '中心经办人'
      }, {
        value: 'resourceClassId',
        label: '资源类型'
      }, {
        value: 'expendPrice',
        label: '消费金额'
      }, {
        value: 'resourceChargingList',
        label: '资源计费说明'
      }, {
        value: 'recoveryStrategy',
        label: '资源回收策略'
      }, {
        value: 'useStatus',
        label: '使用状态'
      }],
      tableHeaderList: ['inventoryNumber', 'createAt', 'operatorName',
        'userName', 'userAccount', 'userCompanyName', 'centreName',
        'resourceClassId', 'expendPrice', 'resourceChargingList', 'recoveryStrategy', 'useStatus'],
      userInfo: null,
    };
  },
  created() {
    this.getList();
    getInfo().then(res => {
      // console.log(res.user)
      this.userInfo = res.user
      // userName
      // phonenumber
      // email
    })
  },
  mounted() {
  },
  methods: {
    checkResourceChargingList(row) {
      
      resourceCharging(row.inventoryId).then(response => {
       this.resourceChargingList = response.data || []
      // this.resourceClassId = row.resourceClassId
      this.showResourceChargingList = true
      });
   
    },
    /** 查询计价清单列表 */
    getList() {
      this.loading = true;
      if (null != this.queryParams.dateRange && '' != this.queryParams.dateRange) {
        this.queryParams["beginCreateAt"] = this.queryParams.dateRange[0];
        this.queryParams["endCreateAt"] = this.queryParams.dateRange[1];
      }
      listCsPricingInventory(this.queryParams).then(response => {
        this.csPricingInventoryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleSearch() {
      this.showSearch = !this.showSearch
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        resourceClassId: '',
        userAccount: '',
        userName: '',
        userCompanyName: '',
        userPhone: '',
        userEmail: '',
        operatorName: '',
        operatorOmpanyName: '',
        operatorPhone: '',
        procureExplain: '',
        centreAccount: '',
        centreName: '',
        centreEmail: '',
        centrePhone: '',
        useStatus: '0',
        recoveryStrategy: '',
        resourceChargingList: [],
        expireRemindList: []
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.showSearch = false
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        keyword: '',
        resourceClassId: null,
        userAccount: null,
        userName: null,
        userCompanyName: null,
        centreAccount: null,
        expendPrice: null,
        useStatus: null,
        dateRange: [],
      },
        this.handleQuery();
    },

    addChildren(type) {
      if (type == 0) {
        this.form.resourceChargingList.push({
          sort: this.form.resourceChargingList.length + 1,
          resourceClass: this.form.resourceClassId == 0 ? 'HPC' : this.form.resourceClassId == 1 ? '商业软件' : '云计算',
          acAccount: '',
          queueName: '',
          coreNum: '',
          maxWorkNum: '',
          cpuPrice: '',
          dcuPrice: '',
          storagePrice: '',
          storageTotal: '',
          storageNum: '',
          machinePrice: '',
          consumePrice: '',
          rechargePrice: '',
          remarks: '',
          softwareName: '',
          softwarePrice: '',
          softwareCoreNum: '',
          useDays: '',
          contractName: '',
          annexUrl: '',
          isEdit: true
        })
      } else {
        this.form.expireRemindList.push({
          sort: this.form.expireRemindList.length + 1,
          remindTime: '',
          remindRemarks: '',
          isSync: '',
          status: '',
          isEdit: true
        })
      }
    },
    edit(type, id) {
      if (type == 0) {
        this.form.resourceChargingList = this.form.resourceChargingList.map(v => {
          if (v.sort == id) {
            v.isEdit = true
          } else {
            v.isEdit = false
          }
          return v
        })
      } else {
        this.form.expireRemindList = this.form.expireRemindList.map(v => {
          if (v.sort == id) {
            v.isEdit = true
          } else {
            v.isEdit = false
          }
          return v
        })
      }
    },
    save(type, id) {
      if (type == 0) {
        this.form.resourceChargingList = this.form.resourceChargingList.map(v => {
          if (v.sort == id) {
            v.isEdit = false
          }
          return v
        })
      } else {
        this.form.expireRemindList = this.form.expireRemindList.map(v => {
          if (v.sort == id) {
            v.isEdit = false
          }
          return v
        })
      }
      // console.log(this.form.expireRemindList)
    },
    del(type, id) {
      if (type == 0) {
        this.form.resourceChargingList.splice(id, 1)
      } else {
        this.form.expireRemindList.splice(id, 1)
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.inventoryId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd(type) {
      if (type == -1) {
        this.show = true
        return
      }
      this.reset();
      this.show = false
      this.open = true;
      this.title = "添加计价清单";
      this.form.resourceClassId = type
      this.addChildren(0)
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const inventoryId = row.inventoryId || this.ids
      getCsPricingInventory(inventoryId).then(response => {
        console.log(response.data)
        this.form = response.data;
        this.form.expireRemindList = response.data.expireRemindList || []
        this.form.resourceChargingList = response.data.resourceChargingList || []
        this.open = true;
        this.title = "修改计价清单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      let smallValid1,smallValid2,smallValid3
      this.$refs["form1"].validate(valid => smallValid1 = valid)
      this.$refs['form2'].validate(valid => smallValid2 = valid)
      this.$refs['form3'].validate(valid => smallValid3 = valid)
      if (smallValid1 && smallValid2 && smallValid3) {
        if (this.form.inventoryId != null) {
          updateCsPricingInventory(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
        } else {
          addCsPricingInventory(this.form).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getList();
          });
        }
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const inventoryIds = row.inventoryId || this.ids;
      this.$modal.confirm(
        '是否确认删除清单编号为"' + inventoryIds + '"的数据项？'
      ).then(function () {
        return delCsPricingInventory(inventoryIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cs/csPricingInventory/export', {
        ...this.queryParams
      }, `计价清单_${new Date().getTime()}.xlsx`)
    },
    handleExportTemplate() {
      this.download('/cs/csPricingInventory/exportTemplate', {
        ...this.queryParams
      }, `计价清单模板_${new Date().getTime()}.xlsx`)
    },

  }
};
</script>
<style scoped>
::v-deep .dialog1 {
  background-color: #F8F8F8;
}

.addStyle {
  display: flex;
  justify-content: space-around;
}

.searchForm {
  width: 650px;
  padding: 20px;
  position: absolute;
  left: 200px;
  z-index: 100;
  background-color: #FFFFFF;
  border: 1px solid #777777;
}

.module1 {
  height: auto;
  padding: 0 16px 0 10px;
  background: #FFFFFF;
  border-radius: 4px;
}

.moduleTitle {
  height: 22px;
  margin-bottom: 6px;
  /* margin-left: 6px; */
  font-weight: bold;
  font-size: 16px;
  color: #0051AA;
  line-height: 22px;
  text-align: left;
  font-style: normal;
  text-transform: none;
}

::v-deep .el-form-item {
  margin-bottom: 10px;
}

.tableData {
  padding: 0px 20px 10px 20px;
  height: auto;
  background-color: #FFFFFF;
}

.tableTitle {
  width: 96px;
  height: 32px;
  background: #EDF3FF;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  font-weight: 400;
  font-size: 14px;
  color: #0051AA;
  line-height: 32px;
  text-align: center;
  font-style: normal;
  text-transform: none;
  float: right;
  margin-right: 20px;
  margin-bottom: 10px;
  cursor: pointer;
}

::v-deep .el-dialog__header {
  border-bottom: 1px solid #333333;
}

::v-deep .el-dialog__body {
  padding-top: 10px;
}
</style>