index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <template>
  2. <div class="page-container">
  3. <div class="create-layout">
  4. <!-- 左侧:下单填写区 -->
  5. <div class="form-container">
  6. <!-- 1. 服务类型选择 -->
  7. <div class="type-selection">
  8. <div
  9. v-for="item in serviceList"
  10. :key="item.type"
  11. class="type-card"
  12. :class="[item.type, { active: form.type === item.type }]"
  13. @click="handleTypeChange(item.type)"
  14. >
  15. <div class="icon-box"><el-icon><component :is="item.icon" /></el-icon></div>
  16. <div class="text">
  17. <div class="type-name">{{ item.name }}</div>
  18. <div class="type-desc">{{ item.desc }}</div>
  19. </div>
  20. </div>
  21. </div>
  22. <!-- 2. 基础信息:门店与宠主 -->
  23. <el-card shadow="never" class="section-card">
  24. <template #header>
  25. <div class="card-title">
  26. <span class="step-num">02</span> 基础信息
  27. </div>
  28. </template>
  29. <div class="card-body">
  30. <el-form label-position="top" class="base-form">
  31. <el-row :gutter="20">
  32. <el-col :span="12">
  33. <el-form-item>
  34. <template #label>
  35. <div style="display:flex; align-items:center; height: 24px;">
  36. <span>服务门店 (平台代下单)</span>
  37. </div>
  38. </template>
  39. <el-select v-model="form.merchantId" placeholder="请选择商户门店" size="large" style="width: 100%" filterable>
  40. <el-option v-for="m in merchants" :key="m.id" :label="m.name" :value="m.id" />
  41. </el-select>
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="12">
  45. <el-form-item>
  46. <template #label>
  47. <div style="display:flex; justify-content:space-between; align-items:center; width:100%; height: 24px;">
  48. <span>宠主用户</span>
  49. <el-button type="primary" plain size="small" @click="openAddUser" icon="Plus" style="margin-left: 15px;">添加用户</el-button>
  50. </div>
  51. </template>
  52. <el-select
  53. v-model="form.userId"
  54. placeholder="搜索手机号/姓名"
  55. size="large"
  56. style="width: 100%"
  57. filterable
  58. remote
  59. :remote-method="searchUser"
  60. :loading="userLoading"
  61. @change="handleUserChange"
  62. >
  63. <el-option v-for="u in userOptions" :key="u.id" :label="u.name + ' - ' + u.phone" :value="u.id" />
  64. </el-select>
  65. </el-form-item>
  66. </el-col>
  67. </el-row>
  68. <el-form-item label="选择宠物" v-if="form.userId">
  69. <div class="pet-select-row">
  70. <div
  71. v-for="p in currentPets"
  72. :key="p.id"
  73. class="pet-card"
  74. :class="{ active: form.petId === p.id }"
  75. @click="form.petId = p.id"
  76. >
  77. <el-avatar :size="48" :src="p.avatar" shape="square" style="border-radius: 6px;">{{ p.name.charAt(0) }}</el-avatar>
  78. <div class="pet-info">
  79. <div class="name">{{ p.name }}</div>
  80. <div class="sub">{{ p.breed }}</div>
  81. </div>
  82. <div class="check-mark" v-if="form.petId === p.id"><el-icon><Check /></el-icon></div>
  83. </div>
  84. <!-- Add Button Card (Last Item in Grid) -->
  85. <div class="pet-card add-card" @click="openAddPet">
  86. <el-icon :size="24"><Plus /></el-icon>
  87. <span style="font-size: 15px; font-weight: bold;">新增宠物</span>
  88. </div>
  89. </div>
  90. </el-form-item>
  91. </el-form>
  92. </div>
  93. </el-card>
  94. <!-- 3. 业务详情表单 -->
  95. <el-card shadow="never" class="section-card form-card" v-if="form.type">
  96. <template #header>
  97. <div class="card-title">
  98. <span class="step-num">03</span>
  99. {{ getStepTitle(form.type) }}
  100. </div>
  101. </template>
  102. <div class="card-body">
  103. <!-- 服务套餐信息 -->
  104. <el-form-item label="团购套餐">
  105. <el-input v-model="form.groupBuyPackage" placeholder="请输入团购套餐名称 (选填)" clearable />
  106. </el-form-item>
  107. <div class="divider"></div>
  108. <!-- A. 宠物接送表单 -->
  109. <TransportForm v-show="form.type === 'transport'" :transport-data="form.transport" :pca-options="pcaOptions" @change="calcPrice" />
  110. <!-- B. 上门喂遛表单 -->
  111. <FeedingForm v-show="form.type === 'feeding'" :feeding-data="form.feeding" :pca-options="pcaOptions" @change="calcPrice" />
  112. <!-- C. 上门洗护表单 -->
  113. <WashingForm v-show="form.type === 'washing'" :washing-data="form.washing" :pca-options="pcaOptions" @change="calcPrice" />
  114. </div>
  115. </el-card>
  116. </div>
  117. <!-- 右侧:收银台概览 -->
  118. <div class="summary-sidebar">
  119. <div class="summary-panel">
  120. <div class="summary-header">订单概览</div>
  121. <div class="summary-content">
  122. <div class="row" v-if="selectedMerchantName">
  123. <span class="label">服务门店</span>
  124. <span class="value">{{ selectedMerchantName }}</span>
  125. </div>
  126. <div class="row" v-if="selectedUserName">
  127. <span class="label">客户</span>
  128. <span class="value">{{ selectedUserName }}</span>
  129. </div>
  130. <div class="row" v-if="selectedPetName">
  131. <span class="label">服务对象</span>
  132. <span class="value action-text">{{ selectedPetName }} ({{ selectedPetBreed }})</span>
  133. </div>
  134. <div class="divider"></div>
  135. <div class="service-preview" v-if="form.type">
  136. <div class="preview-title">{{ getTypeName(form.type) }}</div>
  137. <!-- 套餐显示 -->
  138. <div class="preview-detail" v-if="selectedPkgName">
  139. <div style="font-weight:bold; color:#409eff">{{ selectedPkgName }}</div>
  140. </div>
  141. <div class="preview-detail" v-else>
  142. <div style="color:#e6a23c">非服务套餐 (单次)</div>
  143. </div>
  144. <!-- 接送预览 -->
  145. <div v-if="form.type === 'transport'" class="preview-detail">
  146. <div>{{ form.transport.subType === 'round' ? '往返接送' : (form.transport.subType === 'pick' ? '单程接' : '单程送') }}</div>
  147. <div class="minor">接: {{ form.transport.pickTime ? formatTime(form.transport.pickTime) : '未选时间' }}</div>
  148. <div class="minor" v-if="form.transport.subType !== 'pick'">送: {{ form.transport.dropTime ? formatTime(form.transport.dropTime) : '未选' }}</div>
  149. </div>
  150. </div>
  151. </div>
  152. <div class="summary-footer">
  153. <el-button type="primary" size="large" class="submit-btn" :disabled="!canSubmit" @click="handleSubmit">
  154. 立即下单
  155. </el-button>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. <!-- Dialogs -->
  161. <!-- Add User Dialog -->
  162. <AddUserDialog v-model:visible="userDialogVisible" :pca-options="pcaOptions" @success="handleUserSuccess" />
  163. <AddPetDialog v-model:visible="petDialogVisible" :user-id="form.userId" :user-options="userOptions" @success="handlePetSuccess" />
  164. </div>
  165. </template>
  166. <script setup>
  167. import { ref, reactive, computed, onMounted, watch } from 'vue'
  168. import { ElMessage } from 'element-plus'
  169. import TransportForm from './components/TransportForm.vue'
  170. import FeedingForm from './components/FeedingForm.vue'
  171. import WashingForm from './components/WashingForm.vue'
  172. import AddUserDialog from './components/AddUserDialog.vue'
  173. import AddPetDialog from './components/AddPetDialog.vue'
  174. // --- Mock Data ---
  175. const merchants = ref([
  176. { id: 1, name: '萌它宠物三里屯店' },
  177. { id: 2, name: '宠爱国际动物医院' }
  178. ])
  179. const userOptions = ref([
  180. { id: 101, name: '张三', phone: '13812345678' },
  181. { id: 102, name: '李四', phone: '13987654321' }
  182. ])
  183. const mockPets = {
  184. 101: [
  185. { id: 1, name: '旺财', breed: '金毛', avatar: '', region: ['北京市', '市辖区', '朝阳区'], address: '三里屯SOHO A座 1001' },
  186. { id: 2, name: '咪咪', breed: '布偶', avatar: '', region: ['北京市', '市辖区', '朝阳区'], address: '三里屯SOHO A座 1001' }
  187. ],
  188. 102: [
  189. { id: 3, name: '奥利奥', breed: '边牧', avatar: '', region: ['上海市', '市辖区', '浦东新区'], address: '陆家嘴一号院 5-502' }
  190. ]
  191. }
  192. const serviceList = [
  193. { type: 'transport', name: '宠物接送', icon: 'Van', desc: '专车接送 · 全程监护', basePrice: 35 },
  194. { type: 'feeding', name: '上门喂遛', icon: 'Food', desc: '喂食添水 · 陪玩遛狗', basePrice: 68 },
  195. { type: 'washing', name: '上门洗护', icon: 'Soap', desc: '专业设备 · 深度清洁', basePrice: 88 }
  196. ]
  197. const allPackages = [
  198. { id: 10, type: 'transport', name: '包月接送套餐', price: 0 },
  199. { id: 11, type: 'feeding', name: '基础喂猫套餐', price: 0 },
  200. { id: 12, type: 'feeding', name: '深度陪玩套餐', price: 0 },
  201. { id: 13, type: 'washing', name: '精致洗护+美容', price: 0 },
  202. { id: 14, type: 'washing', name: '除菌药浴套餐', price: 0 },
  203. ]
  204. // --- State ---
  205. const userLoading = ref(false)
  206. const currentPets = ref([])
  207. const form = reactive({
  208. merchantId: '',
  209. userId: '',
  210. petId: '',
  211. type: 'transport',
  212. groupBuyPackage: '',
  213. // Sub Forms Data
  214. transport: {
  215. pkgId: '',
  216. price: 0,
  217. pickPrice: 35,
  218. dropPrice: 35,
  219. subType: 'round',
  220. pickRegion: [], pickDetail: '', pickContact: '', pickPhone: '', pickTime: '',
  221. dropRegion: [], dropDetail: '', dropContact: '', dropPhone: '', dropTime: ''
  222. },
  223. feeding: {
  224. pkgId: '', price: 68,
  225. appointments: [{ startTime: '', endTime: '' }],
  226. region: [], addressDetail: '',
  227. count: 1, dates: [], area: '', itemLoc: '', cleanLoc: '', foodAmount: '', other: ''
  228. },
  229. washing: {
  230. pkgId: '', price: 88,
  231. appointments: [{ startTime: '', endTime: '' }],
  232. region: [], addressDetail: '',
  233. time: '', petStatus: '', cleanLoc: '', toolLoc: '', other: ''
  234. }
  235. })
  236. // Address Autofill Watcher
  237. watch(() => form.petId, (newId) => {
  238. if (!newId) return
  239. const pet = currentPets.value.find(p => p.id === newId)
  240. if (!pet) return
  241. const user = userOptions.value.find(u => u.id === form.userId)
  242. // Fill Transport
  243. form.transport.pickRegion = pet.region || []
  244. form.transport.pickDetail = pet.address || ''
  245. form.transport.pickContact = user?.name || ''
  246. form.transport.pickPhone = user?.phone || ''
  247. form.transport.dropRegion = pet.region || []
  248. form.transport.dropDetail = pet.address || ''
  249. form.transport.dropContact = user?.name || ''
  250. form.transport.dropPhone = user?.phone || ''
  251. // Fill Feeding
  252. form.feeding.region = pet.region || []
  253. form.feeding.addressDetail = pet.address || ''
  254. // Fill Washing
  255. form.washing.region = pet.region || []
  256. form.washing.addressDetail = pet.address || ''
  257. })
  258. // Current Active Data Helper
  259. const activeData = computed(() => {
  260. return form[form.type]
  261. })
  262. // --- Logic ---
  263. const handleTypeChange = (type) => {
  264. form.type = type
  265. calcPrice(type)
  266. }
  267. const currentPackages = computed(() => {
  268. return allPackages.filter(p => p.type === form.type)
  269. })
  270. const handlePkgSelect = (id) => {
  271. activeData.value.pkgId = id
  272. // Price calculation should remain same (base price), just payable changes
  273. calcPrice(form.type)
  274. }
  275. const calcPrice = (type) => {
  276. const data = form[type]
  277. const base = serviceList.find(s => s.type === type)?.basePrice || 0
  278. // Always use Base Logic for "Order Value", regardless of package
  279. if (type === 'transport') {
  280. if(data.subType === 'round') {
  281. data.pickPrice = base
  282. data.dropPrice = base
  283. } else if (data.subType === 'pick') {
  284. data.pickPrice = base
  285. data.dropPrice = 0
  286. } else if (data.subType === 'drop') {
  287. data.pickPrice = 0
  288. data.dropPrice = base
  289. }
  290. } else if (type === 'feeding') {
  291. data.price = base * data.count
  292. } else if (type === 'washing') {
  293. data.price = base
  294. }
  295. }
  296. // Add User Logic
  297. const userDialogVisible = ref(false)
  298. const openAddUser = () => { userDialogVisible.value = true }
  299. const handleUserSuccess = (newUser) => {
  300. userOptions.value.push(newUser)
  301. form.userId = newUser.id
  302. currentPets.value = []
  303. form.petId = ''
  304. ElMessage.success('用户添加成功并已选中')
  305. }
  306. const pcaOptions = [
  307. {
  308. value: '北京市', label: '北京市',
  309. children: [
  310. { value: '市辖区', label: '市辖区', children: [ { value: '朝阳区', label: '朝阳区' }, { value: '海淀区', label: '海淀区' } ] }
  311. ]
  312. },
  313. {
  314. value: '上海市', label: '上海市',
  315. children: [
  316. { value: '市辖区', label: '市辖区', children: [ { value: '浦东新区', label: '浦东新区' }, { value: '徐汇区', label: '徐汇区' } ] }
  317. ]
  318. }
  319. ]
  320. // Add Pet Logic
  321. const petDialogVisible = ref(false)
  322. const openAddPet = () => { petDialogVisible.value = true }
  323. const handlePetSuccess = (newPet) => {
  324. if(!currentPets.value) currentPets.value = []
  325. currentPets.value.push(newPet)
  326. form.petId = newPet.id
  327. ElMessage.success('宠物添加成功')
  328. }
  329. // --- Computed Helpers ---
  330. const selectedMerchantName = computed(() => merchants.value.find(m => m.id === form.merchantId)?.name)
  331. const selectedUserName = computed(() => userOptions.value.find(u => u.id === form.userId)?.name)
  332. const selectedPet = computed(() => currentPets.value.find(p => p.id === form.petId))
  333. const selectedPetName = computed(() => selectedPet.value?.name)
  334. const selectedPetBreed = computed(() => selectedPet.value?.breed)
  335. const selectedPkgName = computed(() => {
  336. const pkgId = activeData.value.pkgId
  337. return allPackages.find(p => p.id === pkgId)?.name || ''
  338. })
  339. const canSubmit = computed(() => {
  340. if(!form.merchantId || !form.userId || !form.petId) return false
  341. return true
  342. })
  343. // --- Methods ---
  344. const searchUser = (query) => { /* Mock */ }
  345. const handleUserChange = (val) => {
  346. currentPets.value = mockPets[val] || []
  347. form.petId = ''
  348. }
  349. const getStepTitle = (type) => {
  350. const map = { transport: '填写接送路线与时间', feeding: '选择套餐与服务的细则', washing: '选择套餐与服务的细则' }
  351. return map[type]
  352. }
  353. const getTypeName = (type) => {
  354. const map = { transport: '宠物接送', feeding: '上门喂遛', washing: '上门洗护' }
  355. return map[type]
  356. }
  357. const formatTime = (time) => {
  358. if(!time) return ''
  359. const d = new Date(time)
  360. return `${d.getMonth()+1}-${d.getDate()} ${d.getHours()}:${d.getMinutes() < 10 ? '0'+d.getMinutes() : d.getMinutes()}`
  361. }
  362. const handleSubmit = () => {
  363. ElMessage.success('下单成功!订单号:ORD20248888')
  364. }
  365. // Initialize
  366. onMounted(() => {
  367. calcPrice('transport')
  368. })
  369. </script>
  370. <style scoped>
  371. .page-container { padding: 20px; background-color: #f0f2f5; min-height: 100vh; }
  372. .create-layout { display: flex; gap: 20px; align-items: flex-start; max-width: 1400px; margin: 0 auto; }
  373. /* Left Content */
  374. .form-container { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
  375. .section-card { border-radius: 8px; border: none; }
  376. .card-title { font-size: 16px; font-weight: bold; color: #303133; display: flex; align-items: center; gap: 10px; }
  377. .step-num {
  378. background: #e6f7ff; color: #1890ff; width: 28px; height: 28px; border-radius: 50%;
  379. text-align: center; line-height: 28px; font-family: Impact, sans-serif;
  380. }
  381. .base-form .el-form-item { margin-bottom: 18px; }
  382. /* Pet Selection */
  383. /* Pet Selection */
  384. .pet-select-row {
  385. display: grid;
  386. grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  387. gap: 15px;
  388. width: 100%;
  389. }
  390. .pet-card {
  391. border: 1px solid #8D9095;
  392. border-radius: 8px;
  393. padding: 12px 15px;
  394. cursor: pointer;
  395. display: flex;
  396. align-items: center;
  397. gap: 12px;
  398. position: relative;
  399. transition: all 0.2s ease-in-out;
  400. background: #fff;
  401. min-height: 70px;
  402. }
  403. .pet-card:hover {
  404. border-color: #303133;
  405. transform: translateY(-2px);
  406. box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  407. }
  408. .pet-card.active {
  409. border-color: #409eff;
  410. background-color: #fff;
  411. box-shadow: 0 0 0 1px #409eff inset;
  412. }
  413. .check-mark {
  414. position: absolute;
  415. right: 0;
  416. top: 0;
  417. background: #409eff;
  418. color: white;
  419. width: 28px;
  420. height: 18px;
  421. border-radius: 0 8px 0 12px;
  422. display: flex;
  423. align-items: center;
  424. justify-content: center;
  425. font-size: 12px;
  426. }
  427. .pet-info .name { font-weight: bold; font-size: 15px; color: #303133; margin-bottom: 2px; }
  428. .pet-info .sub { font-size: 12px; color: #606266; line-height: 1.2; }
  429. .pet-card.add-card {
  430. border: 1px solid #8D9095;
  431. justify-content: center;
  432. align-items: center;
  433. color: #303133;
  434. flex-direction: row;
  435. gap: 8px;
  436. background: #fff;
  437. box-shadow: none;
  438. height: auto;
  439. min-height: 70px;
  440. }
  441. .pet-card.add-card:hover {
  442. border-color: #303133;
  443. color: #303133;
  444. background: #f9f9f9;
  445. transform: translateY(-2px);
  446. }
  447. /* Type Selection */
  448. .type-selection { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; }
  449. .type-card {
  450. background: white; border-radius: 8px; padding: 20px; cursor: pointer; position: relative;
  451. display: flex; align-items: center; gap: 15px; transition: all 0.2s;
  452. border: 2px solid transparent; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  453. }
  454. .type-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.1); }
  455. .type-card.active { border-color: #409eff; background-color: #f0f9ff; }
  456. .type-card .icon-box {
  457. width: 48px; height: 48px; border-radius: 12px; background: #f2f3f5;
  458. display: flex; align-items: center; justify-content: center; font-size: 24px; color: #606266;
  459. }
  460. .type-card.active .icon-box { background: #409eff; color: white; }
  461. /* Colors */
  462. .type-card.transport.active .icon-box { background: #409eff; }
  463. .type-card.transport.active { border-color: #409eff; background-color: #f0f9ff; }
  464. .type-card.feeding.active .icon-box { background: #e6a23c; }
  465. .type-card.feeding.active { border-color: #e6a23c; background-color: #fdf6ec; }
  466. .type-card.washing.active .icon-box { background: #67c23a; }
  467. .type-card.washing.active { border-color: #67c23a; background-color: #f0f9eb; }
  468. .type-name { font-weight: bold; font-size: 16px; color: #303133; margin-bottom: 4px; }
  469. .type-desc { font-size: 12px; color: #909399; margin-bottom: 4px; }
  470. .type-price { font-size: 14px; color: #f56c6c; font-weight: bold; }
  471. /* Package Selection Grid */
  472. .form-section-title { font-weight: bold; margin-bottom: 12px; font-size: 14px; }
  473. .package-selection-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
  474. .pkg-select-card {
  475. border: 1px solid #dcdfe6; border-radius: 8px; padding: 10px 15px; cursor: pointer; position: relative;
  476. background: #fff; transition: all 0.2s; min-height: 56px; display: flex; flex-direction: column; justify-content: center;
  477. }
  478. .pkg-select-card:hover { border-color: #409eff; }
  479. .pkg-select-card.active { border-color: #409eff; background-color: #ecf5ff; }
  480. .pkg-select-card .pkg-name { font-weight: bold; font-size: 14px; color: #303133; }
  481. .pkg-select-card .pkg-desc { font-size: 12px; color: #909399; margin-top: 2px; }
  482. .divider { height: 1px; background: #EBEEF5; margin: 15px 0; }
  483. /* Sidebar */
  484. .summary-sidebar { width: 320px; flex-shrink: 0; }
  485. .summary-panel { background: white; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); position: sticky; top: 20px; }
  486. .summary-header { background: #304156; color: white; padding: 15px 20px; font-weight: bold; font-size: 16px; border-radius: 8px 8px 0 0; }
  487. .summary-content { padding: 20px; }
  488. .row { display: flex; justify-content: space-between; margin-bottom: 12px; font-size: 14px; }
  489. .row .label { color: #909399; }
  490. .row .value { color: #303133; font-weight: 500; }
  491. .preview-title { font-weight: bold; margin-bottom: 8px; color: #333; }
  492. .preview-detail { background: #f8f9fa; padding: 10px; border-radius: 4px; font-size: 13px; margin-bottom: 8px; }
  493. .preview-detail .minor { color: #999; font-size: 12px; margin-top: 2px; }
  494. .placeholder { color: #C0C4CC; text-align: center; padding: 20px 0; font-size: 13px; font-style: italic; }
  495. .summary-footer { background: #f9f9fc; padding: 15px 20px; border-top: 1px solid #ebeef5; text-align: center; border-radius: 0 0 8px 8px; }
  496. .submit-btn { width: 100%; font-weight: bold; border-radius: 22px; }
  497. </style>