<template>
  <div>
    <crumbs :title="title" linkTo="/admin/LT-YXSJWH-BBXXWH"></crumbs>
    <div class="contents">
      <div class="content">
        <el-form ref="form" :label-position="labelPosition" label-width="95px" class="add-admin-form" :model="form" :rules="rules">
          <el-form-item label="版本号：" prop="name">
              <el-input v-model="form.name" placeholder="请输入版本号" maxlength="120"></el-input>
          </el-form-item>
          <el-form-item label="版本时间：" prop="refreshTime">
            <el-date-picker
              v-model="form.refreshTime"
              type="date"
              placeholder="选择日期"
              :picker-options="pickerOptions1"
              value-format="yyyy-MM-dd"
              :clearable='false'>
            </el-date-picker>
          </el-form-item>
          <el-form-item label="版本备注：" prop="remark" class="discDesc">
              <el-input type="textarea" :rows="3" placeholder="请输入版本备注" v-model="form.remark" maxlength="120"></el-input>
          </el-form-item>
          <el-form-item label="版本说明：" v-if="list.length>0">
          </el-form-item>
        </el-form>
        <VersionDesc v-if="id" :detail="list" :versionId="id" :isFirst="isFirst"/>
        <el-button class="disclButn" size="small" type="primary" @click="comfirn">确定</el-button>
      </div>    
    </div>
  </div>
</template>
<script type="text/javascript">
  import api from '@api/icss.js';
  import VersionDesc from './VersionDesc.vue';
  export default {
    name:'AddVersion',
    data(){
      return{
        // data:{},
        list:[],
        labelPosition:'left',
        isFirst:false,
        title:'版本信息维护-添加版本信息',
        form:{
          name:'',
          refreshTime:'',
          remark:''
        },
        id:null,
        rules:{
          name:{ required: true, message: '请输入版本号', trigger: ['blur', 'change'] },
          refreshTime:{ required: true, message: '请选择时间', trigger: ['blur', 'change'] }
        },
        pickerOptions1:{
          disabledDate(time) {
            return time.getTime() < Date.now();
          },
        }
      }
    },
    created(){
      let info = this.$route.params.info;
      if(info){
        this.id = info.id;
        this.form.name = info.name;
        this.form.refreshTime = info.refreshTime;
        this.form.remark = info.remark;
        this.title = "版本信息维护-修改版本信息";
        this.isFirst = true;
        this.getList();
      }
    },
    methods:{
      getList(){
        api.getVersionDetlInfo({id:this.id}).then((res)=>{
          const result = res.data;
          if(result.code==0){
            this.list = result.data;
          }else{
            this.$message.error(result.msg);
          }
        })
      },
      comfirn(){
        if(this.id){//修改
          const param = Object.assign({},this.form,{id:this.id})
          api.updateVersInfo(param).then((res)=>{
            if(res.data.code==0){
              this.$message({
                message:"修改成功",
                type:'success'
              })
              this.$router.push({path: 'LT-YXSJWH-BBXXWH'});
            }else{
              this.$message.error(res.data.msg);
            }
          })
        }else{//添加
          api.addVersInfo(this.form).then((res)=>{
            if(res.data.code==0){
              this.$message({
                message:"添加成功",
                type:'success'
              })
              this.$router.push({path: 'LT-YXSJWH-BBXXWH'});
            }else{
              this.$message.error(res.data.msg);
            }
          })
        }
      },
    },
    components:{
      VersionDesc
    }
  }
</script>
<style lang="less" scoped>
  @import "../../less/admin.less";
  .content{
    background: #fff;
    // padding: 20px 20px 30px;
    padding: 20px 20px 50px;
    color: #545455;
    min-width: 980px;
    position: relative;
    .discDesc{
      margin-bottom: 20px;
    }
    .disclButn{
      position: absolute;
      right: 80px;
      bottom: 0px;
    }
  }

</style>