<template>
  <a-card :bordered="false" v-show="visible" class="card" :title="modalTitle">
    <a-row :gutter="48" slot="extra">
      <a-col :md="48" :sm="48">
        <span class="table-page-search-submitButtons" style="float: right">
          <a-button v-if="3 === model.status" style="margin-left: 8px" type="danger" @click="adjustCheckPlan()">出入库矫正</a-button>
          <a-button style="margin-left: 8px" @click="handleCancel()">返回</a-button>
        </span>
      </a-col>
    </a-row>
    <title-divider title="型号信息" width="90px"></title-divider>
    <detail-list title="" :col="2">
      <detail-list-item term="编码">{{ model.no }}</detail-list-item>
      <detail-list-item term="计划名称">{{ model.name }}</detail-list-item>
      <detail-list-item term="盘点项目部">{{ model.storeName }}</detail-list-item>
      <detail-list-item term="备件类型">{{ model.spareTypeName }}</detail-list-item>
      <detail-list-item term="计划开始时间">{{ model.startTime }}</detail-list-item>
      <detail-list-item term="计划结束时间">{{ model.endTime }}</detail-list-item>
      <detail-list-item term="是否启用"><badge :status="DictCache.COLOR.YES_NO[model.enable]" :text="enableMap[model.enable]"></badge></detail-list-item>
      <detail-list-item term="状态"><badge :status="DictCache.COLOR.STORE_CHECK_PLAN_STATUS[model.status]" :text="statusMap[model.status]"></badge></detail-list-item>
      <detail-list-item term="更新时间">{{ model.updateTime }}</detail-list-item>
    </detail-list>
    <detail-list title="" :col="1">
      <detail-list-item term="备注">{{ model.remark }}</detail-list-item>
    </detail-list>
    <title-divider title="盘点明细" width="90px"></title-divider>
    <store-check-job-table-2 :dataSource="model.jobList" @ok="handleOk"></store-check-job-table-2>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">返回</a-button>
    </template>
  </a-card>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import StoreCheckJobTable2 from '@/views/sb/storecheckjob/modules/StoreCheckJobTable2'
import { adjustCheckPlan, fetchCheckPlan } from '@/api/sb/sbstorecheckplan'
const DetailListItem = DetailList.Item

export default {
  name: 'StoreCheckPlanDetail',
  components: {
    DetailList,
    DetailListItem,
    StoreCheckJobTable2
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      // 下拉框map
      typeMap: {},
      statusMap: {},
      checkUserTypeMap: {},
      periodTypeMap: {},
      validTimeTypeMap: {},
      enableMap: {},
      model: {
        'no': null,
        'name': null,
        'storeId': null,
        'spareType': null,
        'startTime': null,
        'storeName': null,
        'spareTypeName': null,
        'endTime': null,
        'enable': null,
        'remark': null,
        'updateUserName': null,
        'updateTime': null
      },
      rowSelection: {
        onChange: (selectedRowKeys, selectedRows) => {
          this.selectedRowKeys = selectedRowKeys
          this.selectedRows = selectedRows
        }
      },
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  created () {
    // 下拉框map
    this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_TYPE)
    this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
    this.checkUserTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_USER_TYPE)
    this.validTimeTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
    this.enableMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.STORE_CHECK_PLAN_STATUS)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
    },
    adjustCheckPlan () {
      adjustCheckPlan({ id: this.model.id }).then(res => {
        this.$message.info('已补录出入库单据，请核对出入库明细。')
        fetchCheckPlan({ id: this.model.id }).then(res => {
          this.model = res.data
        })
      })
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
      this.$emit('ok')
    },
    handleOk () {
      fetchCheckPlan({ id: this.model.id }).then(res => {
        this.model = res.data
      })
    }
  }
}
</script>
