<template>
  <el-dialog
    :visible.sync="visibleProxy"
    :show-close="false"
    width="520px"
    :close-on-click-modal="false"
    custom-class="tuoke-dialog"
    append-to-body
  >
    <div class="tuoke-dialog-inner">
      <div class="tuoke-header">
        <div class="tuoke-title-wrap">
          <div class="tuoke-title">录入拓客信息</div>
        </div>
      </div>

      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="96px"
        size="small"
        class="tuoke-form"
      >
        <el-form-item label="拓客活动" prop="eventId">
          <el-select v-model="form.eventId" placeholder="请选择拓客活动" filterable>
            <el-option
              v-for="item in eventOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="顾客姓名" prop="customerName">
          <el-input v-model="form.customerName" placeholder="请输入顾客姓名" />
        </el-form-item>

        <el-form-item label="电话号码" prop="customerPhone">
          <el-input v-model="form.customerPhone" placeholder="请输入电话号码" />
        </el-form-item>

        <el-form-item label="支付方式" prop="paymentMethod">
          <el-select v-model="form.paymentMethod" placeholder="请选择支付方式">
            <el-option
              v-for="item in paymentOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="是否加微信" prop="isAddWeChat">
          <el-radio-group v-model="form.isAddWeChat">
            <el-radio label="是">是</el-radio>
            <el-radio label="否">否</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="备注" prop="remarks">
          <el-input
            v-model="form.remarks"
            type="textarea"
            :rows="3"
            placeholder="请输入备注信息"
          />
        </el-form-item>
      </el-form>

      <div class="tuoke-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: 'TuokeLeadDialog',
  props: {
    visible: { type: Boolean, default: false }
  },
  data() {
    return {
      submitting: false,
      form: {
        eventId: '',
        customerName: '',
        customerPhone: '',
        paymentMethod: '微信',
        isAddWeChat: '否',
        remarks: ''
      },
      eventOptions: [
        { label: '社区拓客活动', value: '1' },
        { label: '商场联营活动', value: '2' },
        { label: '老客转介绍', value: '3' }
      ],
      paymentOptions: [
        { label: '微信', value: '微信' },
        { label: '支付宝', value: '支付宝' },
        { label: '现金', value: '现金' },
        { label: '银行转账', value: '银行转账' }
      ],
      rules: {
        eventId: [{ required: true, message: '请选择拓客活动', trigger: 'change' }],
        customerName: [{ required: true, message: '请输入顾客姓名', trigger: 'blur' }],
        customerPhone: [
          { required: true, message: '请输入电话号码', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
        ],
        paymentMethod: [{ required: true, message: '请选择支付方式', trigger: 'change' }],
        isAddWeChat: [{ required: true, message: '请选择是否加微信', trigger: 'change' }]
      }
    }
  },
  computed: {
    visibleProxy: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  methods: {
    resetForm() {
      this.form = {
        eventId: '',
        customerName: '',
        customerPhone: '',
        paymentMethod: '微信',
        isAddWeChat: '否',
        remarks: ''
      }
      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>
.tuoke-dialog-inner {
  padding: 18px 22px 14px;
}

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

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

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

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

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

::v-deep .tuoke-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 .tuoke-dialog .el-input__inner {
  border-radius: 999px;
  height: 32px;
  line-height: 32px;
  border-color: #e5e7eb;
  background-color: #f9fafb;
}

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

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

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

/* 统一按钮风格：胶囊 + 蓝色主按钮，与会员弹窗一致 */
::v-deep .tuoke-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 .tuoke-dialog .el-button--primary.is-disabled {
  box-shadow: none;
}

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

