<!--
 * @Description: 
 * @Author: gcz
 * @Date: 2024-01-10 16:31:18
 * @LastEditors: gcz
 * @LastEditTime: 2024-01-10 17:25:54
 * @FilePath: \great_webui\src\views\printdesign\templates\templatesindex.vue
 * @Copyright: Copyright (c) 2016~2024 by gcz, All Rights Reserved. 
-->
<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="模板名称">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入模板名称"
            clearable
            style="width: 240px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="退款状态">
          <el-select
            v-model="queryParams.status"
            placeholder="退款状态"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="dict in statusList"
              :key="dict.id"
              :label="dict.name"
              :value="dict.value"
            />
          </el-select>
        </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">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table ref="tables" v-loading="loading" :data="dataList" border>
        <el-table-column label="序号" align="center" type="index" width="60"></el-table-column>
        <el-table-column label="模板ID" align="center" prop="id" />
        <el-table-column label="模板名称" align="center" prop="name" />
        <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="openDetails(scope.row)"
              v-hasPermi="['printdesign:printdesign:details']"
            >详情</el-button>
            <el-button
              size="mini"
              type="text"
              @click="delTemplate(scope.row)"
              v-hasPermi="['printdesign:printdesign:del']"
            >删除</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"
      />
  
    </div>
  </template>
  
  <script>
  
  import { pageList,deleteById } from '@/api/printdesign/printdesign'
  export default {
    name: "templates",
    dicts: [],
    components: { },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 用户表格数据
        dataList: null,
        // 弹出层标题
        title: "",
  
        // 是否显示弹出层
        open: false,
        // 日期范围
        dateRange: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询列表 */
      getList() {
        this.loading = true;
        pageList(this.addDateRange(this.queryParams, this.dateRange))
        .then(response => {
            this.dataList = response.data.rows;
            this.total = response.data.total;
            this.loading = false;
          }
        );
      },
      // 取消按钮
      cancel() {
        this.open = false;
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.$set(this.queryParams, 'name', '');
        this.queryParams.pageNum = 1;
        this.handleQuery();
      },
      /** 详情按钮操作 */
      openDetails(row) {
        this.$router.push({
          path: '/printdesign/printdesign',
          query: {
            id: row.id
          }
        });
      },
      delTemplate(row) {
        this.$confirm('确认删除该打印模板吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true;
          deleteById(row.id).then(res => {
            this.loading = false;
            if (res.code === 200) {}
            this.getList();
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        })
    }
  }
  };
  </script>
  