<template>
  <div v-if="showPage" class="shelfOrderDetail-wrap">
    <a-spin :spinning="spinning" tip="Loading...">
      <a-page-header :ghost="false" :backIcon="false" class="shelfOrderDetail-cont" :style="{ padding: !outBizSn ? '16px 24px' : '0px 24px' }">
        <template slot="subTitle" v-if="!outBizSn">
          <a href="javascript:;" @click="handleBack"><a-icon type="left"></a-icon> 返回列表</a>
          <a style="margin: 0 10px 0 20px;color: #666;font-size: 14px;font-weight: 600;">订单号：{{ detailData&&detailData.orderBillNo || '--' }}</a>
        </template>
      </a-page-header>
      <!-- 基础信息 -->
      <a-card size="small" :bordered="false" class="shelfOrderDetail-cont">
        <a-collapse :activeKey="['1']">
          <a-collapse-panel key="1" header="基础信息">
            <a-descriptions size="small" :column="3">
              <a-descriptions-item label="订单编号">{{ detailData&&detailData.orderBillNo || '--' }}</a-descriptions-item>
              <a-descriptions-item label="货架名称">{{ detailData&&detailData.shelfName || '--' }}</a-descriptions-item>
              <a-descriptions-item label="下单时间">{{ detailData&&detailData.orderDate || '--' }}</a-descriptions-item>
              <a-descriptions-item label="下单人员">{{ detailData&&detailData.orderPersonName || '--' }}</a-descriptions-item>
              <a-descriptions-item label="订单状态"> {{ detailData&&detailData.billStateDictValue || '--' }}</a-descriptions-item>
              <a-descriptions-item label="VIN" v-if="detailData&&detailData.vin">{{ detailData&&detailData.vin || '--' }}</a-descriptions-item>
              <a-descriptions-item label="车型" v-if="detailData&&detailData.vehicleModel">{{ detailData&&detailData.vehicleModel || '--' }}</a-descriptions-item>
            </a-descriptions>
          </a-collapse-panel>
        </a-collapse>
      </a-card>
      <a-card size="small" :bordered="false" class="pages-wrap">
        <!-- alert -->
        <a-alert type="info" style="margin-bottom: 10px;">
          <div style="display: flex;align-items: center;justify-content: space-between;" slot="message">
            <div>
              总款数：<strong>{{ countDetail&&(countDetail.productCategory || countDetail.productCategory==0) ? countDetail.productCategory : '--' }}</strong>；
              总数量：<strong>{{ countDetail&&(countDetail.totalQty || countDetail.totalQty==0) ? countDetail.totalQty : '--' }}</strong>；
              总结算金额：<strong>{{ countDetail&&(countDetail.settleAmount || countDetail.settleAmount==0) ? toThousands(countDetail.settleAmount,2) : '--' }}</strong>；
            </div>
          </div>
        </a-alert>
        <!-- 列表 -->
        <a-table
          class="sTable"
          ref="table"
          size="small"
          :rowKey="(record) => record.id"
          :columns="columns"
          :data-source="detailList"
          :pagination="false"
          bordered>
        </a-table>
      </a-card>
    </a-spin>
  </div>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { STable, VSelect } from '@/components'
import { orderBillQueryPage, orderBillDetailCount } from '@/api/shelf'
export default {
  name: 'SalesDetail',
  components: { STable, VSelect },
  mixins: [commonMixin],
  props: {
    outBizSn: { //  有值则为弹框，无值则为页面
      type: [Number, String],
      default: ''
    }
  },
  data () {
    return {
      showPage: false,
      spinning: false,
      disabled: false,
      detailList: [],
      detailData: null, //  详情数据
      countDetail: null
    }
  },
  computed: {
    columns () {
      let _this=this
      const arr = [
        { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
        { title: '货位号', dataIndex: 'shelfPlaceCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品编码', dataIndex: 'productCode', width: '15%', scopedSlots: { customRender: 'productCode' }, align: 'center' },
        { title: '产品名称', dataIndex: 'productName', width: '40%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '结算价', dataIndex: 'settlePrice', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text,2) : '--') } },
        { title: '下单数量', dataIndex: 'totalQty', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '结算金额小计', dataIndex: 'settleAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ?  _this.toThousands(text,2) : '--') } }
      ]
      return arr
    }
  },
  methods: {
    //  返回
    handleBack () {
      this.$router.push({ name: 'shelfOrderList' })
    },
    getDetail () {
      this.spinning = true
      orderBillQueryPage({ pageNo: 1, pageSize: 1, orderBillSn: this.outBizSn || this.$route.params.sn }).then(res => {
        this.spinning = false
        this.detailData = res.data.list && res.data.list[0]
        this.detailList = this.detailData.orderBillDetailApiEntityList
        this.detailList.map((item, index) => {
          item.no = index + 1
        })
      })

      orderBillDetailCount({ orderBillSn: this.outBizSn || this.$route.params.sn }).then(res => {
        this.countDetail = res.data || null
      })
    },
    pageInit () {
      const vm = this
      vm.$nextTick(() => {
        vm.spinning = false
        vm.disabled = false
        vm.getDetail()
      })
    }
  },
  activated () {
    this.showPage = true
    this.pageInit()
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {})
  }
}
</script>

<style lang="less">
  .shelfOrderDetail-wrap{
    .shelfOrderDetail-cont{
      margin-bottom: 6px;
    }
  }
</style>
