newGroup.vue 87 KB

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