<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <bu-zy-jcw-online-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :dataType="dataType" :queryMonth="queryMonth"></bu-zy-jcw-online-form>
  </j-modal>
</template>

<script>

  import BuZyJcwOnlineForm from './BuZyJcwOnlineForm'
  export default {
    name: 'BuZyJcwOnlineModal',
    components: {
      BuZyJcwOnlineForm
    },
    data () {
      return {
        title:'',
        width:800,
        visible: false,
        disableSubmit: false,
        dataType: 'online', // 查询类型: online/history
        queryMonth: ''      // 历史数据查询月份
      }
    },
    methods: {
      add () {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.add();
        })
      },
      edit (record, dataType, queryMonth) {
        // Pass dataType and queryMonth to the form
        this.dataType = dataType || 'online';
        this.queryMonth = queryMonth || '';
        
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.edit(record);
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.$refs.realForm.submitForm();
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      }
    }
  }
</script>