<template>
  <div class="Sell">
    <page-header-wrapper
      :title="false"
      content="用于配置销售目录"
      :tab-list="tabList"
      :tab-active-key="tabActiveKey"
      @tabChange="handleTabChange"
    >
      <a-card
        :body-style="{padding: '24px 32px'}"
        :bordered="false"
        title="明细"
      >
        <template slot="extra">
          <a-button type="primary" @click="visible = true">新增{{ modalText }}</a-button>
        </template>
        <a-table
          row-key="index"
          size="small"
          :columns="searchTableColumns"
          :dataSource="searchData"
          :pagination="{ pageSize: 5 }"
        >
          <span slot="range" slot-scope="text, record">
            <trend :flag="record.status === 0 ? 'up' : 'down'">
              {{ text }}%
            </trend>
          </span>
          <template slot="action" >
            <a>编辑</a>
            <a-divider type="vertical" />
            <a-popconfirm
              title="你确定要删除这个标签吗?"
              ok-text="Yes"
              cancel-text="No"
              @confirm="() => {}"
              @cancel="() => {}"
            >
              <a>删除</a>
            </a-popconfirm>
          </template>
        </a-table>
        <!-- <a-row> -->
        <!-- <a-col :xs="24" :sm="24" :md="12" :lg="8" > -->
        <!-- <div class="cate-item" v-for="(item, index) in cateList" :key="index">
              <div><span class="sort">{{ index + 1 }}</span> <span></span> {{ item.label }}</div>
              <div class="opration"><a-icon type="form" /> <a-icon type="delete" /></div>
            </div> -->
        <!-- </a-col> -->
        <!-- </a-row> -->
      </a-card>
    </page-header-wrapper>

    <!-- 新建各种类目 -->
    <a-modal
      :title="'新增' + modalText"
      v-model="visible"
      :confirm-loading="confirmLoading"
      ok-text="确认"
      cancel-text="取消"
      @ok="handleOk"
    >
      <a-input v-model="cateValue" :placeholder="'请输入' + modalText" />
    </a-modal>
  </div>
</template>

<script>
import { getConfig } from '@/api/basics'
const searchTableColumns = [
  {
    dataIndex: 'index',
    title: '序号',
    width: 90
  },
  {
    dataIndex: 'keyword',
    title: '类目名'
  },
  {
    title: '操作',
    key: 'action',
    scopedSlots: { customRender: 'action' }
  }
]
const searchData = []
for (let i = 0; i < 50; i += 1) {
  searchData.push({
    index: i + 1,
    keyword: `搜索关键词-${i}`,
    count: Math.floor(Math.random() * 1000),
    range: Math.floor(Math.random() * 100),
    status: Math.floor((Math.random() * 10) % 2)
  })
}

export default {
  name: 'Sell',
  computed: {
    modalText () {
      return this.tabList[this.tabActiveKey].tab
    }
  },
  created () {
    this.getConfig()
  },
  data () {
      return {
        searchTableColumns,
        searchData,
        tabList: [
            { key: '0', tab: '意向度' },
            { key: '1', tab: '来源渠道' },
            { key: '2', tab: '意向课程' },
            { key: '3', tab: '年级' },
            { key: '4', tab: '流失原因' }
        ],
        tabActiveKey: '0',
        visible: false,
        confirmLoading: false,
        cateValue: '', // 各种类目的名称
        cateList: [
          {
            label: '客户不满意'
          }
        ], //  类目集合
        queryParams: {
          curPage: 1,
          type: 'INTENTION'
        }
      }
  },
  methods: {
    // 获取销售配置
    async getConfig () {
      console.log('helorenwenhao')
      const { curPage, type } = this.queryParams
      const $par = {
        curPage,
        type
      }
      const { code, data } = await getConfig($par)
      if (code === 0) {
        console.log(data)
      }
    },
    handleTabChange (key) {
      this.tabActiveKey = key
    },
    handleOk (e) {
      this.ModalText = 'The modal will be closed after two seconds'
      this.confirmLoading = true
      setTimeout(() => {
        this.visible = false
        this.confirmLoading = false
      }, 2000)
    }
  }
}
</script>
<style scoped lang="less">
.sort {
    background-color: #f5f5f5;
    border-radius: 20px;
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    margin-right: 24px;
    height: 20px;
    line-height: 20px;
    width: 20px;
    text-align: center;
}
.cate-item {
  height: 40px;
  border: 1px solid #f3f3f3;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
