<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="作业单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['comNo_dictText']" placeholder="" disabled></a-input>
        </a-form-item>
        <a-form-item label="作业地点" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['gemoId_dictText']" placeholder="" disabled></a-input>
        </a-form-item>
<!--        <a-form-item label="设备编号" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--          <a-input v-decorator="['adDeviceId']" placeholder=""></a-input>-->
<!--        </a-form-item>-->
        <a-form-item label="开始使用时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="" v-decorator="['startTime']" :trigger-change="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" disabled/>
        </a-form-item>
        <a-form-item label="截止使用时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="" v-decorator="['endTime']" :trigger-change="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" disabled/>
        </a-form-item>
        <a-form-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['phone']" placeholder="" disabled></a-input>
        </a-form-item>
        <a-form-item label="用电量(kW-h)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['consumption']" placeholder="" style="width: 100%" disabled/>
        </a-form-item>
        <a-form-item label="开始使用表读数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['startPower']" placeholder="" style="width: 100%" disabled/>
        </a-form-item>
        <a-form-item label="结束使用表读数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['endPower']" placeholder="" style="width: 100%" disabled/>
        </a-form-item>
        <a-form-item label="实际开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="" v-decorator="['realStartTime']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" disabled/>
        </a-form-item>
        <a-form-item label="实际结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="" v-decorator="['realEndTime']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" disabled/>
        </a-form-item>
<!--        <a-form-item label="充电孔" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--          <a-input v-decorator="['jackId']" placeholder=""></a-input>-->
<!--        </a-form-item>-->
        <a-form-item label="用电船舶名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shipNameCn']" placeholder="" disabled></a-input>
        </a-form-item>
<!--        <a-form-item label="状态，对于非智能设备，需要码头人员确认用电订单。0-未确认；1-已确认；" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['status']" placeholder="请输入状态，对于非智能设备，需要码头人员确认用电订单。0-未确认；1-已确认；"></a-input>
        </a-form-item>
        <a-form-item label="确认者id（对于非智能设备的用电订单，码头人员进行确认）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['confirmUserId']" placeholder="请输入确认者id（对于非智能设备的用电订单，码头人员进行确认）" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="确认时间（对于非智能设备的用电订单，码头人员进行确认）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择确认时间（对于非智能设备的用电订单，码头人员进行确认）" v-decorator="['confirmTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>-->
        <a-form-item label="停靠时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="" v-decorator="['residenceTime']" :trigger-change="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" disabled/>
        </a-form-item>
        <a-form-item label="离开时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="" v-decorator="['leaveTime']" :trigger-change="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" disabled/>
        </a-form-item>
        <a-form-item label="是否充电" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['isRecharge_dictText']" placeholder="" disabled></a-input>
        </a-form-item>

      </a-form>
    </a-spin>
<!--    <a-button type="primary" @click="handleOk">确定</a-button>-->
    <a-button type="primary" @click="handleCancel">关闭</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'

  export default {
    name: "AdChargingRecordModal",
    components: {
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ad/adChargingRecord/add",
          edit: "/ad/adChargingRecord/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'comNo_dictText','shipId','gemoId_dictText','adDeviceId','startTime','endTime','phone','createTime','consumption','updateTime','startPower','endPower','realStartTime','realEndTime','jackId','shipNameCn','status','confirmUserId','confirmTime','residenceTime','leaveTime','isRecharge_dictText'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        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{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'comNo','shipId','gemoId','adDeviceId','startTime','endTime','phone','createTime','consumption','updateTime','startPower','endPower','realStartTime','realEndTime','jackId','shipNameCn','status','confirmUserId','confirmTime','residenceTime','leaveTime','isRecharge'))
      }

    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }

  /deep/ .ant-input-disabled, .ant-input-number{
    color: rgb(27, 28, 29);
  }
</style>