<template>
  <a-card size="small" :bordered="false" class="storeTransferOutTypeList-wrap">
    <a-spin :spinning="spinning" tip="Loading...">
      <!-- 操作按钮 -->
      <div class="table-operator-nobor">
        <a-button
          v-if="$hasPermissions('B_basicData_storeTransferOutType_add')"
          id="storeTransferOutTypeList-add"
          type="primary"
          class="button-error"
          @click="handleEdit()">新增</a-button>
      </div>
      <!-- 列表 -->
      <s-table
        class="sTable"
        ref="table"
        size="default"
        :rowKey="(record) => record.id"
        :columns="columns"
        :data="loadData"
        :scroll="{ y: 300 }"
        bordered>
        <!-- 操作 -->
        <template slot="action" slot-scope="text, record">
          <a-button
            v-if="$hasPermissions('B_basicData_storeTransferOutType_edit')"
            size="small"
            type="link"
            class="button-info"
            @click="handleEdit(record)"
            id="storeTransferOutTypeList-edit-btn">编辑</a-button>
          <a-button
            v-if="$hasPermissions('B_basicData_storeTransferOutType_del')"
            size="small"
            type="link"
            class="button-error"
            @click="handleDel(record)"
            id="storeTransferOutTypeList-del-btn">删除</a-button>
        </template>
      </s-table>
    </a-spin>
    <!-- 新增/编辑店内调出类型 -->
    <storeTransferOut-type-edit-modal :openModal="openModal" :nowData="nowData" :itemId="itemId" @close="closeModal" />
  </a-card>
</template>

<script>
import { STable, VSelect } from '@/components'
import storeTransferOutTypeEditModal from './editModal.vue'
import { storeCallOutTypeList, storeCallOutTypeDel } from '@/api/storeCallOutType'
export default {
  components: { STable, VSelect, storeTransferOutTypeEditModal },
  data () {
    return {
      spinning: false,
      queryParam: { //  查询条件
        name: '' //  店内调出类型名称
      },
      disabled: false, //  查询、重置按钮是否可操作
      columns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
        { title: '店内调出类型名称', dataIndex: 'name', align: 'center', ellipsis: true },
        { title: '创建时间', dataIndex: 'createDate', align: 'center' },
        { title: '操作', scopedSlots: { customRender: 'action' }, width: 200, align: 'center' }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        return storeCallOutTypeList(Object.assign(parameter, this.queryParam)).then(res => {
          const data = res.data
          const no = (data.pageNo - 1) * data.pageSize
          for (var i = 0; i < data.list.length; i++) {
            data.list[i].no = no + i + 1
          }
          this.disabled = false
          return data
        })
      },
      openModal: false, //  新增编辑店内调出类型  弹框
      itemId: '', //  当前id
      nowData: null //  当前记录数据
    }
  },
  methods: {
    //  重置
    resetSearchForm () {
      this.queryParam.name = ''
      this.$refs.table.refresh(true)
    },
    //  新增/编辑
    handleEdit (row) {
      this.itemId = row ? row.id : null
      this.nowData = row || null
      this.openModal = true
    },
    //  删除
    handleDel (row) {
      const _this = this
      _this.$confirm({
        title: '提示',
        content: '删除后原数据不可恢复，是否删除？',
        centered: true,
        onOk () {
          _this.spinning = true
          storeCallOutTypeDel({ id: row.id }).then(res => {
            if (res.status == 200) {
              _this.$message.success(res.message)
              _this.$refs.table.refresh()
              _this.spinning = false
            } else {
              _this.spinning = false
            }
          })
        }
      })
    },
    //  关闭弹框
    closeModal () {
      this.itemId = ''
      this.openModal = false
      this.$refs.table.refresh(true)
    }
  }
}
</script>
