<template>
  <view class="form-section">
    <view class="section-title">客户信息</view>
    
    <!-- 客户类型 -->
    <view class="form-item clickable-item" @click="$emit('open-picker', 'customerType')">
      <text v-if="formData.customerType" class="form-value">{{ getCustomerTypeText(formData.customerType) }}</text>
      <text v-else class="form-placeholder">选择客户类型</text>
      <text class="arrow">›</text>
    </view>

    <!-- 客户名称 -->
    <view class="form-item">
      <input 
        :value="formData.name" 
        @input="updateField('name', $event.detail.value)"
        class="form-input" 
        placeholder="输入客户名称" 
        placeholder-style="color: #999;"
      />
    </view>

    <!-- 联系电话 -->
    <view class="form-item">
      <input 
        :value="formData.mobile" 
        @input="updateField('mobile', $event.detail.value)"
        class="form-input" 
        placeholder="输入电话号码" 
        placeholder-style="color: #999;"
        type="number"
      />
    </view>

    <!-- 微信号 -->
    <view class="form-item">
      <input 
        :value="formData.wechat" 
        @input="updateField('wechat', $event.detail.value)"
        class="form-input" 
        placeholder="输入微信号" 
        placeholder-style="color: #999;"
      />
    </view>

    <!-- 客户来源 -->
    <view class="form-item clickable-item" @click="$emit('open-picker', 'source')">
      <text v-if="formData.source" class="form-value">{{ formData.source }}</text>
      <text v-else class="form-placeholder">选择客户来源</text>
      <text class="arrow">›</text>
    </view>

    <!-- 客户意向 -->
    <view class="form-item clickable-item" @click="$emit('open-picker', 'intent')">
      <text v-if="formData.intents && formData.intents.length > 0" class="form-value">{{ formData.intents.join('、') }}</text>
      <text v-else class="form-placeholder">选择客户意向（可多选）</text>
      <text class="arrow">›</text>
    </view>

    <!-- 意向强度 -->
    <view class="form-item clickable-item" @click="$emit('open-picker', 'intentLevel')">
      <text v-if="formData.intentLevel" class="form-value">{{ getIntentLevelText(formData.intentLevel) }}</text>
      <text v-else class="form-placeholder">选择意向强度</text>
      <text class="arrow">›</text>
    </view>

    <!-- 客户状态 -->
    <view class="form-item clickable-item" @click="$emit('open-picker', 'customerStatus')">
      <text v-if="formData.customerStatus" class="form-value">{{ getCustomerStatusText(formData.customerStatus) }}</text>
      <text v-else class="form-placeholder">选择客户状态</text>
      <text class="arrow">›</text>
    </view>

    <!-- 客户地区 -->
    <view class="form-item clickable-item" @click="$emit('open-picker', 'region')">
      <text v-if="formData.region" class="form-value">{{ formData.region }}</text>
      <text v-else class="form-placeholder">选择客户地区</text>
      <text class="arrow">›</text>
    </view>

    <!-- 工作微信 -->
    <view class="form-item clickable-item" @click="$emit('open-picker', 'workWechat')">
      <text v-if="formData.workWechat" class="form-value">{{ formData.workWechat }}</text>
      <text v-else class="form-placeholder">选择工作微信</text>
      <text class="arrow">›</text>
    </view>
  </view>
</template>

<script setup>
import { computed } from 'vue';

const props = defineProps({
  formData: {
    type: Object,
    required: true
  },
  customerTypeOptions: {
    type: Array,
    default: () => []
  },
  intentLevelOptions: {
    type: Array,
    default: () => []
  },
  customerStatusOptions: {
    type: Array,
    default: () => []
  }
});

const emit = defineEmits(['update:formData', 'open-picker']);

const updateField = (field, value) => {
  emit('update:formData', {
    ...props.formData,
    [field]: value
  });
};

const getCustomerTypeText = (value) => {
  const option = props.customerTypeOptions.find(opt => opt.value === value);
  return option ? option.label : '';
};

const getIntentLevelText = (value) => {
  const option = props.intentLevelOptions.find(opt => opt.value === value);
  return option ? option.label : '';
};

const getCustomerStatusText = (value) => {
  const option = props.customerStatusOptions.find(opt => opt.value === value);
  return option ? option.label : '';
};
</script>

<style lang="scss" scoped>
.form-section {
  background-color: #fff;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #eee;
}

.form-item {
  margin-bottom: 16px;
  
  &:last-child {
    margin-bottom: 0;
  }
}

.form-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  font-size: 15px;
  color: #333;
  background-color: #f8f8f8;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
}

.clickable-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 12px;
  background-color: #f8f8f8;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.form-value {
  font-size: 15px;
  color: #333;
}

.form-placeholder {
  font-size: 15px;
  color: #999;
}

.arrow {
  font-size: 20px;
  color: #999;
}
</style>

