<template>
  <div class="manage-container">
    <div class="manage-wrap">
      <div class="manage-input">
        <el-form ref="queryForm" :model="queryForm" label-width="80px">
          <vab-query-form>
            <el-form-item width="100" prop="iccid" label="iccid">
              <el-input
                v-model="queryForm.iccid"
                size="small"
                placeholder="请输入iccid"
              ></el-input>
            </el-form-item>
            <el-form-item prop="status" label="选择状态">
              <el-select
                v-model="queryForm.status"
                size="small"
                placeholder="请选择状态"
              >
                <el-option
                  v-for="item in statusData"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </vab-query-form>
        </el-form>
      </div>
      <div class="manage-button">
        <el-button size="small" @click="resetForm()">重置</el-button>
        <el-button type="primary" size="small" @click="search">查询</el-button>
      </div>
    </div>
    <el-table
      v-loading="listLoading"
      :data="flowData"
      border
      stripe
      style="width: 100%"
    >
      <el-table-column
        prop="iccid"
        label="iccid"
        width="200"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="accNumber"
        label="接入号码"
        width="150"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="deviceName"
        label="设备"
        width="150"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="activationTime"
        label="激活时间"
        width="200"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间/开卡时间"
        width="200"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="status"
        label="连接状态"
        width="120"
        align="center"
      >
        <template #default="{ row }">
          <el-tag
            v-if="row.simStatus == 1"
            key="可激活"
            effect="dark"
            type="success"
            size="mini"
          >
            可激活
          </el-tag>
          <el-tag
            v-if="row.simStatus == 2"
            key="测试激活"
            effect="dark"
            type="success"
            size="mini"
          >
            测试激活
          </el-tag>
          <el-tag
            v-if="row.simStatus == 3"
            key="测试去激活"
            effect="dark"
            type="success"
            size="mini"
          >
            测试去激活
          </el-tag>
          <el-tag
            v-if="row.simStatus == 4"
            key="在用"
            effect="dark"
            type="success"
            size="mini"
          >
            在用
          </el-tag>
          <el-tag
            v-if="row.simStatus == 5"
            key="停机"
            effect="dark"
            type="danger"
            size="mini"
          >
            停机
          </el-tag>
          <el-tag
            v-if="row.simStatus == 6"
            key="运营商管理状态"
            effect="dark"
            type="success"
            size="mini"
          >
            运营商管理状态
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center">
        <template #default="{ row }">
          <el-button
            v-if="isBtnPerm('/telcom/api/simBindDevice')"
            type="text"
            @click="bindDevice(row)"
          >
            绑定设备
          </el-button>
          <el-button
            v-if="isBtnPerm('/telcom/api/xiangqing')"
            type="text"
            @click="ShowDetail(row)"
          >
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :background="background"
      :current-page="queryForm.pageIndex"
      :layout="layout"
      :page-size="queryForm.size"
      :total="total"
      style="text-align: right"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
    <show-detail ref="details"></show-detail>
    <bind-device ref="device"></bind-device>
  </div>
</template>
<script>
import { getList } from '@/api/flow';
import showDetail from './showDetail';
import bindDevice from './bindDevice';
export default {
  name: 'Index',
  components: {
    bindDevice,
    showDetail,
  },
  data() {
    return {
      flowData: [],
      layout: 'total, sizes, prev, pager, next, jumper',
      total: 0,
      background: true,
      listLoading: true,
      elementLoadingText: '正在加载...',
      statusData: [
        {
          value: 1,
          label: '可激活',
        },
        {
          value: 2,
          label: '测试激活',
        },
        {
          value: 3,
          label: '测试去激活',
        },
        {
          value: 4,
          label: '在用',
        },
        {
          value: 5,
          label: '停机',
        },
        {
          value: 6,
          label: '运营商管理状态',
        },
      ],
      queryForm: {
        page: 1,
        size: 20,
        iccid: '',
        status: '',
      },
    };
  },
  computed: {
    height() {
      return 500;
    },
  },
  created() {
    this.fetchData();
  },
  methods: {
    async fetchData() {
      this.listLoading = true;
      const { data } = await getList(this.queryForm);
      this.flowData = data.items;
      this.total = data.total;
      setTimeout(() => {
        this.listLoading = false;
      }, 500);
    },
    search() {
      this.fetchData();
    },
    resetForm() {
      this.$refs.queryForm.resetFields();
    },
    bindDevice(row) {
      this.$refs['device'].showDetail(row.accNumber);
    },
    ShowDetail(row) {
      this.$refs['details'].showDetail(row.accNumber);
    },
    handleQuery() {
      this.queryForm.page = 1;
      this.fetchData();
    },
    handleSizeChange(val) {
      this.queryForm.size = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      this.queryForm.page = val;
      this.fetchData();
    },
  },
};
</script>

<style lang="scss" scoped>
.manage-wrap {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  .el-input {
    width: 200px !important;
  }
  .el-select {
    width: 200px !important;
  }
  .manage-button {
    padding-left: 12px;
    margin-bottom: 30px;
  }
}
</style>

<style lang="scss">
.el-submenu__title:hover {
  background-color: rgba(#1890ff, 0.085) !important;
  color: hsla(208, 100%, 55%, 0.95) !important;
}
</style>
