<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最早打卡时间">
          <!-- <a-date-picker  format='YYYY-MM-DD HH:mm:ss' v-model="startDate" /> -->
          <a-date-picker
                :mode="mode1" format='YYYY-MM-DD HH:mm:ss' v-model="startDate" :allowClear="false"
                show-time
                @openChange="handleOpenChange1"
                @panelChange="handlePanelChange1"
              />
        </a-form-item>
        
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最迟打卡时间">
          <!-- <a-date-picker  format='YYYY-MM-DD HH:mm:ss' v-model="endDate" /> -->
          <a-date-picker
                :mode="mode1" format='YYYY-MM-DD HH:mm:ss' v-model="endDate" :allowClear="false"
                show-time
                @openChange="handleOpenChange1"
                @panelChange="handlePanelChange1"
              />
        </a-form-item>
       
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import {
    jiaozhun
  } from '@/api/api'
  
  export default {
    name: "StatutoryLeaveModal",
    data () {
      return {
        mode1: 'time',
        startDate:"",
        endDate:"",
        viewDate:"",
        username:"",
        setInfo:"",
        title:"操作",
        visible: false,
        type:"2",
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        url: {
          add: "/statutoryleave/statutoryLeave/add",
          edit: "/statutoryleave/statutoryLeave/edit",
        },
      }
    },
    created () {
    },
    methods: {
      handleOpenChange1(open) {
            if (open) {
              this.mode1 = 'time';
            }
        },
        handlePanelChange1(value, mode) {
          this.mode1 = mode;
        },
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'name','sum'))
		  //时间格式化
          this.form.setFieldsValue({startDate:this.model.startDate?moment(this.model.startDate):null})
          this.form.setFieldsValue({endDate:this.model.endDate?moment(this.model.endDate):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        this.startDate = moment(this.startDate).format('YYYY-MM-DD HH:mm:ss');
        this.endDate = moment(this.endDate).format('YYYY-MM-DD HH:mm:ss');
        
        // 触发表单验证
            // that.confirmLoading = true;
            // let httpurl = '';
            // let method = '';
            // if(!this.model.id){
            //   httpurl+=this.url.add;
            //   method = 'post';
            // }else{
            //   httpurl+=this.url.edit;
            //    method = 'put';
            // }
            //时间格式化
            
            jiaozhun({shiftTimeS:this.startDate,shiftTimeX:this.endDate,viewDate:this.viewDate,username:this.username,setInfo:this.setInfo}).then((res) => {
              if (res.success) {
                that.$message.success("已成功校准");
                that.loadData();
              } else {
                that.$message.warning(res.message);
                 that.$emit('ok');
              }
            });
            // httpAction(httpurl,formData,method).then((res)=>{
            //   if(res.success){
            //     that.$message.success(res.message);
            //     that.$emit('ok');
            //   }else{
            //     that.$message.warning(res.message);
            //   }
            // }).finally(() => {
            //   that.confirmLoading = false;
              that.close();
            // })


      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>