<template>
  <div class="app-container">
    <!-- 顶部操作区域 -->
    <div class="filter-container">
      <manage-tab @change="handleChange" />

      <div v-if="listQuery.type === 5">
        <el-tabs v-model="listQuery.type2">
          <el-tab-pane label="企业话术" name="1" />
          <el-tab-pane label="个人话术" name="2" />
        </el-tabs>
      </div>

      <div class="filter-control">
        <span>标题:</span>
        <el-input
          v-model="listQuery.name"
          placeholder="标题"
          clearable
          @keyup.enter.native="handleChange(listQuery.type)"
          @clear="handleChange(listQuery.type)"
        />
      </div>
      <div v-if="listQuery.type !== 5" class="filter-control">
        <span>用户阶段:</span>
        <el-select v-model="listQuery.userClass" placeholder="用户阶段" @change="handleChange(listQuery.type)">
          <el-option
            v-for="(i, index) in userClass"
            :key="index"
            :label="i.value"
            :value="i.id"
          />
        </el-select>
      </div>
      <div v-if="listQuery.type !== 5" class="filter-control">
        <span>标签:</span>
        <el-select v-model="listQuery.userType" placeholder="标签" @change="handleChange(listQuery.type)">
          <el-option
            v-for="(i, index) in userType"
            :key="index"
            :label="i.value"
            :value="i.id"
          />
        </el-select>
      </div>
      <div v-if="listQuery.type === 5" class="filter-control">
        <span>上传者:</span>
        <el-select v-model="listQuery.userClass" placeholder="上传者" @change="handleChange(listQuery.type)">
          <el-option
            v-for="(i, index) in userClass"
            :key="index"
            :label="i.value"
            :value="i.id"
          />
        </el-select>
      </div>
      <div class="filter-control">
        <el-button type="primary" @click="handleChange(listQuery.type)">查询</el-button>
        <el-button v-if="listQuery.type !== 5" type="primary" @click="$router.push('/database/store-list/data-manage/edit?id=' + id + '&t=' + listQuery.type)">添加</el-button>
        <el-button v-if="listQuery.type !== 5" type="primary" @click="exportDialogVisible = true">删除</el-button>
      </div>
    </div>

    <el-table
      ref="table"
      v-loading="isLoading"
      :data="list"
      border
    >
      <!--<el-table-column type="selection" width="55" align="center" />-->
      <el-table-column
        label="ID"
        prop="id"
        align="center"
        width="80"
      />
      <el-table-column prop="serviceLevel" label="标题" align="center" />
      <el-table-column prop="userClass" label="用户阶段" align="center">
        <template slot-scope="scope">
          <div>
            {{ scope.row.userClass | userStateFilter(userClass) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="userType" label="标签" align="center">
        <template slot-scope="scope">
          <div>
            {{ scope.row.userType | userTypeFilter(userType) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="contractStartDate" label="浏览量" align="center" />
      <el-table-column prop="contractStartDate" label="添加时间" align="center" />
      <el-table-column prop="contractStartDate" label="创建人" align="center" />
      <el-table-column label="操作" align="center" width="250">
        <template slot-scope="{ row }">
          <div class="labelCenter">
            <el-button
              v-if="listQuery.type2 === '1'"
              type="primary"
              size="mini"
              @click="$router.push('/database/store-list/data-manage/edit?id=' + id + '&t=' + listQuery.type + '&tId=' + row.id)"
            >编辑</el-button>
            <el-button
              v-if="listQuery.type2 === '1'"
              type="primary"
              size="mini"
              @click="
                handleDelete(row.id)
              "
            >删除</el-button>
            <el-button
              v-if="listQuery.type === 5 && listQuery.type2 === '2'"
              type="primary"
              size="mini"
              @click="
                $router.push('/database/store-list/data-manage/edit?id=' + row.id)
              "
            >查看</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <!-- 页码 -->
    <pagination
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="handleChange(listQuery.type)"
    />

    <el-dialog title="选择商品" :visible.sync="exportDialogVisible" width="70%">
      <data-list-selector
        v-if="exportDialogVisible"
        @cancel="onSelectorCancel"
        @confirm="onSelectorConfirm"
      />
    </el-dialog>
  </div>
</template>

<script>
import ManageTab from '../../components/dataManageTab.vue'
import DataListSelector from '../../components/dialogTable.vue'
import databaseMixin from '../../mixins/index'

export default {
  components: {
    ManageTab,
    DataListSelector
  },
  mixins: [databaseMixin],
  data() {
    return {
      listQuery: {
        type: '',
        pageNum: 1,
        pageSize: 10,
        userType: 0,
        userClass: 0,
        type2: '1'
      },
      list: [
        {
          id: 1,
          userClass: 1,
          userType: 1
        }
      ],
      total: 0,
      isLoading: false,
      exportDialogVisible: false
    }
  },
  methods: {
    getInfo() {
      this.isLoading = false
    },
    handleChange($event) {
      if (this.id && $event) {
        this.listQuery.type = Number($event)
        this.listQuery.type2 = '1'
        this.isLoading = true
        this.getInfo()
      }
    },
    handleDelete(val) {},
    onSelectorCancel() {},
    onSelectorConfirm() {}
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-tabs__nav-wrap::after {
  background: none;
}
</style>
