newGroup.vue 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507
  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="imageList" 本地服务测不了上传图片 先去掉必填-->
  16. <el-form-item label="图片">
  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="startTimeValue" v-if="storeInfoModel.startTimeType == 1">
  48. <el-date-picker
  49. v-model="storeInfoModel.startTimeValue"
  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. <!-- 预约规则 prop="reservationRules"-->
  339. <el-form-item label="预约规则">
  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. <!-- 使用规则 prop="useRules"-->
  349. <el-form-item label="使用规则">
  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. <!-- 其他规则 prop="otherRules"-->
  363. <el-form-item label="其他规则">
  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. <!-- 发票信息 prop="invoiceInformation"-->
  373. <el-form-item label="发票信息">
  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. <!-- 发票说明 prop="invoiceDescribe"-->
  381. <el-form-item label="发票说明">
  382. <el-input v-model="storeInfoModel.invoiceDescribe" maxlength="30" 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. saveDraft,
  456. getStoreDetail,
  457. getHolidayList,
  458. getUserByPhone,
  459. getMenuByStoreId,
  460. getThaliById,
  461. saveThali
  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. startTimeValue: [
  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.startTimeValue) {
  531. const startDate = new Date(storeInfoModel.value.startTimeValue);
  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. startTimeValue: "",
  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. qty: "", // 数量
  898. dishesUnit: ""
  899. }
  900. ]
  901. }
  902. ]);
  903. // 菜品选择对话框相关
  904. const dishDialogVisible = ref(false);
  905. const dishSearchKeyword = ref("");
  906. const filteredDishList: any = ref([]);
  907. const selectedDishId = ref<number | string | null>(null);
  908. const currentDishGroupIndex = ref<number>(-1);
  909. const currentDishIndex = ref<number>(-1);
  910. // 套餐内容整体展开收起状态
  911. const allGroupsCollapsed = ref(false);
  912. // 每个分组的收起状态(数组,索引对应分组索引)
  913. const groupCollapsedStates = ref<boolean[]>([false]); // 默认第一个分组展开
  914. // 计算属性:过滤要显示的分组(收起全部时只显示第一个分组),保留原始索引
  915. const visibleGroups = computed(() => {
  916. if (allGroupsCollapsed.value) {
  917. return lifeGroupBuyThalis.value.map((group, index) => ({ group, originalIndex: index })).filter((_, index) => index === 0);
  918. }
  919. return lifeGroupBuyThalis.value.map((group, index) => ({ group, originalIndex: index }));
  920. });
  921. // ==================== 监听器 ====================
  922. /**
  923. * 监听不可用日期选项变化
  924. * 当切换到自定义不可用日期时,确保至少有一个日期项
  925. */
  926. watch(
  927. () => storeInfoModel.value.disableDateType,
  928. newVal => {
  929. if (newVal === 2) {
  930. // 切换到自定义不可用日期时,如果disableDateList为空,则添加一个默认项
  931. if (!storeInfoModel.value.disableDateList || storeInfoModel.value.disableDateList.length === 0) {
  932. storeInfoModel.value.disableDateList = [null];
  933. }
  934. }
  935. },
  936. { immediate: true }
  937. );
  938. /**
  939. * 监听开始售卖时间变化
  940. * 当开始时间改变时,重新验证结束时间
  941. */
  942. watch(
  943. () => storeInfoModel.value.startTimeValue,
  944. () => {
  945. if (storeInfoModel.value.endTime) {
  946. nextTick(() => {
  947. ruleFormRef.value?.validateField("endTime");
  948. });
  949. }
  950. }
  951. );
  952. /**
  953. * 监听结束售卖时间变化
  954. * 当结束时间改变时,重新验证开始时间
  955. */
  956. watch(
  957. () => storeInfoModel.value.endTime,
  958. () => {
  959. if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.startTimeValue) {
  960. nextTick(() => {
  961. ruleFormRef.value?.validateField("startTimeValue");
  962. });
  963. }
  964. }
  965. );
  966. /**
  967. * 监听所有分组的类别值变化
  968. * 当任何一个分组的类别值改变时,重新验证所有分组的类别字段,确保重复性校验实时生效
  969. */
  970. watch(
  971. () => lifeGroupBuyThalis.value.map(group => group.groupName),
  972. () => {
  973. // 当类别值改变时,重新验证所有分组的类别字段
  974. nextTick(() => {
  975. if (packageFormRef.value) {
  976. lifeGroupBuyThalis.value.forEach((_, groupIndex) => {
  977. const prop = `groups.${groupIndex}.groupName`;
  978. packageFormRef.value?.validateField(prop, () => {});
  979. });
  980. }
  981. });
  982. },
  983. { deep: true }
  984. );
  985. // ==================== 生命周期钩子 ====================
  986. /**
  987. * 组件挂载时初始化
  988. * 从路由参数中获取页面类型和ID
  989. */
  990. onMounted(async () => {
  991. id.value = (route.query.id as string) || "";
  992. type.value = (route.query.type as string) || "";
  993. // 不要删除-开始
  994. // let param = {
  995. // // phone: localGet("iphone")
  996. // phone: "18641153170"
  997. // };
  998. // const resP: any = await getUserByPhone(param);
  999. // if (resP.data && resP.data.storeId) {
  1000. // localSet("createdId", resP.data.storeId);
  1001. // const resD: any = await getDetail({
  1002. // id: localGet("createdId")
  1003. // });
  1004. // if (resD.data && resD.data.commissionRate) {
  1005. // localSet("commissionRate", resD.data.commissionRate);
  1006. // }
  1007. // if (resD.data && resD.data.businessSection) {
  1008. // localSet("businessSection", resD.data.businessSection);
  1009. // }
  1010. // } else {
  1011. // ElMessage.warning("请完成商家入驻后再进行新建团购");
  1012. // }
  1013. // if (!getGroupCombination()) {
  1014. // ElMessage.warning("请完成商家入驻后重新登录再进行新建团购");
  1015. // return;
  1016. // }
  1017. // 不要删除-结束
  1018. let params = {
  1019. year: new Date().getFullYear(),
  1020. page: 1,
  1021. size: 500,
  1022. openFlag: 1,
  1023. holidayName: ""
  1024. };
  1025. let res: any = await getHolidayList(params);
  1026. if (res && res.code == 200) {
  1027. holidayList.value = res.data.records;
  1028. }
  1029. if (type.value != "add") {
  1030. const params = {
  1031. id: id.value,
  1032. userId: localGet("userId") || "104"
  1033. };
  1034. let res: any = await getThaliById(params);
  1035. storeInfoModel.value = { ...storeInfoModel.value, ...res.data.lifeGroupBuyMain };
  1036. let imageList: any[] = [];
  1037. handleImageParam((res.data as any).businessLicenseAddress || [], imageList);
  1038. storeInfoModel.value.imageList = imageList;
  1039. storeInfoModel.value.invoiceInformation = storeInfoModel.value.invoiceType.split(";");
  1040. // 确保星期和节日字段存在
  1041. const listVal = storeInfoModel.value.disableDateValue.split(";");
  1042. storeInfoModel.value.unavailableWeekdays = listVal[0].split(",");
  1043. storeInfoModel.value.unavailableHolidays = listVal[1].split(",");
  1044. if (res.data.lifeGroupBuyThalis && res.data.lifeGroupBuyThalis.length > 0) {
  1045. lifeGroupBuyThalis.value = res.data.lifeGroupBuyThalis;
  1046. // 确保每个分组都有必要的字段
  1047. lifeGroupBuyThalis.value.forEach((group: any) => {
  1048. if (!group.dishes || group.dishes.length === 0) {
  1049. group.dishes = [
  1050. {
  1051. detailId: "",
  1052. qty: ""
  1053. }
  1054. ];
  1055. }
  1056. });
  1057. // 初始化所有分组的收起状态为展开
  1058. groupCollapsedStates.value = new Array(lifeGroupBuyThalis.value.length).fill(false);
  1059. } else {
  1060. // 如果没有数据,使用默认值
  1061. lifeGroupBuyThalis.value = [
  1062. {
  1063. groupName: "",
  1064. dishes: [
  1065. {
  1066. detailId: "",
  1067. dishName: "",
  1068. dishPrice: "",
  1069. qty: "",
  1070. dishesUnit: ""
  1071. }
  1072. ]
  1073. }
  1074. ];
  1075. // 初始化默认分组的收起状态为展开
  1076. groupCollapsedStates.value = [false];
  1077. }
  1078. // 确保自定义不可用日期字段存在
  1079. if (storeInfoModel.value.disableDateType === 2) {
  1080. // 后端直接返回 disableDateList 字段,如果为空则初始化为默认值
  1081. if (!storeInfoModel.value.disableDateList || storeInfoModel.value.disableDateList.length === 0) {
  1082. storeInfoModel.value.disableDateList = [null];
  1083. }
  1084. }
  1085. }
  1086. });
  1087. // ==================== 事件处理函数 ====================
  1088. /**
  1089. * 返回上一页
  1090. */
  1091. const goBack = () => {
  1092. router.go(-1);
  1093. };
  1094. /**
  1095. * 图片上传 - 删除前确认
  1096. * @param uploadFile 要删除的文件对象
  1097. * @param uploadFiles 当前文件列表
  1098. * @returns Promise<boolean>,true 允许删除,false 阻止删除
  1099. */
  1100. const handleBeforeRemove = async (uploadFile: any, uploadFiles: any[]): Promise<boolean> => {
  1101. try {
  1102. await ElMessageBox.confirm("确定要删除这张图片吗?", "提示", {
  1103. confirmButtonText: "确定",
  1104. cancelButtonText: "取消",
  1105. type: "warning"
  1106. });
  1107. // 用户确认删除,返回 true 允许删除
  1108. return true;
  1109. } catch {
  1110. // 用户取消删除,返回 false 阻止删除
  1111. return false;
  1112. }
  1113. };
  1114. /**
  1115. * 图片上传 - 移除图片回调(删除成功后调用)
  1116. * @param uploadFile 已删除的文件对象
  1117. * @param uploadFiles 删除后的文件列表
  1118. */
  1119. const handleRemove: UploadProps["onRemove"] = (uploadFile, uploadFiles) => {
  1120. // 删除成功后提示
  1121. ElMessage.success("图片已删除");
  1122. };
  1123. /**
  1124. * 图片上传 - 上传成功回调
  1125. * @param response 上传响应数据
  1126. */
  1127. const handleSuccess = (response: any) => {
  1128. ElMessage.success("图片上传成功");
  1129. // 上传成功后,imageList 会自动更新,response.data 包含图片URL
  1130. };
  1131. /**
  1132. * 图片预览 - 使用 el-image 预览功能
  1133. * @param file 上传文件对象
  1134. */
  1135. const handlePictureCardPreview = (file: any) => {
  1136. // 获取所有图片的 URL 列表
  1137. const urlList = storeInfoModel.value.imageList.map((item: any) => item.url || item.response?.data || item);
  1138. // 找到当前点击的图片索引
  1139. const currentIndex = urlList.findIndex((url: string) => url === file.url);
  1140. imageViewerUrlList.value = urlList;
  1141. imageViewerInitialIndex.value = currentIndex >= 0 ? currentIndex : 0;
  1142. imageViewerVisible.value = true;
  1143. };
  1144. /**
  1145. * 添加自定义不可用日期
  1146. */
  1147. const addDate = () => {
  1148. storeInfoModel.value.disableDateList.push(null);
  1149. };
  1150. /**
  1151. * 删除自定义不可用日期
  1152. * @param index 要删除的日期索引
  1153. */
  1154. const removeDate = (index: number) => {
  1155. if (storeInfoModel.value.disableDateList.length <= 1) {
  1156. ElMessage.warning("至少需要保留一个日期项");
  1157. return;
  1158. }
  1159. storeInfoModel.value.disableDateList.splice(index, 1);
  1160. // 删除日期项后,重新验证表单以清除旧的验证错误
  1161. nextTick(() => {
  1162. ruleFormRef.value?.validateField("customUnavailableDates");
  1163. });
  1164. };
  1165. /**
  1166. * 切换星期选择
  1167. * @param value 星期值
  1168. */
  1169. const toggleWeekday = value => {
  1170. if (!storeInfoModel.value.unavailableWeekdays) {
  1171. storeInfoModel.value.unavailableWeekdays = [];
  1172. }
  1173. const index = storeInfoModel.value.unavailableWeekdays.indexOf(value);
  1174. if (index > -1) {
  1175. storeInfoModel.value.unavailableWeekdays.splice(index, 1);
  1176. } else {
  1177. storeInfoModel.value.unavailableWeekdays.push(value);
  1178. }
  1179. console.log(storeInfoModel.value.unavailableWeekdays);
  1180. // 触发表单验证
  1181. nextTick(() => {
  1182. ruleFormRef.value?.validateField("unavailableWeekdays");
  1183. });
  1184. };
  1185. /**
  1186. * 切换节日选择
  1187. * @param value 节日值
  1188. */
  1189. const toggleHoliday = value => {
  1190. if (!storeInfoModel.value.unavailableHolidays) {
  1191. storeInfoModel.value.unavailableHolidays = [];
  1192. }
  1193. const index = storeInfoModel.value.unavailableHolidays.indexOf(value);
  1194. if (index > -1) {
  1195. storeInfoModel.value.unavailableHolidays.splice(index, 1);
  1196. } else {
  1197. storeInfoModel.value.unavailableHolidays.push(value);
  1198. }
  1199. console.log(storeInfoModel.value.unavailableHolidays);
  1200. // 触发表单验证
  1201. nextTick(() => {
  1202. ruleFormRef.value?.validateField("unavailableHolidays");
  1203. });
  1204. };
  1205. /**
  1206. * 添加套餐分组
  1207. */
  1208. const addGroup = () => {
  1209. if (!lifeGroupBuyThalis.value) {
  1210. lifeGroupBuyThalis.value = [];
  1211. }
  1212. // 检查分组数量限制(最多20个)
  1213. if (lifeGroupBuyThalis.value.length >= 20) {
  1214. ElMessage.warning("最多只能添加20个分组");
  1215. return;
  1216. }
  1217. // 使用表单验证来验证所有现有分组
  1218. if (packageFormRef.value) {
  1219. packageFormRef.value.validate((valid: boolean) => {
  1220. if (!valid) {
  1221. ElMessage.warning("请先完成现有分组的填写");
  1222. return;
  1223. }
  1224. // 验证通过,添加新分组
  1225. lifeGroupBuyThalis.value.push({
  1226. groupName: "",
  1227. dishes: [
  1228. {
  1229. detailId: "",
  1230. dishName: "",
  1231. dishPrice: "",
  1232. qty: "",
  1233. dishesUnit: ""
  1234. }
  1235. ]
  1236. });
  1237. // 初始化新分组的收起状态为展开
  1238. groupCollapsedStates.value.push(false);
  1239. // 清除表单验证状态,避免新分组显示验证错误
  1240. // 使用延迟清除,确保在验证规则更新和 DOM 渲染完成后再清除
  1241. nextTick(() => {
  1242. requestAnimationFrame(() => {
  1243. setTimeout(() => {
  1244. if (packageFormRef.value) {
  1245. // 只清除新添加分组的验证状态
  1246. const newGroupIndex = lifeGroupBuyThalis.value.length - 1;
  1247. const propsToClear = [
  1248. `groups.${newGroupIndex}.groupName`,
  1249. `groups.${newGroupIndex}.dishes.0.detailId`,
  1250. `groups.${newGroupIndex}.dishes.0.qty`
  1251. ];
  1252. // Element Plus 的 clearValidate 可以接受字符串数组
  1253. propsToClear.forEach(prop => {
  1254. packageFormRef.value?.clearValidate(prop);
  1255. });
  1256. }
  1257. }, 50);
  1258. });
  1259. });
  1260. });
  1261. } else {
  1262. // 如果表单引用不存在,直接添加(兜底逻辑)
  1263. lifeGroupBuyThalis.value.push({
  1264. groupName: "",
  1265. dishes: [
  1266. {
  1267. detailId: "",
  1268. dishName: "",
  1269. dishPrice: "",
  1270. qty: "",
  1271. dishesUnit: ""
  1272. }
  1273. ]
  1274. });
  1275. groupCollapsedStates.value.push(false);
  1276. }
  1277. };
  1278. /**
  1279. * 删除套餐分组
  1280. * @param groupIndex 分组索引
  1281. */
  1282. const removeGroup = (groupIndex: number) => {
  1283. if (lifeGroupBuyThalis.value.length <= 1) {
  1284. ElMessage.warning("至少需要保留一个分组");
  1285. return;
  1286. }
  1287. ElMessageBox.confirm("确定要删除这个分组吗?", "提示", {
  1288. confirmButtonText: "确定",
  1289. cancelButtonText: "取消",
  1290. type: "warning"
  1291. })
  1292. .then(() => {
  1293. lifeGroupBuyThalis.value.splice(groupIndex, 1);
  1294. // 同步删除收起状态数组中的对应项
  1295. if (groupCollapsedStates.value.length > groupIndex) {
  1296. groupCollapsedStates.value.splice(groupIndex, 1);
  1297. }
  1298. ElMessage.success("删除成功");
  1299. })
  1300. .catch(() => {});
  1301. };
  1302. /**
  1303. * 判断分组是否收起
  1304. * @param groupIndex 分组索引
  1305. * @returns 是否收起(收起时只显示类别和第一行菜品,隐藏其他菜品行)
  1306. */
  1307. const isGroupCollapsed = (groupIndex: number): boolean => {
  1308. // 如果"收起全部"状态为true,第一个分组应该展开(显示所有菜品),其他分组收起
  1309. if (allGroupsCollapsed.value) {
  1310. return groupIndex !== 0;
  1311. }
  1312. // 否则根据分组的收起状态判断
  1313. return groupCollapsedStates.value[groupIndex] === true;
  1314. };
  1315. /**
  1316. * 切换单个分组的收起/展开状态
  1317. * @param groupIndex 分组索引
  1318. */
  1319. const toggleGroupCollapse = (groupIndex: number) => {
  1320. // 如果当前是"收起全部"状态,先取消该状态
  1321. if (allGroupsCollapsed.value) {
  1322. allGroupsCollapsed.value = false;
  1323. // 设置所有分组状态:第一个分组当前是展开的,其他分组当前是收起的
  1324. // 所以第一个分组应该设置为收起,其他分组应该设置为展开
  1325. groupCollapsedStates.value = new Array(lifeGroupBuyThalis.value.length).fill(true);
  1326. groupCollapsedStates.value[0] = false; // 第一个分组原本是展开的
  1327. // 然后切换当前分组的状态
  1328. groupCollapsedStates.value[groupIndex] = !groupCollapsedStates.value[groupIndex];
  1329. } else {
  1330. // 确保数组长度足够
  1331. while (groupCollapsedStates.value.length <= groupIndex) {
  1332. groupCollapsedStates.value.push(false);
  1333. }
  1334. groupCollapsedStates.value[groupIndex] = !groupCollapsedStates.value[groupIndex];
  1335. }
  1336. };
  1337. /**
  1338. * 切换所有分组的收起/展开状态
  1339. * 收起全部时保留第一个分组展开
  1340. */
  1341. const toggleAllGroupsCollapse = () => {
  1342. if (allGroupsCollapsed.value) {
  1343. // 展开全部:将所有分组设置为展开状态
  1344. allGroupsCollapsed.value = false;
  1345. groupCollapsedStates.value = groupCollapsedStates.value.map(() => false);
  1346. } else {
  1347. // 收起全部:收起除第一个分组外的所有分组
  1348. allGroupsCollapsed.value = true;
  1349. groupCollapsedStates.value = groupCollapsedStates.value.map((_, index) => index !== 0);
  1350. // 确保数组长度足够
  1351. while (groupCollapsedStates.value.length < lifeGroupBuyThalis.value.length) {
  1352. groupCollapsedStates.value.push(true);
  1353. }
  1354. }
  1355. };
  1356. /**
  1357. * 添加菜品
  1358. * @param groupIndex 分组索引
  1359. */
  1360. const addDish = (groupIndex: number) => {
  1361. const group = lifeGroupBuyThalis.value[groupIndex];
  1362. // 检查菜品数量限制(每个分组最多20个菜品)
  1363. if (group.dishes && group.dishes.length >= 20) {
  1364. ElMessage.warning("每个分组最多只能添加20个菜品");
  1365. return;
  1366. }
  1367. // 使用表单验证来验证当前分组的所有字段
  1368. if (packageFormRef.value) {
  1369. // 收集当前分组的所有字段路径
  1370. const fieldsToValidate: string[] = [];
  1371. // 添加类别字段
  1372. fieldsToValidate.push(`groups.${groupIndex}.groupName`);
  1373. // 添加当前分组所有菜品的字段
  1374. if (group.dishes && group.dishes.length > 0) {
  1375. group.dishes.forEach((_, dishIndex) => {
  1376. fieldsToValidate.push(`groups.${groupIndex}.dishes.${dishIndex}.detailId`);
  1377. fieldsToValidate.push(`groups.${groupIndex}.dishes.${dishIndex}.qty`);
  1378. });
  1379. }
  1380. if (fieldsToValidate.length === 0) {
  1381. // 如果没有字段需要验证,直接添加
  1382. if (!group.dishes) {
  1383. group.dishes = [];
  1384. }
  1385. group.dishes.push({
  1386. detailId: "",
  1387. dishName: "",
  1388. dishPrice: "",
  1389. qty: "",
  1390. dishesUnit: ""
  1391. });
  1392. return;
  1393. }
  1394. // 使用 Promise 等待所有字段验证完成
  1395. const validatePromises = fieldsToValidate.map(field => {
  1396. return new Promise<boolean>(resolve => {
  1397. packageFormRef.value?.validateField(field, (isValid: boolean) => {
  1398. resolve(isValid);
  1399. });
  1400. });
  1401. });
  1402. Promise.all(validatePromises).then(results => {
  1403. const allValid = results.every(result => result === true);
  1404. if (!allValid) {
  1405. ElMessage.warning("请先完成现有菜品的填写");
  1406. return;
  1407. }
  1408. // 验证通过,添加新菜品
  1409. if (!group.dishes) {
  1410. group.dishes = [];
  1411. }
  1412. group.dishes.push({
  1413. detailId: "",
  1414. dishName: "",
  1415. dishPrice: "",
  1416. qty: "",
  1417. dishesUnit: ""
  1418. });
  1419. // 清除新添加菜品的验证状态,避免立即显示验证错误
  1420. // 使用延迟清除,确保在验证规则更新和 DOM 渲染完成后再清除
  1421. nextTick(() => {
  1422. requestAnimationFrame(() => {
  1423. setTimeout(() => {
  1424. if (packageFormRef.value) {
  1425. // 只清除新添加菜品的验证状态
  1426. const newDishIndex = group.dishes.length - 1;
  1427. const propsToClear = [
  1428. `groups.${groupIndex}.dishes.${newDishIndex}.detailId`,
  1429. `groups.${groupIndex}.dishes.${newDishIndex}.qty`
  1430. ];
  1431. // Element Plus 的 clearValidate 可以接受字符串
  1432. propsToClear.forEach(prop => {
  1433. packageFormRef.value?.clearValidate(prop);
  1434. });
  1435. }
  1436. }, 50);
  1437. });
  1438. });
  1439. });
  1440. } else {
  1441. // 如果表单引用不存在,直接添加(兜底逻辑)
  1442. if (!group.dishes) {
  1443. group.dishes = [];
  1444. }
  1445. group.dishes.push({
  1446. detailId: "",
  1447. dishName: "",
  1448. dishPrice: "",
  1449. qty: "",
  1450. dishesUnit: ""
  1451. });
  1452. }
  1453. };
  1454. /**
  1455. * 删除菜品
  1456. * @param groupIndex 分组索引
  1457. * @param dishIndex 菜品索引
  1458. */
  1459. const removeDish = (groupIndex: number, dishIndex: number) => {
  1460. const dishes = lifeGroupBuyThalis.value[groupIndex].dishes;
  1461. if (dishes.length <= 1) {
  1462. ElMessage.warning("至少需要保留一个菜品");
  1463. return;
  1464. }
  1465. dishes.splice(dishIndex, 1);
  1466. };
  1467. /**
  1468. * 打开菜品选择对话框
  1469. * @param groupIndex 分组索引
  1470. * @param dishIndex 菜品索引
  1471. */
  1472. const openDishDialog = async (groupIndex: number, dishIndex: number) => {
  1473. currentDishGroupIndex.value = groupIndex;
  1474. currentDishIndex.value = dishIndex;
  1475. dishSearchKeyword.value = "";
  1476. const params = {
  1477. storeId: 104,
  1478. phoneId: 18641153170,
  1479. dishType: 0
  1480. };
  1481. const res = await getMenuByStoreId(params);
  1482. if (res && res.code == 200) {
  1483. dishOptions.value = res.data;
  1484. }
  1485. // 如果已有选中的菜品,设置选中状态
  1486. const currentDish = lifeGroupBuyThalis.value[groupIndex].dishes[dishIndex];
  1487. selectedDishId.value = currentDish?.detailId || null;
  1488. filterDishList();
  1489. dishDialogVisible.value = true;
  1490. };
  1491. /**
  1492. * 选择菜品
  1493. * @param dish 菜品对象
  1494. */
  1495. const selectDish = (dish: any) => {
  1496. selectedDishId.value = dish.id;
  1497. };
  1498. /**
  1499. * 确认菜品选择
  1500. */
  1501. const confirmDishSelection = () => {
  1502. if (selectedDishId.value === null) {
  1503. ElMessage.warning("请选择一个菜品");
  1504. return;
  1505. }
  1506. const selectedDish: any = dishOptions.value.find(dish => dish.id === selectedDishId.value);
  1507. if (selectedDish && currentDishGroupIndex.value >= 0 && currentDishIndex.value >= 0) {
  1508. const dish = lifeGroupBuyThalis.value[currentDishGroupIndex.value].dishes[currentDishIndex.value];
  1509. dish.detailId = selectedDish.id;
  1510. dish.dishName = selectedDish.dishName;
  1511. dish.dishPrice = selectedDish.dishPrice;
  1512. dish.dishesUnit = selectedDish.dishesUnit;
  1513. dishDialogVisible.value = false;
  1514. // 重新验证对应的字段,如果验证通过,错误提示会消失
  1515. nextTick(() => {
  1516. if (packageFormRef.value) {
  1517. const prop = `groups.${currentDishGroupIndex.value}.dishes.${currentDishIndex.value}.detailId`;
  1518. packageFormRef.value.validateField(prop, () => {});
  1519. }
  1520. });
  1521. }
  1522. };
  1523. /**
  1524. * 过滤菜品列表
  1525. * 排除已经在其他分组中被选择的菜品(当前正在编辑的菜品除外)
  1526. */
  1527. const filterDishList = () => {
  1528. // 获取当前正在编辑的菜品ID(如果有)
  1529. const currentDishId = selectedDishId.value;
  1530. // 收集所有其他分组中已选择的菜品ID
  1531. const selectedDishIds = new Set<number | string>();
  1532. lifeGroupBuyThalis.value.forEach((group, groupIndex) => {
  1533. if (group.dishes && group.dishes.length > 0) {
  1534. group.dishes.forEach((dish, dishIndex) => {
  1535. // 排除当前正在编辑的菜品
  1536. if (dish.detailId && !(groupIndex === currentDishGroupIndex.value && dishIndex === currentDishIndex.value)) {
  1537. selectedDishIds.add(dish.detailId);
  1538. }
  1539. });
  1540. }
  1541. });
  1542. // 先根据搜索关键词过滤
  1543. let filtered = dishOptions.value;
  1544. if (dishSearchKeyword.value && dishSearchKeyword.value.trim() !== "") {
  1545. const keyword = dishSearchKeyword.value.trim().toLowerCase();
  1546. filtered = dishOptions.value.filter(dish => dish.dishName.toLowerCase().includes(keyword));
  1547. }
  1548. // 再排除已在其他分组中被选择的菜品(但保留当前正在编辑的菜品)
  1549. filteredDishList.value = filtered.filter(dish => {
  1550. // 如果是当前正在编辑的菜品,保留
  1551. if (currentDishId && dish.id === currentDishId) {
  1552. return true;
  1553. }
  1554. // 如果菜品已在其他分组中被选择,排除
  1555. return !selectedDishIds.has(dish.id);
  1556. });
  1557. };
  1558. // ==================== 表单引用 ====================
  1559. const ruleFormRef = ref<FormInstance>(); // 表单引用
  1560. const packageFormRef = ref<FormInstance>(); // 套餐内容表单引用
  1561. // 套餐内容表单模型(用于验证)
  1562. const packageFormModel = computed(() => {
  1563. return {
  1564. groups: lifeGroupBuyThalis.value
  1565. };
  1566. });
  1567. // 套餐内容验证规则
  1568. const packageFormRules = computed(() => {
  1569. const rules: any = {};
  1570. lifeGroupBuyThalis.value.forEach((group, groupIndex) => {
  1571. // 类别验证规则 - 使用与 prop 相同的路径格式
  1572. rules[`groups.${groupIndex}.groupName`] = [
  1573. {
  1574. required: true,
  1575. message: `第${groupIndex + 1}个分组的类别不能为空`,
  1576. trigger: "blur"
  1577. },
  1578. {
  1579. validator: (rule: any, value: any, callback: any) => {
  1580. // 如果值为空,由 required 规则处理,这里直接通过
  1581. if (!value || value.toString().trim() === "") {
  1582. callback();
  1583. return;
  1584. }
  1585. const trimmedValue = value.toString().trim();
  1586. // 检查是否与其他分组的类别重复
  1587. for (let i = 0; i < lifeGroupBuyThalis.value.length; i++) {
  1588. // 跳过当前分组
  1589. if (i === groupIndex) {
  1590. continue;
  1591. }
  1592. const otherGroupName = lifeGroupBuyThalis.value[i].groupName;
  1593. // 如果其他分组的类别值与当前值相同(忽略前后空格),则重复
  1594. if (otherGroupName && otherGroupName.toString().trim() === trimmedValue) {
  1595. callback(new Error(`第${groupIndex + 1}个分组的类别与第${i + 1}个分组的类别重复`));
  1596. return;
  1597. }
  1598. }
  1599. callback();
  1600. },
  1601. trigger: "blur"
  1602. }
  1603. ];
  1604. // 每个菜品的验证规则
  1605. if (group.dishes) {
  1606. group.dishes.forEach((dish, dishIndex) => {
  1607. // 菜品选择验证
  1608. rules[`groups.${groupIndex}.dishes.${dishIndex}.detailId`] = [
  1609. {
  1610. required: true,
  1611. message: `第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品未选择`,
  1612. trigger: "change"
  1613. }
  1614. ];
  1615. // 菜品数量验证
  1616. rules[`groups.${groupIndex}.dishes.${dishIndex}.qty`] = [
  1617. {
  1618. required: true,
  1619. message: `第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品数量不能为空`,
  1620. trigger: "blur"
  1621. },
  1622. {
  1623. validator: (rule: any, value: any, callback: any) => {
  1624. if (!value || value.toString().trim() === "") {
  1625. callback();
  1626. return;
  1627. }
  1628. const num = Number(value);
  1629. if (isNaN(num) || num <= 0) {
  1630. callback(new Error(`第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品数量必须为正整数`));
  1631. return;
  1632. }
  1633. if (!Number.isInteger(num)) {
  1634. callback(new Error(`第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品数量必须为正整数`));
  1635. return;
  1636. }
  1637. callback();
  1638. },
  1639. trigger: "blur"
  1640. }
  1641. ];
  1642. });
  1643. }
  1644. });
  1645. return rules;
  1646. });
  1647. /**
  1648. * 提交数据(新增/编辑)
  1649. * 验证表单,通过后调用相应的API接口
  1650. */
  1651. const handleSubmit = async (type?) => {
  1652. let params: any = { ...storeInfoModel.value };
  1653. if (params.disableDateType == 1) {
  1654. params.disableDateValue = params.unavailableWeekdays.join(",") + ";" + params.unavailableHolidays.join(",");
  1655. // params.disableDateValue = [params.unavailableWeekdays, params.unavailableHolidays];
  1656. delete params.unavailableWeekdays;
  1657. delete params.unavailableHolidays;
  1658. } else if (params.disableDateType == 2) {
  1659. // params.disableDateValue = params.disableDateList.map(subArray => subArray.join(",")).join(";");
  1660. }
  1661. params.invoiceType = params.invoiceInformation.join(",");
  1662. // const output = lifeGroupBuyThalis.value.flatMap(group =>
  1663. // group.dishes.map(dish => ({
  1664. // groupName: group.groupName,
  1665. // detailId: dish.detailId,
  1666. // qty: dish.qty,
  1667. // dishPrice: dish.dishPrice
  1668. // }))
  1669. // );
  1670. const paramsObj: any = {
  1671. lifeGroupBuyMain: params,
  1672. lifeGroupBuyThalis: lifeGroupBuyThalis.value
  1673. };
  1674. paramsObj.lifeGroupBuyMain.status = type ? "0" : "1";
  1675. paramsObj.lifeGroupBuyMain.groupType = 1;
  1676. paramsObj.lifeGroupBuyMain.storeId = localGet("storeId") || "104";
  1677. if (id.value) {
  1678. paramsObj.lifeGroupBuyMain.id = id.value;
  1679. }
  1680. console.log(paramsObj);
  1681. if (type) {
  1682. if (!storeInfoModel.value.groupName) {
  1683. ElMessage.warning("请填写团购名称");
  1684. return;
  1685. }
  1686. let res: any = await saveDraft(paramsObj);
  1687. if (res && res.code == 200) {
  1688. ElMessage.success("保存成功");
  1689. goBack();
  1690. }
  1691. } else {
  1692. await ruleFormRef.value!.validate(async valid => {
  1693. if (!valid) {
  1694. ElMessage.warning("请完善表单内容信息");
  1695. return;
  1696. }
  1697. // 验证套餐内容表单
  1698. if (packageFormRef.value) {
  1699. let packageValid = false;
  1700. await new Promise<void>(resolve => {
  1701. packageFormRef.value!.validate(valid => {
  1702. packageValid = valid;
  1703. if (!valid) {
  1704. ElMessage.warning("请完善套餐内容信息");
  1705. }
  1706. resolve();
  1707. });
  1708. });
  1709. if (!packageValid) {
  1710. return;
  1711. }
  1712. }
  1713. // 组装提交参数
  1714. let res: any = await saveThali(paramsObj);
  1715. if (res && res.code == 200) {
  1716. ElMessage.success("保存成功");
  1717. }
  1718. });
  1719. }
  1720. };
  1721. // ==================== 工具函数 ====================
  1722. /**
  1723. * 禁用开始售卖时间的日期
  1724. * 不能选择早于当前时间的日期
  1725. * @param time 日期对象
  1726. * @returns 是否禁用该日期
  1727. */
  1728. const disabledStartDate = (time: Date) => {
  1729. const today = new Date();
  1730. today.setHours(0, 0, 0, 0);
  1731. return time.getTime() < today.getTime();
  1732. };
  1733. /**
  1734. * 禁用结束售卖时间的日期
  1735. * 不能选择早于当前时间的日期,也不能选择早于或等于开始售卖时间的日期
  1736. * @param time 日期对象
  1737. * @returns 是否禁用该日期
  1738. */
  1739. const disabledEndDate = (time: Date) => {
  1740. const today = new Date();
  1741. today.setHours(0, 0, 0, 0);
  1742. // 不能早于当前时间
  1743. if (time.getTime() < today.getTime()) {
  1744. return true;
  1745. }
  1746. // 如果开始售卖时间已设置,不能早于或等于开始时间
  1747. if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.startTimeValue) {
  1748. const startDate = new Date(storeInfoModel.value.startTimeValue);
  1749. startDate.setHours(0, 0, 0, 0);
  1750. return time.getTime() <= startDate.getTime();
  1751. }
  1752. return false;
  1753. };
  1754. /**
  1755. * 禁用指定时间段内可用的日期
  1756. * 不能选择早于当前时间的日期
  1757. * @param time 日期对象
  1758. * @returns 是否禁用该日期
  1759. */
  1760. const disabledEffectiveDate = (time: Date) => {
  1761. const today = new Date();
  1762. today.setHours(0, 0, 0, 0);
  1763. return time.getTime() < today.getTime();
  1764. };
  1765. /**
  1766. * 禁用自定义不可用日期的日期
  1767. * 不能选择早于当前时间的日期
  1768. * @param time 日期对象
  1769. * @returns 是否禁用该日期
  1770. */
  1771. const disabledCustomUnavailableDate = (time: Date) => {
  1772. const today = new Date();
  1773. today.setHours(0, 0, 0, 0);
  1774. return time.getTime() < today.getTime();
  1775. };
  1776. /**
  1777. * 处理图片结果
  1778. * 将上传组件的文件对象或URL字符串转换为URL数组
  1779. * @param list 图片列表(可能是文件对象或URL字符串)
  1780. * @returns URL字符串数组
  1781. */
  1782. const handleImageResult = (list: any[]): string[] => {
  1783. let result: string[] = [];
  1784. (list || []).forEach((item: any) => {
  1785. if (item.uid) {
  1786. // 如果是上传组件的文件对象,取url属性
  1787. result.push(item.url);
  1788. } else {
  1789. // 如果是URL字符串,直接添加
  1790. result.push(item);
  1791. }
  1792. });
  1793. return result;
  1794. };
  1795. //图片list 转换为upload 组件的参数
  1796. const handleImageParam = (list: any[], result: any[]) => {
  1797. (list || []).forEach((item: any) => {
  1798. // 使用split方法以'/'为分隔符将URL拆分成数组
  1799. const parts = item.split("/");
  1800. // 取数组的最后一项,即图片名称
  1801. const imageName = parts[parts.length - 1];
  1802. result.push({
  1803. name: imageName,
  1804. percentage: 100,
  1805. url: item
  1806. });
  1807. });
  1808. };
  1809. </script>
  1810. <style scoped lang="scss">
  1811. /* 页面容器 */
  1812. .table-box {
  1813. display: flex;
  1814. flex-direction: column;
  1815. height: auto !important;
  1816. min-height: 100%;
  1817. }
  1818. /* 头部区域 */
  1819. .header {
  1820. display: flex;
  1821. align-items: center;
  1822. padding: 20px;
  1823. border-bottom: 1px solid #e4e7ed;
  1824. }
  1825. .title {
  1826. flex: 1;
  1827. margin: 0;
  1828. font-size: 18px;
  1829. font-weight: bold;
  1830. text-align: center;
  1831. }
  1832. /* 内容区域布局 */
  1833. .content {
  1834. display: flex;
  1835. flex: 1;
  1836. column-gap: 20px;
  1837. width: 98%;
  1838. margin: 20px auto;
  1839. /* 左侧内容区域 */
  1840. .contentLeft {
  1841. width: 50%;
  1842. }
  1843. /* 右侧内容区域 */
  1844. .contentRight {
  1845. width: 50%;
  1846. }
  1847. }
  1848. /* 模块容器 */
  1849. .model {
  1850. margin-bottom: 50px;
  1851. }
  1852. /* 表单容器 */
  1853. .formBox {
  1854. display: flex;
  1855. flex-direction: column;
  1856. width: 100%;
  1857. min-height: 100%;
  1858. }
  1859. /* 底部按钮容器 - 居中显示 */
  1860. .button-container {
  1861. display: flex;
  1862. gap: 12px;
  1863. align-items: center;
  1864. justify-content: center;
  1865. padding: 20px 0;
  1866. margin-top: 20px;
  1867. }
  1868. /* 日期选择器容器 */
  1869. .date-picker-container {
  1870. display: flex;
  1871. flex-direction: column;
  1872. gap: 12px;
  1873. width: 100%;
  1874. }
  1875. /* 添加日期按钮 */
  1876. .add-date-btn {
  1877. width: fit-content;
  1878. margin-bottom: 8px;
  1879. }
  1880. /* 日期项容器 */
  1881. .date-item {
  1882. display: flex;
  1883. gap: 12px;
  1884. align-items: center;
  1885. padding: 8px;
  1886. // background-color: #f5f7fa;
  1887. border-radius: 4px;
  1888. transition: background-color 0.1s;
  1889. &:hover {
  1890. background-color: #ecf5ff;
  1891. }
  1892. }
  1893. /* 日期选择器 */
  1894. .date-item .date-picker {
  1895. flex: 1;
  1896. max-width: 500px;
  1897. }
  1898. /* 删除按钮 */
  1899. .date-item .delete-btn {
  1900. flex-shrink: 0;
  1901. }
  1902. /* 有效期天数容器 */
  1903. .expiration-date-container {
  1904. display: flex;
  1905. gap: 12px;
  1906. align-items: center;
  1907. width: fit-content;
  1908. padding: 8px 12px;
  1909. // background-color: #f5f7fa;
  1910. border-radius: 4px;
  1911. }
  1912. /* 有效期标签文字 */
  1913. .expiration-label {
  1914. font-size: 14px;
  1915. color: #606266;
  1916. white-space: nowrap;
  1917. }
  1918. /* 有效期输入框 */
  1919. .expiration-input {
  1920. width: 150px;
  1921. }
  1922. /* 不可用日期容器 */
  1923. .unavailable-dates-container {
  1924. display: flex;
  1925. flex-direction: column;
  1926. gap: 20px;
  1927. width: 100%;
  1928. }
  1929. /* 日期选择区块 */
  1930. .date-select-section {
  1931. display: flex;
  1932. flex-direction: column;
  1933. gap: 12px;
  1934. }
  1935. /* 区块标题 */
  1936. .section-title {
  1937. font-size: 14px;
  1938. font-weight: 500;
  1939. color: #606266;
  1940. }
  1941. /* 按钮组 */
  1942. .button-group {
  1943. display: flex;
  1944. flex-wrap: wrap;
  1945. gap: 10px;
  1946. }
  1947. /* 日期选择按钮 */
  1948. .date-select-btn {
  1949. min-width: 80px;
  1950. height: 36px;
  1951. padding: 8px 16px;
  1952. margin: 0;
  1953. font-size: 14px;
  1954. border-radius: 4px;
  1955. transition: all 0.1s;
  1956. }
  1957. /* 套餐内容相关样式 */
  1958. .package-content-item {
  1959. width: 100%;
  1960. }
  1961. .package-content-form {
  1962. width: 100%;
  1963. }
  1964. /* 表单项基础样式 */
  1965. .package-content-form :deep(.el-form-item) {
  1966. margin-bottom: 0;
  1967. }
  1968. .package-content-form :deep(.el-form-item__label) {
  1969. display: none;
  1970. }
  1971. /* 类别表单项样式 */
  1972. .category-form-item {
  1973. width: 100%;
  1974. margin-bottom: 16px;
  1975. }
  1976. .category-form-item :deep(.el-form-item__content) {
  1977. display: flex;
  1978. flex-wrap: wrap;
  1979. align-items: flex-start;
  1980. width: 100%;
  1981. }
  1982. .category-form-item :deep(.el-form-item__error) {
  1983. position: static;
  1984. width: 100%;
  1985. padding-top: 4px;
  1986. padding-left: 62px;
  1987. margin-top: 0;
  1988. font-size: 12px;
  1989. line-height: 1.5;
  1990. color: #f56c6c;
  1991. }
  1992. .category-row .el-input {
  1993. flex: 1;
  1994. max-width: 400px;
  1995. }
  1996. /* 菜品表单项样式 */
  1997. .dish-form-item {
  1998. position: relative;
  1999. flex: 1;
  2000. margin-bottom: 0;
  2001. }
  2002. .dish-form-item :deep(.el-form-item__content) {
  2003. display: flex;
  2004. flex-wrap: wrap;
  2005. gap: 12px;
  2006. align-items: center;
  2007. }
  2008. .dish-form-item :deep(.el-form-item__error) {
  2009. position: absolute;
  2010. top: 100%;
  2011. left: 0;
  2012. z-index: 1;
  2013. padding-top: 4px;
  2014. padding-right: 4px;
  2015. font-size: 12px;
  2016. line-height: 1.5;
  2017. color: #f56c6c;
  2018. white-space: nowrap;
  2019. background-color: #ffffff;
  2020. }
  2021. .package-content-wrapper {
  2022. display: flex;
  2023. flex-direction: column;
  2024. gap: 12px;
  2025. width: 100%;
  2026. }
  2027. .package-content-header {
  2028. display: flex;
  2029. align-items: center;
  2030. justify-content: space-between;
  2031. width: 100%;
  2032. }
  2033. .add-group-btn {
  2034. width: fit-content;
  2035. }
  2036. .package-content-container {
  2037. display: flex;
  2038. flex-direction: column;
  2039. gap: 16px;
  2040. width: 100%;
  2041. }
  2042. .package-group {
  2043. overflow: hidden;
  2044. background-color: white;
  2045. border: 1px solid #e4e7ed;
  2046. border-radius: 4px;
  2047. }
  2048. .package-group-header {
  2049. display: flex;
  2050. align-items: center;
  2051. justify-content: space-between;
  2052. height: 50px;
  2053. padding: 12px 16px;
  2054. background-color: #f5f7fa;
  2055. border-bottom: 1px solid #e4e7ed;
  2056. }
  2057. .group-index {
  2058. flex: 1;
  2059. overflow: hidden;
  2060. font-size: 14px;
  2061. font-weight: 500;
  2062. color: #303133;
  2063. text-overflow: ellipsis;
  2064. white-space: nowrap;
  2065. }
  2066. .header-right {
  2067. display: flex;
  2068. flex-shrink: 0;
  2069. gap: 12px;
  2070. align-items: center;
  2071. }
  2072. .package-group-content {
  2073. display: flex;
  2074. flex-direction: column;
  2075. gap: 16px;
  2076. min-height: 60px;
  2077. padding: 16px;
  2078. }
  2079. .extra-dishes-container {
  2080. display: flex;
  2081. flex-direction: column;
  2082. gap: 16px;
  2083. margin-top: 0;
  2084. }
  2085. .extra-dishes-container .dish-row {
  2086. margin-bottom: 4px;
  2087. }
  2088. .extra-dishes-container .dish-row:last-child {
  2089. margin-bottom: 0;
  2090. }
  2091. .package-group-collapsed {
  2092. padding: 16px;
  2093. background-color: #fafafa;
  2094. border-top: 1px solid #e4e7ed;
  2095. }
  2096. .collapsed-dish-row {
  2097. display: flex;
  2098. gap: 12px;
  2099. align-items: center;
  2100. }
  2101. .dish-info-text {
  2102. font-size: 14px;
  2103. color: #606266;
  2104. white-space: nowrap;
  2105. }
  2106. .dish-info-text.empty-text {
  2107. color: #c0c4cc;
  2108. }
  2109. .category-row {
  2110. display: flex;
  2111. gap: 12px;
  2112. align-items: center;
  2113. width: 100%;
  2114. }
  2115. .dish-row {
  2116. position: relative;
  2117. display: flex;
  2118. gap: 12px;
  2119. align-items: flex-start;
  2120. width: 100%;
  2121. margin-bottom: 4px;
  2122. }
  2123. .dish-row:last-child {
  2124. padding-bottom: 0;
  2125. margin-bottom: 0;
  2126. }
  2127. /* 当表单项有错误时,增加底部间距 */
  2128. .dish-row .dish-form-item.is-error {
  2129. margin-bottom: 0;
  2130. }
  2131. .label {
  2132. min-width: 50px;
  2133. font-size: 14px;
  2134. color: #606266;
  2135. white-space: nowrap;
  2136. }
  2137. .dish-select-block {
  2138. position: relative;
  2139. display: flex;
  2140. flex: 1;
  2141. align-items: center;
  2142. max-width: 300px;
  2143. min-height: 32px;
  2144. padding: 0 11px;
  2145. cursor: pointer;
  2146. background-color: #ffffff;
  2147. border: 1px solid #dcdfe6;
  2148. border-radius: 4px;
  2149. transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  2150. }
  2151. .dish-select-block:hover {
  2152. border-color: #c0c4cc;
  2153. }
  2154. .dish-select-block:focus-within {
  2155. border-color: #409eff;
  2156. }
  2157. /* 当菜品选择有验证错误时,显示错误边框 */
  2158. .dish-form-item.is-error .dish-select-block {
  2159. border-color: #f56c6c;
  2160. }
  2161. .dish-form-item.is-error .dish-select-block:hover {
  2162. border-color: #f56c6c;
  2163. }
  2164. .dish-form-item.is-error .dish-select-block:focus-within {
  2165. border-color: #f56c6c;
  2166. }
  2167. /* 优化表单项的错误状态 */
  2168. .package-content-form :deep(.el-form-item.is-error .el-input__wrapper) {
  2169. box-shadow: 0 0 0 1px #f56c6c inset;
  2170. }
  2171. .package-content-form :deep(.el-form-item.is-error .el-input__wrapper:hover) {
  2172. box-shadow: 0 0 0 1px #f56c6c inset;
  2173. }
  2174. .package-content-form :deep(.el-form-item.is-error .el-input__wrapper.is-focus) {
  2175. box-shadow: 0 0 0 1px #f56c6c inset;
  2176. }
  2177. .dish-selected-name {
  2178. font-size: 14px;
  2179. color: #606266;
  2180. }
  2181. .dish-placeholder {
  2182. font-size: 14px;
  2183. color: #c0c4cc;
  2184. }
  2185. .quantity-input {
  2186. flex-shrink: 0;
  2187. width: 150px;
  2188. }
  2189. .delete-dish-btn {
  2190. flex-shrink: 0;
  2191. margin-left: 8px;
  2192. }
  2193. .add-dish-btn {
  2194. width: fit-content;
  2195. margin-top: 8px;
  2196. }
  2197. /* 优化菜品行的布局,确保在有验证错误时也能正确显示 */
  2198. .dish-row .dish-form-item {
  2199. min-width: 0;
  2200. }
  2201. .dish-row .dish-form-item:first-child {
  2202. flex: 1;
  2203. min-width: 200px;
  2204. max-width: 350px;
  2205. }
  2206. .dish-row .dish-form-item:last-child {
  2207. display: flex;
  2208. flex: 0 0 auto;
  2209. gap: 8px;
  2210. align-items: center;
  2211. }
  2212. /* 确保数量输入框和删除按钮在同一行 */
  2213. .dish-form-item:last-child :deep(.el-form-item__content) {
  2214. display: flex;
  2215. flex-wrap: nowrap;
  2216. gap: 8px;
  2217. align-items: center;
  2218. }
  2219. /* 响应式布局优化 */
  2220. @media (width <= 768px) {
  2221. .dish-row {
  2222. flex-direction: column;
  2223. align-items: stretch;
  2224. }
  2225. .dish-row .dish-form-item {
  2226. width: 100%;
  2227. max-width: 100%;
  2228. }
  2229. .dish-row .dish-form-item:first-child {
  2230. max-width: 100%;
  2231. }
  2232. .category-row {
  2233. flex-direction: column;
  2234. align-items: stretch;
  2235. }
  2236. .category-row .el-input {
  2237. max-width: 100%;
  2238. }
  2239. }
  2240. /* 菜品选择对话框样式 */
  2241. .dish-dialog-content {
  2242. display: flex;
  2243. flex-direction: column;
  2244. gap: 16px;
  2245. }
  2246. .dish-search-input {
  2247. width: 100%;
  2248. }
  2249. .dish-list-container {
  2250. :deep(.el-scrollbar__wrap) {
  2251. overflow-x: hidden;
  2252. }
  2253. :deep(.el-scrollbar__view) {
  2254. display: flex;
  2255. flex-direction: column;
  2256. gap: 12px;
  2257. }
  2258. }
  2259. .dish-empty-state {
  2260. display: flex;
  2261. flex-direction: column;
  2262. align-items: center;
  2263. justify-content: center;
  2264. padding: 60px 20px;
  2265. text-align: center;
  2266. }
  2267. .empty-text {
  2268. margin-bottom: 8px;
  2269. font-size: 16px;
  2270. color: #909399;
  2271. }
  2272. .empty-hint {
  2273. font-size: 14px;
  2274. color: #c0c4cc;
  2275. }
  2276. .dish-item {
  2277. position: relative;
  2278. display: flex;
  2279. gap: 12px;
  2280. align-items: center;
  2281. padding: 12px;
  2282. cursor: pointer;
  2283. border: 1px solid #e4e7ed;
  2284. border-radius: 4px;
  2285. transition: all 0.1s;
  2286. }
  2287. .dish-item:hover {
  2288. background-color: #f5f7fa;
  2289. border-color: #409eff;
  2290. }
  2291. .dish-item-selected {
  2292. background-color: #ecf5ff;
  2293. border-color: #409eff;
  2294. border-width: 1px;
  2295. }
  2296. .dish-item-selected:hover {
  2297. background-color: #d9ecff;
  2298. }
  2299. .dish-image {
  2300. flex-shrink: 0;
  2301. width: 60px;
  2302. height: 60px;
  2303. overflow: hidden;
  2304. background-color: #f5f7fa;
  2305. border-radius: 4px;
  2306. }
  2307. .dish-img {
  2308. width: 100%;
  2309. height: 100%;
  2310. }
  2311. .dish-image-placeholder {
  2312. display: flex;
  2313. align-items: center;
  2314. justify-content: center;
  2315. width: 100%;
  2316. height: 100%;
  2317. font-size: 24px;
  2318. color: #c0c4cc;
  2319. }
  2320. .dish-info {
  2321. display: flex;
  2322. flex: 1;
  2323. flex-direction: column;
  2324. gap: 4px;
  2325. }
  2326. .dish-name {
  2327. font-size: 14px;
  2328. font-weight: 500;
  2329. color: #606266;
  2330. }
  2331. .dish-price {
  2332. font-size: 14px;
  2333. color: #909399;
  2334. }
  2335. .dish-selected-icon {
  2336. display: flex;
  2337. flex-shrink: 0;
  2338. align-items: center;
  2339. justify-content: center;
  2340. width: 24px;
  2341. height: 24px;
  2342. font-size: 16px;
  2343. color: #ffffff;
  2344. background-color: #409eff;
  2345. border-radius: 50%;
  2346. }
  2347. .dialog-footer {
  2348. display: flex;
  2349. justify-content: center;
  2350. }
  2351. /* 展开收起动画 - 高度过渡 */
  2352. .slide-fade-enter-active {
  2353. overflow: hidden;
  2354. transition:
  2355. max-height 0.1s ease-out,
  2356. opacity 0.1s ease-out;
  2357. }
  2358. .slide-fade-leave-active {
  2359. overflow: hidden;
  2360. transition:
  2361. max-height 0.1s ease-in,
  2362. opacity 0.1s ease-in;
  2363. }
  2364. .slide-fade-enter-from {
  2365. max-height: 0;
  2366. opacity: 0;
  2367. }
  2368. .slide-fade-leave-to {
  2369. max-height: 0;
  2370. opacity: 0;
  2371. }
  2372. .slide-fade-enter-to,
  2373. .slide-fade-leave-from {
  2374. max-height: 2000px;
  2375. opacity: 1;
  2376. }
  2377. /* 分组收起全部动画 */
  2378. .group-fade-enter-active {
  2379. transition: all 0.1s ease-out;
  2380. }
  2381. .group-fade-leave-active {
  2382. transition: all 0.1s ease-in;
  2383. }
  2384. .group-fade-enter-from {
  2385. opacity: 0;
  2386. transform: translateY(-10px);
  2387. }
  2388. .group-fade-leave-to {
  2389. opacity: 0;
  2390. transform: translateY(-10px);
  2391. }
  2392. .group-fade-move {
  2393. transition: transform 0.1s linear;
  2394. }
  2395. </style>