<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="5" :sm="15">
            <a-form-item label="报修单号">
              <a-input placeholder="请输入报修单号" v-model="queryParam.sn" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-tabs default-active-key="1" @change="callback">
      <a-tab-pane key="1" tab="全部信息">
        <a-table
          size="default"
          rowKey="id"
          :columns="columns"
          :data-source="workerData"
        >
          <span slot="name" slot-scope="text, record">
           <a-tag color="blue">
          消息提示
          </a-tag>
          </span>
          <span slot="content" slot-scope="text, record">
            <a @click="toRepair(record.repairId)">{{ record.content }}</a>
          </span>
          <span slot="action" slot-scope="text, record">
        <a v-if="editEnabel" @click="handleView(record.id)">详情</a>
        <a-divider type="vertical" />
      </span>
        </a-table>
      </a-tab-pane>
      <a-tab-pane key="2" tab="未读通知" force-render>
        <a-table
          size="default"
          rowKey="id"
          :columns="columns"
          :data-source="noReadData"
        >
          <span slot="name" slot-scope="text, record">
           <a-tag color="blue">
          消息提示
          </a-tag>
          </span>
          <span slot="content" slot-scope="text, record">
            <a @click="toRepair(record.repairId)">{{ record.content }}</a>
          </span>
          <span slot="action" slot-scope="text, record">
        <a v-if="editEnabel" @click="handleView(record.id)">详情</a>
        <a-divider type="vertical" />
      </span>
        </a-table>
      </a-tab-pane>
      <a-tab-pane key="3" tab="已读通知" force-render>
        <a-table
          size="default"
          rowKey="id"
          :columns="columns"
          :data-source="readData"
        >
          <span slot="name" slot-scope="text, record">
           <a-tag color="blue">
          消息提示
          </a-tag>
          </span>
          <span slot="content" slot-scope="text, record">
            <a @click="toRepair(record.repairId)">{{ record.content }}</a>
          </span>
          <span slot="action" slot-scope="text, record">
        <a v-if="editEnabel" @click="handleView(record.id)">详情</a>
        <a-divider type="vertical" />
      </span>
        </a-table>
      </a-tab-pane>
    </a-tabs>
  </a-card>
</template>

<script>
import { STable } from '@/components'
import { getRepairRemindList } from '@/api/admin/repair/repairRemind'
import { checkPermission } from '@/utils/permissions'

export default {
  name: 'TableList',
  components: {
    STable
  },
  data () {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      form: this.$form.createForm(this),
      mdl: {},
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '提醒类型',
          dataIndex: 'name',
          scopedSlots: { customRender: 'name' }
        },
        {
          title: '提醒内容',
          dataIndex: 'content',
          scopedSlots: { customRender: 'content' }

        },
        {
          title: '时间',
          dataIndex: 'createTime'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      // loadData: parameter => {
      //   return getRepairList(Object.assign(parameter, this.queryParam))
      // },
      addEnable: checkPermission('admin:repair:add'),
      editEnabel: checkPermission('admin:repair:edit'),
      removeEnable: checkPermission('admin:repair:list'),
      readData: [],
      workerData: [],
      noReadData: []
    }
  },

  created () {
    this.workerList()
  },
  methods: {
    // admin/repair/stats/workerList
    workerList () {
      getRepairRemindList().then(res => {
        this.workerData = res.rows

        this.noReadData = res.rows.filter(item => item.read == 0)

        this.readData = res.rows.filter(item => item.read == 1)

      })
    },
    callback () {

    },

    handleAdd () {
      this.$refs.modal.add()
    },
    handleView (workerId) {
      this.$router.push({ name: 'repair', query: { repairUserId: workerId } })
    },

    toRepair (repairId) {
      this.$router.push({ name: 'repairView', query: { repairId: repairId } })
    },

    handleEdit (record) {
      this.$refs.modal.edit(record)
    },
    handleOk () {
      this.$refs.table.refresh(true)
      console.log('handleSaveOk')
    },
    handleComplete (id) {
      const _this = this
      this.$confirm({
        title: '警告',
        content: '确认要完成工单吗?',
        okText: '是',
        okType: 'warning',
        cancelText: '否',
        onOk () {
          complete(id).then(res => {
            if (res.code === 0) {
              _this.$message.success('操作成功')
              _this.$refs.table.refresh(true)
            } else {
              _this.$message.error(res.msg)
            }
          }).catch(() => {
            this.$message.error('系统错误，请稍后再试')
          })
        },
        onCancel () {
        }
      })
    }
  },
  watch: {}
}
</script>
