<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="thetopbox">
      <el-form label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item class="dizhi" label="套餐名称" prop="">
              <el-input v-model="queryParams.packageName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'套餐日期'">
              <el-date-picker
                @change="checkTime2"
                v-model="queryParams.times2"
                type="daterange"
                range-separator="——"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'创建日期'">
              <el-date-picker
                @change="checkTime1"
                v-model="queryParams.times1"
                type="daterange"
                range-separator="——"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <div class="searchbox">
              <el-button class="my_search" @click="getSearch">
                {{ '搜索' }}</el-button
              >
              <el-button class="my_reset" @click="reChongzhi">
                {{ '重置' }}</el-button
              >
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button
            size="mini"
            @click="addPackage"
            style="background: #48b2fd"
            class="addBtn"
            > {{'添加'}}</el-button
          >

          <el-button
            size="mini"
            style="background: #ffad41; color: #fff; border: none"
            class="addBtn"
            @click="handleExport"
            >{{'导出'}}</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          ref="multipleTable"
          :data="tableData"
          v-loading="loading"
          height="720px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>

          <el-table-column align="center" prop="packageName" label="套餐名称">
          </el-table-column>
          <el-table-column align="center" prop="price" label="套餐价格">
          </el-table-column>
          <el-table-column align="center" prop="time" label="套餐运行时间(分)">
          </el-table-column>
          <el-table-column align="center" prop="packageDate" :label="'套餐日期'">
          </el-table-column>
          <el-table-column align="center" prop="creationTime" :label="'创建日期'" >
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSearch"
    />
  </div>
</template>

          <script>
import topBar from "@/components/topBar";
import * as equ from "@/api/equipment.js";
export default {
  name: "EquipmentPackage",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "equipmentPackage",
      topList: [
        {
          name: "套餐配置",
          path: "equipmentPackage",
        },
      ],
      tableData: [],
      loading:false,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      total: 0,
      multipleSelection: [],
    };
  },
  created() {
    this.getSearch();
  },
  methods: {
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "/system/manage/thali/export",
          Object.assign({}, this.queryParams),
          `套餐设置${new Date().getTime()}.xlsx`
        );
      });
    },
    addPackage() {
      this.$router.push({
        path: "addPackage",
      });
    },
    checkTime1(val) {
      this.queryParams.startCreateTime = val[0];
      this.queryParams.endCreateTime = val[1];
    },
    checkTime2(val) {
      this.queryParams.startPackageTime = val[0];
      this.queryParams.startPackageTime = val[1];
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
      };
      this.getSearch();
    },
    getSearch() {
      this.loading = true
      equ.getThaliList(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.loading = false
      });
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}
.page {
  padding: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 15px 20px 15px 0;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      margin-left: 40px;
    }
    .searchtitle {
      margin-right: 10px;
    }
    .searchbtn {
      background: #08143f;
      color: #ffffff;
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #48b2fd;
        }
        .thebtn2 {
          color: #ffffff;
          background: #ffad41;
        }
      }
    }
  }
}
</style>
