liveSaveDialog.vue 2.37 KB
<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      :before-close="handleCloseDialog">
      <el-form :model="liveForm" ref="liveForm" :rules="liveRules" label-width="130px">
          <el-form-item label="时间:" prop="liveTime">
            <el-date-picker
              v-model="liveForm.liveTime"
              type="datetime"
              value-format="timestamp"
              placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="内容:" prop="liveContent">
            <el-input type="textarea" v-model="liveForm.liveContent" maxlength="500" show-word-limit></el-input>
          </el-form-item>
        </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('liveForm')">提交</el-button>
        <el-button @click="handleCloseDialog">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import { request } from '@/api/fetch-api'


  let urls = {
    liveSaveUrl: '/tianbao_edu_api/admin/live/save',
  }
  export default {
    props: ['dialogVisible', 'title', 'liveTemp'],
    data() {
      return {
        title: '',
        liveForm:{},
        liveRules:{
          liveTime: [
            {required: true, message: '请选择时间', trigger: 'blur'}
          ],
          liveContent: [
            {required: true, message: '请输入内容', trigger: 'blur'}
          ],
        }

      }
    },
    methods: {
      handleCloseDialog() {
        this.$emit('closedialog', false)
      },
      init(){
        if (JSON.parse(JSON.stringify(this.liveTemp)) == null) {
          this.title='创建'
        } else {
          this.title="修改"
          this.liveForm = JSON.parse(JSON.stringify(this.liveTemp))
        }
      },
      submitForm(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            request.post(urls.liveSaveUrl, this.liveForm).then(response => {
              this.$emit('initLive')
              this.$emit('closedialog', false)
              this.$message.success("保存成功")
            }).catch(() => {

            })
          } else {
            console.log('error submit!!')
            return false
          }
        })

      }

    },
    created() {
        this.init()
    }
  }
</script>

<style scoped>

</style>