<template>
  <el-dialog
    :title="'' "
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
      <el-form-item label="月份"  >
        <el-select v-model="dataForm.monthTime" placeholder="请选择">
          <el-option
            v-for="item in dataList"
            :key="item.key"
            :label="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>

    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="commitRecord()">确认</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {getMyDate, updateDate} from '@/api/api_result'

export default {
  data () {
    return {
      visible: false,
      recordResultId: 0,
      dataList: [{value: '2017-03', key: '2017-04'}],
      dataForm: {
        monthTime: ''
      },
      dataRule: {}
    }
  },
  mounted () {

  },
  computed: {},
  methods: {
    async init (recordResultId) {
      this.recordResultId = recordResultId
      this.visible = true
      this.$nextTick(async () => {
        this.$refs['dataForm'].resetFields()
        getMyDate({
          'recordResultId': this.recordResultId
        }).then(data => {
          if (data && data.code === 0) {
            this.dataList = data.list
            this.dataForm.monthTime = this.dataList[0].value
          } else {
            this.alertInfo(data.msg)
          }
        })
      })
    },
    alertInfo (msg) {
      this.$message({
        message: msg,
        type: 'success',
        duration: 1500,
        onClose: () => {
        }
      })
    },
    commitRecord () {
      updateDate({
        'recordResultId': this.recordResultId,
        'monthTime': this.dataForm.monthTime
      }).then(data => {
        if (data && data.code === 0) {
          this.$emit('refreshDataList', this.recordResultId)
          this.visible = false
          this.alertInfo('更新成功')
        } else {
          this.alertInfo(data.msg)
        }
      })
    },
    stringIsNull (str) {
      if (typeof str === 'undefined' || str === null || str === '') {
        return true
      }
      return false
    }
  }
}
</script>
