<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-popconfirm v-if="model.status==1" title="是否要出库，出库将更新库存？"  @confirm="updateStore()">
            <a-button type="primary">出库</a-button>
           </a-popconfirm>
           <a-button v-if="$auth('store-out-store-forms-edit')&&model.status==1" style="margin-left: 8px" type="danger" @click="handleEdit()">修改</a-button>
           <a-button style="margin-left: 8px" @click="handleCancel">返回</a-button>
         </span>
       </a-col>
    </a-row>
    <detail-list title="" :col="3">
      <detail-list-item term="出库单号">{{ model.outNo }}</detail-list-item>
      <detail-list-item term="出库类型">{{ BaseTool.Object.getField(typeMap,model.type) }}</detail-list-item>
      <detail-list-item term="仓库">{{ model.storeName }}</detail-list-item>
      <detail-list-item term="总价">{{ model.totalPrice }}</detail-list-item>
      <detail-list-item term="领用/退货单id">{{ model.pickId }}</detail-list-item>
      <detail-list-item term="领用/退货单号">{{ model.pickNo }}</detail-list-item>
      <detail-list-item term="状态"><badge :text="BaseTool.Object.getField(statusMap,model.status)" :status="statusMap[model.status]"/></detail-list-item>
      <detail-list-item term="创建人">{{ model.createdUserName }}</detail-list-item>
      <detail-list-item term="更新人">{{ model.updateUserName }}</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>
    <a-tabs type="card" default-active-key="1">
      <a-tab-pane key="1" tab="出库详情">
        <a-table
          bordered
          :data-source="data"
          :columns="columns"
          tableLayout="auto"
          rowKey="id">

        </a-table>
      </a-tab-pane>
    </a-tabs>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">返回</a-button>
    </template>
  </a-card>
</template>

<script>
import { updateStore, fetchOutStoreForm } from '@/api/store/outstoreform'
import DetailList from '@/components/tools/DetailList'
const DetailListItem = DetailList.Item

export default {
  name: 'OutStoreFormDetail',
  components: {
    DetailList,
    DetailListItem
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      // 下拉框map
      typeMap: {},
      statusMap: {},
      model: {
        'outNo': null,
        'type': null,
        'pickId': null,
        'storeId':null,
        'storeName':null,
        'pickNo': null,
        'totalPrice': null,
        'remark': null,
        'createdUserId': null,
        'updateUserId': null,
        'updateTime': null,
        'createdUserName': null,
        'updateUserName': null
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          customRender: (text, record, index) => {
            return index + 1
          }
        },
        //{
         // title: '出库仓库',
        //  dataIndex: 'storeId',
         // customRender: (text, record, index) => {
         //   return record.storeName
         // }
        //},
        {
          title: '数量',
          dataIndex: 'num'
        },
        {
          title: '单价',
          dataIndex: 'price',
          customRender: (text, record, index) => {
            return this.BaseTool.Amount.formatter(text)
          }
        },
        {
          title: '总价',
          dataIndex: 'totalPrice',
          customRender: (text, record, index) => {
            return this.BaseTool.Amount.formatter(text)
          }
        },
        {
          title: '备件名称',
          dataIndex: 'spareId',
          customRender: (text, record, index) => {
            return record.spareName
          }
        },
        {
          title: '编号',
          dataIndex: 'no'
        },
        {
          title: '备件规格',
          dataIndex: 'ggxh'
        },
        {
          title: '原厂编号',
          dataIndex: 'initNo'
        }
      ],
      data: []
    }
  },
  created () {
    // 下拉框map
    this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.OUT_STORE_FORM_TYPE)
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.OUT_STORE_FORM_STATUS)

  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
      this.data = record.detailList
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
      this.$emit('ok')
    },
    handleEdit () {
      fetchOutStoreForm({ id: this.model.id }).then(res => {
        const modal = this.$refs.baseModal
        modal.base(res.data)
      })
    },
    handleOk () {
      fetchOutStoreForm({ id: this.model.id }).then(res => {
        this.model = res.data
      })
    },
    updateStore(){
      updateStore({id:this.model.id}).then(res => {
        this.$message.info('出库成功')
        this.handleOk()
      })
    }
  }
}
</script>
