<template>
  <a-modal
    centered
    class="addProvincialWarehouse-modal"
    :footer="null"
    :maskClosable="false"
    :title="modalTit"
    v-model="isShow"
    @cancel="isShow=false"
    :width="700">
    <a-spin :spinning="spinning" tip="Loading...">
      <s-table
        class="sTable fixPagination"
        ref="table"
        :style="{ maxHeight: 300+'px' }"
        size="small"
        :rowKey="(record) => record.id"
        :columns="columns"
        :data="loadData"
        :showPagination="false"
        :scroll="{ y: 270 }"
        :defaultLoadData="false"
        bordered>
      </s-table>
    </a-spin>
  </a-modal>
</template>

<script>
// 组件
import { STable } from '@/components'
// 接口
import { changeRecordList } from '@/api/provinceServiceCenter'
export default {
  name: 'AddProvincialWarehouseModal',
  components: { STable },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      spinning: false,
      isShow: this.openModal, //  是否打开弹框
      modalTit: '变更记录', // 标题
      dealerSn: null, // 经销商sn
      // 表格列表
      columns: [
        { title: '序号', dataIndex: 'no', width: '6%', align: 'center' },
        { title: '启用时间', dataIndex: 'useDate', width: '47%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '禁用时间', dataIndex: 'disableDate', width: '47%', align: 'center', customRender: function (text) { return text || '--' } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        this.spinning = true
        return changeRecordList(Object.assign(parameter, { dealerSn: this.dealerSn })).then(res => {
          let data
          if (res.status == 200) {
            data = res.data
            // 计算表格序号
            for (var i = 0; i < data.length; i++) {
              data[i].no = i + 1
            }
            this.disabled = false
          }
          this.spinning = false
          return data
        })
      }
    }
  },
  methods: {
    // 初始化
    pageInit (itemObj) {
      const _this = this
      _this.dealerSn = itemObj.dealerSn
      _this.modalTit = '变更记录（' + itemObj.dealerName + '）'
      _this.$nextTick(() => {
        _this.$refs.table.refresh(true)
      })
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      }
    }
  }
}
</script>

<style lang="less">
  .addProvincialWarehouse-modal{
    .ant-modal-body {
      padding: 40px 40px 24px;
    }
    .btn-cont {
      text-align: center;
      margin: 35px 0 10px;
    }
    .tree-node{
      height: 300px;
      overflow: auto;
      .tree-box{
        .tree-parent{
          display: flex;
          align-items: center;
          border-bottom: 1px solid #eee;
          padding: 0 10px;
          > span{
            margin:0 5px;
            &:first-child{
              flex-grow: 1;
            }
            &:last-child{
              cursor: pointer;
            }
          }
        }
        .tree-child{
          padding: 10px 10px 10px 35px;
          display: flex;
          align-items: center;
          flex-wrap:wrap ;
          > div{
            margin:0 5px;
          }
        }
      }

    }
  }
</style>
