<template>
  <div>
    <el-dialog
      v-el-drag-dialog
      :title="title"
      :close-on-click-modal="false"
      :visible.sync="visible"
      width="60%"
    >
      <el-form ref="form" v-loading="loading" class="form-full" :model="formItem" label-width="120px" label-suffix=" : ">
<!--        <el-row :gutter="15">-->
<!--          <el-col :span="12">-->
<!--            <el-form-item-->
<!--              label="发布时间"-->
<!--              prop="publishDate"-->
<!--              :rules="[-->
<!--                { required: true, message: '发布时间不能为空', trigger: 'blur' }-->
<!--              ]"-->
<!--            >-->
<!--              <ec-date v-model="formItem.publishDate" type="datetime" format="yyyy-MM-dd" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item-->
<!--              label="状态"-->
<!--              prop="configStatus"-->
<!--              :rules="[-->
<!--                { required: true, message: '状态不能为空', trigger: 'blur' }-->
<!--              ]"-->
<!--            >-->
<!--              <ec-select v-model="formItem.configStatus" dict-type="versionStatus" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item
              label="登录背景图"
              prop="picUrl"
              :rules="[
                { required: true, message: '登录背景图不能为空', trigger: 'change' }
              ]"
            >
              <ec-file-modal v-model="formItem.picUrl" list-type="picture" />
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">-->
<!--            <el-form-item-->
<!--              label="备注信息"-->
<!--              prop="remarks"-->
<!--              :rules="[-->
<!--              ]"-->
<!--            >-->
<!--              <el-input v-model="formItem.remarks" type="textarea" :autosize="{minRows: 1, maxRows: 5}" placeholder="请填写备注信息"     />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">关闭</el-button>
        <el-button v-if="method !== 'view'" type="primary" :loading="saveLoading" @click="save">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

import { findByPrimaryKey, save, update } from 'ecip-web/api/web/loginconfig/sysrLoginConfigApi'

export default {
  name: 'WebLoginconfigSysrLoginConfigForm',
  components: {},
  data() {
    return {
      visible: false,
      loading: false, // 页面加载遮罩
      saveLoading: false, //  保存加载
      method: '',
      title: '',
      record: {},
      formItem: {
        publishDate: '',
        configStatus: '2',
        picUrl: '',
        remarks: ''
      }
    }
  },
  methods: {
    async init(method, record) {
      Object.assign(this.$data, this.$options.data())

      this.method = method
      this.record = record
      if (method === 'add') {
        this.title = `新建登录页面配置`
      } else if (method === 'edit') {
        this.title = '修改登录页面配置'
      } else if (method === 'view') {
        this.title = '查看登录页面配置'
      }
      this.visible = true
      this.loading = false
      await this.$nextTick()
      this.$refs.form.clearValidate()
      if (method === 'edit' || method === 'view') { // 修改或者查看
        this.loading = true
        const { data } = await findByPrimaryKey(record.id)
        this.formItem = Object.assign({}, this.formItem, data)
        this.loading = false
      }
    },
    save() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          try {
            this.saveLoading = true
            if (this.method === 'edit') {
              await update(this.record.id, this.formItem)
            } else {
              await save(this.formItem)
            }
            this.$notify.success('保存成功')
            this.$emit('refreshData')
            this.visible = false
          } finally {
            this.saveLoading = false
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
