newGroup.vue 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503
  1. <template>
  2. <!-- 团购包管理 - 新增/编辑页面 -->
  3. <div class="table-box" style="width: 100%; min-height: 100%; background-color: white">
  4. <div class="header">
  5. <el-button @click="goBack"> 返回 </el-button>
  6. <h2 class="title">新建团购</h2>
  7. </div>
  8. <el-form :model="storeInfoModel" ref="ruleFormRef" :rules="rules" label-width="120px" class="formBox">
  9. <div class="content">
  10. <!-- 左侧内容区域 -->
  11. <div class="contentLeft">
  12. <!-- 基础信息模块 -->
  13. <div class="model">
  14. <h3 style="font-weight: bold">基础信息:</h3>
  15. <!-- 团购图片上传 -->
  16. <el-form-item label="图片" prop="imageList">
  17. <el-upload
  18. v-model:file-list="storeInfoModel.imageList"
  19. :action="uploadUrl"
  20. list-type="picture-card"
  21. :accept="'.jpg,.png'"
  22. :limit="9"
  23. :on-preview="handlePictureCardPreview"
  24. :before-remove="handleBeforeRemove"
  25. :on-remove="handleRemove"
  26. :on-success="handleSuccess"
  27. :show-file-list="true"
  28. >
  29. <el-icon>
  30. <Plus />
  31. </el-icon>
  32. </el-upload>
  33. </el-form-item>
  34. <!-- 团购名称 -->
  35. <el-form-item label="团购名称" prop="groupName">
  36. <el-input maxlength="50" v-model="storeInfoModel.groupName" placeholder="请填写团购名称" clearable />
  37. </el-form-item>
  38. <!-- 开始售卖时间设置方式 -->
  39. <el-form-item label="开始售卖时间" prop="startTimeType">
  40. <el-radio-group v-model="storeInfoModel.startTimeType" class="ml-4">
  41. <el-radio v-for="status in storeStatusList" :value="status.value" :key="status.value">
  42. {{ status.label }}
  43. </el-radio>
  44. </el-radio-group>
  45. </el-form-item>
  46. <!-- 自定义开始售卖时间(当选择"设置售卖时间"时显示) -->
  47. <el-form-item label="" prop="saleTimeStr" v-if="storeInfoModel.startTimeType == 1">
  48. <el-date-picker
  49. v-model="storeInfoModel.saleTimeStr"
  50. format="YYYY/MM/DD"
  51. value-format="YYYY-MM-DD"
  52. placeholder="请选择开始售卖时间"
  53. :disabled-date="disabledStartDate"
  54. />
  55. </el-form-item>
  56. <!-- 结束售卖时间 -->
  57. <el-form-item label="结束售卖时间" prop="endTime">
  58. <el-date-picker
  59. v-model="storeInfoModel.endTime"
  60. format="YYYY/MM/DD"
  61. value-format="YYYY-MM-DD"
  62. placeholder="请选择结束售卖时间"
  63. :disabled-date="disabledEndDate"
  64. />
  65. </el-form-item>
  66. <!-- 库存数量 -->
  67. <el-form-item label="库存数量" prop="inventoryNum">
  68. <el-input v-model="storeInfoModel.inventoryNum" maxlength="15" placeholder="请填写库存数量" clearable />
  69. </el-form-item>
  70. <!-- 每人限购设置 -->
  71. <el-form-item label="每人限购" prop="quotaType">
  72. <el-radio-group v-model="storeInfoModel.quotaType" class="ml-4">
  73. <el-radio v-for="status in perList" :value="status.value" :key="status.value">
  74. {{ status.label }}
  75. </el-radio>
  76. </el-radio-group>
  77. </el-form-item>
  78. <!-- 自定义限购数量(当选择"自定义限购数量"时显示) -->
  79. <el-form-item label="" prop="quotaValue" v-if="storeInfoModel.quotaType == 1">
  80. <el-input v-model="storeInfoModel.quotaValue" maxlength="15" placeholder="请填写自定义限购数量" clearable />
  81. </el-form-item>
  82. <!-- 套餐内容 -->
  83. <el-form-item label="套餐内容" class="package-content-item">
  84. <el-form
  85. ref="packageFormRef"
  86. :model="packageFormModel"
  87. :rules="packageFormRules"
  88. label-width="0"
  89. class="package-content-form"
  90. >
  91. <div class="package-content-wrapper">
  92. <div class="package-content-header">
  93. <el-button type="primary" @click="addGroup" class="add-group-btn"> 添加分组 </el-button>
  94. <el-button
  95. type="primary"
  96. link
  97. @click="toggleAllGroupsCollapse"
  98. :icon="allGroupsCollapsed ? ArrowDown : ArrowUp"
  99. v-show="lifeGroupBuyThalis.length > 1"
  100. >
  101. {{ allGroupsCollapsed ? "展开全部" : "收起全部" }}
  102. </el-button>
  103. </div>
  104. <transition-group name="group-fade" tag="div" class="package-content-container">
  105. <div v-for="item in visibleGroups" :key="item.originalIndex" class="package-group">
  106. <div class="package-group-header">
  107. <span class="group-index">{{ item.group.groupName }}</span>
  108. <div class="header-right">
  109. <el-button
  110. type="primary"
  111. link
  112. @click="toggleGroupCollapse(item.originalIndex)"
  113. :icon="isGroupCollapsed(item.originalIndex) ? ArrowDown : ArrowUp"
  114. v-show="item.group.dishes.length > 1"
  115. >
  116. {{ isGroupCollapsed(item.originalIndex) ? "展开" : "收起" }}
  117. </el-button>
  118. <el-button
  119. type="danger"
  120. link
  121. @click="removeGroup(item.originalIndex)"
  122. :icon="Delete"
  123. v-show="lifeGroupBuyThalis.length > 1"
  124. >
  125. 删除
  126. </el-button>
  127. </div>
  128. </div>
  129. <div class="package-group-content">
  130. <el-form-item
  131. :prop="`groups.${item.originalIndex}.groupName`"
  132. :rules="packageFormRules[`groups.${item.originalIndex}.groupName`]"
  133. class="category-form-item"
  134. >
  135. <div class="category-row">
  136. <span class="label">类别</span>
  137. <el-input v-model="item.group.groupName" placeholder="请输入" clearable />
  138. </div>
  139. </el-form-item>
  140. <!-- 第一行菜品,始终显示 -->
  141. <div v-if="item.group.dishes && item.group.dishes.length > 0" class="dish-row">
  142. <el-form-item
  143. :prop="`groups.${item.originalIndex}.dishes.0.detailId`"
  144. :rules="packageFormRules[`groups.${item.originalIndex}.dishes.0.detailId`]"
  145. class="dish-form-item"
  146. >
  147. <span class="label">菜品</span>
  148. <div class="dish-select-block" @click="openDishDialog(item.originalIndex, 0)">
  149. <span v-if="item.group.dishes[0].dishName" class="dish-selected-name"
  150. >{{ item.group.dishes[0].dishName }},¥{{ item.group.dishes[0].dishPrice }}/{{
  151. item.group.dishes[0].dishesUnit
  152. }}</span
  153. >
  154. <span v-else class="dish-placeholder">请选择</span>
  155. </div>
  156. </el-form-item>
  157. <el-form-item
  158. :prop="`groups.${item.originalIndex}.dishes.0.qty`"
  159. :rules="packageFormRules[`groups.${item.originalIndex}.dishes.0.qty`]"
  160. class="dish-form-item"
  161. >
  162. <span class="label">数量</span>
  163. <el-input v-model="item.group.dishes[0].qty" placeholder="请输入" clearable class="quantity-input" />
  164. <el-button
  165. :icon="Delete"
  166. link
  167. type="danger"
  168. @click="removeDish(item.originalIndex, 0)"
  169. class="delete-dish-btn"
  170. v-show="item.group.dishes.length > 1"
  171. />
  172. </el-form-item>
  173. </div>
  174. <!-- 第二行及以后的菜品,收起时隐藏 -->
  175. <transition name="slide-fade">
  176. <div v-if="!isGroupCollapsed(item.originalIndex)" class="extra-dishes-container">
  177. <div
  178. v-for="(dish, dishIndex) in item.group.dishes"
  179. :key="dishIndex"
  180. class="dish-row"
  181. v-show="dishIndex > 0"
  182. >
  183. <el-form-item
  184. :prop="`groups.${item.originalIndex}.dishes.${dishIndex}.detailId`"
  185. :rules="packageFormRules[`groups.${item.originalIndex}.dishes.${dishIndex}.detailId`]"
  186. class="dish-form-item"
  187. >
  188. <span class="label">菜品</span>
  189. <div class="dish-select-block" @click="openDishDialog(item.originalIndex, dishIndex)">
  190. <span v-if="dish.dishName" class="dish-selected-name"
  191. >{{ dish.dishName }},¥{{ dish.dishPrice }}/{{ dish.dishesUnit }}</span
  192. >
  193. <span v-else class="dish-placeholder">请选择</span>
  194. </div>
  195. </el-form-item>
  196. <el-form-item
  197. :prop="`groups.${item.originalIndex}.dishes.${dishIndex}.qty`"
  198. :rules="packageFormRules[`groups.${item.originalIndex}.dishes.${dishIndex}.qty`]"
  199. class="dish-form-item"
  200. >
  201. <span class="label">数量</span>
  202. <el-input v-model="dish.qty" placeholder="请输入" clearable class="quantity-input" />
  203. <el-button
  204. :icon="Delete"
  205. link
  206. type="danger"
  207. @click="removeDish(item.originalIndex, dishIndex)"
  208. class="delete-dish-btn"
  209. />
  210. </el-form-item>
  211. </div>
  212. <el-button type="primary" @click="addDish(item.originalIndex)" class="add-dish-btn"> 添加 </el-button>
  213. </div>
  214. </transition>
  215. </div>
  216. </div>
  217. </transition-group>
  218. </div>
  219. </el-form>
  220. </el-form-item>
  221. </div>
  222. <!-- 价格信息模块 -->
  223. <div class="model">
  224. <h3 style="font-weight: bold">价格:</h3>
  225. <!-- 原价 -->
  226. <el-form-item label="原价" prop="originalPrice">
  227. <el-input maxlength="50" v-model="storeInfoModel.originalPrice" placeholder="请填写原价" clearable />
  228. </el-form-item>
  229. <!-- 优惠价 -->
  230. <el-form-item label="优惠价" prop="preferentialPrice">
  231. <el-input maxlength="50" v-model="storeInfoModel.preferentialPrice" placeholder="请填写优惠价" clearable />
  232. </el-form-item>
  233. </div>
  234. </div>
  235. <!-- 右侧内容区域 -->
  236. <div class="contentRight">
  237. <!-- 购买须知模块 -->
  238. <div class="model">
  239. <h3 style="font-weight: bold">购买须知:</h3>
  240. <el-form-item label="有效期" prop="effectiveDateType">
  241. <el-radio-group v-model="storeInfoModel.effectiveDateType" class="ml-4">
  242. <el-radio v-for="status in expirationDateStatusList" :value="status.value" :key="status.value">
  243. {{ status.label }}
  244. </el-radio>
  245. </el-radio-group>
  246. </el-form-item>
  247. <el-form-item label="" prop="expirationDate" v-if="storeInfoModel.effectiveDateType == 0">
  248. <div class="expiration-date-container">
  249. <span class="expiration-label">用户购买</span>
  250. <el-input-number v-model="storeInfoModel.expirationDate" placeholder="请输入" :min="0" class="expiration-input" />
  251. <span class="expiration-label">天内有效</span>
  252. </div>
  253. </el-form-item>
  254. <el-form-item label="" prop="expirationDateList" v-else>
  255. <el-date-picker
  256. v-model="storeInfoModel.expirationDateList"
  257. type="daterange"
  258. value-format="YYYY-MM-DD"
  259. range-separator="-"
  260. start-placeholder="开始时间"
  261. end-placeholder="结束时间"
  262. :disabled-date="disabledEffectiveDate"
  263. />
  264. </el-form-item>
  265. <el-form-item label="不可用日期" prop="disableDateType">
  266. <el-radio-group v-model="storeInfoModel.disableDateType" class="ml-4">
  267. <el-radio v-for="status in unavailableDatesList" :value="status.value" :key="status.value">
  268. {{ status.label }}
  269. </el-radio>
  270. </el-radio-group>
  271. </el-form-item>
  272. <template v-if="storeInfoModel.disableDateType == 1">
  273. <el-form-item label="" prop="unavailableWeekdays">
  274. <div class="unavailable-dates-container">
  275. <!-- 星期选择 -->
  276. <div class="date-select-section">
  277. <div class="section-title">星期</div>
  278. <div class="button-group">
  279. <el-button
  280. v-for="weekday in weekdayList"
  281. :key="weekday.oName"
  282. :type="storeInfoModel.unavailableWeekdays?.includes(weekday.oName) ? 'primary' : ''"
  283. class="date-select-btn"
  284. @click="toggleWeekday(weekday.oName)"
  285. >
  286. {{ weekday.name }}
  287. </el-button>
  288. </div>
  289. </div>
  290. </div>
  291. </el-form-item>
  292. <el-form-item label="" prop="unavailableHolidays">
  293. <div class="unavailable-dates-container">
  294. <!-- 节日选择 -->
  295. <div class="date-select-section">
  296. <div class="section-title">节日</div>
  297. <div class="button-group">
  298. <el-button
  299. v-for="holiday in holidayList"
  300. :key="holiday.id"
  301. :type="storeInfoModel.unavailableHolidays?.includes(holiday.id) ? 'primary' : ''"
  302. class="date-select-btn"
  303. @click="toggleHoliday(holiday.id)"
  304. >
  305. {{ holiday.festivalName }}
  306. </el-button>
  307. </div>
  308. </div>
  309. </div>
  310. </el-form-item>
  311. </template>
  312. <el-form-item label="" prop="customUnavailableDates" v-else-if="storeInfoModel.disableDateType == 2">
  313. <div class="date-picker-container">
  314. <el-button :icon="Plus" class="add-date-btn" type="primary" @click="addDate"> 添加日期 </el-button>
  315. <div v-for="(item, index) in storeInfoModel.disableDateList" :key="index" class="date-item">
  316. <el-date-picker
  317. v-model="storeInfoModel.disableDateList[index]"
  318. type="daterange"
  319. value-format="YYYY-MM-DD"
  320. range-separator="-"
  321. start-placeholder="开始时间"
  322. end-placeholder="结束时间"
  323. class="date-picker"
  324. :disabled-date="disabledCustomUnavailableDate"
  325. />
  326. <el-button
  327. :icon="Delete"
  328. type="danger"
  329. circle
  330. size="small"
  331. class="delete-btn"
  332. @click="removeDate(index)"
  333. v-show="storeInfoModel.disableDateList.length > 1"
  334. />
  335. </div>
  336. </div>
  337. </el-form-item>
  338. <!-- 预约规则 -->
  339. <el-form-item label="预约规则" prop="reservationRules">
  340. <el-input
  341. maxlength="300"
  342. v-model="storeInfoModel.reservationRules"
  343. :rows="4"
  344. type="textarea"
  345. placeholder="请输入预约规则"
  346. />
  347. </el-form-item>
  348. <!-- 使用规则 -->
  349. <el-form-item label="使用规则" prop="useRules">
  350. <el-input
  351. maxlength="300"
  352. v-model="storeInfoModel.useRules"
  353. :rows="4"
  354. type="textarea"
  355. placeholder="请输入使用规则"
  356. />
  357. </el-form-item>
  358. <!-- 适用人数 -->
  359. <el-form-item label="适用人数" prop="applicableNum">
  360. <el-input v-model="storeInfoModel.applicableNum" maxlength="15" placeholder="请填写适用人数" clearable />
  361. </el-form-item>
  362. <!-- 其他规则 -->
  363. <el-form-item label="其他规则" prop="otherRules">
  364. <el-input
  365. maxlength="300"
  366. v-model="storeInfoModel.otherRules"
  367. :rows="4"
  368. type="textarea"
  369. placeholder="请输入其他规则"
  370. />
  371. </el-form-item>
  372. <!-- 发票信息 -->
  373. <el-form-item label="发票信息" prop="invoiceInformation">
  374. <el-checkbox-group v-model="storeInfoModel.invoiceInformation">
  375. <el-checkbox v-for="bt in businessTypes" :key="bt.value" :value="bt.value" :label="bt.label">
  376. {{ bt.label }}
  377. </el-checkbox>
  378. </el-checkbox-group>
  379. </el-form-item>
  380. <!-- 发票说明 -->
  381. <el-form-item label="发票说明" prop="invoiceDescribe">
  382. <el-input v-model="storeInfoModel.invoiceDescribe" maxlength="15" placeholder="请填写发票说明" clearable />
  383. </el-form-item>
  384. </div>
  385. </div>
  386. </div>
  387. </el-form>
  388. <!-- 底部按钮区域 -->
  389. <div class="button-container">
  390. <el-button @click="handleSubmit('cg')"> 存草稿 </el-button>
  391. <el-button type="primary" @click="handleSubmit"> 确定 </el-button>
  392. </div>
  393. <!-- 图片预览 -->
  394. <el-image-viewer
  395. v-if="imageViewerVisible"
  396. :url-list="imageViewerUrlList"
  397. :initial-index="imageViewerInitialIndex"
  398. @close="imageViewerVisible = false"
  399. />
  400. <!-- 菜品选择对话框 -->
  401. <el-dialog v-model="dishDialogVisible" title="菜品" width="600px" :close-on-click-modal="false">
  402. <div class="dish-dialog-content">
  403. <el-input
  404. v-model="dishSearchKeyword"
  405. placeholder="请输入菜品名称"
  406. clearable
  407. class="dish-search-input"
  408. @input="filterDishList"
  409. />
  410. <el-scrollbar height="400px" class="dish-list-container">
  411. <template v-if="filteredDishList.length > 0">
  412. <div
  413. v-for="dish in filteredDishList"
  414. :key="dish.id"
  415. :class="['dish-item', { 'dish-item-selected': selectedDishId === dish.id }]"
  416. @click="selectDish(dish)"
  417. >
  418. <div class="dish-image">
  419. <el-image v-if="dish.imgUrl" :src="dish.imgUrl" fit="cover" class="dish-img" />
  420. <div v-else class="dish-image-placeholder">
  421. <el-icon><Picture /></el-icon>
  422. </div>
  423. </div>
  424. <div class="dish-info">
  425. <div class="dish-name">
  426. {{ dish.dishName }}
  427. </div>
  428. <div class="dish-price">¥{{ dish.dishPrice }}/{{ dish.dishesUnit }}</div>
  429. </div>
  430. </div>
  431. </template>
  432. <div v-else class="dish-empty-state">
  433. <div class="empty-text">暂无可选择菜品</div>
  434. <div class="empty-hint">请去全部-门店装修-菜品管理中添加</div>
  435. </div>
  436. </el-scrollbar>
  437. </div>
  438. <template #footer>
  439. <div class="dialog-footer">
  440. <el-button type="primary" @click="confirmDishSelection"> 确定 </el-button>
  441. </div>
  442. </template>
  443. </el-dialog>
  444. </div>
  445. </template>
  446. <script setup lang="tsx" name="newGroup">
  447. /**
  448. * 团购包管理 - 新增/编辑页面
  449. * 功能:支持团购包的新增和编辑操作
  450. */
  451. import { ref, reactive, onMounted, watch, nextTick, computed } from "vue";
  452. import { ElMessage, ElMessageBox } from "element-plus";
  453. import { Plus, Delete, ArrowDown, ArrowUp, Picture } from "@element-plus/icons-vue";
  454. import {
  455. saveStoreInfo,
  456. editStoreInfo,
  457. getDetail,
  458. getStoreDetail,
  459. getHolidayList,
  460. getUserByPhone,
  461. getMenuByStoreId
  462. } from "@/api/modules/groupPackageManagement";
  463. import { useRouter, useRoute } from "vue-router";
  464. import type { UploadProps, FormInstance } from "element-plus";
  465. import { localGet, localSet } from "@/utils";
  466. // ==================== 响应式数据定义 ====================
  467. // 图片预览相关
  468. const imageViewerVisible = ref(false);
  469. const imageViewerUrlList = ref<string[]>([]);
  470. const imageViewerInitialIndex = ref(0);
  471. // 路由相关
  472. const router = useRouter();
  473. const route = useRoute();
  474. // 页面状态
  475. const type = ref<string>(""); // 页面类型:add-新增, edit-编辑
  476. const id = ref<string>(""); // 页面ID参数
  477. // 文件上传地址
  478. const uploadUrl = ref(`${import.meta.env.VITE_API_URL_STORE}/file/upload`);
  479. // ==================== 表单验证规则 ====================
  480. const rules = reactive({
  481. imageList: [{ required: true, message: "请上传图片" }],
  482. groupName: [{ required: true, message: "请填写团购名称" }],
  483. startTimeType: [{ required: true, message: "请选择开始售卖时间" }],
  484. saleTimeStr: [
  485. { required: true, message: "请选择开始售卖时间" },
  486. {
  487. validator: (rule: any, value: any, callback: any) => {
  488. if (storeInfoModel.value.startTimeType === 1) {
  489. if (!value) {
  490. callback(new Error("请选择开始售卖时间"));
  491. return;
  492. }
  493. const selectedDate = new Date(value);
  494. const today = new Date();
  495. today.setHours(0, 0, 0, 0);
  496. if (selectedDate < today) {
  497. callback(new Error("开始售卖时间不能早于当前时间"));
  498. return;
  499. }
  500. // 如果结束时间已设置,验证开始时间必须早于结束时间
  501. if (storeInfoModel.value.endTime) {
  502. const endDate = new Date(storeInfoModel.value.endTime);
  503. if (selectedDate >= endDate) {
  504. callback(new Error("开始售卖时间必须早于结束售卖时间"));
  505. return;
  506. }
  507. }
  508. }
  509. callback();
  510. },
  511. trigger: "change"
  512. }
  513. ],
  514. endTime: [
  515. { required: true, message: "请选择结束售卖时间" },
  516. {
  517. validator: (rule: any, value: any, callback: any) => {
  518. if (!value) {
  519. callback(new Error("请选择结束售卖时间"));
  520. return;
  521. }
  522. const selectedDate = new Date(value);
  523. const today = new Date();
  524. today.setHours(0, 0, 0, 0);
  525. if (selectedDate < today) {
  526. callback(new Error("结束售卖时间不能早于当前时间"));
  527. return;
  528. }
  529. // 如果开始时间已设置,验证结束时间必须晚于开始时间
  530. if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.saleTimeStr) {
  531. const startDate = new Date(storeInfoModel.value.saleTimeStr);
  532. if (selectedDate <= startDate) {
  533. callback(new Error("结束售卖时间必须晚于开始售卖时间"));
  534. return;
  535. }
  536. }
  537. callback();
  538. },
  539. trigger: "change"
  540. }
  541. ],
  542. inventoryNum: [
  543. { required: true, message: "请填写库存数量" },
  544. {
  545. validator: (rule: any, value: any, callback: any) => {
  546. if (!value || value.toString().trim() === "") {
  547. callback();
  548. return;
  549. }
  550. const num = Number(value);
  551. if (isNaN(num) || num <= 0) {
  552. callback(new Error("库存数量必须为正整数"));
  553. return;
  554. }
  555. if (!Number.isInteger(num)) {
  556. callback(new Error("库存数量必须为正整数"));
  557. return;
  558. }
  559. callback();
  560. },
  561. trigger: "blur"
  562. }
  563. ],
  564. quotaType: [{ required: true, message: "请选择每人限购" }],
  565. quotaValue: [
  566. {
  567. required: true,
  568. validator: (rule: any, value: any, callback: any) => {
  569. if (storeInfoModel.value.quotaType === 1) {
  570. if (!value || value.toString().trim() === "") {
  571. callback(new Error("请输入自定义限购数量"));
  572. return;
  573. }
  574. const num = Number(value);
  575. if (isNaN(num) || num <= 0) {
  576. callback(new Error("自定义限购数量必须为正整数"));
  577. return;
  578. }
  579. if (!Number.isInteger(num)) {
  580. callback(new Error("自定义限购数量必须为正整数"));
  581. return;
  582. }
  583. }
  584. callback();
  585. },
  586. trigger: "blur"
  587. }
  588. ],
  589. lifeGroupBuyThalis: [
  590. {
  591. required: true,
  592. validator: (rule: any, value: any, callback: any) => {
  593. try {
  594. // 只检查是否有至少一个分组,详细验证由独立的套餐内容表单处理
  595. const thalis = lifeGroupBuyThalis.value;
  596. if (!thalis || thalis.length === 0) {
  597. callback(new Error("请至少添加一个套餐分组"));
  598. return;
  599. }
  600. callback();
  601. } catch (error) {
  602. // 如果验证过程中出错,直接通过验证,避免报错
  603. callback();
  604. }
  605. },
  606. trigger: "blur"
  607. }
  608. ],
  609. originalPrice: [
  610. { required: true, message: "请输入原价" },
  611. {
  612. validator: (rule: any, value: any, callback: any) => {
  613. if (!value || value.toString().trim() === "") {
  614. callback();
  615. return;
  616. }
  617. const num = Number(value);
  618. if (isNaN(num) || num <= 0) {
  619. callback(new Error("原价必须为正数"));
  620. return;
  621. }
  622. callback();
  623. },
  624. trigger: "blur"
  625. }
  626. ],
  627. preferentialPrice: [
  628. { required: true, message: "请输入优惠价" },
  629. {
  630. validator: (rule: any, value: any, callback: any) => {
  631. if (!value || value.toString().trim() === "") {
  632. callback();
  633. return;
  634. }
  635. const num = Number(value);
  636. if (isNaN(num) || num <= 0) {
  637. callback(new Error("优惠价必须为正数"));
  638. return;
  639. }
  640. callback();
  641. },
  642. trigger: "blur"
  643. }
  644. ],
  645. effectiveDateType: [{ required: true, message: "请选择有效期" }],
  646. expirationDate: [
  647. {
  648. required: true,
  649. validator: (rule: any, value: any, callback: any) => {
  650. if (storeInfoModel.value.expirationDate === 0) {
  651. if (value === null || value === undefined || value === "") {
  652. callback(new Error("请输入用户购买天数"));
  653. return;
  654. }
  655. if (value <= 0) {
  656. callback(new Error("天数必须大于0"));
  657. return;
  658. }
  659. }
  660. callback();
  661. },
  662. trigger: "blur"
  663. }
  664. ],
  665. expirationDateList: [
  666. {
  667. required: true,
  668. validator: (rule: any, value: any, callback: any) => {
  669. if (storeInfoModel.value.effectiveDateType === 1) {
  670. if (!value || value.length !== 2) {
  671. callback(new Error("请选择指定时间段"));
  672. return;
  673. }
  674. // 验证开始时间和结束时间不能早于当前时间
  675. const today = new Date();
  676. today.setHours(0, 0, 0, 0);
  677. const startDate = new Date(value[0]);
  678. const endDate = new Date(value[1]);
  679. if (startDate < today) {
  680. callback(new Error("开始时间不能早于当前时间"));
  681. return;
  682. }
  683. if (endDate < today) {
  684. callback(new Error("结束时间不能早于当前时间"));
  685. return;
  686. }
  687. // 验证开始时间必须早于结束时间
  688. if (startDate >= endDate) {
  689. callback(new Error("开始时间必须早于结束时间"));
  690. return;
  691. }
  692. }
  693. callback();
  694. },
  695. trigger: "change"
  696. }
  697. ],
  698. disableDateType: [{ required: true, message: "请选择不可用日期" }],
  699. unavailableWeekdays: [
  700. {
  701. required: true,
  702. validator: (rule: any, value: any, callback: any) => {
  703. if (storeInfoModel.value.disableDateType === 1) {
  704. if (!value || value.length === 0) {
  705. callback(new Error("至少需要选择一个星期"));
  706. return;
  707. }
  708. }
  709. callback();
  710. },
  711. trigger: "change"
  712. }
  713. ],
  714. unavailableHolidays: [
  715. {
  716. required: true,
  717. validator: (rule: any, value: any, callback: any) => {
  718. if (storeInfoModel.value.disableDateType === 1) {
  719. if (!value || value.length === 0) {
  720. callback(new Error("至少需要选择一个节日"));
  721. return;
  722. }
  723. }
  724. callback();
  725. },
  726. trigger: "change"
  727. }
  728. ],
  729. customUnavailableDates: [
  730. {
  731. required: true,
  732. validator: (rule: any, value: any, callback: any) => {
  733. if (storeInfoModel.value.disableDateType === 2) {
  734. if (!storeInfoModel.value.disableDateList || storeInfoModel.value.disableDateList.length === 0) {
  735. callback(new Error("至少需要添加一个自定义不可用日期"));
  736. return;
  737. }
  738. const today = new Date();
  739. today.setHours(0, 0, 0, 0);
  740. // 验证每个日期项是否已填写
  741. for (let i = 0; i < storeInfoModel.value.disableDateList.length; i++) {
  742. if (!storeInfoModel.value.disableDateList[i] || storeInfoModel.value.disableDateList[i].length !== 2) {
  743. callback(new Error(`第${i + 1}个日期项未完整填写`));
  744. return;
  745. }
  746. // 验证开始时间和结束时间不能早于当前时间
  747. const startDate = new Date(storeInfoModel.value.disableDateList[i][0]);
  748. const endDate = new Date(storeInfoModel.value.disableDateList[i][1]);
  749. if (startDate < today) {
  750. callback(new Error(`第${i + 1}个日期项的开始时间不能早于当前时间`));
  751. return;
  752. }
  753. if (endDate < today) {
  754. callback(new Error(`第${i + 1}个日期项的结束时间不能早于当前时间`));
  755. return;
  756. }
  757. // 验证开始时间必须早于结束时间
  758. if (startDate >= endDate) {
  759. callback(new Error(`第${i + 1}个日期项的开始时间必须早于结束时间`));
  760. return;
  761. }
  762. }
  763. }
  764. callback();
  765. },
  766. trigger: "change"
  767. }
  768. ],
  769. reservationRules: [{ required: true, message: "请输入预约规则" }],
  770. useRules: [{ required: true, message: "请输入使用规则" }],
  771. applicableNum: [
  772. { required: true, message: "请输入适用人数" },
  773. {
  774. validator: (rule: any, value: any, callback: any) => {
  775. if (!value || value.toString().trim() === "") {
  776. callback();
  777. return;
  778. }
  779. const num = Number(value);
  780. if (isNaN(num) || num <= 0) {
  781. callback(new Error("适用人数必须为正整数"));
  782. return;
  783. }
  784. if (!Number.isInteger(num)) {
  785. callback(new Error("适用人数必须为正整数"));
  786. return;
  787. }
  788. callback();
  789. },
  790. trigger: "blur"
  791. }
  792. ],
  793. otherRules: [{ required: true, message: "请输入其他规则" }],
  794. invoiceInformation: [{ required: true, message: "请选择发票信息" }],
  795. invoiceDescribe: [{ required: true, message: "请输入发票说明" }]
  796. });
  797. // ==================== 团购包信息数据模型 ====================
  798. const storeInfoModel = ref<any>({
  799. // 团购图片列表
  800. imageList: [],
  801. // 团购名称
  802. groupName: "",
  803. // 开始售卖时间设置方式:0-审核通过后立即开始,1-设置售卖时间
  804. startTimeType: 0,
  805. // 开始售卖时间(当storeStatus为1时必填)
  806. saleTimeStr: "",
  807. // 结束售卖时间
  808. endTime: "",
  809. // 库存数量
  810. inventoryNum: "",
  811. // 每人限购设置:0-不限量,1-自定义限购数量
  812. quotaType: 0,
  813. // 自定义限购数量(当quotaType为1时必填)
  814. quotaValue: 0,
  815. // 套餐内容(虚拟字段,用于表单验证,实际数据在 lifeGroupBuyThalis 变量中)
  816. lifeGroupBuyThalis: null,
  817. // 原价
  818. originalPrice: "",
  819. // 优惠价
  820. preferentialPrice: "",
  821. // 有效期设置:0-指定天数,1-指定时间段内可用
  822. effectiveDateType: 0,
  823. expirationDate: 0,
  824. expirationDateList: [],
  825. // 不可用日期设置:0-全部日期可用,1-限制日期,2-自定义不可用日期
  826. disableDateType: 0,
  827. // 限制日期 - 星期选择(数组,存储选中的星期值)
  828. unavailableWeekdays: [],
  829. // 限制日期 - 节日选择(数组,存储选中的节日值)
  830. unavailableHolidays: [],
  831. // 自定义不可用日期列表
  832. disableDateList: [],
  833. // 预约规则
  834. reservationRules: "",
  835. // 使用规则
  836. useRules: "",
  837. // 适用人数
  838. applicableNum: "",
  839. // 其他规则
  840. otherRules: "",
  841. // 发票信息(复选框,可多选)
  842. invoiceInformation: [],
  843. // 发票说明
  844. invoiceDescribe: ""
  845. });
  846. // ==================== 下拉选项数据 ====================
  847. // 发票类型列表
  848. const businessTypes = ref([
  849. { value: 0, label: "提供电子发票" },
  850. { value: 1, label: "提供纸质发票" }
  851. ]);
  852. // 开始售卖时间设置方式列表
  853. const storeStatusList = ref([
  854. { value: 0, label: "审核通过后立即开始" },
  855. { value: 1, label: "设置售卖时间" }
  856. ]);
  857. // 每人限购设置
  858. const perList = ref([
  859. { value: 0, label: "不限量" },
  860. { value: 1, label: "自定义限购数量" }
  861. ]);
  862. // 有效期设置
  863. const expirationDateStatusList = ref([
  864. { value: 0, label: "指定天数" },
  865. { value: 1, label: "指定时间段内可用" }
  866. ]);
  867. // 有效期设置
  868. const unavailableDatesList = ref([
  869. { value: 0, label: "全部日期可用" },
  870. { value: 1, label: "限制日期" },
  871. { value: 2, label: "自定义不可用日期" }
  872. ]);
  873. // 星期选项列表
  874. const weekdayList = ref([
  875. { name: "周一", id: "0", oName: "星期一" },
  876. { name: "周二", id: "1", oName: "星期二" },
  877. { name: "周三", id: "2", oName: "星期三" },
  878. { name: "周四", id: "3", oName: "星期四" },
  879. { name: "周五", id: "4", oName: "星期五" },
  880. { name: "周六", id: "5", oName: "星期六" },
  881. { name: "周日", id: "6", oName: "星期日" }
  882. ]);
  883. // 节日选项列表
  884. const holidayList: any = ref([]);
  885. // 菜品选项列表
  886. const dishOptions: any = ref([]);
  887. // 套餐内容(数组,每个元素是一个分组)
  888. const lifeGroupBuyThalis = ref([
  889. {
  890. groupName: "", // 类别
  891. dishes: [
  892. // 菜品列表
  893. {
  894. detailId: "", // 菜品ID
  895. dishName: "", // 菜品名称
  896. dishPrice: "", // 菜品价格
  897. dishImage: "", // 菜品图片
  898. qty: "", // 数量
  899. dishesUnit: ""
  900. }
  901. ]
  902. }
  903. ]);
  904. // 菜品选择对话框相关
  905. const dishDialogVisible = ref(false);
  906. const dishSearchKeyword = ref("");
  907. const filteredDishList: any = ref([]);
  908. const selectedDishId = ref<number | string | null>(null);
  909. const currentDishGroupIndex = ref<number>(-1);
  910. const currentDishIndex = ref<number>(-1);
  911. // 套餐内容整体展开收起状态
  912. const allGroupsCollapsed = ref(false);
  913. // 每个分组的收起状态(数组,索引对应分组索引)
  914. const groupCollapsedStates = ref<boolean[]>([false]); // 默认第一个分组展开
  915. // 计算属性:过滤要显示的分组(收起全部时只显示第一个分组),保留原始索引
  916. const visibleGroups = computed(() => {
  917. if (allGroupsCollapsed.value) {
  918. return lifeGroupBuyThalis.value.map((group, index) => ({ group, originalIndex: index })).filter((_, index) => index === 0);
  919. }
  920. return lifeGroupBuyThalis.value.map((group, index) => ({ group, originalIndex: index }));
  921. });
  922. // ==================== 监听器 ====================
  923. /**
  924. * 监听不可用日期选项变化
  925. * 当切换到自定义不可用日期时,确保至少有一个日期项
  926. */
  927. watch(
  928. () => storeInfoModel.value.disableDateType,
  929. newVal => {
  930. if (newVal === 2) {
  931. // 切换到自定义不可用日期时,如果disableDateList为空,则添加一个默认项
  932. if (!storeInfoModel.value.disableDateList || storeInfoModel.value.disableDateList.length === 0) {
  933. storeInfoModel.value.disableDateList = [null];
  934. }
  935. }
  936. },
  937. { immediate: true }
  938. );
  939. /**
  940. * 监听开始售卖时间变化
  941. * 当开始时间改变时,重新验证结束时间
  942. */
  943. watch(
  944. () => storeInfoModel.value.saleTimeStr,
  945. () => {
  946. if (storeInfoModel.value.endTime) {
  947. nextTick(() => {
  948. ruleFormRef.value?.validateField("endTime");
  949. });
  950. }
  951. }
  952. );
  953. /**
  954. * 监听结束售卖时间变化
  955. * 当结束时间改变时,重新验证开始时间
  956. */
  957. watch(
  958. () => storeInfoModel.value.endTime,
  959. () => {
  960. if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.saleTimeStr) {
  961. nextTick(() => {
  962. ruleFormRef.value?.validateField("saleTimeStr");
  963. });
  964. }
  965. }
  966. );
  967. // ==================== 生命周期钩子 ====================
  968. /**
  969. * 组件挂载时初始化
  970. * 从路由参数中获取页面类型和ID
  971. */
  972. onMounted(async () => {
  973. id.value = (route.query.id as string) || "";
  974. type.value = (route.query.type as string) || "";
  975. // 不要删除-开始
  976. // let param = {
  977. // // phone: localGet("iphone")
  978. // phone: "18641153170"
  979. // };
  980. // const resP: any = await getUserByPhone(param);
  981. // if (resP.data && resP.data.storeId) {
  982. // localSet("createdId", resP.data.storeId);
  983. // const resD: any = await getDetail({
  984. // id: localGet("createdId")
  985. // });
  986. // if (resD.data && resD.data.commissionRate) {
  987. // localSet("commissionRate", resD.data.commissionRate);
  988. // }
  989. // if (resD.data && resD.data.businessSection) {
  990. // localSet("businessSection", resD.data.businessSection);
  991. // }
  992. // } else {
  993. // ElMessage.warning("请完成商家入驻后再进行新建团购");
  994. // }
  995. // if (!getGroupCombination()) {
  996. // ElMessage.warning("请完成商家入驻后重新登录再进行新建团购");
  997. // return;
  998. // }
  999. // 不要删除-结束
  1000. let params = {
  1001. year: new Date().getFullYear(),
  1002. page: 1,
  1003. size: 500,
  1004. openFlag: 1,
  1005. holidayName: ""
  1006. };
  1007. let res: any = await getHolidayList(params);
  1008. if (res && res.code == 200) {
  1009. holidayList.value = res.data.records;
  1010. }
  1011. if (type.value != "add") {
  1012. let res: any = await getStoreDetail({ id: id.value } as any);
  1013. storeInfoModel.value = { ...storeInfoModel.value, ...res.data.lifeGroupBuyMain };
  1014. let imageList: any[] = [];
  1015. handleImageParam((res.data as any).businessLicenseAddress || [], imageList);
  1016. storeInfoModel.value.imageList = imageList;
  1017. storeInfoModel.value.expirationDateList = storeInfoModel.value.expirationDateList.split(";");
  1018. storeInfoModel.value.invoiceInformation = storeInfoModel.value.invoiceType.split(";");
  1019. // 确保星期和节日字段存在
  1020. const listVal = storeInfoModel.value.disableDateValue.split(";");
  1021. storeInfoModel.value.unavailableWeekdays = listVal[0].split(",");
  1022. storeInfoModel.value.unavailableHolidays = listVal[1].split(",");
  1023. if (res.data.lifeGroupBuyThalis && res.data.lifeGroupBuyThalis.length > 0) {
  1024. lifeGroupBuyThalis.value = res.data.lifeGroupBuyThalis;
  1025. // 确保每个分组都有必要的字段
  1026. lifeGroupBuyThalis.value.forEach((group: any) => {
  1027. if (!group.dishes || group.dishes.length === 0) {
  1028. group.dishes = [
  1029. {
  1030. detailId: "",
  1031. qty: ""
  1032. }
  1033. ];
  1034. }
  1035. });
  1036. // 初始化所有分组的收起状态为展开
  1037. groupCollapsedStates.value = new Array(lifeGroupBuyThalis.value.length).fill(false);
  1038. } else {
  1039. // 如果没有数据,使用默认值
  1040. lifeGroupBuyThalis.value = [
  1041. {
  1042. groupName: "",
  1043. dishes: [
  1044. {
  1045. detailId: "",
  1046. dishName: "",
  1047. dishPrice: "",
  1048. dishImage: "",
  1049. qty: "",
  1050. dishesUnit: ""
  1051. }
  1052. ]
  1053. }
  1054. ];
  1055. // 初始化默认分组的收起状态为展开
  1056. groupCollapsedStates.value = [false];
  1057. }
  1058. // 确保自定义不可用日期字段存在
  1059. if (storeInfoModel.value.disableDateType === 2) {
  1060. // 后端直接返回 disableDateList 字段,如果为空则初始化为默认值
  1061. if (!storeInfoModel.value.disableDateList || storeInfoModel.value.disableDateList.length === 0) {
  1062. storeInfoModel.value.disableDateList = [null];
  1063. }
  1064. }
  1065. }
  1066. });
  1067. // ==================== 事件处理函数 ====================
  1068. /**
  1069. * 返回上一页
  1070. */
  1071. const goBack = () => {
  1072. router.go(-1);
  1073. };
  1074. /**
  1075. * 图片上传 - 删除前确认
  1076. * @param uploadFile 要删除的文件对象
  1077. * @param uploadFiles 当前文件列表
  1078. * @returns Promise<boolean>,true 允许删除,false 阻止删除
  1079. */
  1080. const handleBeforeRemove = async (uploadFile: any, uploadFiles: any[]): Promise<boolean> => {
  1081. try {
  1082. await ElMessageBox.confirm("确定要删除这张图片吗?", "提示", {
  1083. confirmButtonText: "确定",
  1084. cancelButtonText: "取消",
  1085. type: "warning"
  1086. });
  1087. // 用户确认删除,返回 true 允许删除
  1088. return true;
  1089. } catch {
  1090. // 用户取消删除,返回 false 阻止删除
  1091. return false;
  1092. }
  1093. };
  1094. /**
  1095. * 图片上传 - 移除图片回调(删除成功后调用)
  1096. * @param uploadFile 已删除的文件对象
  1097. * @param uploadFiles 删除后的文件列表
  1098. */
  1099. const handleRemove: UploadProps["onRemove"] = (uploadFile, uploadFiles) => {
  1100. // 删除成功后提示
  1101. ElMessage.success("图片已删除");
  1102. };
  1103. /**
  1104. * 图片上传 - 上传成功回调
  1105. * @param response 上传响应数据
  1106. */
  1107. const handleSuccess = (response: any) => {
  1108. ElMessage.success("图片上传成功");
  1109. // 上传成功后,imageList 会自动更新,response.data 包含图片URL
  1110. };
  1111. /**
  1112. * 图片预览 - 使用 el-image 预览功能
  1113. * @param file 上传文件对象
  1114. */
  1115. const handlePictureCardPreview = (file: any) => {
  1116. // 获取所有图片的 URL 列表
  1117. const urlList = storeInfoModel.value.imageList.map((item: any) => item.url || item.response?.data || item);
  1118. // 找到当前点击的图片索引
  1119. const currentIndex = urlList.findIndex((url: string) => url === file.url);
  1120. imageViewerUrlList.value = urlList;
  1121. imageViewerInitialIndex.value = currentIndex >= 0 ? currentIndex : 0;
  1122. imageViewerVisible.value = true;
  1123. };
  1124. /**
  1125. * 添加自定义不可用日期
  1126. */
  1127. const addDate = () => {
  1128. storeInfoModel.value.disableDateList.push(null);
  1129. };
  1130. /**
  1131. * 删除自定义不可用日期
  1132. * @param index 要删除的日期索引
  1133. */
  1134. const removeDate = (index: number) => {
  1135. if (storeInfoModel.value.disableDateList.length <= 1) {
  1136. ElMessage.warning("至少需要保留一个日期项");
  1137. return;
  1138. }
  1139. storeInfoModel.value.disableDateList.splice(index, 1);
  1140. // 删除日期项后,重新验证表单以清除旧的验证错误
  1141. nextTick(() => {
  1142. ruleFormRef.value?.validateField("customUnavailableDates");
  1143. });
  1144. };
  1145. /**
  1146. * 切换星期选择
  1147. * @param value 星期值
  1148. */
  1149. const toggleWeekday = value => {
  1150. if (!storeInfoModel.value.unavailableWeekdays) {
  1151. storeInfoModel.value.unavailableWeekdays = [];
  1152. }
  1153. const index = storeInfoModel.value.unavailableWeekdays.indexOf(value);
  1154. if (index > -1) {
  1155. storeInfoModel.value.unavailableWeekdays.splice(index, 1);
  1156. } else {
  1157. storeInfoModel.value.unavailableWeekdays.push(value);
  1158. }
  1159. console.log(storeInfoModel.value.unavailableWeekdays);
  1160. // 触发表单验证
  1161. nextTick(() => {
  1162. ruleFormRef.value?.validateField("unavailableWeekdays");
  1163. });
  1164. };
  1165. /**
  1166. * 切换节日选择
  1167. * @param value 节日值
  1168. */
  1169. const toggleHoliday = value => {
  1170. if (!storeInfoModel.value.unavailableHolidays) {
  1171. storeInfoModel.value.unavailableHolidays = [];
  1172. }
  1173. const index = storeInfoModel.value.unavailableHolidays.indexOf(value);
  1174. if (index > -1) {
  1175. storeInfoModel.value.unavailableHolidays.splice(index, 1);
  1176. } else {
  1177. storeInfoModel.value.unavailableHolidays.push(value);
  1178. }
  1179. console.log(storeInfoModel.value.unavailableHolidays);
  1180. // 触发表单验证
  1181. nextTick(() => {
  1182. ruleFormRef.value?.validateField("unavailableHolidays");
  1183. });
  1184. };
  1185. /**
  1186. * 添加套餐分组
  1187. */
  1188. const addGroup = () => {
  1189. if (!lifeGroupBuyThalis.value) {
  1190. lifeGroupBuyThalis.value = [];
  1191. }
  1192. // 检查分组数量限制(最多20个)
  1193. if (lifeGroupBuyThalis.value.length >= 20) {
  1194. ElMessage.warning("最多只能添加20个分组");
  1195. return;
  1196. }
  1197. // 验证所有现有分组是否填写完整
  1198. for (let i = 0; i < lifeGroupBuyThalis.value.length; i++) {
  1199. const group = lifeGroupBuyThalis.value[i];
  1200. // 验证类别
  1201. if (!group.groupName || group.groupName.trim() === "") {
  1202. ElMessage.warning("请先完成现有分组的填写");
  1203. // 触发表单验证,显示验证错误
  1204. nextTick(() => {
  1205. if (packageFormRef.value) {
  1206. packageFormRef.value.validate(() => {});
  1207. }
  1208. });
  1209. return;
  1210. }
  1211. // 验证是否有菜品
  1212. if (!group.dishes || group.dishes.length === 0) {
  1213. ElMessage.warning("请先完成现有分组的填写");
  1214. // 触发表单验证,显示验证错误
  1215. nextTick(() => {
  1216. if (packageFormRef.value) {
  1217. packageFormRef.value.validate(() => {});
  1218. }
  1219. });
  1220. return;
  1221. }
  1222. // 验证当前分组中每个菜品是否填写完整
  1223. for (let j = 0; j < group.dishes.length; j++) {
  1224. const dish = group.dishes[j];
  1225. // 验证菜品是否已选择
  1226. if (!dish.detailId) {
  1227. ElMessage.warning("请先完成现有分组的填写");
  1228. // 触发表单验证,显示验证错误
  1229. nextTick(() => {
  1230. if (packageFormRef.value) {
  1231. packageFormRef.value.validate(() => {});
  1232. }
  1233. });
  1234. return;
  1235. }
  1236. // 验证数量是否已填写
  1237. if (!dish.qty || dish.qty.toString().trim() === "") {
  1238. ElMessage.warning("请先完成现有分组的填写");
  1239. // 触发表单验证,显示验证错误
  1240. nextTick(() => {
  1241. if (packageFormRef.value) {
  1242. packageFormRef.value.validate(() => {});
  1243. }
  1244. });
  1245. return;
  1246. }
  1247. // 验证数量格式
  1248. const quantityNum = Number(dish.qty);
  1249. if (isNaN(quantityNum) || quantityNum <= 0 || !Number.isInteger(quantityNum)) {
  1250. ElMessage.warning("请先完成现有分组的填写");
  1251. // 触发表单验证,显示验证错误
  1252. nextTick(() => {
  1253. if (packageFormRef.value) {
  1254. packageFormRef.value.validate(() => {});
  1255. }
  1256. });
  1257. return;
  1258. }
  1259. }
  1260. }
  1261. // 添加新分组
  1262. lifeGroupBuyThalis.value.push({
  1263. groupName: "",
  1264. dishes: [
  1265. {
  1266. detailId: "",
  1267. dishName: "",
  1268. dishPrice: "",
  1269. dishImage: "",
  1270. qty: "",
  1271. dishesUnit: ""
  1272. }
  1273. ]
  1274. });
  1275. // 初始化新分组的收起状态为展开
  1276. groupCollapsedStates.value.push(false);
  1277. // 清除表单验证状态,避免新分组显示验证错误
  1278. // 使用延迟清除,确保在验证规则更新和 DOM 渲染完成后再清除
  1279. nextTick(() => {
  1280. requestAnimationFrame(() => {
  1281. setTimeout(() => {
  1282. if (packageFormRef.value) {
  1283. // 只清除新添加分组的验证状态
  1284. const newGroupIndex = lifeGroupBuyThalis.value.length - 1;
  1285. const propsToClear = [
  1286. `groups.${newGroupIndex}.groupName`,
  1287. `groups.${newGroupIndex}.dishes.0.detailId`,
  1288. `groups.${newGroupIndex}.dishes.0.qty`
  1289. ];
  1290. // Element Plus 的 clearValidate 可以接受字符串数组
  1291. propsToClear.forEach(prop => {
  1292. packageFormRef.value?.clearValidate(prop);
  1293. });
  1294. }
  1295. }, 150);
  1296. });
  1297. });
  1298. };
  1299. /**
  1300. * 删除套餐分组
  1301. * @param groupIndex 分组索引
  1302. */
  1303. const removeGroup = (groupIndex: number) => {
  1304. if (lifeGroupBuyThalis.value.length <= 1) {
  1305. ElMessage.warning("至少需要保留一个分组");
  1306. return;
  1307. }
  1308. ElMessageBox.confirm("确定要删除这个分组吗?", "提示", {
  1309. confirmButtonText: "确定",
  1310. cancelButtonText: "取消",
  1311. type: "warning"
  1312. })
  1313. .then(() => {
  1314. lifeGroupBuyThalis.value.splice(groupIndex, 1);
  1315. // 同步删除收起状态数组中的对应项
  1316. if (groupCollapsedStates.value.length > groupIndex) {
  1317. groupCollapsedStates.value.splice(groupIndex, 1);
  1318. }
  1319. ElMessage.success("删除成功");
  1320. })
  1321. .catch(() => {});
  1322. };
  1323. /**
  1324. * 判断分组是否收起
  1325. * @param groupIndex 分组索引
  1326. * @returns 是否收起(收起时只显示类别和第一行菜品,隐藏其他菜品行)
  1327. */
  1328. const isGroupCollapsed = (groupIndex: number): boolean => {
  1329. // 如果"收起全部"状态为true,第一个分组应该展开(显示所有菜品),其他分组收起
  1330. if (allGroupsCollapsed.value) {
  1331. return groupIndex !== 0;
  1332. }
  1333. // 否则根据分组的收起状态判断
  1334. return groupCollapsedStates.value[groupIndex] === true;
  1335. };
  1336. /**
  1337. * 切换单个分组的收起/展开状态
  1338. * @param groupIndex 分组索引
  1339. */
  1340. const toggleGroupCollapse = (groupIndex: number) => {
  1341. // 如果当前是"收起全部"状态,先取消该状态
  1342. if (allGroupsCollapsed.value) {
  1343. allGroupsCollapsed.value = false;
  1344. // 设置所有分组状态:第一个分组当前是展开的,其他分组当前是收起的
  1345. // 所以第一个分组应该设置为收起,其他分组应该设置为展开
  1346. groupCollapsedStates.value = new Array(lifeGroupBuyThalis.value.length).fill(true);
  1347. groupCollapsedStates.value[0] = false; // 第一个分组原本是展开的
  1348. // 然后切换当前分组的状态
  1349. groupCollapsedStates.value[groupIndex] = !groupCollapsedStates.value[groupIndex];
  1350. } else {
  1351. // 确保数组长度足够
  1352. while (groupCollapsedStates.value.length <= groupIndex) {
  1353. groupCollapsedStates.value.push(false);
  1354. }
  1355. groupCollapsedStates.value[groupIndex] = !groupCollapsedStates.value[groupIndex];
  1356. }
  1357. };
  1358. /**
  1359. * 切换所有分组的收起/展开状态
  1360. * 收起全部时保留第一个分组展开
  1361. */
  1362. const toggleAllGroupsCollapse = () => {
  1363. if (allGroupsCollapsed.value) {
  1364. // 展开全部:将所有分组设置为展开状态
  1365. allGroupsCollapsed.value = false;
  1366. groupCollapsedStates.value = groupCollapsedStates.value.map(() => false);
  1367. } else {
  1368. // 收起全部:收起除第一个分组外的所有分组
  1369. allGroupsCollapsed.value = true;
  1370. groupCollapsedStates.value = groupCollapsedStates.value.map((_, index) => index !== 0);
  1371. // 确保数组长度足够
  1372. while (groupCollapsedStates.value.length < lifeGroupBuyThalis.value.length) {
  1373. groupCollapsedStates.value.push(true);
  1374. }
  1375. }
  1376. };
  1377. /**
  1378. * 添加菜品
  1379. * @param groupIndex 分组索引
  1380. */
  1381. const addDish = (groupIndex: number) => {
  1382. const group = lifeGroupBuyThalis.value[groupIndex];
  1383. // 检查菜品数量限制(每个分组最多20个菜品)
  1384. if (group.dishes && group.dishes.length >= 20) {
  1385. ElMessage.warning("每个分组最多只能添加20个菜品");
  1386. return;
  1387. }
  1388. // 验证当前分组是否填写完整
  1389. // 验证类别
  1390. if (!group.groupName || group.groupName.trim() === "") {
  1391. ElMessage.warning("请先完成现有菜品的填写");
  1392. // 触发表单验证,显示验证错误
  1393. nextTick(() => {
  1394. if (packageFormRef.value) {
  1395. packageFormRef.value.validate(() => {});
  1396. }
  1397. });
  1398. return;
  1399. }
  1400. // 验证是否有菜品
  1401. if (!group.dishes || group.dishes.length === 0) {
  1402. ElMessage.warning("请先完成现有菜品的填写");
  1403. // 触发表单验证,显示验证错误
  1404. nextTick(() => {
  1405. if (packageFormRef.value) {
  1406. packageFormRef.value.validate(() => {});
  1407. }
  1408. });
  1409. return;
  1410. }
  1411. // 验证当前分组中每个菜品是否填写完整
  1412. for (let j = 0; j < group.dishes.length; j++) {
  1413. const dish = group.dishes[j];
  1414. // 验证菜品是否已选择
  1415. if (!dish.detailId) {
  1416. ElMessage.warning("请先完成现有菜品的填写");
  1417. // 触发表单验证,显示验证错误
  1418. nextTick(() => {
  1419. if (packageFormRef.value) {
  1420. packageFormRef.value.validate(() => {});
  1421. }
  1422. });
  1423. return;
  1424. }
  1425. // 验证数量是否已填写
  1426. if (!dish.qty || dish.qty.toString().trim() === "") {
  1427. ElMessage.warning("请先完成现有菜品的填写");
  1428. // 触发表单验证,显示验证错误
  1429. nextTick(() => {
  1430. if (packageFormRef.value) {
  1431. packageFormRef.value.validate(() => {});
  1432. }
  1433. });
  1434. return;
  1435. }
  1436. // 验证数量格式
  1437. const quantityNum = Number(dish.qty);
  1438. if (isNaN(quantityNum) || quantityNum <= 0 || !Number.isInteger(quantityNum)) {
  1439. ElMessage.warning("请先完成现有菜品的填写");
  1440. // 触发表单验证,显示验证错误
  1441. nextTick(() => {
  1442. if (packageFormRef.value) {
  1443. packageFormRef.value.validate(() => {});
  1444. }
  1445. });
  1446. return;
  1447. }
  1448. }
  1449. // 所有验证通过,添加新菜品
  1450. if (!group.dishes) {
  1451. group.dishes = [];
  1452. }
  1453. group.dishes.push({
  1454. detailId: "",
  1455. dishName: "",
  1456. dishPrice: "",
  1457. dishImage: "",
  1458. qty: "",
  1459. dishesUnit: ""
  1460. });
  1461. // 清除新添加菜品的验证状态,避免立即显示验证错误
  1462. // 使用延迟清除,确保在验证规则更新和 DOM 渲染完成后再清除
  1463. nextTick(() => {
  1464. requestAnimationFrame(() => {
  1465. setTimeout(() => {
  1466. if (packageFormRef.value) {
  1467. // 只清除新添加菜品的验证状态
  1468. const newDishIndex = group.dishes.length - 1;
  1469. const propsToClear = [
  1470. `groups.${groupIndex}.dishes.${newDishIndex}.detailId`,
  1471. `groups.${groupIndex}.dishes.${newDishIndex}.qty`
  1472. ];
  1473. // Element Plus 的 clearValidate 可以接受字符串
  1474. propsToClear.forEach(prop => {
  1475. packageFormRef.value?.clearValidate(prop);
  1476. });
  1477. }
  1478. }, 150);
  1479. });
  1480. });
  1481. };
  1482. /**
  1483. * 删除菜品
  1484. * @param groupIndex 分组索引
  1485. * @param dishIndex 菜品索引
  1486. */
  1487. const removeDish = (groupIndex: number, dishIndex: number) => {
  1488. const dishes = lifeGroupBuyThalis.value[groupIndex].dishes;
  1489. if (dishes.length <= 1) {
  1490. ElMessage.warning("至少需要保留一个菜品");
  1491. return;
  1492. }
  1493. dishes.splice(dishIndex, 1);
  1494. };
  1495. /**
  1496. * 打开菜品选择对话框
  1497. * @param groupIndex 分组索引
  1498. * @param dishIndex 菜品索引
  1499. */
  1500. const openDishDialog = async (groupIndex: number, dishIndex: number) => {
  1501. currentDishGroupIndex.value = groupIndex;
  1502. currentDishIndex.value = dishIndex;
  1503. dishSearchKeyword.value = "";
  1504. const params = {
  1505. storeId: 104,
  1506. phoneId: 18641153170,
  1507. dishType: 0
  1508. };
  1509. const res = await getMenuByStoreId(params);
  1510. if (res && res.code == 200) {
  1511. dishOptions.value = res.data;
  1512. }
  1513. // 如果已有选中的菜品,设置选中状态
  1514. const currentDish = lifeGroupBuyThalis.value[groupIndex].dishes[dishIndex];
  1515. selectedDishId.value = currentDish?.detailId || null;
  1516. filterDishList();
  1517. dishDialogVisible.value = true;
  1518. };
  1519. /**
  1520. * 选择菜品
  1521. * @param dish 菜品对象
  1522. */
  1523. const selectDish = (dish: any) => {
  1524. selectedDishId.value = dish.id;
  1525. };
  1526. /**
  1527. * 确认菜品选择
  1528. */
  1529. const confirmDishSelection = () => {
  1530. if (selectedDishId.value === null) {
  1531. ElMessage.warning("请选择一个菜品");
  1532. return;
  1533. }
  1534. const selectedDish: any = dishOptions.value.find(dish => dish.id === selectedDishId.value);
  1535. if (selectedDish && currentDishGroupIndex.value >= 0 && currentDishIndex.value >= 0) {
  1536. const dish = lifeGroupBuyThalis.value[currentDishGroupIndex.value].dishes[currentDishIndex.value];
  1537. dish.detailId = selectedDish.id;
  1538. dish.dishName = selectedDish.dishName;
  1539. dish.dishPrice = selectedDish.dishPrice;
  1540. dish.dishImage = selectedDish.imgUrl;
  1541. dish.dishesUnit = selectedDish.dishesUnit;
  1542. dishDialogVisible.value = false;
  1543. // 重新验证对应的字段,如果验证通过,错误提示会消失
  1544. nextTick(() => {
  1545. if (packageFormRef.value) {
  1546. const prop = `groups.${currentDishGroupIndex.value}.dishes.${currentDishIndex.value}.detailId`;
  1547. packageFormRef.value.validateField(prop, () => {});
  1548. }
  1549. });
  1550. }
  1551. };
  1552. /**
  1553. * 过滤菜品列表
  1554. * 排除已经在其他分组中被选择的菜品(当前正在编辑的菜品除外)
  1555. */
  1556. const filterDishList = () => {
  1557. // 获取当前正在编辑的菜品ID(如果有)
  1558. const currentDishId = selectedDishId.value;
  1559. // 收集所有其他分组中已选择的菜品ID
  1560. const selectedDishIds = new Set<number | string>();
  1561. lifeGroupBuyThalis.value.forEach((group, groupIndex) => {
  1562. if (group.dishes && group.dishes.length > 0) {
  1563. group.dishes.forEach((dish, dishIndex) => {
  1564. // 排除当前正在编辑的菜品
  1565. if (dish.detailId && !(groupIndex === currentDishGroupIndex.value && dishIndex === currentDishIndex.value)) {
  1566. selectedDishIds.add(dish.detailId);
  1567. }
  1568. });
  1569. }
  1570. });
  1571. // 先根据搜索关键词过滤
  1572. let filtered = dishOptions.value;
  1573. if (dishSearchKeyword.value && dishSearchKeyword.value.trim() !== "") {
  1574. const keyword = dishSearchKeyword.value.trim().toLowerCase();
  1575. filtered = dishOptions.value.filter(dish => dish.dishName.toLowerCase().includes(keyword));
  1576. }
  1577. // 再排除已在其他分组中被选择的菜品(但保留当前正在编辑的菜品)
  1578. filteredDishList.value = filtered.filter(dish => {
  1579. // 如果是当前正在编辑的菜品,保留
  1580. if (currentDishId && dish.id === currentDishId) {
  1581. return true;
  1582. }
  1583. // 如果菜品已在其他分组中被选择,排除
  1584. return !selectedDishIds.has(dish.id);
  1585. });
  1586. };
  1587. // ==================== 表单引用 ====================
  1588. const ruleFormRef = ref<FormInstance>(); // 表单引用
  1589. const packageFormRef = ref<FormInstance>(); // 套餐内容表单引用
  1590. // 套餐内容表单模型(用于验证)
  1591. const packageFormModel = computed(() => {
  1592. return {
  1593. groups: lifeGroupBuyThalis.value
  1594. };
  1595. });
  1596. // 套餐内容验证规则
  1597. const packageFormRules = computed(() => {
  1598. const rules: any = {};
  1599. lifeGroupBuyThalis.value.forEach((group, groupIndex) => {
  1600. // 类别验证规则 - 使用与 prop 相同的路径格式
  1601. rules[`groups.${groupIndex}.groupName`] = [
  1602. {
  1603. required: true,
  1604. message: `第${groupIndex + 1}个分组的类别不能为空`,
  1605. trigger: "blur"
  1606. }
  1607. ];
  1608. // 每个菜品的验证规则
  1609. if (group.dishes) {
  1610. group.dishes.forEach((dish, dishIndex) => {
  1611. // 菜品选择验证
  1612. rules[`groups.${groupIndex}.dishes.${dishIndex}.detailId`] = [
  1613. {
  1614. required: true,
  1615. message: `第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品未选择`,
  1616. trigger: "change"
  1617. }
  1618. ];
  1619. // 菜品数量验证
  1620. rules[`groups.${groupIndex}.dishes.${dishIndex}.qty`] = [
  1621. {
  1622. required: true,
  1623. message: `第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品数量不能为空`,
  1624. trigger: "blur"
  1625. },
  1626. {
  1627. validator: (rule: any, value: any, callback: any) => {
  1628. if (!value || value.toString().trim() === "") {
  1629. callback();
  1630. return;
  1631. }
  1632. const num = Number(value);
  1633. if (isNaN(num) || num <= 0) {
  1634. callback(new Error(`第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品数量必须为正整数`));
  1635. return;
  1636. }
  1637. if (!Number.isInteger(num)) {
  1638. callback(new Error(`第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品数量必须为正整数`));
  1639. return;
  1640. }
  1641. callback();
  1642. },
  1643. trigger: "blur"
  1644. }
  1645. ];
  1646. });
  1647. }
  1648. });
  1649. return rules;
  1650. });
  1651. /**
  1652. * 提交数据(新增/编辑)
  1653. * 验证表单,通过后调用相应的API接口
  1654. */
  1655. const handleSubmit = (type?) => {
  1656. let params: any = { ...storeInfoModel.value };
  1657. if (params.effectiveDateType == 0) {
  1658. // params.couponCompDate = `用户购买${params.expirationDate}天内有效`;
  1659. } else {
  1660. params.expirationDateList = params.expirationDateList.join(",");
  1661. }
  1662. if (params.disableDateType == 1) {
  1663. params.disableDateValue = params.unavailableWeekdays.join(",") + ";" + params.unavailableHolidays.join(",");
  1664. // params.disableDateValue = [params.unavailableWeekdays, params.unavailableHolidays];
  1665. delete params.unavailableWeekdays;
  1666. delete params.unavailableHolidays;
  1667. } else if (params.disableDateType == 2) {
  1668. // params.disableDateValue = params.disableDateList.map(subArray => subArray.join(",")).join(";");
  1669. }
  1670. params.invoiceType = params.invoiceInformation.join(",");
  1671. // const output = lifeGroupBuyThalis.value.flatMap(group =>
  1672. // group.dishes.map(dish => ({
  1673. // groupName: group.groupName,
  1674. // detailId: dish.detailId,
  1675. // qty: dish.qty,
  1676. // dishPrice: dish.dishPrice
  1677. // }))
  1678. // );
  1679. const paramsObj = {
  1680. lifeGroupBuyMain: params,
  1681. lifeGroupBuyThalis: lifeGroupBuyThalis.value
  1682. };
  1683. console.log(paramsObj);
  1684. if (type) {
  1685. return;
  1686. }
  1687. // 验证表单
  1688. ruleFormRef.value!.validate(async valid => {
  1689. if (!valid) return;
  1690. // 验证套餐内容表单
  1691. if (packageFormRef.value) {
  1692. let packageValid = false;
  1693. await new Promise<void>(resolve => {
  1694. packageFormRef.value!.validate(valid => {
  1695. packageValid = valid;
  1696. if (!valid) {
  1697. ElMessage.error("请完善套餐内容信息");
  1698. }
  1699. resolve();
  1700. });
  1701. });
  1702. if (!packageValid) {
  1703. return;
  1704. }
  1705. }
  1706. // 组装提交参数
  1707. let params: any = { ...storeInfoModel.value };
  1708. params.lifeGroupBuyThalis = lifeGroupBuyThalis.value;
  1709. });
  1710. };
  1711. // ==================== 工具函数 ====================
  1712. /**
  1713. * 禁用开始售卖时间的日期
  1714. * 不能选择早于当前时间的日期
  1715. * @param time 日期对象
  1716. * @returns 是否禁用该日期
  1717. */
  1718. const disabledStartDate = (time: Date) => {
  1719. const today = new Date();
  1720. today.setHours(0, 0, 0, 0);
  1721. return time.getTime() < today.getTime();
  1722. };
  1723. /**
  1724. * 禁用结束售卖时间的日期
  1725. * 不能选择早于当前时间的日期,也不能选择早于或等于开始售卖时间的日期
  1726. * @param time 日期对象
  1727. * @returns 是否禁用该日期
  1728. */
  1729. const disabledEndDate = (time: Date) => {
  1730. const today = new Date();
  1731. today.setHours(0, 0, 0, 0);
  1732. // 不能早于当前时间
  1733. if (time.getTime() < today.getTime()) {
  1734. return true;
  1735. }
  1736. // 如果开始售卖时间已设置,不能早于或等于开始时间
  1737. if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.saleTimeStr) {
  1738. const startDate = new Date(storeInfoModel.value.saleTimeStr);
  1739. startDate.setHours(0, 0, 0, 0);
  1740. return time.getTime() <= startDate.getTime();
  1741. }
  1742. return false;
  1743. };
  1744. /**
  1745. * 禁用指定时间段内可用的日期
  1746. * 不能选择早于当前时间的日期
  1747. * @param time 日期对象
  1748. * @returns 是否禁用该日期
  1749. */
  1750. const disabledEffectiveDate = (time: Date) => {
  1751. const today = new Date();
  1752. today.setHours(0, 0, 0, 0);
  1753. return time.getTime() < today.getTime();
  1754. };
  1755. /**
  1756. * 禁用自定义不可用日期的日期
  1757. * 不能选择早于当前时间的日期
  1758. * @param time 日期对象
  1759. * @returns 是否禁用该日期
  1760. */
  1761. const disabledCustomUnavailableDate = (time: Date) => {
  1762. const today = new Date();
  1763. today.setHours(0, 0, 0, 0);
  1764. return time.getTime() < today.getTime();
  1765. };
  1766. /**
  1767. * 处理图片结果
  1768. * 将上传组件的文件对象或URL字符串转换为URL数组
  1769. * @param list 图片列表(可能是文件对象或URL字符串)
  1770. * @returns URL字符串数组
  1771. */
  1772. const handleImageResult = (list: any[]): string[] => {
  1773. let result: string[] = [];
  1774. (list || []).forEach((item: any) => {
  1775. if (item.uid) {
  1776. // 如果是上传组件的文件对象,取url属性
  1777. result.push(item.url);
  1778. } else {
  1779. // 如果是URL字符串,直接添加
  1780. result.push(item);
  1781. }
  1782. });
  1783. return result;
  1784. };
  1785. //图片list 转换为upload 组件的参数
  1786. const handleImageParam = (list: any[], result: any[]) => {
  1787. (list || []).forEach((item: any) => {
  1788. // 使用split方法以'/'为分隔符将URL拆分成数组
  1789. const parts = item.split("/");
  1790. // 取数组的最后一项,即图片名称
  1791. const imageName = parts[parts.length - 1];
  1792. result.push({
  1793. name: imageName,
  1794. percentage: 100,
  1795. url: item
  1796. });
  1797. });
  1798. };
  1799. </script>
  1800. <style scoped lang="scss">
  1801. /* 页面容器 */
  1802. .table-box {
  1803. display: flex;
  1804. flex-direction: column;
  1805. height: auto !important;
  1806. min-height: 100%;
  1807. }
  1808. /* 头部区域 */
  1809. .header {
  1810. display: flex;
  1811. align-items: center;
  1812. padding: 20px;
  1813. border-bottom: 1px solid #e4e7ed;
  1814. }
  1815. .title {
  1816. flex: 1;
  1817. margin: 0;
  1818. font-size: 18px;
  1819. font-weight: bold;
  1820. text-align: center;
  1821. }
  1822. /* 内容区域布局 */
  1823. .content {
  1824. display: flex;
  1825. flex: 1;
  1826. column-gap: 20px;
  1827. width: 98%;
  1828. margin: 20px auto;
  1829. /* 左侧内容区域 */
  1830. .contentLeft {
  1831. width: 50%;
  1832. }
  1833. /* 右侧内容区域 */
  1834. .contentRight {
  1835. width: 50%;
  1836. }
  1837. }
  1838. /* 模块容器 */
  1839. .model {
  1840. margin-bottom: 50px;
  1841. }
  1842. /* 表单容器 */
  1843. .formBox {
  1844. display: flex;
  1845. flex-direction: column;
  1846. width: 100%;
  1847. min-height: 100%;
  1848. }
  1849. /* 底部按钮容器 - 居中显示 */
  1850. .button-container {
  1851. display: flex;
  1852. gap: 12px;
  1853. align-items: center;
  1854. justify-content: center;
  1855. padding: 20px 0;
  1856. margin-top: 20px;
  1857. }
  1858. /* 日期选择器容器 */
  1859. .date-picker-container {
  1860. display: flex;
  1861. flex-direction: column;
  1862. gap: 12px;
  1863. width: 100%;
  1864. }
  1865. /* 添加日期按钮 */
  1866. .add-date-btn {
  1867. width: fit-content;
  1868. margin-bottom: 8px;
  1869. }
  1870. /* 日期项容器 */
  1871. .date-item {
  1872. display: flex;
  1873. gap: 12px;
  1874. align-items: center;
  1875. padding: 8px;
  1876. // background-color: #f5f7fa;
  1877. border-radius: 4px;
  1878. transition: background-color 0.1s;
  1879. &:hover {
  1880. background-color: #ecf5ff;
  1881. }
  1882. }
  1883. /* 日期选择器 */
  1884. .date-item .date-picker {
  1885. flex: 1;
  1886. max-width: 500px;
  1887. }
  1888. /* 删除按钮 */
  1889. .date-item .delete-btn {
  1890. flex-shrink: 0;
  1891. }
  1892. /* 有效期天数容器 */
  1893. .expiration-date-container {
  1894. display: flex;
  1895. gap: 12px;
  1896. align-items: center;
  1897. width: fit-content;
  1898. padding: 8px 12px;
  1899. // background-color: #f5f7fa;
  1900. border-radius: 4px;
  1901. }
  1902. /* 有效期标签文字 */
  1903. .expiration-label {
  1904. font-size: 14px;
  1905. color: #606266;
  1906. white-space: nowrap;
  1907. }
  1908. /* 有效期输入框 */
  1909. .expiration-input {
  1910. width: 150px;
  1911. }
  1912. /* 不可用日期容器 */
  1913. .unavailable-dates-container {
  1914. display: flex;
  1915. flex-direction: column;
  1916. gap: 20px;
  1917. width: 100%;
  1918. }
  1919. /* 日期选择区块 */
  1920. .date-select-section {
  1921. display: flex;
  1922. flex-direction: column;
  1923. gap: 12px;
  1924. }
  1925. /* 区块标题 */
  1926. .section-title {
  1927. font-size: 14px;
  1928. font-weight: 500;
  1929. color: #606266;
  1930. }
  1931. /* 按钮组 */
  1932. .button-group {
  1933. display: flex;
  1934. flex-wrap: wrap;
  1935. gap: 10px;
  1936. }
  1937. /* 日期选择按钮 */
  1938. .date-select-btn {
  1939. min-width: 80px;
  1940. height: 36px;
  1941. padding: 8px 16px;
  1942. margin: 0;
  1943. font-size: 14px;
  1944. border-radius: 4px;
  1945. transition: all 0.1s;
  1946. }
  1947. /* 套餐内容相关样式 */
  1948. .package-content-item {
  1949. width: 100%;
  1950. }
  1951. .package-content-form {
  1952. width: 100%;
  1953. }
  1954. /* 表单项基础样式 */
  1955. .package-content-form :deep(.el-form-item) {
  1956. margin-bottom: 0;
  1957. }
  1958. .package-content-form :deep(.el-form-item__label) {
  1959. display: none;
  1960. }
  1961. /* 类别表单项样式 */
  1962. .category-form-item {
  1963. width: 100%;
  1964. margin-bottom: 16px;
  1965. }
  1966. .category-form-item :deep(.el-form-item__content) {
  1967. display: flex;
  1968. flex-wrap: wrap;
  1969. align-items: flex-start;
  1970. width: 100%;
  1971. }
  1972. .category-form-item :deep(.el-form-item__error) {
  1973. position: static;
  1974. width: 100%;
  1975. padding-top: 4px;
  1976. padding-left: 62px;
  1977. margin-top: 0;
  1978. font-size: 12px;
  1979. line-height: 1.5;
  1980. color: #f56c6c;
  1981. }
  1982. .category-row .el-input {
  1983. flex: 1;
  1984. max-width: 400px;
  1985. }
  1986. /* 菜品表单项样式 */
  1987. .dish-form-item {
  1988. position: relative;
  1989. flex: 1;
  1990. margin-bottom: 0;
  1991. }
  1992. .dish-form-item :deep(.el-form-item__content) {
  1993. display: flex;
  1994. flex-wrap: wrap;
  1995. gap: 12px;
  1996. align-items: center;
  1997. }
  1998. .dish-form-item :deep(.el-form-item__error) {
  1999. position: absolute;
  2000. top: 100%;
  2001. left: 0;
  2002. z-index: 1;
  2003. padding-top: 4px;
  2004. padding-right: 4px;
  2005. font-size: 12px;
  2006. line-height: 1.5;
  2007. color: #f56c6c;
  2008. white-space: nowrap;
  2009. background-color: #ffffff;
  2010. }
  2011. .package-content-wrapper {
  2012. display: flex;
  2013. flex-direction: column;
  2014. gap: 12px;
  2015. width: 100%;
  2016. }
  2017. .package-content-header {
  2018. display: flex;
  2019. align-items: center;
  2020. justify-content: space-between;
  2021. width: 100%;
  2022. }
  2023. .add-group-btn {
  2024. width: fit-content;
  2025. }
  2026. .package-content-container {
  2027. display: flex;
  2028. flex-direction: column;
  2029. gap: 16px;
  2030. width: 100%;
  2031. }
  2032. .package-group {
  2033. overflow: hidden;
  2034. background-color: white;
  2035. border: 1px solid #e4e7ed;
  2036. border-radius: 4px;
  2037. }
  2038. .package-group-header {
  2039. display: flex;
  2040. align-items: center;
  2041. justify-content: space-between;
  2042. height: 50px;
  2043. padding: 12px 16px;
  2044. background-color: #f5f7fa;
  2045. border-bottom: 1px solid #e4e7ed;
  2046. }
  2047. .group-index {
  2048. flex: 1;
  2049. overflow: hidden;
  2050. font-size: 14px;
  2051. font-weight: 500;
  2052. color: #303133;
  2053. text-overflow: ellipsis;
  2054. white-space: nowrap;
  2055. }
  2056. .header-right {
  2057. display: flex;
  2058. flex-shrink: 0;
  2059. gap: 12px;
  2060. align-items: center;
  2061. }
  2062. .package-group-content {
  2063. display: flex;
  2064. flex-direction: column;
  2065. gap: 16px;
  2066. min-height: 60px;
  2067. padding: 16px;
  2068. }
  2069. .extra-dishes-container {
  2070. display: flex;
  2071. flex-direction: column;
  2072. gap: 16px;
  2073. margin-top: 0;
  2074. }
  2075. .extra-dishes-container .dish-row {
  2076. padding-bottom: 22px;
  2077. margin-bottom: 4px;
  2078. }
  2079. .extra-dishes-container .dish-row:last-child {
  2080. padding-bottom: 0;
  2081. margin-bottom: 0;
  2082. }
  2083. .package-group-collapsed {
  2084. padding: 16px;
  2085. background-color: #fafafa;
  2086. border-top: 1px solid #e4e7ed;
  2087. }
  2088. .collapsed-dish-row {
  2089. display: flex;
  2090. gap: 12px;
  2091. align-items: center;
  2092. }
  2093. .dish-info-text {
  2094. font-size: 14px;
  2095. color: #606266;
  2096. white-space: nowrap;
  2097. }
  2098. .dish-info-text.empty-text {
  2099. color: #c0c4cc;
  2100. }
  2101. .category-row {
  2102. display: flex;
  2103. gap: 12px;
  2104. align-items: center;
  2105. width: 100%;
  2106. }
  2107. .dish-row {
  2108. position: relative;
  2109. display: flex;
  2110. gap: 12px;
  2111. align-items: flex-start;
  2112. width: 100%;
  2113. margin-bottom: 4px;
  2114. }
  2115. .dish-row:last-child {
  2116. padding-bottom: 0;
  2117. margin-bottom: 0;
  2118. }
  2119. /* 当表单项有错误时,增加底部间距 */
  2120. .dish-row .dish-form-item.is-error {
  2121. margin-bottom: 0;
  2122. }
  2123. .label {
  2124. min-width: 50px;
  2125. font-size: 14px;
  2126. color: #606266;
  2127. white-space: nowrap;
  2128. }
  2129. .dish-select-block {
  2130. position: relative;
  2131. display: flex;
  2132. flex: 1;
  2133. align-items: center;
  2134. max-width: 300px;
  2135. min-height: 32px;
  2136. padding: 0 11px;
  2137. cursor: pointer;
  2138. background-color: #ffffff;
  2139. border: 1px solid #dcdfe6;
  2140. border-radius: 4px;
  2141. transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  2142. }
  2143. .dish-select-block:hover {
  2144. border-color: #c0c4cc;
  2145. }
  2146. .dish-select-block:focus-within {
  2147. border-color: #409eff;
  2148. }
  2149. /* 当菜品选择有验证错误时,显示错误边框 */
  2150. .dish-form-item.is-error .dish-select-block {
  2151. border-color: #f56c6c;
  2152. }
  2153. .dish-form-item.is-error .dish-select-block:hover {
  2154. border-color: #f56c6c;
  2155. }
  2156. .dish-form-item.is-error .dish-select-block:focus-within {
  2157. border-color: #f56c6c;
  2158. }
  2159. /* 优化表单项的错误状态 */
  2160. .package-content-form :deep(.el-form-item.is-error .el-input__wrapper) {
  2161. box-shadow: 0 0 0 1px #f56c6c inset;
  2162. }
  2163. .package-content-form :deep(.el-form-item.is-error .el-input__wrapper:hover) {
  2164. box-shadow: 0 0 0 1px #f56c6c inset;
  2165. }
  2166. .package-content-form :deep(.el-form-item.is-error .el-input__wrapper.is-focus) {
  2167. box-shadow: 0 0 0 1px #f56c6c inset;
  2168. }
  2169. .dish-selected-name {
  2170. font-size: 14px;
  2171. color: #606266;
  2172. }
  2173. .dish-placeholder {
  2174. font-size: 14px;
  2175. color: #c0c4cc;
  2176. }
  2177. .quantity-input {
  2178. flex-shrink: 0;
  2179. width: 150px;
  2180. }
  2181. .delete-dish-btn {
  2182. flex-shrink: 0;
  2183. margin-left: 8px;
  2184. }
  2185. .add-dish-btn {
  2186. width: fit-content;
  2187. margin-top: 8px;
  2188. }
  2189. /* 优化菜品行的布局,确保在有验证错误时也能正确显示 */
  2190. .dish-row .dish-form-item {
  2191. min-width: 0;
  2192. }
  2193. .dish-row .dish-form-item:first-child {
  2194. flex: 1;
  2195. min-width: 200px;
  2196. max-width: 350px;
  2197. }
  2198. .dish-row .dish-form-item:last-child {
  2199. display: flex;
  2200. flex: 0 0 auto;
  2201. gap: 8px;
  2202. align-items: center;
  2203. }
  2204. /* 确保数量输入框和删除按钮在同一行 */
  2205. .dish-form-item:last-child :deep(.el-form-item__content) {
  2206. display: flex;
  2207. flex-wrap: nowrap;
  2208. gap: 8px;
  2209. align-items: center;
  2210. }
  2211. /* 响应式布局优化 */
  2212. @media (width <= 768px) {
  2213. .dish-row {
  2214. flex-direction: column;
  2215. align-items: stretch;
  2216. }
  2217. .dish-row .dish-form-item {
  2218. width: 100%;
  2219. max-width: 100%;
  2220. }
  2221. .dish-row .dish-form-item:first-child {
  2222. max-width: 100%;
  2223. }
  2224. .category-row {
  2225. flex-direction: column;
  2226. align-items: stretch;
  2227. }
  2228. .category-row .el-input {
  2229. max-width: 100%;
  2230. }
  2231. }
  2232. /* 菜品选择对话框样式 */
  2233. .dish-dialog-content {
  2234. display: flex;
  2235. flex-direction: column;
  2236. gap: 16px;
  2237. }
  2238. .dish-search-input {
  2239. width: 100%;
  2240. }
  2241. .dish-list-container {
  2242. :deep(.el-scrollbar__wrap) {
  2243. overflow-x: hidden;
  2244. }
  2245. :deep(.el-scrollbar__view) {
  2246. display: flex;
  2247. flex-direction: column;
  2248. gap: 12px;
  2249. }
  2250. }
  2251. .dish-empty-state {
  2252. display: flex;
  2253. flex-direction: column;
  2254. align-items: center;
  2255. justify-content: center;
  2256. padding: 60px 20px;
  2257. text-align: center;
  2258. }
  2259. .empty-text {
  2260. margin-bottom: 8px;
  2261. font-size: 16px;
  2262. color: #909399;
  2263. }
  2264. .empty-hint {
  2265. font-size: 14px;
  2266. color: #c0c4cc;
  2267. }
  2268. .dish-item {
  2269. position: relative;
  2270. display: flex;
  2271. gap: 12px;
  2272. align-items: center;
  2273. padding: 12px;
  2274. cursor: pointer;
  2275. border: 1px solid #e4e7ed;
  2276. border-radius: 4px;
  2277. transition: all 0.1s;
  2278. }
  2279. .dish-item:hover {
  2280. background-color: #f5f7fa;
  2281. border-color: #409eff;
  2282. }
  2283. .dish-item-selected {
  2284. background-color: #ecf5ff;
  2285. border-color: #409eff;
  2286. border-width: 1px;
  2287. }
  2288. .dish-item-selected:hover {
  2289. background-color: #d9ecff;
  2290. }
  2291. .dish-image {
  2292. flex-shrink: 0;
  2293. width: 60px;
  2294. height: 60px;
  2295. overflow: hidden;
  2296. background-color: #f5f7fa;
  2297. border-radius: 4px;
  2298. }
  2299. .dish-img {
  2300. width: 100%;
  2301. height: 100%;
  2302. }
  2303. .dish-image-placeholder {
  2304. display: flex;
  2305. align-items: center;
  2306. justify-content: center;
  2307. width: 100%;
  2308. height: 100%;
  2309. font-size: 24px;
  2310. color: #c0c4cc;
  2311. }
  2312. .dish-info {
  2313. display: flex;
  2314. flex: 1;
  2315. flex-direction: column;
  2316. gap: 4px;
  2317. }
  2318. .dish-name {
  2319. font-size: 14px;
  2320. font-weight: 500;
  2321. color: #606266;
  2322. }
  2323. .dish-price {
  2324. font-size: 14px;
  2325. color: #909399;
  2326. }
  2327. .dish-selected-icon {
  2328. display: flex;
  2329. flex-shrink: 0;
  2330. align-items: center;
  2331. justify-content: center;
  2332. width: 24px;
  2333. height: 24px;
  2334. font-size: 16px;
  2335. color: #ffffff;
  2336. background-color: #409eff;
  2337. border-radius: 50%;
  2338. }
  2339. .dialog-footer {
  2340. display: flex;
  2341. justify-content: center;
  2342. }
  2343. /* 展开收起动画 - 高度过渡 */
  2344. .slide-fade-enter-active {
  2345. overflow: hidden;
  2346. transition:
  2347. max-height 0.1s ease-out,
  2348. opacity 0.1s ease-out;
  2349. }
  2350. .slide-fade-leave-active {
  2351. overflow: hidden;
  2352. transition:
  2353. max-height 0.1s ease-in,
  2354. opacity 0.1s ease-in;
  2355. }
  2356. .slide-fade-enter-from {
  2357. max-height: 0;
  2358. opacity: 0;
  2359. }
  2360. .slide-fade-leave-to {
  2361. max-height: 0;
  2362. opacity: 0;
  2363. }
  2364. .slide-fade-enter-to,
  2365. .slide-fade-leave-from {
  2366. max-height: 2000px;
  2367. opacity: 1;
  2368. }
  2369. /* 分组收起全部动画 */
  2370. .group-fade-enter-active {
  2371. transition: all 0.1s ease-out;
  2372. }
  2373. .group-fade-leave-active {
  2374. transition: all 0.1s ease-in;
  2375. }
  2376. .group-fade-enter-from {
  2377. opacity: 0;
  2378. transform: translateY(-10px);
  2379. }
  2380. .group-fade-leave-to {
  2381. opacity: 0;
  2382. transform: translateY(-10px);
  2383. }
  2384. .group-fade-move {
  2385. transition: transform 0.1s linear;
  2386. }
  2387. </style>