<template lang="html">
  <div class="">
    <ifbp-button-area>
        <el-button type="primary" @click="addButton">新增</el-button>
    </ifbp-button-area>
    <ifbp-main-area type="list">
      <!-- UI模板组件 -->
      <ifbp-template ref="buttonTableRef"
                    tpl-id="buttonTableId"
                    :funnode="buttonTableFunnode"
                    :nexuskey="buttonTableNexuskey"
                    :tpl-data="buttonTableData"
                    show-type="table"
                    :tplResetFun="buttonTableResetFun"
                    @edit-table-click="buttonTableEditClick"
                    @delete-table-click="buttonTableDeleteClick">
      </ifbp-template>
      <!--分页组件-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalElements"
        >
      </el-pagination>
    </ifbp-main-area>
    <ifbp-del-dialog
      v-model="delDialogVisible"
      message="确认删除该数据？删除后无法恢复。"
      @click="deleteClick"
      >
    </ifbp-del-dialog>
  </div>
    <!-- <ifbp-page> -->

    <!-- </ifbp-page> -->
</template>
<script>
export default {
  data() {
    return {
      totalElements: 0,
      currentPage: 0,
      size: 10,
      delDialogVisible: false,
      buttonTableFunnode: 'YMDZ',
      buttonTableNexuskey: 'YMPZ_BTN_LIST',
      buttonTableData: {},
      btnDelId: '',
      btnDelData: {},
      buttonTableResetFun: function($node) {
        var $table = this.getTableDom($node);
        var operateHtml = this.getBaseTableOperateHtml();
        $table.append(operateHtml);
        return $node[0].outerHTML;
      }

    };
  },
  props: ['busicode'],
  methods: {
    buttonTableDeleteClick(scope) {
      this.delDialogVisible = true;
      this.btnDelData = scope.row;
    },
    buttonTableEditClick(scope) {
      // debugger;
      this.$router.push("/button/detail/" + scope.row.pk);
    },
    buttonRequest(curPage, size) {
      // var data = {
      //   pageNum: curPage || 0,
      //   pageSize: size || this.size
      // };
      // if (this.searchData) {
      //   data.searchParams = {
      //     searchMap: {
      //       "busicode":this.busicode
      //     }
      //   };
      // }
      var data = {
        "searchParams": {
          "searchMap": {
            "busicode": this.busicode
          }
        }
        // pageNum: this.pageCurrentPage-1,
        // pageSize: this.pagePageSize
      };
      this.$http({
          url: "/ifbp-app-sm-infoset-web/page_operate/page",
          method: "post",
          data: data,
          headers: {
            "Content-Type": "application/json"
          },
          dataType: "application/json"
        })
        .then(res => {
          var resData = res.data.data.content || [];
          this.$nextTick(() => {
            if (this.$refs.buttonTableRef) {
              this.$refs.buttonTableRef.setTableData(resData);
            } else {
              this.$set(this.buttonTableData, 'uitemplateTableData', resData);
            }
          });
          this.totalElements = res.data.data.totalElements;
          this.size = res.data.data.size;
        })
        .catch(() => {
          this.$message({
            message: "信息获取失败",
            type: "error"
          });
        });
    },
    addButton() {
      this.$router.push("/button/add/" + this.busicode);
    },
    deleteClick() {
      // debugger;
      var vm = this;
      // var data = {
      //   id: this.btnDelId
      // };
      var data = this.btnDelData;
      this.$http({
          url: "/ifbp-app-sm-infoset-web/page_operate/delete",
          method: "post",
          data: data,
          headers: {
            "Content-Type": "application/json"
          },
          dataType: "application/json"
        })
        .then(res => {
          if (res.data.success === true) {
            this.$message({
              message: "删除成功",
              type: "success"
            });
            this.delDialogVisible = false;
            this.buttonRequest(0, this.size);
          } else {
            this.$message({
              message: res.data.msg,
              type: "error"
            });
          }
        })
        .catch(e => {
          this.$message({
            message: "删除失败",
            type: "error"
          });
        });

    },
    // 翻页标签改变每页显示数据
    handleSizeChange(val) {
      this.buttonRequest(0, val);
    },

    // 翻页标签改变当前页
    handleCurrentChange(val) {
      this.buttonRequest(val - 1, this.size);
    }
  },
  mounted() {
    // this.buttonRequest();
  },
  created() {

  },
  watch: {
    busicode(val) {
      this.buttonRequest();
    }
  }
}
</script>

<style lang="css">
</style>
