<template>
  <!-- 单位用户单位管理员账号管理 -->
  <div class="dbUnit-wrapper height100">
    <div class="search-container">
      <div class="page-tip">
        <span class="page-tip-title">页面说明:</span>
        <span class="page-tips"
          >可查看本单位其他管理员信息，可以修改自己的管理员信息，修改后的信息同步到平台管理员信息列表中</span
        >
      </div>
    </div>
    <div class="table-content">
      <db-unit-table
        :feildList="feildList"
        :list="list"
        @action="handleAction"
      />
      <party-pagination :page="page" @changePage="handleChangeCurrent" />
    </div>
    <edit-dialog ref="editDialog" @success="getFirstPageList()" />
  </div>
</template>
<script>
import { partyPagination } from "@/components/index";
import dbUnitTable from "./components/dbUnitTable";
import { editDialog } from "./dbUnitDialog";
export default {
  data() {
    return {
      form: {
        type: 2, //1.用户账号 2.平台单位单位管理员账号 3.机顶盒账号 4.运维账号
      },
      feildList: [
        { prop: "userName", label: "管理员姓名" },
        { prop: "phone", label: "手机号码" },
        { prop: "telephone", label: "固定电话" },
        { prop: "weChat", label: "微信号" },
        { prop: "email", label: "邮箱" },
        { prop: "", label: "操作", isEdit: true, width: 120 },
      ],
      list: [],
      page: {
        _index: 1,
        _size: 10,
        total: 0,
      },
      activeRow: {},
    };
  },
  components: {
    partyPagination,
    dbUnitTable,
    editDialog,
  },
  mounted() {
    this.getFirstPageList();
  },
  methods: {
    // 获取第一页数据列表
    getFirstPageList() {
      this.page._index = 1;
      this.getPageList();
    },
    getPageList() {
      let requestParams = {};
      requestParams._index = this.page._index;
      requestParams._size = this.page._size;
      requestParams.type = this.form.type;
      this.$https(
        {
          method: "get",
          url: "tUser/getPageList",
          authType: this.backToken,
        },
        requestParams
      )
        .then((res) => {
          if (res.status != 200) {
            this.getResWithOutData();
          } else {
            if (res.data.resultCode == 200) {
              this.list = res.data.data.records;
              this.page._size = res.data.data.size;
              this.page.total = res.data.data.total;
            } else {
              this.getResWithOutData();
            }
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 页面返回值为空
    getResWithOutData() {
      this.list = [];
      this.page = {
        _index: 1,
        _size: 10,
        total: 0,
      };
    },
    // 编辑
    handleEdit() {
      this.$refs.editDialog.id = this.activeRow.id;
      this.$refs.editDialog.getDetailById();
      this.$refs.editDialog.dialogVisible = true;
      this.$refs.editDialog.isEdit = true;
    },
    // 查看详情
    handleDetail() {
      this.$refs.editDialog.id = this.activeRow.id;
      this.$refs.editDialog.getDetailById();
      this.$refs.editDialog.dialogVisible = true;
      this.$refs.editDialog.isEdit = false;
    },
    handleAction(params) {
      this.activeRow = params.row;
      switch (params.type) {
        case "detail":
          this.handleDetail();
          break;
        case "edit":
          this.handleEdit();
          break;
        default:
          break;
      }
    },
    // 翻页
    handleChangeCurrent() {
      this.page._index = val;
      this.getPageList();
    },
  },
};
</script>
<style lang="less" scoped>
.dbUnit-wrapper {
  .page-tips {
    white-space: nowrap;
  }
}
</style>