<template>
    <div style="padding: 0 20px">
      <div ref="lxHeader">
        <lx-header icon="md-apps" text="拜访时段管理" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <slot>
            <div style="display: flex;align-items: center;">

              <div style="margin-right: 10px;">关键词</div>

              <el-input size="mini" placeholder="请输入关键词" v-model="select.keyword" style="width: 160px;margin-right: 10px;"></el-input>

              <el-button size="medium" type="primary" @click="getList" style="margin-left: 10px">查询</el-button>

              <el-button size="medium" type="primary" @click="$refs['addVisitTime'].isShow = true,$refs['addVisitTime'].type = 'add'" style="margin-left: 10px">新增</el-button>
            </div>
          </slot>
        </lx-header>
      </div>

    <xy-table
      :table-item="table"
      :list="data"
      :total="total"
      :auths="['edit','delete']"
      @pageSizeChange="e => {select.page_size = e;select.page = 1;getList()}"
      @pageIndexChange="e => {select.page = e;getList()}"
      @delete="deleteRow"
      @editor="editorRow">
    </xy-table>
    <addVisitTime ref="addVisitTime" @refresh="getList"></addVisitTime>
  </div>
</template>

<script>

import {getList,destroy} from '@/api/resource/visittime.js'
import addVisitTime from '@/views/resource/component/addVisitTime'
export default {
  components: {
    addVisitTime
  },
  data() {
    return {
      select:{
        page:1,
        rows:10,
        keyword:""
      },
      total:0,
      data:[],
      table:[
        {
            label: '序号',
            type: "index",
            fixed: "left",
          },
        {
          label:'开始时间',
          sortable:false,
          prop:'start_time'
        },
        {
          label:'结束时间',
          sortable:false,
          prop:'end_time',
        }
      ]
    }
  },
  computed: {},
  mounted() {
    this.getList()
  },
  methods: {
    async getList(){
      let res = await getList(this.select)
      this.data = res.data
      this.total = res.total
    },
    deleteRow(row){
      destroy({id:row.id}).then(res => {
        this.$successMessage('destroy','时段')
        this.getList()
      })
    },
    editorRow(row){
      this.$refs['addVisitTime'].id = row.id
      this.$refs['addVisitTime'].type = 'editor'
      this.$refs['addVisitTime'].isShow = true
    }
  },
}
</script>

<style scoped lang="scss">
//::v-deep .el-button + .el-button{
//  margin-left: 0 !important;
//}
::v-deep .el-button{
  padding: 5px 8px !important;
}
</style>
