<template>
  <!-- 添加油价信息 -->
  <div class="addWagonLoad">
    <page-title>返回</page-title>
    <div class="form_box" style="margin-right: 10rem">
      <dil-form :formId="357" v-model="form1" ref="from1" @change="onchang"></dil-form>
      <div class="addbtn">
        <el-button type="primary" @click="dialogVisible = true">新增油品名称</el-button>
      </div>
    </div>
    <div class="button_box">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="makeSure">确定</el-button>
    </div>
    <el-dialog
      title="新增油品名称"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <el-input v-model="input" placeholder="请输入内容"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogCancel">取 消</el-button>
        <el-button type="primary" @click="dialogMakeSure">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";
import { isNumber } from '@/utils/sharedJsFile'
export default {
  components: { PageTitle },
  data() {
    return {
      isagain:false,
      loading:false,
      input:null,
      dialogVisible:false,
      form1: {
        priceOilName:'',
        priceValue:'',
        priceDate:new Date(),
        enableStatus:false,
      },
    };
  },
  methods: {
    dialogCancel(){

    },
    onchang(val){
      if(val.enableStatus){
        this.$message.warning('确认启用后将停用现在正在执行的油品价格')
      }
    },
    dialogMakeSure(){
      // this.loading = true;
      // if(this.input){
      //   this.axios.post('',{text:this.input}).then((res)=>{
      //     if(res.data.code == "200"){
      //       this.loading = false;
      //       this.$message.success('新增成功')
            this.dialogVisible = false;
      //     }
      //   })
      // }else{
      //   this.$message.warning('请输入油品名称')
      // } 
    },
    makeSure() {
      this.loading = true;
      let state = false;
      if(!this.form1.priceOilName){
        this.$message.warning('请填写油品名称')
      }else if(!this.form1.priceValue){
        this.$message.warning('请填写油品价格')
      }else if(!isNumber(this.form1.priceValue)){
        this.$message.warning('油品价格必修为整数或者小数')
      }else{
        // state = true;            
      }
      if(state){
        let RmsOilPrice = this.form1;
        this.axios.post("/api/v1/rms/insertOilPrice" , RmsOilPrice)
        .then((res) => {
          if (res.data.code == "200") {
            this.loading = true;
            this.$message.success('新增成功');
            this.cancel();
          }
        });
      }else{
        this.loading = true;
      }
    },
    // 取消
    cancel() {
      this.$router.push("/oilPrice");
    },
  },
};
</script>
<style lang='scss'>
.addWagonLoad{
  .form_box{
    margin-left: 35%;
    padding-top: 30px;
    width: 470px;
    display: flex;
    .el-form{
      .el-form-item{
        display: flex;
        align-items: center;
        .el-form-item__content{
          .el-input{
            width: 250px;
          }
          .el-switch{
            margin-left: -250px;
          }
        }
      }
    }
    .addbtn{
      margin-left: 30px;
    }
  }
  .button_box{
    margin-left: 40%;
    padding-top: 30px;
    width: 310px;
    display: flex;
    justify-content: center;
  }
}
</style>