<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :bodyStyle="bodyStyle"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    cancelText="关闭"
    :footer="null">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">



        <a-form-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择结束时间" v-decorator="[ 'endDate', validatorRules.endDate]" :trigger-change="true" style="width: 100%" />
        </a-form-item>

      </a-form>
    </a-spin>

    <div class="drawer-bootom-button">
      <a-button class="ant-btn"  @click="handleCancel">取消</a-button>
      <a-button class="ant-btn ant-btn-primary" style="margin-left: 8px"  @click="handleOk">确定</a-button>
    </div>
  </j-modal>
</template>

<script>

  import { httpAction, getAction  } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'
  import AFormItem from 'ant-design-vue/es/form/FormItem'
  import JDictSelectTag from '@/components/dict/JDictSelectTag'
  import { duplicateCheck } from '@/api/api'
  import SubcontractorSelectWindow from '../../hlwsubcontractor/modules/SubcontractorSelectWindow'


  export default {
    name: "HlwTaxEditEndDateModal",
    components: {
      JDate,
      AFormItem,
      JDictSelectTag
    },
    data () {
      return {
        bodyStyle: {
          paddingTop: '20px',
          paddingBottom:'50px',
          height: (window.innerHeight * 0.50) + 'px',
          'overflow-y': 'auto'
        },
        form: this.$form.createForm(this),
        title:"操作",
        width:700,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        disableSubmit:false,
        selectedDepartKeys:[], //保存用户选择服务商id
        checkedDepartKeys:[],
        hlwTaxRateList:[{}],
        validatorRules: {

          endDate: {
            rules: [
              { required: true, message: '请输入结束时间!'},
            ]
          },

        },
        url: {
          edit: "/wisdom/hlwTax/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form = this.$form.createForm(this)
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'subcontracctorId','taxWarning','accumulationType','startDate','endDate','createTime','createBy','updateTime','updateBy','hlwTaxRateList','hlwSubcontractorName'))
        })

      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.selectedDepartKeys = [];
        this.checkedDepartKeys = [];
      },
      handleOk () {


        this.endDate=this.form.getFieldValue('endDate')
        if(new Date(this.endDate).getTime()<new Date().getTime()){
          this.$message.warning('结束时间不能早于今天')
          return
        }
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                this.$error({
                  title: '提示',
                  content: res.message,
                  okText: '确定',
                  centered:true,
                  onOk: () => {

                  }
                })
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'subcontracctorId','taxWarning','accumulationType','startDate','endDate','createTime','createBy','updateTime','updateBy'))
      },

      
    }
  }
</script>
<style lang="less" scoped>
  .drawer-bootom-button {
    position: absolute;
    bottom: -8px;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
  }
</style>