<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
<!--        <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch" label-width="68px" style="height:40px;">
          <el-form-item label="规则名称" prop="name1" style="white-space: nowrap;">
            <el-input
              v-model="queryParams.summary"
              placeholder="规则名称"
              clearable
              size="small"
              style="width: 130px"
              @keyup.enter.native="handleQuery"
            />
          </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-table v-loading="loading" :data="codeList"   row-key="id" @row-click="refreshApplyView" >
          <el-table-column  width="50" align="center" />
          <el-table-column label="序号" align="center" key="xh" prop="xh" />
          <el-table-column label="编码规则" align="center" key="levelcode" prop="levelcode" v-if="false" />
          <el-table-column label="规则名称" align="center" key="summary" prop="summary" />

          <el-table-column   label="操作"  align="center"  width="160"  class-name="small-padding fixed-width">
            <template slot-scope="scope" >
              <el-button id="taskId"  size="mini"   type="text"     @click.native.stop="handleAdd(scope.row)"
                          v-hasPermi="['taskId:taskId:add']" >申请</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-col>
    </el-row>


  </div>
</template>

<script>

import { listLevelAndRule, getRule } from "@/api/code/rule"
import {  addApply } from "@/api/apply/apply";

export default {
  name: "Rule",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      codeList: null,
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      // 是否显示弹出层
      open: false,
      // 部门名称
      levelname: undefined,

      len1:2,

      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },


      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined
      },
      // 表单校验
      rules: {
      }

    };
  },


  created() {
    this.getList();
  },
  methods: {
    /** 查询编码规则列表 */
    getList() {
      this.loading = true;
      listLevelAndRule(this.queryParams).then(response => {
          this.codeList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    refreshApplyView(row) {
      console.log('refreshApplyView')
      this.$emit('refreshApplyView', row)
    },

    handleAdd(row){
      row.codeid = row.id;
      row.codevalue = row.levelcode;
      this.loading = true;
      addApply(row).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.$emit('refreshApplyView', row)
        this.getList();
        this.loading = false;
      });
    },

    // 节点单击事件
    handleNodeClick(data) {
       this.queryParams.levelid = data.id;
      this.getList();
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        name:undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.summary="";
      this.handleQuery();
    },

  }
};
</script>
