<template>
  <div class="finish-followup" v-if="showThisPage">
    <el-dialog
      :title="finishData.title"
      :visible.sync="showFinishFollowup"
      v-if="showThisPage"
      :before-close="clickClose"
      width="30%"
      center>
      <div class="finish-content">
        <el-form
          :model="finishData"
          :rules="rules"
          label-width="100px" ref="finishData">
          <el-form-item label="居民：">
            {{finishData.patientName}}
          </el-form-item>
          <el-form-item :label="finishData.reasonName" prop="finishReason">
            <el-input
              type="textarea"
              v-model="finishData.finishReason"
              placeholder="请输入原因"
              maxlength="30"
              rows="3"
              resize="none"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="button-white" @click="clickClose" size="small" plain>取 消</el-button>
        <el-button class="button-green" @click="finishFollowUp" size="small" type="primary">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import { mapActions } from 'vuex';
  import { finishPlan } from '../../../../utils/followup/followapis'
  export default {
    name: "finish-followup",
    props: {
      showThisPage: { //是否显示model
        type: Boolean,
        default: function () {
          return false;
        }
      },
      finishData: {
        type: Object,
        default: function () {
          return {};
        }
      }
    },
    data() {
      return {
        showFinishFollowup: true,
        rules: {
          finishReason: [
            { required: true, message: '请输入原因', trigger: 'blur' },
            { min: 1, max: 30, message: '长度在30个字符内', trigger: 'blur' }
          ],
        },
      }
    },
    methods: {
      ...mapActions('planManage', ['getResidentList','getResidentDetail']),
      clickClose() {
        this.$emit('closeFinishFollowup',false)
      },
      finishFollowUp() {
        this.$refs['finishData'].validate(valid => {
          if (valid) {
            const { changeCode, planId, patientIdList, planPatientsIdList } = this.finishData;
            finishPlan({
              changeCode,
              planId,
              patientIdList,
              planPatientsIdList
            }).then((data) => {
              if(data.code == '000000') {
                this.$message({
                  message: '操作成功！',
                  type: 'success'
                });
                if(this.$route.name == 'residentList') {
                  this.getResidentList({
                    planId,
                    status: changeCode
                  })
                } else if(this.$route.name == 'residentDetail') {
                  this.getResidentDetail({
                    planId,
                    patientId: patientIdList[0],
                    fuPlanPatientId: planPatientsIdList[0]
                  })
                }

                this.clickClose()
              } else {
                this.$message({
                  message: `${data.message}`,
                  type: 'error'
                });
              }
            }).catch((err) => {
              this.$message({
                message: `${err.message}`,
                type: 'error'
              });
            });
          } else {
            return false;
          }
        });
      }
    }
  }
</script>
<style scoped>
  .el-input__inner:disabled {
    background-color: #ffffff!important;
  }
</style>
<style lang="scss" scoped>
  @import '../../../../style/followup/followup-common';
  @import '../../../../style/followup/element-reset.css';

</style>
