<template>
  <div>
    <el-row>
      <el-form ref="changeInfoRef" :model="changeInfoForm" label-width="70px">
        <el-col :span="7">
          <el-form-item label="变更时间">
            <el-date-picker value-format="yyyy-MM-dd" v-model="changeInfoForm.changeDate" type="date" placeholder="请选择变更时间"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="变更类型">
            <el-select clearable v-model="changeInfoForm.changeType" placeholder="请选择变更类型">
              <el-option
                v-for="item in changeTypeList"
                :key="item.F_ValueId"
                :label="item.F_Value"
                :value="item.F_ValueId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="说明">
            <el-input v-model="changeInfoForm.changeExplain" placeholder="请输入说明"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-button type="primary" style="margin-left:50%" @click="submit">保存</el-button>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
import { getDictionaryValueList } from "@/api/commonAPI";
import { saveChange } from '@/api/mediaCenter/mediaInformation'
import { pickerOptions } from "@/utils";
export default {
  props: {
    rowid: {
      type: String,
      default: ""
    },
    layerid: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      changeTypeList: [], //变更类型
      pickerOptions, //日期数据
      //添加变更数据
      changeInfoForm: {
        changeDate: "", //变更时间
        changeType: "", //变更类型
        changeExplain: "", //变更说明
      }
    };
  },
  created() {
    this.getChangeType(); //获取变更类型
  },
  methods: {
    //获取变更类型
    getChangeType() {
      return new Promise(resolve => {
        const params = {
          isleaf: true,
          code: "MTBGLX"
        };
        getDictionaryValueList(params).then(response => {
          if (response.state.toLowerCase() === "success") {
            this.changeTypeList = response.data.Rows;
          }
        });
      });
    },
    submit(){
        return new Promise(resolve=>{
            const params={
                id:this.rowid,
                F_Type:1,//媒体变更
                F_ChangeType:this.changeInfoForm.changeType,//变更类型
                F_ChangeTime:this.changeInfoForm.changeDate,//变更时间
                F_Describe:this.changeInfoForm.changeExplain,//变更说明
            }
            saveChange(params).then(response=>{
                if(response.state.toLowerCase()==='success'){
                    this.$parent.$layer.close(this.layerid)
                    this.$parent.getList()
                    this.$message.success('恭喜你，添加成功!')
                }
            }).catch(result=>{
                this.$message.error(result)
            })
        })
    }
  }
};
</script>
<style lang="scss" scoped>
</style>