<template>
  <div class="list-panel defdoc-list">
    <div class="title-header1">
      <h2 class="name fl">自定义档案</h2>
      <div class="fr">
        <el-button type="text" @click="showSearch">
          <i class="el-icon-caret-top" v-if="this.isHide"></i>
          <i class="el-icon-caret-bottom" v-if="!this.isHide"></i>
          筛选
        </el-button>
        <!-- <el-button type="primary" @click="backButton">返回</el-button> -->
      </div>
    </div>
    <!--search-->
    <div id="advanced-search1" :class="{hide: isHide}">
      <div class="search-item">
        <div class="label-name">
            <span>编码</span>
        </div>
        <div class="input-info">
          <el-input v-model="input1" placeholder="请输入编码"></el-input>
        </div>
      </div>
      <div class=" search-item">
        <div class="label-name">
            <span>业务编码</span>
        </div>
        <div class="">
            <el-input v-model="input1" placeholder="请输入业务编码"></el-input>
        </div>
      </div>
      <div class="search-item">
        <div class="label-name">
            <span>名称</span>
        </div>
        <div class="">
            <el-input v-model="input1" placeholder="请输入名称"></el-input>
        </div>
      </div>
      <div class="search-item search-set">
        <div class="label-name">
            <span>系统预置</span>
        </div>
        <div class="">
          <el-radio class="radio" v-model="radio" label="1">是</el-radio>
          <el-radio class="radio" v-model="radio" label="2">否</el-radio>
        </div>
      </div>
      <div class="search-item search-item1 search-set1">
        <div class="search-button">
          <el-button type="primary" icon="search"></el-button>
        </div>
      </div>
    </div>
    <div id="search-container1">
        <i class="el-icon-plus"  @click="createClick">新增</i>
    </div>
    <!-- 用户信息列表 -->
    <div id="defdoc-info-list">
      <el-table ref="multipleTable" :data="tableData" border style="width: 100%;margin:20px 0;" @row-click="check" @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column prop="type_code" label="编码">
        </el-table-column>
        <el-table-column prop="bu_id" label="业务编码">
        </el-table-column>
        <el-table-column prop="type_name" label="名称">
        </el-table-column>
        <el-table-column prop="is_preset" label="系统预置">
          <template scope="scope">
            <div>{{scope.row.is_preset===true? "是":"否"}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="type_desc" label="描述">
        </el-table-column>
      </el-table>
      <!--pagination-->
      <!-- <input type="text" id="p" style="visibility: hidden"> -->
      <el-pagination
        id="staff-pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalElements">
      </el-pagination>
    </div>

    <el-dialog
      title="提示"
      v-model="delDialogVisible"
      :modal="true"
      size="tiny">
      <span>确认删除？删除后无法恢复。</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="delDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="deleteFun">确 定</el-button>
      </span>
    </el-dialog>
    <div class="operation-cloumns" style="">
      <i class="el-icon-delete" @click="deleteClick"></i>
    </div>
  </div>

</template>
<script>
  // import test from "../mock.js";
  import editForm from './defdocEditRules.vue';
  export default {
    data() {
      return {
        isEdit: false,
        isHide: true,
        delDialogVisible: false,
        tableData: [],
        currentPage: 1,
        totalElements: 0,
        pageSize: 10,
        type_code: '',
        editFormData: [],
        editRowIndex: -1,
        editFormVisible: false,
        value3: '100',
        radio: '1',
        input1:'',
        arr:[]
      };
    },
    created() {
      /**
       *   获取列表
       **/
      this.request();
    },
    components:{
       editForm,
    },
    methods: {
      /**
       *   获取列表请求
       **/
      request() {
        console.log('queryStr:' + this.type_code);
        console.log('currentPage:' + this.currentPage);
        console.log('pageSize:' + this.pageSize);
        var url =  '/ifbp-app-sm-defdoc-web/defdoclist/page';
        var data = {
          // searchParams: {
          //   searchMap:{
          //     keyword:this.type_code,
          //   }
          // },
          pageNum: this.currentPage -1,
          pageSize: this.pageSize
        };

        this.$http({
          url: url,
          method: 'post',
          data: data,
          dataType: 'json'
        }).then((res) => {
          this.tableData=res.data.data.content;
          this.totalElements = res.data.data.totalElements ;       // 总条数
          this.pageSize = res.data.data.size;                          // 每页的条数
        }).catch(() => {
          this.$message({
            message: '档案信息获取失败',
            type: 'error'
          });
        });
      },
      // 跳转到新增页面
      createClick:function(){
        this.editRowIndex = -1;
        // const crateFormData ={
        //   type_code:'',
        //   type_name:'',
        //   type_desc:''
        // };
        // this.editFormVisible = true;
        location.hash="/defdocEditRules/add";
        // this.formData = crateFormData;
      },
      // 高级搜索
      showSearch() {
        this.isHide = !this.isHide;
      },
      // 搜索按钮
      search() {
        this.request();
      },
      // 返回按钮
      backButton() {
        this.$router.go(-1);
      },
      handleSelectionChange(val) {
        // debugger;
        this.arr=[];
        if (val.length > 0) {
          val.forEach((v) => {
            if (this.arr.indexOf(v.id) === (-1)) {
              this.arr.push(v);
            }
          });
        }
      },
      getDataItem: function(index) {
        return this.tableData[index];
      },
      // 行查看按钮
      check: function(row , event) {
        // location.hash = '/defdoc/detail/' + scope.row.id + '/' + scope.row.type_name;
        if (event.target.className.indexOf("el-checkbox") < 0) {
          // location.hash = '/defdoc/detail/' + row.id + '/'  + row.type_name + '/' + row.bu_id;
          location.hash = "/defdocEditRules/" + row.id + '/' + row.bu_id;
        }
      },
      // 行编辑按钮
      // editClick: function(scope) {
        // debugger;
        // this.editRowIndex = scope.$index;
        // console.log(scope);
        // location.hash = "/defdocEditRules/" +scope.row.id;
        // this.editFormVisible = true;
        // const rowData = this.getDataItem(this.editRowIndex);
        // this.editFormData = $.extend(true, {}, rowData);
      // },
      // 行删除按钮
      deleteClick: function() {
        if(this.arr && this.arr.length>0){
          this.delDialogVisible = true;
        }
      },
      // 删除确定按钮
      deleteFun: function(){
        var url = '/ifbp-app-sm-defdoc-web/defdoclist/deleteBatch';
        var data = this.arr;
        this.$http({
          url: url,
          method: 'post',
          data: data,
          dataType: 'json',
          headers:{
            'Content-Type':'application/json'
          }
        }).then((res) => {
          if (res.data.success === true) {
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.delDialogVisible = false;
            this.request();
          } else {
            this.$message({
              message: res.data.error.errorMessage,
              type: 'error'
            });
          }
        }).catch(() => {
          this.$message({
            message: '删除失败',
            type: 'error'
          });
        });
      },

      handleSizeChange(val) {
        this.currentPage = 1;
        this.pageSize = val;
        this.request();
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.request();
      },

      onSubmit: function(formData) {
        if(this.editRowIndex > -1){
          this.tableData.splice(this.editRowIndex, 1, formData);
        } else {
          this.tableData.push(formData);
        }
      },
      changeEditFormVisible: function(val) {
        this.editFormVisible = val;
      },
    }
  };
</script>
<style>

</style>
