<template>
  <div class="page-wrap">
    <ui-loading :show="page_loading.show" :msg="page_loading.msg"></ui-loading>

    <div class="page-handle-wrap">
      <ul class="handle-wraper bd-b">
        <li class="f-l">
          <div class="text-exp">
            <b>全部信息</b>
          </div>
        </li>
        <li class="f-r">
          <div class="handle-item">
            <Button
              @click="openEdit(true, null)"
              icon="md-add"
              type="primary"
              v-has="'create'"
            >添加流量池</Button>
          </div>

          <div class="handle-item">
            <Button @click="search.show=!search.show" ghost icon="ios-search" type="primary">搜索</Button>
          </div>

          <div class="handle-item">
            <Button @click="index(1)" icon="md-refresh">刷新</Button>
          </div>

          <div class="handle-item" v-has="'output'">
            <Button @click="exportExcel" icon="md-download">导出</Button>
          </div>

          <div class="handle-item" v-has="'input'">
            <Button @click="importModel = true" type="warning">导入月流量数据</Button>
          </div>
        </li>
      </ul>

      <div class="search-wrap" v-show="search.show">
        <ul class="handle-wraper">
          <li class="handle-item w-250">
            <AutoComplete
              @on-search="handleCompleteCompanies"
              icon="ios-search"
              placeholder="请输入企业名称"
              v-model.trim="options.company_name"
            >
              <Option
                :key="item.id"
                :value="item.name"
                v-for="item in completeHandledCompanies"
              >{{ item.name }}</Option>
            </AutoComplete>
          </li>

          <li class="handle-item w-250">
            <Input clearable placeholder="流量池名称" v-model.trim="options.name"></Input>
          </li>

          <li class="handle-item w-250">
            <Select clearable placeholder="运营商" v-model="options.carrier_operator">
              <Option :value="0">联通</Option>
              <Option :value="1">移动</Option>
              <Option :value="2">电信</Option>
            </Select>
          </li>

          <li class="handle-item w-250">
            <DatePicker
              :editable="false"
              placeholder="请选择时间"
              placement="bottom-start"
              type="month"
              v-model.trim="options.month"
            ></DatePicker>
          </li>

          <li class="f-r">
            <div class="handle-item">
              <Button @click="index(1)" ghost type="primary">立即搜索</Button>
            </div>
            <div class="handle-item">
              <Button @click="resetSearch" ghost type="warning">重置搜索</Button>
            </div>
          </li>
        </ul>
      </div>
    </div>

    <div class="page-list-wrap">
      <Table :columns="table_titles" :data="list_data ? list_data.data : []"></Table>
    </div>

    <div class="page-turn-wrap" v-if="list_data">
      <Page
        :current="Number(list_data.current_page)"
        :page-size="Number(list_data.per_page)"
        :total="Number(list_data.total)"
        @on-change="index"
        show-elevator
        show-total
        show-sizer
        :page-size-opts="[10, 20, 50, 100]"
        @on-page-size-change="changeLimit"
      ></Page>
    </div>

    <ui-edit
      :data="editObj.data"
      :show.sync="editObj.show"
      @add-success="index"
      @update-success="index(list_data.current_page)"
    ></ui-edit>

    <ui-detail
      :data="detailObj.data"
      :show.sync="detailObj.show"
      :month="moment(options.month).format('YYYY-MM')"
    ></ui-detail>

    <ui-setting
      :show.sync="settingObj.show"
      :data="settingObj.data"
      @add-success="index(list_data.current_page)"
      @update-success="index(list_data.current_page)"
    ></ui-setting>

    <ui-flows
      :pool_id="flowsObj.pool_id"
      :show.sync="flowsObj.show"
      :month="moment(options.month).format('YYYY-MM')"
      @add-success="index(list_data.current_page)"
    ></ui-flows>

    <Modal v-model="importModel" title="导入流量数据">
      <ui-loading :show="page_loading.show"></ui-loading>

      <Upload :before-upload="importFlows" action="/" :format="['xls','xlsx','csv']" class="f-l">
        <Button type="primary" ghost>导入</Button>
      </Upload>

      <a
        :href="CONFIG.url + 'storage/templates/import-flows.xls'"
        download="导入流量数据模板.xls"
        class="fz-12 lh-32 umar-l10"
      >下载导入模板</a>

      <footer class="ta-c" slot="footer">
        <Button @click="importModel = false" class="w-80 umar-r5" ghost type="primary">取消</Button>
      </footer>
    </Modal>
  </div>
</template>

<script src="./js/index.js"></script>
