<template>
  <a-modal
    centered
    :footer="null"
    :maskClosable="false"
    class="sales-print-type-modal"
    v-model="isShow"
    @cancel="isShow=false"
    :width="900">
    <div class="title">提示</div>
    <a-spin :spinning="spinning" tip="Loading...">
      <div class="tipModal-content">
        <a-table
          class="sTable"
          ref="table"
          size="small"
          :rowKey="(record) => record.id"
          :columns="columns"
          :dataSource="dataList"
          :scroll="{ y: 300 }"
          :pagination="false"
          bordered>
        </a-table>
        <div style="padding: 20px;text-align: center;" v-if="dataObj&&dataObj.message">
          {{ dataObj.message }}
        </div>
        <div style="margin-top:36px;text-align:center;" v-if="modalType==='0'">
          <!-- <a-button @click="handleCancel" style="margin-right: 15px" id="chooseCustom-btn-back">关闭</a-button> -->
          <a-button type="primary" style="margin-right: 15px" @click="handleSubmit('AUDIT_REJECT')" id="chooseCustom-btn-noPasss">审核不通过</a-button>
          <a-button type="primary" class="button-info" @click="handleSubmit('AUDIT_PASS')" id="chooseCustom-btn-Pass">审核通过</a-button>
        </div>
        <div style="margin-top:36px;text-align:center;" v-else>
          <a-button @click="handleCancel" style="margin-right: 15px" id="chooseCustom-btn-back">关闭</a-button>
        </div>
      </div>
    </a-spin>
  </a-modal>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
export default {
  name: 'VaildPriceModal',
  mixins: [commonMixin],
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    dataObj: {
      type: Object,
      default: () => {
        return null
      }
    },
    modalType: {// 0  来源审核页面  1来源提交页面
      type: String,
      default: '0'
    }
  },
  data () {
    return {
      isShow: this.openModal,
      spinning: false
    }
  },
  computed: {
    dataList () {
      const list = this.dataObj && this.dataObj.salesPromoDetailEntityList || []
      list.map(item => {
        item.totalAmount = this.modalType == 0 ? item.promotionPrice * item.qty : item.totalAmount
        item.totalCostAmount = item.showCost * item.qty
        item.totalKsAmount = item.totalAmount - item.totalCostAmount
      })
      return list
    },
    columns () {
      const _this = this
      const arr = [
        { title: '序号', dataIndex: 'no', width: '5%', align: 'center', customRender: function (text, row, index) { return index + 1 } },
        { title: '产品编码', dataIndex: 'productCode', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '销售数量', dataIndex: 'qty', width: '10%', align: 'center', isShow: false, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '售价小计', dataIndex: 'totalAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } }
      ]
      if (_this.modalType == 0) {
        arr.splice(2, 0, { title: '参考成本价', dataIndex: 'showCost', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } })
        arr.splice(3, 0, { title: '售价', dataIndex: 'promotionPrice', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } })
        arr.splice(5, 0, { title: '单位', dataIndex: 'product.unit', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
        arr.push({ title: '参考成本价小计', dataIndex: 'totalCostAmount', width: '15%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } })
        arr.push({ title: '亏损金额', dataIndex: 'totalKsAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } })
      } else {
        arr.splice(2, 0, { title: '售价', dataIndex: 'price', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } })
        arr.splice(4, 0, { title: '单位', dataIndex: 'productEntity.unit', width: '10%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
      }
      return arr
    }
  },
  methods: {
    // 保存
    handleSubmit (type) {
      this.spinning = true
      this.$emit('ok', type)
    },
    // 关闭弹窗
    handleCancel () {
      this.isShow = false
      this.$emit('close')
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      }
    }
  }
}
</script>
<style lang="less" scoped>
  .tipModal-content{
    width:87%;
    margin:30px auto 0;
    text-align:center;
    .tipModal-tit{
      font-size: 20px;
    }
    .sTable{
      margin:15px 0 25px;
    }
   .ant-radio-wrapper:first-child{
      margin-right:70px !important;
    }
    .redWord{
      color:#ed1c24;
    }
  }
</style>
