<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="diagnosisTimeVisible"
      @close="cancel"
    >
      <!--            <el-row :gutter="30" class="row search" type="flex" style="margin-bottom:0;">-->
      <el-form
        ref="setForm"
        :rules="addRules"
        :model="model"
        label-width="250px"
        label-suffix=":"
        label-position="right"
        size="mini"
        style="width: 100%;"
      >
        <el-form-item
          label="助诊意向时间"
          class="required-label"
          prop="rangeTime"
        >
          <el-col :span="15">
            <el-date-picker
              v-model="rangeTime"
              type="datetimerange"
              value-format="yyyy-MM-dd HH:mm:ss"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions1"
              style="width: 135%;"
            />
          </el-col>
        </el-form-item>

        <el-form-item label="备注">
          <el-col :span="15">
            <el-input
              v-model="model.assistantRemark"
              type="textarea"
              style="width: 135%;"
              size="small"
              minlength="2"
              maxlength="500"
              placeholder="请输入备注"
            />
          </el-col>
        </el-form-item>
      </el-form>
      <!--            </el-row>-->
      <span
        slot="footer"
        class="dialog-footer"
        style="text-align: center;"
      >
        <el-button @click="cancel">取 消</el-button>
        <el-button
          type="primary"
          :disabled-="isClick"
          @click="confirm"
        >确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {updateDiagnosis} from '../../utils/diagnosis';
  let vm = null;
  export default {
    props: {
      diagnosisTimeVisible: {
        type: Boolean,
        default: false
      },
      diagnoseLogId: {
        type: Number,
        default: 0
      },
      bizType: {
        type: Number,
        default: 0
      },
    },
    data() {
      // let checkDate = (rule, value, callback) => {
      //   if(!value) {
      //     callback(new Error("请选择助诊意向时间"));
      //   } else {
      //     callback();
      //   }
      // }
      return {
        show: false,
        title: '设置时间',
        confirmTxt: '确定',
        cancleTxt: '',
        _promise: null,
        isClick: false,
        model: {
          assistantRemark: ''
        },
        rangeTime: '',
        addRules: {
          rangeTime: [
            // {type: 'array',required: true, validator: checkDate, trigger: 'blur,change'}
            {
              type: 'array',
              required: true,
              // message: "预约时间不能为空",
              // validator: checkDate,
              trigger: 'change',
              fields: {
                0: {required: true, type: 'date', message: '开始时间不能为空'},
                1: {required: true, type: 'date', message: '结束时间不能为空'}
              }
            }
          ]
        },
        pickerOptions1: {
          disabledDate: time => {
            return (
              time.getTime() < Date.now() - 1 * 24 * 3600 * 1000
            ); // 减去一天的时间代表可以选择同一天;
          }
        },
      };
    },
    created() {
      vm = this;
    },
    methods: {
      confirm() {
        // this.$refs.setForm.validate((valid) => {
        //   if (valid) {
        if(!(this.rangeTime != null && this.rangeTime.length > 0)) {
          vm.$message.warning('请选择助诊意向时间');
          return;
        }
        vm.isClick = true;
        const req = {
          id:this.diagnoseLogId,
          bizType:this.bizType,
          assistantBeginTime:this.rangeTime[0],
          assistantEndTime:this.rangeTime[1],
          assistantRemark:this.model.assistantRemark
        };
        updateDiagnosis(req).then(function (res) {
          vm.isClick = false;
          if(res.code == '000000') {
            vm.cancel();
            vm.$emit('search');
          } else {
            vm.$message.error(res.message);
          }
        }).catch(function (error) {
          vm.isClick = false;
          vm.$message.error(res.message);
        });
      //   }
      // })
      },
      cancel() {
        this.rangeTime = '';
        this.model.assistantRemark = '';
        this.$emit('update:diagnosisTimeVisible', false);
      }
    }
  };
</script>

<style lang="scss" scoped>

</style>
