<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="followupVisible"
      @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="toFollowReason"
        >
          <el-col :span="15">
            <el-input
              v-model="model.toFollowReason"
              type="textarea"
              style="width: 130%;"
              size="small"
              minlength="2"
              maxlength="500"
              placeholder="请输入原因"
            />
          </el-col>
        </el-form-item>
      </el-form>
      <span
        slot="footer"
        class="dialog-footer"
        style="text-align: center;"
      >
        <el-button @click="cancel">取 消</el-button>
        <el-button
          type="primary"
          @click="confirm"
        >确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {updateDiagnosis} from '../../utils/diagnosis';
  let vm = null;
  export default {
    props: {
      followupVisible: {
        type: Boolean,
        default: false
      },
      diagnoseLogId: {
        type: Number,
        default: 0
      },
      toFollowReason:{
        type: String,
        default:''
      },
    },
    data() {
      return {
        show: false,
        title: '设为稍后跟进',
        confirmTxt: '确定',
        cancleTxt: '',
        _promise: null,
        model:{
          toFollowReason:''
        },
        addRules:{
          toFollowReason: [
            {required: true, message: '请输入稍后跟进原因', trigger: 'blur'}
          ]
        }
      };
    },
    watch:{
      toFollowReason(newdata, olddata) {
        this.model.toFollowReason = newdata;
      }

    },
    created() {
      vm = this;

    },
    mounted() {

    },
    methods: {

      confirm() {
        this.$refs.setForm.validate((valid) => {
          if (valid) {
            const req = {
              id:this.diagnoseLogId,
              bizType:4,
              toFollowReason:this.model.toFollowReason
            };
            updateDiagnosis(req).then(function (res) {
              if(res.code == '000000') {
                vm.cancel();
                vm.$emit('search');
              } else {
                vm.$message.error(res.message);
              }
            }).catch(function (error) {
              vm.$message.error(res.message);
            });
          }
        });

      },
      cancel() {
        this.model.toFollowReason = '';
        this.$emit('update:followupVisible', false);
      }
    }
  };
</script>

<style lang="scss" scoped>

</style>
