<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 == 'wait_up_audit_price_less_cost'||modalType == 'audit_price_less_cost'">
          <a-button type="primary" style="margin-right: 15px" @click="handleSubmit(modalType == 'wait_up_audit_price_less_cost'?'AUDIT_UP_REJECT':'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-if="modalType == 'price_less_cost'">
          <a-button @click="handleCancel" style="margin-right: 15px" id="chooseCustom-btn-back">取消</a-button>
          <a-button type="primary" class="button-info" @click="handleSubmit('AUDIT_UP_PASS')" id="chooseCustom-btn-Pass">确定</a-button>
        </div>
        <div style="margin-top:36px;text-align:center;" v-if="modalType == 'price_less_0'">
          <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
      }
    }
  },
  data () {
    return {
      isShow: this.openModal,
      spinning: false
    }
  },
  computed: {
    modalType () {
      return this.dataObj && this.dataObj.type
    },
    dataList () {
      const list = this.dataObj && this.dataObj.data || []
      list.map(item => {
        item.totalKsAmount = item.totalShowCost - item.totalAmount
      })
      return list
    },
    columns () {
      const _this = this
      // 特价产品，销售价小于等于0
      if (this.modalType == 'price_less_0') {
        return [
          { 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: 'price', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
          { title: '销售数量', dataIndex: 'qty', width: '10%', align: 'center', isShow: false, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
          { title: '单位', dataIndex: 'productEntity.unit', width: '10%', align: 'center', 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 == 'price_less_cost' || _this.modalType == 'wait_up_audit_price_less_cost' || _this.modalType == 'audit_price_less_cost') {
        return [
          { 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: 'showCost', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
          { title: '售价', dataIndex: 'promotionPrice', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
          { title: '销售数量', dataIndex: 'qty', width: '10%', align: 'center', isShow: false, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
          { title: '单位', dataIndex: 'productEntity.unit', width: '10%', align: 'center', 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) : '--') } },
          { title: '参考成本价小计', dataIndex: 'totalShowCost', width: '15%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
          { title: '亏损金额', dataIndex: 'totalKsAmount', width: '10%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } }
        ]
      }
      return []
    }
  },
  methods: {
    // 保存
    handleSubmit (type) {
      console.log(type, this.modalType)
      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>
