<template>
  <el-dialog
    :visible.sync="visibleProxy"
    :show-close="false"
    width="520px"
    :close-on-click-modal="false"
    custom-class="invite-dialog"
    append-to-body
  >
    <div class="invite-dialog-inner">
      <div class="invite-header">
        <div class="invite-title-wrap">
          <div class="invite-title">新增邀约记录</div>
        </div>
      </div>

      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="96px"
        size="small"
        class="invite-form"
      >
        <el-form-item label="邀约时间" prop="yysj">
          <el-date-picker
            v-model="form.yysj"
            type="datetime"
            placeholder="请选择邀约时间"
            style="width: 100%"
          />
        </el-form-item>

        <el-form-item label="预约客户" prop="yykh">
          <el-select
            v-model="form.yykh"
            placeholder="请选择预约客户"
            filterable
            clearable
          >
            <el-option
              v-for="item in customerOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="联系电话">
          <el-input
            v-model="form.dh"
            placeholder="电话号码"
            disabled
          />
        </el-form-item>

        <el-form-item label="电话是否有效" prop="dhsfyx">
          <el-radio-group v-model="form.dhsfyx">
            <el-radio label="是">是</el-radio>
            <el-radio label="否">否</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="联系记录" prop="lxjl">
          <el-input
            v-model="form.lxjl"
            type="textarea"
            :rows="3"
            placeholder="请输入联系记录"
          />
        </el-form-item>
      </el-form>

      <div class="invite-footer">
        <el-button size="small" @click="handleCancel">取 消</el-button>
        <el-button
          type="primary"
          size="small"
          :loading="submitting"
          @click="handleSubmit"
        >
          {{ submitting ? '提交中...' : '保 存' }}
        </el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'InviteAddDialog',
  props: {
    visible: { type: Boolean, default: false }
  },
  data() {
    return {
      submitting: false,
      form: {
        yysj: '',
        yykh: '',
        dh: '',
        dhsfyx: '',
        lxjl: ''
      },
      customerOptions: [
        { label: '张三', value: 'GK2020082101170', phone: '13800000001' },
        { label: '李四', value: 'GK2020082101171', phone: '13800000002' },
        { label: '王五', value: 'GK2020082101172', phone: '13800000003' }
      ],
      rules: {
        yysj: [{ required: true, message: '请选择邀约时间', trigger: 'change' }],
        yykh: [{ required: true, message: '请选择预约客户', trigger: 'change' }],
        dhsfyx: [{ required: true, message: '请选择电话是否有效', trigger: 'change' }],
        lxjl: [
          { required: true, message: '请输入联系记录', trigger: 'blur' },
          { min: 2, message: '联系记录至少 2 个字', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    visibleProxy: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  watch: {
    'form.yykh'(val) {
      const target = this.customerOptions.find(item => item.value === val)
      this.form.dh = target ? target.phone : ''
    }
  },
  methods: {
    resetForm() {
      this.form = {
        yysj: '',
        yykh: '',
        dh: '',
        dhsfyx: '',
        lxjl: ''
      }
      this.$refs.form && this.$refs.form.clearValidate()
    },
    handleCancel() {
      this.visibleProxy = false
      this.resetForm()
    },
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (!valid) return
        this.submitting = true
        setTimeout(() => {
          this.submitting = false
          this.$message.success('邀约记录已保存（示例）')
          this.visibleProxy = false
          this.resetForm()
        }, 800)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.invite-dialog-inner {
  padding: 18px 22px 14px;
}

.invite-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(219, 234, 254, 0.96);
}

.invite-title-wrap {
  flex: 1;
}

.invite-title {
  font-size: 17px;
  font-weight: 600;
  color: #0f172a;
}

.invite-form {
  padding-top: 6px;
}

::v-deep .invite-dialog .el-form-item__label {
  white-space: nowrap;
}

.invite-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

::v-deep .invite-dialog {
  max-width: 520px;
  margin-top: 10vh !important;
  border-radius: 20px;
  padding: 0;
  background: radial-gradient(
    circle at 0 0,
    rgba(255, 255, 255, 0.96) 0,
    rgba(248, 250, 252, 0.98) 40%,
    rgba(241, 245, 249, 0.98) 100%
  );
  box-shadow:
    0 24px 48px rgba(15, 23, 42, 0.18),
    0 0 0 1px rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

::v-deep .el-dialog__header {
  display: none;
}

::v-deep .el-dialog__body {
  padding: 0;
}

/* 输入框圆角与现代化样式 */
::v-deep .invite-dialog .el-input__inner {
  border-radius: 999px;
  height: 32px;
  line-height: 32px;
  border-color: #e5e7eb;
  background-color: #f9fafb;
}

::v-deep .invite-dialog .el-input__inner:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.18);
}

::v-deep .invite-dialog .el-textarea__inner {
  border-radius: 12px;
  border-color: #e5e7eb;
  background-color: #f9fafb;
}

::v-deep .invite-dialog .el-textarea__inner:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.18);
}

/* 统一按钮风格：胶囊 + 蓝色主按钮，与其他弹窗一致 */
::v-deep .invite-dialog .el-button--primary {
  border-radius: 999px;
  padding: 0 20px;
  height: 30px;
  line-height: 30px;
  background: #2563eb;
  border-color: #2563eb;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
  font-size: 12px;
}

::v-deep .invite-dialog .el-button--primary.is-disabled {
  box-shadow: none;
}

::v-deep .invite-dialog .el-button--default {
  border-radius: 999px;
  padding: 0 18px;
  height: 30px;
  line-height: 30px;
  background: rgba(239, 246, 255, 0.9);
  color: #2563eb;
  border-color: rgba(37, 99, 235, 0.18);
  font-size: 12px;
}

::v-deep .invite-dialog .el-button--default:hover {
  background: rgba(219, 234, 254, 0.95);
  color: #1d4ed8;
}
</style>

