<template>
  <vxe-modal v-model="value" id="freightModal" width="400" v-loading="load" @hide="hide" height="200" show-footer title="修改运费">
    <by-form :propConfig="config" ref="form"></by-form>
    <template #footer>
      <div class="btn">
        <el-button plain size="small" @click="value = false">取消</el-button>
        <el-button type="primary" size="small" @click="btn">确定</el-button>
      </div>
    </template>
  </vxe-modal>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { editFreight } from '@/api/omsOrder'
@Component({components:{}})
export default class FreightModal extends Vue {
  value=false;
  load=false;
  billValue:Array<any>=[];
  config:any={
    attr:{
      rules:{
        freight: [
          { required: true, message: '运费不能为空！', trigger: 'input' }
        ]
      }
    },
    columns:[
      [{
        label:'运费',
        prop:'freight',
        labelWidth:'80px',
        component:'by-input',
        compConfig:{
          attr:{
            placeholder:'保留两位小数',
            type:'number'
          }
        }
      }]
    ]
  }
  setShow(v:boolean){
    this.value = v;
  }
  setBillValue(data:Array<any>){
    this.billValue = data;
  }
  hide(){
    (this.$refs.form as any).clearValidate();
    (this.$refs.form as any).clearValue();
  }
  btn(){
    (this.$refs.form as any).validate({noMsg:true}).then(()=>{
      let data = (this.$refs.form as any).getValue();
      data.idList = this.billValue;
      data.freight = Math.floor(Number(data.freight) * 100) / 100;
      this.load = true
      editFreight(data).then(()=>{
        this.load = false;
        (this.$message({
          message:'操作成功！',
          type:'success'
        }));
        this.$emit('handleSuccess');
        this.value = false;
      }).catch(()=>{
        this.load = false;
      })
    })
  }
}
</script>

<style lang="scss" scoped>

</style>