<template>
  <div class="booking-page">
    <div class="booking-shell">
      <div class="booking-header">
        <div class="title-main">新建预约</div>
        <div class="title-sub">保持和手机端一致的预约信息</div>
      </div>

      <el-card
        class="booking-card"
        :body-style="{ padding: '18px 22px 16px' }"
        shadow="hover"
      >
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          label-width="110px"
          size="small"
          class="booking-form"
        >
          <el-form-item label="预约体验项目" prop="yytyxm">
            <el-select
              v-model="form.yytyxm"
              placeholder="请选择体验项目"
              filterable
              clearable
            >
              <el-option
                v-for="item in projectOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="顾客姓名" prop="gkxm">
            <el-select
              v-model="form.gkxm"
              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="预约健康师" prop="yyjks">
            <el-select
              v-model="form.yyjks"
              placeholder="请选择健康师"
              filterable
              clearable
            >
              <el-option
                v-for="item in healthWorkerOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="预约日期" prop="yyrq">
            <el-date-picker
              v-model="form.yyrq"
              type="date"
              placeholder="请选择预约日期"
              style="width: 100%"
            />
          </el-form-item>

          <el-form-item label="预约时间" prop="yysj">
            <el-time-select
              v-model="form.yysj"
              :picker-options="timeOptions"
              placeholder="请选择预约时间"
              style="width: 100%"
            />
          </el-form-item>
        </el-form>

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

<script>
export default {
  name: 'BookingCreate',
  data() {
    return {
      submitting: false,
      form: {
        yytyxm: '',
        gkxm: '',
        yyjks: '',
        yyrq: '',
        yysj: ''
      },
      projectOptions: [
        { value: 'proj001', label: '基础护理' },
        { value: 'proj002', label: '深度清洁' },
        { value: 'proj003', label: '美白护理' },
        { value: 'proj004', label: '抗衰护理' },
        { value: 'proj005', label: '补水保湿' }
      ],
      customerOptions: [
        { value: 'cust001', label: '张三' },
        { value: 'cust002', label: '李四' },
        { value: 'cust003', label: '王五' },
        { value: 'cust004', label: '赵六' },
        { value: 'cust005', label: '钱七' }
      ],
      healthWorkerOptions: [
        { value: 'jks001', label: '张健康师' },
        { value: 'jks002', label: '李健康师' },
        { value: 'jks003', label: '王健康师' },
        { value: 'jks004', label: '赵健康师' },
        { value: 'jks005', label: '钱健康师' }
      ],
      timeOptions: {
        start: '09:00',
        step: '00:30',
        end: '21:00'
      },
      rules: {
        yytyxm: [{ required: true, message: '请选择体验项目', trigger: 'change' }],
        gkxm: [{ required: true, message: '请选择顾客姓名', trigger: 'change' }],
        yyjks: [{ required: true, message: '请选择健康师', trigger: 'change' }],
        yyrq: [{ required: true, message: '请选择预约日期', trigger: 'change' }],
        yysj: [{ required: true, message: '请选择预约时间', trigger: 'change' }]
      }
    }
  },
  created() {
    this.prefillFromQuery()
  },
  methods: {
    prefillFromQuery() {
      const { name } = this.$route.query || {}
      if (name) {
        this.form.gkxm = name
      }
      // 默认日期 = 今天
      const today = new Date()
      this.form.yyrq = today
    },
    handleCancel() {
      this.$router.push('/dashboard')
    },
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (!valid) return
        this.submitting = true
        setTimeout(() => {
          this.submitting = false
          this.$message.success('预约已保存（示例）')
          this.$router.push('/dashboard')
        }, 800)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.booking-page {
  min-height: 100%;
  padding: 20px 24px;
  background: radial-gradient(
    circle at 10% 20%,
    #eef2ff 0,
    #eef2ff 26%,
    #fdf2ff 60%,
    #fff7ed 100%
  );
  box-sizing: border-box;
  display: flex;
  justify-content: center;
}

.booking-shell {
  width: 720px;
  max-width: 100%;
}

.booking-header {
  margin-bottom: 16px;
  padding: 6px 12px;
  border-radius: 14px;
  background: rgba(239, 246, 255, 0.9);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.title-sub {
  font-size: 12px;
  color: #6b7280;
}

.booking-card {
  border-radius: 20px;
  border: none;
  box-shadow:
    0 24px 48px rgba(15, 23, 42, 0.18),
    0 0 0 1px rgba(255, 255, 255, 0.9);
  background: radial-gradient(
    circle at 0 0,
    rgba(255, 255, 255, 0.97) 0,
    rgba(248, 250, 252, 0.99) 40%,
    rgba(241, 245, 249, 0.99) 100%
  );
}

.booking-form {
  padding-top: 4px;
}

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

::v-deep .el-input__inner {
  border-radius: 999px;
  height: 32px;
  line-height: 32px;
  border-color: #e5e7eb;
  background-color: #f9fafb;
}

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

::v-deep .el-picker-panel {
  border-radius: 12px;
}

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

