<template>
  <el-dialog
    title="修改激活截止日期"
    :visible.sync="visible"
    width="500px"
    @close="handleClose">
    <el-form
      inline
      v-loading="loading"
      :model="form"
      ref="form"
      style="padding:20px"
      label-width="120px">
      <el-form-item
        verify
        label="激活截止时间"
        prop="activate_end_time">
        <el-date-picker
          :picker-options="dateOption"
          v-model="form.activate_end_time"
          type="date"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
    </el-form>

    <span slot="footer">
      <el-button @click="visible=false">取 消</el-button>
      <el-button
        type="primary"
        @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { apiMember, getSingleMember } from '@/api/member'
import moment from 'moment'

export default {
  data () {
    return {
      visible: false,
      loading: false,
      dateOption: {
        disabledDate (theTime) {
          let startTime = moment().format('YYYY-MM-DD') + ' 00:00:00'
          return moment(theTime).isBefore(startTime)
        }
      },
      form: {
        activate_end_time: ''
      }
    }
  },
  methods: {
    show (id) {
      this.visible = true
      this.loading = true
      getSingleMember(id).then(res => {
        this.form = res
      }).finally(() => {
        this.loading = false
      })
    },
    handleClose () {
      this.visible = false
    },
    submit () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          apiMember('updateMember', this.form).then(res => {
            this.$message.success('修改成功')
            this.$emit('updateList')
            this.handleClose()
          }).catch(err => {
            console.error(err)
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog .el-form-item {
  display: inline-block;
}
</style>
