<template>
  <div class="enterPrise pagePadding">
    <div
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <ex-table
        v-loading="loading"
        v-if="
          powers && powers.length > 0 && powers.some((item) => item == '001')
        "
        :table="table"
        :data="tableData"
        :columns="columns"
        :page="pageInfo"
        :size="size"
        @page-curr-change="handlePageChange"
        @page-size-change="handleSizeChange"
        @screen-reset="
          pageInfo.curr = 1;
          searchList();
        "
        @screen-submit="
          pageInfo.curr = 1;
          searchList();
        "
      >
        <template #table-header="{}">
          <div style="width: 100%">
            <el-row>
              <el-col :span="24">
                <el-col :span="4" style="width: 180px">
                  <el-select
                    :size="searchSize"
                    v-model="parmValue.status"
                    filterable
                    clearable
                    placeholder="账号状态"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in statusList"
                      :key="'status' + item.id"
                      :label="item.label"
                      :value="item.id"
                    />
                  </el-select>
                </el-col>
                <el-col :span="4" style="width: 380px; padding: 0 0 0 10px">
                  <el-input
                    :size="searchSize"
                    v-model="input"
                    :maxlength="40"
                    placeholder="关键字"
                  >
                    <el-select
                      v-model="select"
                      slot="prepend"
                      style="width: 95px"
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="(item, index) in selectList"
                        :label="item.name"
                        :value="item.code"
                        :key="index + 'se'"
                      ></el-option>
                    </el-select>

                    <el-button
                      slot="append"
                      icon="el-icon-search"
                      @click.native="searchList"
                    ></el-button>
                  </el-input>
                </el-col>

                <el-col
                  :span="4"
                  style="width: 80px; padding: 0 0 0 10px"
                  v-if="powers.some((item) => item == '008')"
                >
                  <el-button
                    type="warning"
                    :size="searchSize"
                    @click="restSearch"
                  >
                    重置
                  </el-button>
                </el-col>
                <el-col
                  :span="3"
                  v-if="powers.some((item) => item == '002')"
                  style="width: 80px; padding: 0 0 0 10px; float: right"
                >
                  <el-button
                    :size="searchSize"
                    type="primary"
                    style="float: right"
                    @click="searchList"
                  >
                    刷新
                  </el-button>
                </el-col>

                <el-col
                  :span="3"
                  style="width: 60px; float: right"
                  v-if="powers.some((item) => item == '003')"
                >
                  <el-button
                    type="success"
                    :size="searchSize"
                    style="float: right"
                    @click="openModal('add', '003', {})"
                  >
                    添加
                  </el-button>
                </el-col>
              </el-col>
            </el-row>
          </div>
        </template>
        <template #status="{ scope }">
          <el-tag
            :size="tablebtnSize"
            :type="
              scope.row.status == '0'
                ? 'warning'
                : scope.row.status == '1'
                ? 'success'
                : ''
            "
            v-text="
              (statusList.find((item) => item.id == scope.row.status) || {})
                .label || '--'
            "
          ></el-tag>
        </template>
        <template #time="{ scope }">
          <span>{{ scope.row.starttime }}~{{ scope.row.expiretime }}</span>
        </template>
        <template #operation="{ scope }">
           <!-- v-if="roles === 'admin'" -->
          
          <el-tooltip
            v-if="powers.some((item) => item == '007')"
            class="item"
            effect="dark"
            content="详情"
            placement="top"
          >
            <i
              class="el-icon-view tb-icon"
              @click="openModal(scope.row.id, '007', scope.row)"
            ></i>
          </el-tooltip>
          <el-tooltip
            v-if="powers.some((item) => item == '005')"
            class="item"
            effect="dark"
            content="修改"
            placement="top"
          >
            <i
              class="el-icon-edit tb-icon"
              @click="openModal(scope.row.id, '005', scope.row)"
            ></i>
          </el-tooltip>
        </template>
      </ex-table>
      <add-edit
        :id="modelId"
        :sitem="sitem"
        :show-model="showModel"
        :is-detail="isDetail"
        @refresh="searchList"
        @cancel="showModel = false"
      />

      <!-- <reset-password
        :id="passwordModelId"
        :show-model="passwordModel"
        :is-detail="isPasswordDetail"
        @refresh="searchList"
        @cancel="passwordModel = false"
      /> -->
    </div>
    <div v-else>
      <no-auth></no-auth>
    </div>
  </div>
</template>
<script>
import mixinPage from "@/mixins/elPaginationHandle";
import asyncRequest from "@/apis/service/superTube/enterPrise";
import ExTable from "@/components/ExTableNew.vue";
import addEdit from "./addEdit";
import { mapGetters } from "vuex";
// import resetPassword from "./resetPassword";
import resToken from "@/mixins/resToken";
export default {
  name: "enterPrise",
  components: {
    addEdit,
    ExTable,
    // resetPassword,
  },
  mixins: [mixinPage, resToken],
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size", "roles"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find((item) => item.menu_route == "enterPrise") ||
        {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      showDetail: "",
      sitem: null,
      select: "1",
      input: "",
      selectList: [
        { code: "1", name: "账号" },
        { code: "2", name: "客户姓名" },
        { code: "3", name: "手机号" },
      ],
      // 状态
      statusList: [
        { id: "0", label: "未激活" },
        { id: "1", label: "已激活" },
        { id: "2", label: "已过期" },
      ],
      loading: true,
      showModel: false,
      isDetail: false,
      modelId: 0,
      parmValue: {
        username: "", // 账户名
        nickname: "", // 用户名
        status: "", //状态
        mobile: "",//手机号
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      passwordModel: false,
      passwordModelId: 0,
      isPasswordDetail: false,
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: [
        {
          prop: "username",
          label: "账号",
          width: "120px",
          fixed: "left",
        },
        {
          prop: "status",
          label: "账号状态",
          _slot_: "status",
          width: "80px",
        },
        {
          prop: "nickname",
          label: "客户姓名",
        },
        {
          prop: "mobile",
          label: "客户手机号",
          width: "110px",
        },
        {
          prop: "time",
          label: "账户有效期",
          _slot_: "time",
          width: "280px",
        },
        {
          prop: "activetime",
          label: "账户激活时间",
        //   sortable: true,
          width: "140px",
        },

        {
          prop: "addtime",
          label: "创建时间",
        //   sortable: true,
          width: "140px",
        },
        {
          prop: "",
          label: "操作",
          fixed: "right",
          _noset_: true,
          width: "80px",
          _slot_: "operation",
        },
      ],
    };
  },
  mounted() {
    alert("table数据非真实数据，需要更换表头，筛选及数据需要更换接口")
    this.searchList();
  },
  methods: {
    restSearch() {
      this.select = "1";
      this.input = "";
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.parmValue = {
        username: "", // 账户名
        nickname: "", // 用户名
        status: "", //状态
        mobile: "",//手机号
        page: 1, // 页码
        size: 15, // 每页显示条数
      };
      this.searchList();
    },
    openModal(id, isDetail, sitem) {
      this.showModel = true; //显示弹窗框
      this.modelId = id;
      this.isDetail = isDetail;
      this.sitem = sitem;
    },
    openPasswordModal(id, isDetail) {
      this.passwordModel = true;
      this.passwordModelId = id;
      this.isPasswordDetail = isDetail;
    },
    async searchList() {
      this.loading = true;
      this.parmValue.username = this.select === "1" ? this.input : "";
      this.parmValue.nickname = this.select === "2" ? this.input : "";
      this.parmValue.mobile = this.select === "3" ? this.input : "";
      const res = await asyncRequest.list(this.parmValue);
      if (res && res.code === 0 && res.data) {
        this.tableData = res.data.list;
        this.pageInfo.total = Number(res.data.count);
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
      }
      this.loading = false;
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
