<template>
  <div>
    <x-card>
      <div slot="content" class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="4" :sm="24">
              <a-form-item>
                <a-input v-model="queryParam.phone" allow-clear placeholder="请输入手机号" />
              </a-form-item>
            </a-col>
            <a-col :md="(!advanced && 6) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <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>
    </x-card>
    <a-card :bordered="false">
      <s-table ref="table" :columns="columns" :data="loadData" :alert="true" :rowKey="record => record.id">
        <span slot="action" slot-scope="text, record">
          <a v-if="hasPerm('order:edit')" @click="AddorEdit(record, 1)">编辑</a>
          <a-divider type="vertical" v-if="hasPerm('order:status') && record.status === 2" />
          <a-popconfirm
            v-if="hasPerm('order:status') && (record.status === 2 || record.status === 3)"
            placement="topRight"
            title="确认启用？"
            @confirm="() => setstatus(record, 1)"
          >
            <a>启用</a>
          </a-popconfirm>
          <a-divider type="vertical" v-if="hasPerm('order:status') && record.status == 1" />
          <a-popconfirm
            v-if="hasPerm('order:status') && record.status == 1"
            placement="topRight"
            title="确认停用？"
            @confirm="() => setstatus(record, 2)"
          >
            <a>停用</a>
          </a-popconfirm>
        </span>
        <span slot="status" slot-scope="text, record">
          <span style="color: #1dbb1d" v-if="record.status === 1"> {{ GetClientDataItem('orderstatus', text) }}</span>
          <span style="color: red" v-else-if="record.status === 3"> {{ GetClientDataItem('orderstatus', text) }}</span>
          <span style="color: #b3b3b3" v-else> {{ GetClientDataItem('orderstatus', text) }}</span>
        </span>
      </s-table>
    </a-card>
  </div>
</template>
<script>
import { STable, XCard } from '@/components'
import { RegUserList } from '@/api/modular/main/reguser'
import { GetClientDataItem, GetClientDataList } from '@/utils/clientdata'
export default {
  components: {
    XCard,
    STable
  },
  data() {
    return {
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      title: '添加配置',
      // 表头
      columns: [
        {
          title: '用户',
          dataIndex: 'name'
        },
        {
          title: '手机号',
          dataIndex: 'phone'
        },
        {
          title: '最近登录时间',
          dataIndex: 'lastlogintime'
        },
        {
          title: '注册时间',
          dataIndex: 'createtime'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return RegUserList(Object.assign(parameter, this.queryParam)).then(res => {
          return res.data
        })
      }
    }
  },
  created() {
    if (this.hasPerm('order:edit')) {
      this.columns.push({
        title: '操作',
        width: '150px',
        dataIndex: 'action',
        scopedSlots: { customRender: 'action' }
      })
    }
  },
  methods: {
    GetClientDataList,
    GetClientDataItem,
    handleOk() {
      this.$refs.table.refresh()
    },
    // 修改状态
    setstatus(record, status) {
      SetStatus({
        id: record.id,
        status: status
      })
        .then(res => {
          if (res.code === 0) {
            this.$message.success('状态设置成功')
            this.$refs.table.refresh()
          } else {
            this.$myerror(res.message)
          }
        })
        .catch(err => {
          this.$myerror(err.message)
        })
    }
  }
}
</script>
<style scoped lang="less">
/deep/ .ant-table td {
  white-space: nowrap;
}
/deep/ .ant-table-body {
  overflow-x: auto !important;
}
/deep/ .ant-table-thead > tr > th,
.ant-table-tbody > tr > td {
  white-space: nowrap;
}
.table-operator {
  margin-bottom: 18px;
}
button {
  margin-right: 8px;
}
</style>
