<template>
  <div class="goodsAllocationSet-page">
    <a-spin :spinning="spinning" tip="Loading...">
      <a-page-header :ghost="false" :backIcon="false" class="goodsAllocationSet-baseInfo">
        <template slot="subTitle">
          <a href="javascript:;" @click="handleBack"><a-icon type="left"></a-icon> 返回列表</a>
        </template>
      </a-page-header>
      <a-card :bordered="false" size="small" class="goodsAllocationSet-baseInfo">
        <a-collapse :activeKey="['1']">
          <a-collapse-panel key="1" header="基础信息">
            <a-descriptions size="small" :column="3">
              <a-descriptions-item label="货架名称">{{ }}</a-descriptions-item>
              <a-descriptions-item label="配件经销商">{{ }}</a-descriptions-item>
              <a-descriptions-item label="汽车修理厂">{{ }}</a-descriptions-item>
            </a-descriptions>
          </a-collapse-panel>
        </a-collapse>
      </a-card>
      <a-card :bordered="false" size="small" class="pages-wrap">
        <div class="goodsAllocationSet-baseInfo">
          <a-button @click="handleExport" type="primary">导入货位</a-button>
        </div>
        <s-table
          class="sTable fixPagination"
          ref="table"
          size="small"
          rowKey="id"
          :showPagination="false"
          :columns="columns"
          :data="loadData"
          :defaultLoadData="false"
          bordered>
          <template slot="name" slot-scope="text, record">
            <a-input allowClear placeholder="请输入货位号" v-if="isEdit" style="width: 80%;"/>
            <span v-if="!isEdit">{{ record.name }}</span>
          </template>
          <template slot="status" slot-scope="text, record">
            <a-button type="link" @click="handleEdit(record)" v-if="!isEdit">编辑</a-button>
            <a-button type="link" @click="handleSave(record,0)" v-if="isEdit">保存</a-button>
            <a-button type="link" @click="handleSave(record,1)" v-if="isEdit">取消</a-button>
          <!-- <span v-if="!($hasPermissions('B_powerMD_user_edit') && record.superAdmin!=1) && !(record.loginFlag==1 && record.ownerOrgFlag==1 && $hasPermissions('B_powerMD_user_restPwd')) && !(record.loginFlag==0 && record.ownerOrgFlag==1 && $hasPermissions('B_powerMD_user_del'))">--</span> -->
          </template>
        </s-table>
      </a-card>

    </a-spin>
  </div>
</template>

<script>
import { STable } from '@/components'
import { getPowerUserList } from '@/api/power-user.js'
export default {
  components: { STable },
  data () {
    return {
      spinning: false,
      isEdit: false, // 货位号是否为编辑
      // 表头
      columns: [
        { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
        { title: '货位号', dataIndex: 'name', width: '11%', align: 'center', scopedSlots: { customRender: 'name' } },
        { title: '创建时间', dataIndex: 'createDate', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '最后修改时间', dataIndex: '', width: '18%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '操作', width: '9%', align: 'center', scopedSlots: { customRender: 'status' } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.spinning = true
        return getPowerUserList(Object.assign(parameter)).then(res => {
          let data
          if (res.status == 200) {
            data = res.data
            const no = (data.pageNo - 1) * data.pageSize
            for (let i = 0; i < data.list.length; i++) {
              const _item = data.list[i]
              _item.no = no + i + 1
              _item.loginFlag = _item.loginFlag + '' === '1'
            }
          }
          this.spinning = false
          return data
        })
      }
    }
  },
  mounted () {
    this.$refs.table.refresh()
  },
  methods: {
    handleBack () {
      this.$router.go(-1)
    },
    handleExport () {
      console.log('=========导入货位')
    },
    handleEdit (row) {
      this.isEdit = true
    },
    handleSave (row, type) {
      if (type == 0) {
        console.log('====保存')
      } else {
        console.log('=====取消')
      }
      this.$nextTick(() => {
        this.isEdit = false
        this.$refs.table.refresh()
      })
    }
  }
}
</script>

<style lang="less">
  .goodsAllocationSet-page{
    position: relative;
    height: 100%;
    padding-bottom: 51px;
    box-sizing: border-box;
    .goodsAllocationSet-baseInfo{
      margin-bottom: 10px;
    }
  }
</style>
