<template>
  <!-- 添加公告信息 -->
  <div class="addWagonLoad">
    <PageTitle>返回</PageTitle>

    <div class="form-box" style="margin-right: 10rem">
      <dil-form :formId="389" v-model="form1" ref="from1"></dil-form>
    </div>

    <div class="button-box">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="makeSure">确定</el-button>
    </div>
  </div>
</template>

<script>
import { getCookie } from '@/utils/util.js'
import PageTitle from "@/components/Page/Title";
export default {
  components: { PageTitle },
  data() {
    return {
      form1: {
        permission:"销售商"
      },
      value: undefined,
    };
  },
  mounted() {
    this.userId = getCookie('userId')
    /*console.log("新增")
    console.log(this.userId)
    //this.form1.insertTime=new Date()*/
    this.$set(this.form1, 'insertTime',new Date())
    this.information()
  },
  methods: {
    async information(){
      await this.axios.post("/api/v1/ams/queryName/"+this.userId)
        .then((res=>{
          console.log(res)
          let userName=res.data.data
          this.$set(this.form1, 'insertUsername',userName)
        }))
    },
    makeSure() {
      console.log(this.form1);
      let time=this.msToDate(this.form1.insertTime)
      let DilNotice = {
        noticeTitle:this.form1.noticeTitle,
        insertUsername:this.form1.insertUsername,
        noticeContent:this.form1.noticeContent,
        permissions:this.form1.permission,
        insertTime:time
        /*这里permissions拿的是描述也就是name值*/
      }
      this.axios
        .post(
          "/api/v1/ams/insertNotice",DilNotice
        )
        .then((res) => {
          this.$router.go(-1);
        });
    },
    msToDate(msec){
      let datetime = new Date(msec);
      let year = datetime.getFullYear();
      let month = datetime.getMonth();
      let date = datetime.getDate();
      let hour = datetime.getHours();
      let minute = datetime.getMinutes();
      let second = datetime.getSeconds();

      let result=year+
        '-'+
        ((month + 1) >= 10 ? (month + 1) : '0' + (month + 1)) +
        '-' +
        ((date + 1) < 10 ? '0' + date : date) +
        ' ' +
        ((hour + 1) < 10 ? '0' + hour : hour) +
        ':' +
        ((minute + 1) < 10 ? '0' + minute : minute) +
        ':' +
        ((second + 1) < 10 ? '0' + second : second);
      return result;
    },
    // 取消
    cancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss' scoped>
.from {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 5px;
  margin-bottom: 20px;
}
.button-box{
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  margin-top: 0.3125rem;
  margin-bottom: 1.25rem;
}
.form-box{
  .el-form{
    margin-top: 100px;
    margin-left: 200px;
    .preview-group{
      .el-form-item{
        width: 600px;
        height: 60px;
      }
    }
  }
}
</style>
