/* eslint-disable */
<template>
  <el-form
    ref="MedicalManagerDataForm"
    v-loading="loading"
    :model="form"
    size="small"
    :rules="rules"
    label-width="140px"
  >
    <div class="base-dialog-body">
      <!-- 医学经理 -->
      <el-form-item :label="$t('trials:pmMedicalReview:allocation:MIM')" prop="MedicalManagerUserId">
        <el-select v-model="form.MedicalManagerUserId" clearable>
          <el-option v-for="item of doctorUserList" :label="`${item.UserName}(${item.FullName})`" :value="item.UserId" :key="item.UserId" />
        </el-select>
      </el-form-item>
    </div>
    <div class="base-dialog-footer" style="text-align:right;margin-top:10px;">
      <el-form-item>
        <!-- 取消 -->
        <el-button
          :disabled="btnLoading"
          size="small"
          type="primary"
          @click="close"
        >
          {{ $t('common:button:cancel') }}
        </el-button>
        <!-- 保存 -->
        <el-button size="small" type="primary" :loading="btnLoading" @click="save">
          {{ $t('common:button:save') }}
        </el-button>
      </el-form-item>
    </div>
  </el-form>
</template>
<script>
import { manuallyGeneratedAndAssignedMedicalReview } from '@/api/trials/reading'

export default {
  name: 'AddOrUpdateTaskAllocationRuleData',
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    },
    doctorUserList: {
      type: Array,
      default() {
        return []
      }
    },
    selectList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      form: {
        MedicalManagerUserId: null,
        TaskOptType: 1
      },
      rules: {
        MedicalManagerUserId: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }],
      },
      loading: false,
      btnLoading: false
    }
  },
  mounted() {
    this.form.TrialId = this.$route.query.trialId
    if (this.data.Id) {
      this.form.TaskIdList = [this.data.Id]
      this.form.TaskOptType = 2
      this.form.MedicalManagerUserId = this.data.MedicalManagerUserId
    } else {
      this.form.TaskIdList = Object.assign([], this.selectList.map(v => v.Id))
    }
  },
  methods: {
    save() {
      this.$refs.MedicalManagerDataForm.validate(valid => {
        console.log(valid)
        if (!valid) return
        this.btnLoading = true
        this.loading = true
        manuallyGeneratedAndAssignedMedicalReview(this.form).then(res => {
          this.loading = false
          this.btnLoading = false
          // '保存成功'
          this.$message.success(this.$t('common:message:savedSuccessfully'))
          this.$emit('getList')
        }).catch(() => {
          this.loading = false
          this.btnLoading = false
        })
      })
    },
    close() { this.$emit('close') }
  }
}
</script>
<style lang="scss" scoped>
</style>
