<template>
  <div>
    <el-card class="resi-card-table">
      <div class="resi-row-btn">
        <el-button type="success" size="small" @click="handleAdd"
          >新增</el-button
        >
      </div>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        class="resi-table"
        :max-height="maxTableHeight"
      >
        <el-table-column label="序号" type="index" align="center" width="50" />
        <el-table-column prop="centerName" label="组织名称"> </el-table-column>
        <el-table-column fixed="right" label="操作" align="center" width="120">
          <template slot-scope="scope">
            <el-button
              @click="handleWatch(scope.$index)"
              type="text"
              size="small"
              >查看</el-button
            >

            <el-button
              @click="handleEdit(scope.$index)"
              type="text"
              size="small"
              style="margin-right: 10px; color: #00a7a9"
              >编辑</el-button
            >

            <el-popconfirm
              title="删除之后无法回复，确认删除？"
              @onConfirm="handleDel(scope.row, scope.$index)"
              @confirm="handleDel(scope.row, scope.$index)"
            >
              <el-button
                slot="reference"
                type="text"
                size="small"
                style="color: #d51010"
                >删除</el-button
              >
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 修改弹出框 -->
    <el-dialog
      :visible.sync="formShow"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="formTitle"
      width="850px"
      top="5vh"
      @closed="handleClose"
    >
      <edit-form
        ref="eleEditForm"
        @dialogCancle="handleClose"
        @dialogOk="handleEditSuccess"
      ></edit-form>
    </el-dialog>
  </div>
</template>

<script>
import { requestPost } from "@/js/dai/request";
import nextTick from "dai-js/tools/nextTick";
import { mapGetters } from "vuex";
import editForm from "./cpts/edit";

export default {
  components: { editForm },
  data() {
    return {
      openSearch: false,

      formShow: false,
      formTitle: "",
      formShow: false,

      agencyId: "",

      tableData: [],
    };
  },
  computed: {
    maxTableHeight() {
      return this.clientHeight - 410;
    },
    ...mapGetters(["clientHeight"]),
  },
  watch: {},
  async mounted() {
    await this.loadAgency();
    this.getTableData();
  },
  methods: {
    handleClose() {
      this.formShow = false;
    },

    async handleAdd() {
      this.formShow = true;
      await nextTick();
      console.log(this.$refs);
      this.$refs.eleEditForm.initForm("add");
    },

    async handleWatch(rowIndex) {
      this.formShow = true;
      await nextTick();
      this.$refs.eleEditForm.initForm("detail", this.tableData[rowIndex]);
    },

    async handleEdit(rowIndex) {
      this.formShow = true;
      await nextTick();
      this.$refs.eleEditForm.initForm("edit", this.tableData[rowIndex]);
    },

    handleEditSuccess() {
      this.handleClose();
      this.getTableData();
    },

    async handleDel(rowData, rowIndex) {
      console.log(rowData, rowIndex);
      const url =
        "/heart/iccommunityselforganization/delcommunityselforganization";
      const { tableData } = this;

      const { data, code, msg } = await requestPost(url, {
        orgId: tableData[rowIndex].orgId,
      });

      if (code === 0) {
        this.$message.success("删除成功！");
        this.getTableData();
      } else {
        this.$message.success("操作失败！");
      }
    },

    async getTableData() {
      const url = "/gov/org/icpartyservicecenter/partyservicecenterlist";
      const { data, code, msg } = await requestPost(url, {
        orgId: this.agencyId,
        orgType: "agency",
      });
      if (code === 0) {
        console.log("列表请求成功！！！！！！！！！！！！！！");
        this.total = data.total || 0;
        this.tableData = data.list
          ? data.list.map((item) => {
              return item;
            })
          : [];
      } else {
      }
    },

    //加载组织
    async loadAgency() {
      const url = "/epmetuser/customerstaff/staffbasicinfo";
      let params = {};

      const { data, code, msg } = await requestPost(url, params);

      if (code === 0) {
        this.agencyId = data.agencyId;
      } else {
        this.$message.error(msg);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.tabs-other-info {
  .el-tabs__item {
    // width: 50px;
    height: 20px;
    box-sizing: border-box;
    margin-right: 7px;
    padding: 0 10px !important;
    font-size: 8px;
    font-weight: 500;
    color: #666666;
    line-height: 20px;
    background: #ebecf1;
    border-radius: 2px;
  }
  .el-tabs__nav-wrap::after,
  .el-tabs__active-bar {
    display: none;
  }
  .el-tabs__nav-next,
  .el-tabs__nav-prev {
    line-height: 20px;
  }
}

.resi-card-table {
  margin-top: 20px;
}
.resi-row-btn {
  margin-bottom: 13px;
  .upload-btn {
    display: inline-block;
    margin: 0 10px;
  }
}
.resi-other {
  width: 100%;
  display: flex;
  .resi-other-title {
    width: 100px;
    box-sizing: border-box;
    margin-bottom: 10px;
    // padding: 6px 12px 0 0;
    font-size: 16px;
    font-weight: 500;
    color: #333;
    text-align: center;
  }
  .tabs-other-info {
    // padding-left: 60px;
  }
}

.resi-btns {
  margin-top: 20px;
  text-align: center;
}

.resi-container .resi-card {
  position: relative;
  overflow: visible;
}
.resi-down {
  position: absolute;
  left: 50%;
  bottom: -10px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 46px;
  height: 12px;
  box-sizing: border-box;
  margin-left: -23rpx;
  cursor: pointer;
  background: #ffffff;
  border-radius: 0 0 10px 10px;
  img {
    display: block;
  }
}
.resi-row-box {
  // height: 104px;
  overflow: hidden;
  transition: height 0.5s;
}
.resi-row-more {
  height: max-content;
  transition: height 0.5s;
}
.resi-row {
  margin-bottom: 20px;
}
.resi-search {
  .el-col {
    text-align: right;
  }
}
.resi-cell {
  display: flex;
  align-items: center;
  .resi-cell-label {
    width: 70px;
    box-sizing: border-box;
    margin-right: 15px;
    text-align: right;
    // line-height: 32;
  }
  .resi-cell-value-radio {
    display: flex;
    align-items: center;
    min-height: 32px;
  }
  .resi-cell-input {
    width: 180px;
  }
  .resi-cell-select {
    width: 180px;
    box-sizing: border-box;
    margin-right: 10px;
    &-middle {
      width: 130px;
    }
    &-small {
      width: 88px;
    }
  }
  .resi-cell-select:last-child {
    margin-right: 0;
  }
}
</style>
