newGroup.vue 76 KB

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