<template>
  <div>
    <a-modal
      centered
      wrapClassName="settlementModifyModal-modal"
      :footer="null"
      :maskClosable="false"
      title="订单详情"
      v-model="isshow"
      @cancle="handleBack"
      width="80%">
      <a-spin :spinning="spinning" tip="Loading...">
        <div ref="tableSearch" class="table-page-search-wrapper" v-if="itemData">
          <a-descriptions>
            <a-descriptions-item label="活动名称">
              {{ itemData.rewardRuleName|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="货架名称">
              {{ itemData.shelfName|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="配件经销商">
              {{ itemData.dealerName|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="汽车修理厂">
              {{ itemData.storeName|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="员工姓名">
              {{ itemData.userName|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="员工手机号码">
              {{ itemData.userMobile|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="订单编号">
              {{ itemData.orderNo|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="订单类型">
              {{ itemData.orderTypeDictValue|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="订单状态">
              {{ itemData.orderSourceDictValue|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="红包奖励时间">
              {{ itemData.rewardCreateDate|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="红包发放状态">
              {{ itemData.rewardStatusDictValue|| '--' }}
            </a-descriptions-item>
            <a-descriptions-item label="红包发放时间">
              {{ itemData.giveDate|| '--' }}
            </a-descriptions-item>
          </a-descriptions>
        </div>
        <a-alert type="info" style="margin-bottom:10px" v-if="itemData">
          <div slot="message">
            红包金额小计：<strong>{{ itemData&&(itemData.totalRewardAmount || itemData.totalRewardAmount==0) ? itemData.totalRewardAmount : '--' }}</strong>；
          </div>
        </a-alert>
        <s-table
          class="sTable"
          ref="table"
          size="small"
          rowKey="id"
          :columns="columns"
          :data="loadData"
          :showPagination="false"
          :defaultLoadData="false"
          :scroll="{ y: 350 }"
          bordered>
        </s-table>
        <div style="padding:10px;text-align:center;">
          <a-button type="default" @click="handleBack">关闭</a-button>
        </div>
      </a-spin>
    </a-modal>
  </div>
</template>

<script>
import { STable, VSelect } from '@/components'
import { rewardOrderQueryList } from '@/api/rewardOrder.js'
export default {
  name: 'StatisticsDetail',
  components: {
    STable, VSelect
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    itemData: {
      type: Object,
      default: function () {
        return null
      }
    }
  },
  data () {
    return {
      spinning: false,
      isshow: this.visible,
      // 表头
      columns: [
        { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
        { title: '产品编码', dataIndex: 'productCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品名称', dataIndex: 'productName', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '下单数量', dataIndex: 'productQty', width: '8%', align: 'center', customRender: function (text) { return (text || text == 0) ? text : '--' } },
        { title: '售价(终端会员价)', dataIndex: 'terminalPrice', width: '10%', align: 'center', customRender: function (text) { return (text || text == 0) ? text : '--' } },
        { title: '成本价(市级价)', dataIndex: 'cityPrice', width: '10%', align: 'center', customRender: function (text) { return (text || text == 0) ? text : '--' } },
        { title: '售价小计', dataIndex: 'terminalPriceTotal', width: '8%', align: 'center', customRender: function (text) { return (text || text == 0) ? text : '--' } },
        { title: '成本小计', dataIndex: 'cityPriceTotal', width: '8%', align: 'center', customRender: function (text) { return (text || text == 0) ? text : '--' } },
        { title: '毛利小计', dataIndex: 'grossAmountTotal', width: '8%', align: 'center', customRender: function (text) { return (text || text == 0) ? text : '--' } },
        { title: '红包毛利比例', dataIndex: 'rewardRatio', width: '10%', align: 'center', customRender: function (text) { return (text || text == 0) ? text : '--' } },
        { title: '红包金额', dataIndex: 'rewardAmount', width: '8%', align: 'center', customRender: function (text) { return (text || text == 0) ? text : '--' } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.spinning = true
        return rewardOrderQueryList(Object.assign(parameter, { rewardOrderSn: this.itemData.rewardOrderSn })).then(res => {
          let data
          if (res.status == 200) {
            data = res.data
            const no = 0
            for (let i = 0; i < data.length; i++) {
              const _item = data[i]
              _item.no = no + i + 1
            }
          }
          this.spinning = false
          return data
        })
      }
    }
  },
  methods: {
    handleBack () {
      this.$emit('close')
    }
  },
  watch: {
    visible (newValue, oldValue) {
      this.isshow = newValue
    },
    isshow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      } else {
        this.$nextTick(() => {
          this.$refs.table.refresh(true)
        })
      }
    }
  }
}
</script>
<style lang="less">
.settlementModifyModal-modal{
  .ant-input-number-handler-wrap{
    display: none;
  }
}
</style>
