<template>
  <a-modal title="调整价格" :visible="showAlt" :confirm-loading="confirmSubmit" @ok="fnSetOrderMoney" @cancel="fnHideAlt" width="700px" :footer='false'>
  <a-spin :spinning="confirmSubmit">
    <a-form-model :model="form" :rules="rules" v-bind="layout" ref="ruleForm">
      <template v-if="sourceType==2">
        <a-row v-if="form">
          <a-col :span="12"><a-form-model-item label="工程费"><a-input :disabled="!isEdit" type="number" v-model="form.costCostruction" /></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="加急费"><a-input :disabled="!isEdit" type="number" v-model="form.costJiaJi" /></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="工程费"><a-input :disabled="!isEdit" type="number" v-model="form.costCostruction"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="加急费"><a-input :disabled="!isEdit" type="number" v-model="form.costJiaJi"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="浮动金额"><a-input :disabled="!isEdit" type="number" v-model="form.orderPreferentialMoney"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="锣程费"><a-input :disabled="!isEdit" type="number" v-model="form.routLengthMoney"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="孔费"><a-input :disabled="!isEdit" type="number" v-model="form.holeMoney"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="板费"><a-input :disabled="!isEdit" type="number" v-model="form.costBoard"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="测试费"><a-input :disabled="!isEdit" type="number" v-model="form.costTest"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="拼版费"><a-input :disabled="!isEdit" type="number" v-model="form.costPinBan"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="表面处理费"><a-input :disabled="!isEdit" type="number" v-model="form.costMetallize"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="菲林费"><a-input :disabled="!isEdit" type="number" v-model="form.costFilm"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="颜料费"><a-input :disabled="!isEdit" type="number" v-model="form.costColor"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="成型费"><a-input :disabled="!isEdit" type="number" v-model="form.costShap"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="其他费"><a-input :disabled="!isEdit" type="number" v-model="form.costOther"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="产品费"><a-input :disabled="!isEdit" type="number" v-model="form.orderTotalMoney"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="税费"><a-input :disabled="!isEdit" type="number" v-model="form.orderTaxMoney"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="运费"><a-input :disabled="!isEdit" type="number" v-model="form.orderShipMoney"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="会员优惠券优惠金额"><a-input :disabled="!isEdit" type="number" v-model="form.memberCouponMoney"/></a-form-model-item></a-col>
        </a-row>
      </template>
      <template v-else-if="sourceType==4">
        <a-row v-if="form.orderPriceDetail">
          <a-col :span="12"><a-form-model-item label="产品费(含税)"><a-input disabled="disabled" type="number" v-model="form.totalPrice"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="单片价格"><a-input disabled="disabled" type="number" v-model="form.singlePrice"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="快递费"><a-input disabled="disabled" type="number" v-model="form.shipPrice"/></a-form-model-item></a-col>
          <a-col :span="24"><a-form-model-item label="其他费用明细" :label-col="{ span:4, offset: 0 }" :wrapper-col="{ span:20, offset:0 }"><a-input disabled="disabled" v-model="form.costOther"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="板费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.costBoard"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="工程费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.costCostruction"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="菲林费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.costFilm"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="表面处理费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.costMetallize"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="其他费用"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.costOther"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="测试费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.costTest"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="孔费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.holeMoney"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="拼版费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.costPinBan"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="加急费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.costJiaJi"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="颜料费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.costColor"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="成型费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.costShap"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="锣程费"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.routLengthMoney"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="浮动价格"><a-input disabled="disabled" type="number" v-model="form.orderPriceDetail.orderPreferentialMoney"/></a-form-model-item></a-col>
          <a-col :span="12"><a-form-model-item label="调整金额">
            <a-tooltip placement="topLeft" title="在原始调整金额上加减！">
              <a-input :disabled="!isEdit" type="number" v-model="form.adjustAmount"/>
            </a-tooltip>
          </a-form-model-item></a-col>
          <a-col :span="24"><a-form-model-item label="调整备注" :label-col="{ span:4, offset: 0 }" :wrapper-col="{ span:20, offset:0 }"><a-input :disabled="!isEdit" v-model="form.adjustRemark"/></a-form-model-item></a-col>
        </a-row>
      </template>
      <div class="bn">
        <a-space v-if="!isEdit"><a-button @click="fnHideAlt">关闭</a-button><a-button type="primary" @click="isEdit = true">编辑</a-button></a-space>
        <a-space v-else><a-button @click="fnGetOrderMoney">取消</a-button><a-button type="primary" @click="fnSetOrderMoney">提交保存</a-button></a-space>
      </div>
    </a-form-model>
  </a-spin>
  </a-modal>
</template>

<script>
import {OrderMoney, OrderUpdateMoney} from "@/services/order/Order";

export default {
  name: "orderMoney",
  props:['orderId','sourceType','showAlt','fnHiddenAlt'],
  data(){
    return{
      confirmSubmit:true,tabMoneyForm:['2','4'],isEdit:false,
      detail:{},
      form:{},
      rules:{},
      layout:{labelCol:{span:8},wrapperCol:{span:16},},
    }
  },
  watch:{
    showAlt(){
      if (this.showAlt) this.fnGetOrderMoney();
    }
  },
  methods:{
    fnGetOrderMoney(){
      if (this.tabMoneyForm.indexOf(this.sourceType)<0){
        this.$message.warn('暂无匹配的价格模板！');
        return false;
      }
      this.isEdit = false;
      this.confirmSubmit = true;
      OrderMoney(this.orderId).then(res=>{
        // console.log(this.sourceType,this.orderId);
        if (res.success){
          let db = JSON.parse(res.message);
          this.form = db;
          // let OST = this.sourceType;
          this.confirmSubmit = false;
        }else{
          this.$message.error(res.message);
        }
      }).finally(()=>{})
    },
    fnHideAlt(){
      this.fnHiddenAlt();
    },
    fnSetOrderMoney(){
      if(this.confirmSubmit) return false;
      let params = {
        id:this.orderId,
        keys:JSON.stringify(this.form)
      }
      this.confirmSubmit = true;
      OrderUpdateMoney(params).then(res=>{
        if (res.success){
          this.$message.success(res.message)
        }else this.$message.error(res.message);
        this.fnGetOrderMoney();
      }).finally(()=>{
        this.confirmSubmit = false;
      })
    },
  }
}
</script>

<style scoped>
/deep/ .ant-form-item-label>label{display:inline-block; line-height:1.2em}
/deep/ .ant-form-item-label{white-space:pre-wrap}
.ant-form-item{margin-bottom:5px}
.bn{text-align:center; clear:both; padding:20px 0}
</style>