| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501 |
- <template>
- <!-- 团购包管理 - 新增/编辑页面 -->
- <div class="table-box" style="width: 100%; min-height: 100%; background-color: white">
- <div class="header">
- <el-button @click="goBack"> 返回 </el-button>
- <h2 class="title">新建团购</h2>
- </div>
- <el-form :model="storeInfoModel" ref="ruleFormRef" :rules="rules" label-width="120px" class="formBox">
- <div class="content">
- <!-- 左侧内容区域 -->
- <div class="contentLeft">
- <!-- 基础信息模块 -->
- <div class="model">
- <h3 style="font-weight: bold">基础信息:</h3>
- <!-- 团购图片上传 -->
- <el-form-item label="图片" prop="imageList">
- <el-upload
- v-model:file-list="storeInfoModel.imageList"
- :action="uploadUrl"
- list-type="picture-card"
- :accept="'.jpg,.png'"
- :limit="9"
- :on-preview="handlePictureCardPreview"
- :before-remove="handleBeforeRemove"
- :on-remove="handleRemove"
- :on-success="handleSuccess"
- :show-file-list="true"
- >
- <el-icon>
- <Plus />
- </el-icon>
- </el-upload>
- </el-form-item>
- <!-- 团购名称 -->
- <el-form-item label="团购名称" prop="groupName">
- <el-input maxlength="50" v-model="storeInfoModel.groupName" placeholder="请填写团购名称" clearable />
- </el-form-item>
- <!-- 开始售卖时间设置方式 -->
- <el-form-item label="开始售卖时间" prop="startTimeType">
- <el-radio-group v-model="storeInfoModel.startTimeType" class="ml-4">
- <el-radio v-for="status in storeStatusList" :value="status.value" :key="status.value">
- {{ status.label }}
- </el-radio>
- </el-radio-group>
- </el-form-item>
- <!-- 自定义开始售卖时间(当选择"设置售卖时间"时显示) -->
- <el-form-item label="" prop="saleTimeStr" v-if="storeInfoModel.startTimeType == 1">
- <el-date-picker
- v-model="storeInfoModel.saleTimeStr"
- format="YYYY/MM/DD"
- value-format="YYYY-MM-DD"
- placeholder="请选择开始售卖时间"
- :disabled-date="disabledStartDate"
- />
- </el-form-item>
- <!-- 结束售卖时间 -->
- <el-form-item label="结束售卖时间" prop="endTime">
- <el-date-picker
- v-model="storeInfoModel.endTime"
- format="YYYY/MM/DD"
- value-format="YYYY-MM-DD"
- placeholder="请选择结束售卖时间"
- :disabled-date="disabledEndDate"
- />
- </el-form-item>
- <!-- 库存数量 -->
- <el-form-item label="库存数量" prop="inventoryNum">
- <el-input v-model="storeInfoModel.inventoryNum" maxlength="15" placeholder="请填写库存数量" clearable />
- </el-form-item>
- <!-- 每人限购设置 -->
- <el-form-item label="每人限购" prop="quotaType">
- <el-radio-group v-model="storeInfoModel.quotaType" class="ml-4">
- <el-radio v-for="status in perList" :value="status.value" :key="status.value">
- {{ status.label }}
- </el-radio>
- </el-radio-group>
- </el-form-item>
- <!-- 自定义限购数量(当选择"自定义限购数量"时显示) -->
- <el-form-item label="" prop="quotaValue" v-if="storeInfoModel.quotaType == 1">
- <el-input v-model="storeInfoModel.quotaValue" maxlength="15" placeholder="请填写自定义限购数量" clearable />
- </el-form-item>
- <!-- 套餐内容 -->
- <el-form-item label="套餐内容" class="package-content-item">
- <el-form
- ref="packageFormRef"
- :model="packageFormModel"
- :rules="packageFormRules"
- label-width="0"
- class="package-content-form"
- >
- <div class="package-content-wrapper">
- <div class="package-content-header">
- <el-button type="primary" @click="addGroup" class="add-group-btn"> 添加分组 </el-button>
- <el-button
- type="primary"
- link
- @click="toggleAllGroupsCollapse"
- :icon="allGroupsCollapsed ? ArrowDown : ArrowUp"
- v-show="lifeGroupBuyThalis.length > 1"
- >
- {{ allGroupsCollapsed ? "展开全部" : "收起全部" }}
- </el-button>
- </div>
- <transition-group name="group-fade" tag="div" class="package-content-container">
- <div v-for="item in visibleGroups" :key="item.originalIndex" class="package-group">
- <div class="package-group-header">
- <span class="group-index">{{ item.group.groupName }}</span>
- <div class="header-right">
- <el-button
- type="primary"
- link
- @click="toggleGroupCollapse(item.originalIndex)"
- :icon="isGroupCollapsed(item.originalIndex) ? ArrowDown : ArrowUp"
- v-show="item.group.dishes.length > 1"
- >
- {{ isGroupCollapsed(item.originalIndex) ? "展开" : "收起" }}
- </el-button>
- <el-button
- type="danger"
- link
- @click="removeGroup(item.originalIndex)"
- :icon="Delete"
- v-show="lifeGroupBuyThalis.length > 1"
- >
- 删除
- </el-button>
- </div>
- </div>
- <div class="package-group-content">
- <el-form-item
- :prop="`groups.${item.originalIndex}.groupName`"
- :rules="packageFormRules[`groups.${item.originalIndex}.groupName`]"
- class="category-form-item"
- >
- <div class="category-row">
- <span class="label">类别</span>
- <el-input v-model="item.group.groupName" placeholder="请输入" clearable />
- </div>
- </el-form-item>
- <!-- 第一行菜品,始终显示 -->
- <div v-if="item.group.dishes && item.group.dishes.length > 0" class="dish-row">
- <el-form-item
- :prop="`groups.${item.originalIndex}.dishes.0.detailId`"
- :rules="packageFormRules[`groups.${item.originalIndex}.dishes.0.detailId`]"
- class="dish-form-item"
- >
- <span class="label">菜品</span>
- <div class="dish-select-block" @click="openDishDialog(item.originalIndex, 0)">
- <span v-if="item.group.dishes[0].dishName" class="dish-selected-name"
- >{{ item.group.dishes[0].dishName }},¥{{ item.group.dishes[0].dishPrice }}/{{
- item.group.dishes[0].dishesUnit
- }}</span
- >
- <span v-else class="dish-placeholder">请选择</span>
- </div>
- </el-form-item>
- <el-form-item
- :prop="`groups.${item.originalIndex}.dishes.0.qty`"
- :rules="packageFormRules[`groups.${item.originalIndex}.dishes.0.qty`]"
- class="dish-form-item"
- >
- <span class="label">数量</span>
- <el-input v-model="item.group.dishes[0].qty" placeholder="请输入" clearable class="quantity-input" />
- <el-button
- :icon="Delete"
- link
- type="danger"
- @click="removeDish(item.originalIndex, 0)"
- class="delete-dish-btn"
- v-show="item.group.dishes.length > 1"
- />
- </el-form-item>
- </div>
- <!-- 第二行及以后的菜品,收起时隐藏 -->
- <transition name="slide-fade">
- <div v-if="!isGroupCollapsed(item.originalIndex)" class="extra-dishes-container">
- <div
- v-for="(dish, dishIndex) in item.group.dishes"
- :key="dishIndex"
- class="dish-row"
- v-show="dishIndex > 0"
- >
- <el-form-item
- :prop="`groups.${item.originalIndex}.dishes.${dishIndex}.detailId`"
- :rules="packageFormRules[`groups.${item.originalIndex}.dishes.${dishIndex}.detailId`]"
- class="dish-form-item"
- >
- <span class="label">菜品</span>
- <div class="dish-select-block" @click="openDishDialog(item.originalIndex, dishIndex)">
- <span v-if="dish.dishName" class="dish-selected-name"
- >{{ dish.dishName }},¥{{ dish.dishPrice }}/{{ dish.dishesUnit }}</span
- >
- <span v-else class="dish-placeholder">请选择</span>
- </div>
- </el-form-item>
- <el-form-item
- :prop="`groups.${item.originalIndex}.dishes.${dishIndex}.qty`"
- :rules="packageFormRules[`groups.${item.originalIndex}.dishes.${dishIndex}.qty`]"
- class="dish-form-item"
- >
- <span class="label">数量</span>
- <el-input v-model="dish.qty" placeholder="请输入" clearable class="quantity-input" />
- <el-button
- :icon="Delete"
- link
- type="danger"
- @click="removeDish(item.originalIndex, dishIndex)"
- class="delete-dish-btn"
- />
- </el-form-item>
- </div>
- <el-button type="primary" @click="addDish(item.originalIndex)" class="add-dish-btn"> 添加 </el-button>
- </div>
- </transition>
- </div>
- </div>
- </transition-group>
- </div>
- </el-form>
- </el-form-item>
- </div>
- <!-- 价格信息模块 -->
- <div class="model">
- <h3 style="font-weight: bold">价格:</h3>
- <!-- 原价 -->
- <el-form-item label="原价" prop="originalPrice">
- <el-input maxlength="50" v-model="storeInfoModel.originalPrice" placeholder="请填写原价" clearable />
- </el-form-item>
- <!-- 优惠价 -->
- <el-form-item label="优惠价" prop="preferentialPrice">
- <el-input maxlength="50" v-model="storeInfoModel.preferentialPrice" placeholder="请填写优惠价" clearable />
- </el-form-item>
- </div>
- </div>
- <!-- 右侧内容区域 -->
- <div class="contentRight">
- <!-- 购买须知模块 -->
- <div class="model">
- <h3 style="font-weight: bold">购买须知:</h3>
- <el-form-item label="有效期" prop="effectiveDateType">
- <el-radio-group v-model="storeInfoModel.effectiveDateType" class="ml-4">
- <el-radio v-for="status in expirationDateStatusList" :value="status.value" :key="status.value">
- {{ status.label }}
- </el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item label="" prop="expirationDate" v-if="storeInfoModel.effectiveDateType == 0">
- <div class="expiration-date-container">
- <span class="expiration-label">用户购买</span>
- <el-input-number v-model="storeInfoModel.expirationDate" placeholder="请输入" :min="0" class="expiration-input" />
- <span class="expiration-label">天内有效</span>
- </div>
- </el-form-item>
- <el-form-item label="" prop="expirationDateList" v-else>
- <el-date-picker
- v-model="storeInfoModel.expirationDateList"
- type="daterange"
- value-format="YYYY-MM-DD"
- range-separator="-"
- start-placeholder="开始时间"
- end-placeholder="结束时间"
- :disabled-date="disabledEffectiveDate"
- />
- </el-form-item>
- <el-form-item label="不可用日期" prop="disableDateType">
- <el-radio-group v-model="storeInfoModel.disableDateType" class="ml-4">
- <el-radio v-for="status in unavailableDatesList" :value="status.value" :key="status.value">
- {{ status.label }}
- </el-radio>
- </el-radio-group>
- </el-form-item>
- <template v-if="storeInfoModel.disableDateType == 1">
- <el-form-item label="" prop="unavailableWeekdays">
- <div class="unavailable-dates-container">
- <!-- 星期选择 -->
- <div class="date-select-section">
- <div class="section-title">星期</div>
- <div class="button-group">
- <el-button
- v-for="weekday in weekdayList"
- :key="weekday.oName"
- :type="storeInfoModel.unavailableWeekdays?.includes(weekday.oName) ? 'primary' : ''"
- class="date-select-btn"
- @click="toggleWeekday(weekday.oName)"
- >
- {{ weekday.name }}
- </el-button>
- </div>
- </div>
- </div>
- </el-form-item>
- <el-form-item label="" prop="unavailableHolidays">
- <div class="unavailable-dates-container">
- <!-- 节日选择 -->
- <div class="date-select-section">
- <div class="section-title">节日</div>
- <div class="button-group">
- <el-button
- v-for="holiday in holidayList"
- :key="holiday.id"
- :type="storeInfoModel.unavailableHolidays?.includes(holiday.id) ? 'primary' : ''"
- class="date-select-btn"
- @click="toggleHoliday(holiday.id)"
- >
- {{ holiday.festivalName }}
- </el-button>
- </div>
- </div>
- </div>
- </el-form-item>
- </template>
- <el-form-item label="" prop="customUnavailableDates" v-else-if="storeInfoModel.disableDateType == 2">
- <div class="date-picker-container">
- <el-button :icon="Plus" class="add-date-btn" type="primary" @click="addDate"> 添加日期 </el-button>
- <div v-for="(item, index) in storeInfoModel.disableDateList" :key="index" class="date-item">
- <el-date-picker
- v-model="storeInfoModel.disableDateList[index]"
- type="daterange"
- value-format="YYYY-MM-DD"
- range-separator="-"
- start-placeholder="开始时间"
- end-placeholder="结束时间"
- class="date-picker"
- :disabled-date="disabledCustomUnavailableDate"
- />
- <el-button
- :icon="Delete"
- type="danger"
- circle
- size="small"
- class="delete-btn"
- @click="removeDate(index)"
- v-show="storeInfoModel.disableDateList.length > 1"
- />
- </div>
- </div>
- </el-form-item>
- <!-- 预约规则 -->
- <el-form-item label="预约规则" prop="reservationRules">
- <el-input
- maxlength="300"
- v-model="storeInfoModel.reservationRules"
- :rows="4"
- type="textarea"
- placeholder="请输入预约规则"
- />
- </el-form-item>
- <!-- 使用规则 -->
- <el-form-item label="使用规则" prop="useRules">
- <el-input
- maxlength="300"
- v-model="storeInfoModel.useRules"
- :rows="4"
- type="textarea"
- placeholder="请输入使用规则"
- />
- </el-form-item>
- <!-- 适用人数 -->
- <el-form-item label="适用人数" prop="applicableNum">
- <el-input v-model="storeInfoModel.applicableNum" maxlength="15" placeholder="请填写适用人数" clearable />
- </el-form-item>
- <!-- 其他规则 -->
- <el-form-item label="其他规则" prop="otherRules">
- <el-input
- maxlength="300"
- v-model="storeInfoModel.otherRules"
- :rows="4"
- type="textarea"
- placeholder="请输入其他规则"
- />
- </el-form-item>
- <!-- 发票信息 -->
- <el-form-item label="发票信息" prop="invoiceInformation">
- <el-checkbox-group v-model="storeInfoModel.invoiceInformation">
- <el-checkbox v-for="bt in businessTypes" :key="bt.value" :value="bt.value" :label="bt.label">
- {{ bt.label }}
- </el-checkbox>
- </el-checkbox-group>
- </el-form-item>
- <!-- 发票说明 -->
- <el-form-item label="发票说明" prop="invoiceDescribe">
- <el-input v-model="storeInfoModel.invoiceDescribe" maxlength="15" placeholder="请填写发票说明" clearable />
- </el-form-item>
- </div>
- </div>
- </div>
- </el-form>
- <!-- 底部按钮区域 -->
- <div class="button-container">
- <el-button @click="handleSubmit('cg')"> 存草稿 </el-button>
- <el-button type="primary" @click="handleSubmit"> 确定 </el-button>
- </div>
- <!-- 图片预览 -->
- <el-image-viewer
- v-if="imageViewerVisible"
- :url-list="imageViewerUrlList"
- :initial-index="imageViewerInitialIndex"
- @close="imageViewerVisible = false"
- />
- <!-- 菜品选择对话框 -->
- <el-dialog v-model="dishDialogVisible" title="菜品" width="600px" :close-on-click-modal="false">
- <div class="dish-dialog-content">
- <el-input
- v-model="dishSearchKeyword"
- placeholder="请输入菜品名称"
- clearable
- class="dish-search-input"
- @input="filterDishList"
- />
- <el-scrollbar height="400px" class="dish-list-container">
- <template v-if="filteredDishList.length > 0">
- <div
- v-for="dish in filteredDishList"
- :key="dish.id"
- :class="['dish-item', { 'dish-item-selected': selectedDishId === dish.id }]"
- @click="selectDish(dish)"
- >
- <div class="dish-image">
- <el-image v-if="dish.imgUrl" :src="dish.imgUrl" fit="cover" class="dish-img" />
- <div v-else class="dish-image-placeholder">
- <el-icon><Picture /></el-icon>
- </div>
- </div>
- <div class="dish-info">
- <div class="dish-name">
- {{ dish.dishName }}
- </div>
- <div class="dish-price">¥{{ dish.dishPrice }}/{{ dish.dishesUnit }}</div>
- </div>
- </div>
- </template>
- <div v-else class="dish-empty-state">
- <div class="empty-text">暂无可选择菜品</div>
- <div class="empty-hint">请去全部-门店装修-菜品管理中添加</div>
- </div>
- </el-scrollbar>
- </div>
- <template #footer>
- <div class="dialog-footer">
- <el-button type="primary" @click="confirmDishSelection"> 确定 </el-button>
- </div>
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup lang="tsx" name="newGroup">
- /**
- * 团购包管理 - 新增/编辑页面
- * 功能:支持团购包的新增和编辑操作
- */
- import { ref, reactive, onMounted, watch, nextTick, computed } from "vue";
- import { ElMessage, ElMessageBox } from "element-plus";
- import { Plus, Delete, ArrowDown, ArrowUp, Picture } from "@element-plus/icons-vue";
- import {
- saveStoreInfo,
- editStoreInfo,
- getDetail,
- getStoreDetail,
- getHolidayList,
- getUserByPhone,
- getMenuByStoreId
- } from "@/api/modules/groupPackageManagement";
- import { useRouter, useRoute } from "vue-router";
- import type { UploadProps, FormInstance } from "element-plus";
- import { localGet, localSet } from "@/utils";
- // ==================== 响应式数据定义 ====================
- // 图片预览相关
- const imageViewerVisible = ref(false);
- const imageViewerUrlList = ref<string[]>([]);
- const imageViewerInitialIndex = ref(0);
- // 路由相关
- const router = useRouter();
- const route = useRoute();
- // 页面状态
- const type = ref<string>(""); // 页面类型:add-新增, edit-编辑
- const id = ref<string>(""); // 页面ID参数
- // 文件上传地址
- const uploadUrl = ref(`${import.meta.env.VITE_API_URL_STORE}/file/upload`);
- // ==================== 表单验证规则 ====================
- const rules = reactive({
- imageList: [{ required: true, message: "请上传图片" }],
- groupName: [{ required: true, message: "请填写团购名称" }],
- startTimeType: [{ required: true, message: "请选择开始售卖时间" }],
- saleTimeStr: [
- { required: true, message: "请选择开始售卖时间" },
- {
- validator: (rule: any, value: any, callback: any) => {
- if (storeInfoModel.value.startTimeType === 1) {
- if (!value) {
- callback(new Error("请选择开始售卖时间"));
- return;
- }
- const selectedDate = new Date(value);
- const today = new Date();
- today.setHours(0, 0, 0, 0);
- if (selectedDate < today) {
- callback(new Error("开始售卖时间不能早于当前时间"));
- return;
- }
- // 如果结束时间已设置,验证开始时间必须早于结束时间
- if (storeInfoModel.value.endTime) {
- const endDate = new Date(storeInfoModel.value.endTime);
- if (selectedDate >= endDate) {
- callback(new Error("开始售卖时间必须早于结束售卖时间"));
- return;
- }
- }
- }
- callback();
- },
- trigger: "change"
- }
- ],
- endTime: [
- { required: true, message: "请选择结束售卖时间" },
- {
- validator: (rule: any, value: any, callback: any) => {
- if (!value) {
- callback(new Error("请选择结束售卖时间"));
- return;
- }
- const selectedDate = new Date(value);
- const today = new Date();
- today.setHours(0, 0, 0, 0);
- if (selectedDate < today) {
- callback(new Error("结束售卖时间不能早于当前时间"));
- return;
- }
- // 如果开始时间已设置,验证结束时间必须晚于开始时间
- if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.saleTimeStr) {
- const startDate = new Date(storeInfoModel.value.saleTimeStr);
- if (selectedDate <= startDate) {
- callback(new Error("结束售卖时间必须晚于开始售卖时间"));
- return;
- }
- }
- callback();
- },
- trigger: "change"
- }
- ],
- inventoryNum: [
- { required: true, message: "请填写库存数量" },
- {
- validator: (rule: any, value: any, callback: any) => {
- if (!value || value.toString().trim() === "") {
- callback();
- return;
- }
- const num = Number(value);
- if (isNaN(num) || num <= 0) {
- callback(new Error("库存数量必须为正整数"));
- return;
- }
- if (!Number.isInteger(num)) {
- callback(new Error("库存数量必须为正整数"));
- return;
- }
- callback();
- },
- trigger: "blur"
- }
- ],
- quotaType: [{ required: true, message: "请选择每人限购" }],
- quotaValue: [
- {
- required: true,
- validator: (rule: any, value: any, callback: any) => {
- if (storeInfoModel.value.quotaType === 1) {
- if (!value || value.toString().trim() === "") {
- callback(new Error("请输入自定义限购数量"));
- return;
- }
- const num = Number(value);
- if (isNaN(num) || num <= 0) {
- callback(new Error("自定义限购数量必须为正整数"));
- return;
- }
- if (!Number.isInteger(num)) {
- callback(new Error("自定义限购数量必须为正整数"));
- return;
- }
- }
- callback();
- },
- trigger: "blur"
- }
- ],
- lifeGroupBuyThalis: [
- {
- required: true,
- validator: (rule: any, value: any, callback: any) => {
- try {
- // 只检查是否有至少一个分组,详细验证由独立的套餐内容表单处理
- const thalis = lifeGroupBuyThalis.value;
- if (!thalis || thalis.length === 0) {
- callback(new Error("请至少添加一个套餐分组"));
- return;
- }
- callback();
- } catch (error) {
- // 如果验证过程中出错,直接通过验证,避免报错
- callback();
- }
- },
- trigger: "blur"
- }
- ],
- originalPrice: [
- { required: true, message: "请输入原价" },
- {
- validator: (rule: any, value: any, callback: any) => {
- if (!value || value.toString().trim() === "") {
- callback();
- return;
- }
- const num = Number(value);
- if (isNaN(num) || num <= 0) {
- callback(new Error("原价必须为正数"));
- return;
- }
- callback();
- },
- trigger: "blur"
- }
- ],
- preferentialPrice: [
- { required: true, message: "请输入优惠价" },
- {
- validator: (rule: any, value: any, callback: any) => {
- if (!value || value.toString().trim() === "") {
- callback();
- return;
- }
- const num = Number(value);
- if (isNaN(num) || num <= 0) {
- callback(new Error("优惠价必须为正数"));
- return;
- }
- callback();
- },
- trigger: "blur"
- }
- ],
- effectiveDateType: [{ required: true, message: "请选择有效期" }],
- expirationDate: [
- {
- required: true,
- validator: (rule: any, value: any, callback: any) => {
- if (storeInfoModel.value.expirationDate === 0) {
- if (value === null || value === undefined || value === "") {
- callback(new Error("请输入用户购买天数"));
- return;
- }
- if (value <= 0) {
- callback(new Error("天数必须大于0"));
- return;
- }
- }
- callback();
- },
- trigger: "blur"
- }
- ],
- expirationDateList: [
- {
- required: true,
- validator: (rule: any, value: any, callback: any) => {
- if (storeInfoModel.value.effectiveDateType === 1) {
- if (!value || value.length !== 2) {
- callback(new Error("请选择指定时间段"));
- return;
- }
- // 验证开始时间和结束时间不能早于当前时间
- const today = new Date();
- today.setHours(0, 0, 0, 0);
- const startDate = new Date(value[0]);
- const endDate = new Date(value[1]);
- if (startDate < today) {
- callback(new Error("开始时间不能早于当前时间"));
- return;
- }
- if (endDate < today) {
- callback(new Error("结束时间不能早于当前时间"));
- return;
- }
- // 验证开始时间必须早于结束时间
- if (startDate >= endDate) {
- callback(new Error("开始时间必须早于结束时间"));
- return;
- }
- }
- callback();
- },
- trigger: "change"
- }
- ],
- disableDateType: [{ required: true, message: "请选择不可用日期" }],
- unavailableWeekdays: [
- {
- required: true,
- validator: (rule: any, value: any, callback: any) => {
- if (storeInfoModel.value.disableDateType === 1) {
- if (!value || value.length === 0) {
- callback(new Error("至少需要选择一个星期"));
- return;
- }
- }
- callback();
- },
- trigger: "change"
- }
- ],
- unavailableHolidays: [
- {
- required: true,
- validator: (rule: any, value: any, callback: any) => {
- if (storeInfoModel.value.disableDateType === 1) {
- if (!value || value.length === 0) {
- callback(new Error("至少需要选择一个节日"));
- return;
- }
- }
- callback();
- },
- trigger: "change"
- }
- ],
- customUnavailableDates: [
- {
- required: true,
- validator: (rule: any, value: any, callback: any) => {
- if (storeInfoModel.value.disableDateType === 2) {
- if (!storeInfoModel.value.disableDateList || storeInfoModel.value.disableDateList.length === 0) {
- callback(new Error("至少需要添加一个自定义不可用日期"));
- return;
- }
- const today = new Date();
- today.setHours(0, 0, 0, 0);
- // 验证每个日期项是否已填写
- for (let i = 0; i < storeInfoModel.value.disableDateList.length; i++) {
- if (!storeInfoModel.value.disableDateList[i] || storeInfoModel.value.disableDateList[i].length !== 2) {
- callback(new Error(`第${i + 1}个日期项未完整填写`));
- return;
- }
- // 验证开始时间和结束时间不能早于当前时间
- const startDate = new Date(storeInfoModel.value.disableDateList[i][0]);
- const endDate = new Date(storeInfoModel.value.disableDateList[i][1]);
- if (startDate < today) {
- callback(new Error(`第${i + 1}个日期项的开始时间不能早于当前时间`));
- return;
- }
- if (endDate < today) {
- callback(new Error(`第${i + 1}个日期项的结束时间不能早于当前时间`));
- return;
- }
- // 验证开始时间必须早于结束时间
- if (startDate >= endDate) {
- callback(new Error(`第${i + 1}个日期项的开始时间必须早于结束时间`));
- return;
- }
- }
- }
- callback();
- },
- trigger: "change"
- }
- ],
- reservationRules: [{ required: true, message: "请输入预约规则" }],
- useRules: [{ required: true, message: "请输入使用规则" }],
- applicableNum: [
- { required: true, message: "请输入适用人数" },
- {
- validator: (rule: any, value: any, callback: any) => {
- if (!value || value.toString().trim() === "") {
- callback();
- return;
- }
- const num = Number(value);
- if (isNaN(num) || num <= 0) {
- callback(new Error("适用人数必须为正整数"));
- return;
- }
- if (!Number.isInteger(num)) {
- callback(new Error("适用人数必须为正整数"));
- return;
- }
- callback();
- },
- trigger: "blur"
- }
- ],
- otherRules: [{ required: true, message: "请输入其他规则" }],
- invoiceInformation: [{ required: true, message: "请选择发票信息" }],
- invoiceDescribe: [{ required: true, message: "请输入发票说明" }]
- });
- // ==================== 团购包信息数据模型 ====================
- const storeInfoModel = ref<any>({
- // 团购图片列表
- imageList: [],
- // 团购名称
- groupName: "",
- // 开始售卖时间设置方式:0-审核通过后立即开始,1-设置售卖时间
- startTimeType: 0,
- // 开始售卖时间(当storeStatus为1时必填)
- saleTimeStr: "",
- // 结束售卖时间
- endTime: "",
- // 库存数量
- inventoryNum: "",
- // 每人限购设置:0-不限量,1-自定义限购数量
- quotaType: 0,
- // 自定义限购数量(当quotaType为1时必填)
- quotaValue: 0,
- // 套餐内容(虚拟字段,用于表单验证,实际数据在 lifeGroupBuyThalis 变量中)
- lifeGroupBuyThalis: null,
- // 原价
- originalPrice: "",
- // 优惠价
- preferentialPrice: "",
- // 有效期设置:0-指定天数,1-指定时间段内可用
- effectiveDateType: 0,
- expirationDate: 0,
- expirationDateList: [],
- // 不可用日期设置:0-全部日期可用,1-限制日期,2-自定义不可用日期
- disableDateType: 0,
- // 限制日期 - 星期选择(数组,存储选中的星期值)
- unavailableWeekdays: [],
- // 限制日期 - 节日选择(数组,存储选中的节日值)
- unavailableHolidays: [],
- // 自定义不可用日期列表
- disableDateList: [],
- // 预约规则
- reservationRules: "",
- // 使用规则
- useRules: "",
- // 适用人数
- applicableNum: "",
- // 其他规则
- otherRules: "",
- // 发票信息(复选框,可多选)
- invoiceInformation: [],
- // 发票说明
- invoiceDescribe: ""
- });
- // ==================== 下拉选项数据 ====================
- // 发票类型列表
- const businessTypes = ref([
- { value: 0, label: "提供电子发票" },
- { value: 1, label: "提供纸质发票" }
- ]);
- // 开始售卖时间设置方式列表
- const storeStatusList = ref([
- { value: 0, label: "审核通过后立即开始" },
- { value: 1, label: "设置售卖时间" }
- ]);
- // 每人限购设置
- const perList = ref([
- { value: 0, label: "不限量" },
- { value: 1, label: "自定义限购数量" }
- ]);
- // 有效期设置
- const expirationDateStatusList = ref([
- { value: 0, label: "指定天数" },
- { value: 1, label: "指定时间段内可用" }
- ]);
- // 有效期设置
- const unavailableDatesList = ref([
- { value: 0, label: "全部日期可用" },
- { value: 1, label: "限制日期" },
- { value: 2, label: "自定义不可用日期" }
- ]);
- // 星期选项列表
- const weekdayList = ref([
- { name: "周一", id: "0", oName: "星期一" },
- { name: "周二", id: "1", oName: "星期二" },
- { name: "周三", id: "2", oName: "星期三" },
- { name: "周四", id: "3", oName: "星期四" },
- { name: "周五", id: "4", oName: "星期五" },
- { name: "周六", id: "5", oName: "星期六" },
- { name: "周日", id: "6", oName: "星期日" }
- ]);
- // 节日选项列表
- const holidayList: any = ref([]);
- // 菜品选项列表
- const dishOptions: any = ref([]);
- // 套餐内容(数组,每个元素是一个分组)
- const lifeGroupBuyThalis = ref([
- {
- groupName: "", // 类别
- dishes: [
- // 菜品列表
- {
- detailId: "", // 菜品ID
- dishName: "", // 菜品名称
- dishPrice: "", // 菜品价格
- dishImage: "", // 菜品图片
- qty: "", // 数量
- dishesUnit: ""
- }
- ]
- }
- ]);
- // 菜品选择对话框相关
- const dishDialogVisible = ref(false);
- const dishSearchKeyword = ref("");
- const filteredDishList: any = ref([]);
- const selectedDishId = ref<number | string | null>(null);
- const currentDishGroupIndex = ref<number>(-1);
- const currentDishIndex = ref<number>(-1);
- // 套餐内容整体展开收起状态
- const allGroupsCollapsed = ref(false);
- // 每个分组的收起状态(数组,索引对应分组索引)
- const groupCollapsedStates = ref<boolean[]>([false]); // 默认第一个分组展开
- // 计算属性:过滤要显示的分组(收起全部时只显示第一个分组),保留原始索引
- const visibleGroups = computed(() => {
- if (allGroupsCollapsed.value) {
- return lifeGroupBuyThalis.value.map((group, index) => ({ group, originalIndex: index })).filter((_, index) => index === 0);
- }
- return lifeGroupBuyThalis.value.map((group, index) => ({ group, originalIndex: index }));
- });
- // ==================== 监听器 ====================
- /**
- * 监听不可用日期选项变化
- * 当切换到自定义不可用日期时,确保至少有一个日期项
- */
- watch(
- () => storeInfoModel.value.disableDateType,
- newVal => {
- if (newVal === 2) {
- // 切换到自定义不可用日期时,如果disableDateList为空,则添加一个默认项
- if (!storeInfoModel.value.disableDateList || storeInfoModel.value.disableDateList.length === 0) {
- storeInfoModel.value.disableDateList = [null];
- }
- }
- },
- { immediate: true }
- );
- /**
- * 监听开始售卖时间变化
- * 当开始时间改变时,重新验证结束时间
- */
- watch(
- () => storeInfoModel.value.saleTimeStr,
- () => {
- if (storeInfoModel.value.endTime) {
- nextTick(() => {
- ruleFormRef.value?.validateField("endTime");
- });
- }
- }
- );
- /**
- * 监听结束售卖时间变化
- * 当结束时间改变时,重新验证开始时间
- */
- watch(
- () => storeInfoModel.value.endTime,
- () => {
- if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.saleTimeStr) {
- nextTick(() => {
- ruleFormRef.value?.validateField("saleTimeStr");
- });
- }
- }
- );
- // ==================== 生命周期钩子 ====================
- /**
- * 组件挂载时初始化
- * 从路由参数中获取页面类型和ID
- */
- onMounted(async () => {
- id.value = (route.query.id as string) || "";
- type.value = (route.query.type as string) || "";
- let param = {
- // phone: localGet("iphone")
- phone: "18641153170"
- };
- const resP: any = await getUserByPhone(param);
- if (resP.data && resP.data.storeId) {
- localSet("createdId", resP.data.storeId);
- const resD: any = await getDetail({
- id: localGet("createdId")
- });
- if (resD.data && resD.data.commissionRate) {
- localSet("commissionRate", resD.data.commissionRate);
- }
- if (resD.data && resD.data.businessSection) {
- localSet("businessSection", resD.data.businessSection);
- }
- } else {
- ElMessage.warning("请完成商家入驻后再进行新建团购");
- }
- // if (!getGroupCombination()) {
- // ElMessage.warning("请完成商家入驻后重新登录再进行新建团购");
- // return;
- // }
- let params = {
- year: new Date().getFullYear(),
- page: 1,
- size: 500,
- openFlag: 1,
- holidayName: ""
- };
- let res: any = await getHolidayList(params);
- if (res && res.code == 200) {
- holidayList.value = res.data.records;
- }
- if (type.value != "add") {
- let res: any = await getStoreDetail({ id: id.value } as any);
- storeInfoModel.value = { ...storeInfoModel.value, ...res.data.lifeGroupBuyMain };
- let imageList: any[] = [];
- handleImageParam((res.data as any).businessLicenseAddress || [], imageList);
- storeInfoModel.value.imageList = imageList;
- storeInfoModel.value.expirationDateList = storeInfoModel.value.expirationDateList.split(";");
- storeInfoModel.value.invoiceInformation = storeInfoModel.value.invoiceType.split(";");
- // 确保星期和节日字段存在
- const listVal = storeInfoModel.value.disableDateValue.split(";");
- storeInfoModel.value.unavailableWeekdays = listVal[0].split(",");
- storeInfoModel.value.unavailableHolidays = listVal[1].split(",");
- if (res.data.lifeGroupBuyThalis && res.data.lifeGroupBuyThalis.length > 0) {
- lifeGroupBuyThalis.value = res.data.lifeGroupBuyThalis;
- // 确保每个分组都有必要的字段
- lifeGroupBuyThalis.value.forEach((group: any) => {
- if (!group.dishes || group.dishes.length === 0) {
- group.dishes = [
- {
- detailId: "",
- qty: ""
- }
- ];
- }
- });
- // 初始化所有分组的收起状态为展开
- groupCollapsedStates.value = new Array(lifeGroupBuyThalis.value.length).fill(false);
- } else {
- // 如果没有数据,使用默认值
- lifeGroupBuyThalis.value = [
- {
- groupName: "",
- dishes: [
- {
- detailId: "",
- dishName: "",
- dishPrice: "",
- dishImage: "",
- qty: "",
- dishesUnit: ""
- }
- ]
- }
- ];
- // 初始化默认分组的收起状态为展开
- groupCollapsedStates.value = [false];
- }
- // 确保自定义不可用日期字段存在
- if (storeInfoModel.value.disableDateType === 2) {
- // 后端直接返回 disableDateList 字段,如果为空则初始化为默认值
- if (!storeInfoModel.value.disableDateList || storeInfoModel.value.disableDateList.length === 0) {
- storeInfoModel.value.disableDateList = [null];
- }
- }
- }
- });
- // ==================== 事件处理函数 ====================
- /**
- * 返回上一页
- */
- const goBack = () => {
- router.go(-1);
- };
- /**
- * 图片上传 - 删除前确认
- * @param uploadFile 要删除的文件对象
- * @param uploadFiles 当前文件列表
- * @returns Promise<boolean>,true 允许删除,false 阻止删除
- */
- const handleBeforeRemove = async (uploadFile: any, uploadFiles: any[]): Promise<boolean> => {
- try {
- await ElMessageBox.confirm("确定要删除这张图片吗?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- });
- // 用户确认删除,返回 true 允许删除
- return true;
- } catch {
- // 用户取消删除,返回 false 阻止删除
- return false;
- }
- };
- /**
- * 图片上传 - 移除图片回调(删除成功后调用)
- * @param uploadFile 已删除的文件对象
- * @param uploadFiles 删除后的文件列表
- */
- const handleRemove: UploadProps["onRemove"] = (uploadFile, uploadFiles) => {
- // 删除成功后提示
- ElMessage.success("图片已删除");
- };
- /**
- * 图片上传 - 上传成功回调
- * @param response 上传响应数据
- */
- const handleSuccess = (response: any) => {
- ElMessage.success("图片上传成功");
- // 上传成功后,imageList 会自动更新,response.data 包含图片URL
- };
- /**
- * 图片预览 - 使用 el-image 预览功能
- * @param file 上传文件对象
- */
- const handlePictureCardPreview = (file: any) => {
- // 获取所有图片的 URL 列表
- const urlList = storeInfoModel.value.imageList.map((item: any) => item.url || item.response?.data || item);
- // 找到当前点击的图片索引
- const currentIndex = urlList.findIndex((url: string) => url === file.url);
- imageViewerUrlList.value = urlList;
- imageViewerInitialIndex.value = currentIndex >= 0 ? currentIndex : 0;
- imageViewerVisible.value = true;
- };
- /**
- * 添加自定义不可用日期
- */
- const addDate = () => {
- storeInfoModel.value.disableDateList.push(null);
- };
- /**
- * 删除自定义不可用日期
- * @param index 要删除的日期索引
- */
- const removeDate = (index: number) => {
- if (storeInfoModel.value.disableDateList.length <= 1) {
- ElMessage.warning("至少需要保留一个日期项");
- return;
- }
- storeInfoModel.value.disableDateList.splice(index, 1);
- // 删除日期项后,重新验证表单以清除旧的验证错误
- nextTick(() => {
- ruleFormRef.value?.validateField("customUnavailableDates");
- });
- };
- /**
- * 切换星期选择
- * @param value 星期值
- */
- const toggleWeekday = value => {
- if (!storeInfoModel.value.unavailableWeekdays) {
- storeInfoModel.value.unavailableWeekdays = [];
- }
- const index = storeInfoModel.value.unavailableWeekdays.indexOf(value);
- if (index > -1) {
- storeInfoModel.value.unavailableWeekdays.splice(index, 1);
- } else {
- storeInfoModel.value.unavailableWeekdays.push(value);
- }
- console.log(storeInfoModel.value.unavailableWeekdays);
- // 触发表单验证
- nextTick(() => {
- ruleFormRef.value?.validateField("unavailableWeekdays");
- });
- };
- /**
- * 切换节日选择
- * @param value 节日值
- */
- const toggleHoliday = value => {
- if (!storeInfoModel.value.unavailableHolidays) {
- storeInfoModel.value.unavailableHolidays = [];
- }
- const index = storeInfoModel.value.unavailableHolidays.indexOf(value);
- if (index > -1) {
- storeInfoModel.value.unavailableHolidays.splice(index, 1);
- } else {
- storeInfoModel.value.unavailableHolidays.push(value);
- }
- console.log(storeInfoModel.value.unavailableHolidays);
- // 触发表单验证
- nextTick(() => {
- ruleFormRef.value?.validateField("unavailableHolidays");
- });
- };
- /**
- * 添加套餐分组
- */
- const addGroup = () => {
- if (!lifeGroupBuyThalis.value) {
- lifeGroupBuyThalis.value = [];
- }
- // 检查分组数量限制(最多20个)
- if (lifeGroupBuyThalis.value.length >= 20) {
- ElMessage.warning("最多只能添加20个分组");
- return;
- }
- // 验证所有现有分组是否填写完整
- for (let i = 0; i < lifeGroupBuyThalis.value.length; i++) {
- const group = lifeGroupBuyThalis.value[i];
- // 验证类别
- if (!group.groupName || group.groupName.trim() === "") {
- ElMessage.warning("请先完成现有分组的填写");
- // 触发表单验证,显示验证错误
- nextTick(() => {
- if (packageFormRef.value) {
- packageFormRef.value.validate(() => {});
- }
- });
- return;
- }
- // 验证是否有菜品
- if (!group.dishes || group.dishes.length === 0) {
- ElMessage.warning("请先完成现有分组的填写");
- // 触发表单验证,显示验证错误
- nextTick(() => {
- if (packageFormRef.value) {
- packageFormRef.value.validate(() => {});
- }
- });
- return;
- }
- // 验证当前分组中每个菜品是否填写完整
- for (let j = 0; j < group.dishes.length; j++) {
- const dish = group.dishes[j];
- // 验证菜品是否已选择
- if (!dish.detailId) {
- ElMessage.warning("请先完成现有分组的填写");
- // 触发表单验证,显示验证错误
- nextTick(() => {
- if (packageFormRef.value) {
- packageFormRef.value.validate(() => {});
- }
- });
- return;
- }
- // 验证数量是否已填写
- if (!dish.qty || dish.qty.toString().trim() === "") {
- ElMessage.warning("请先完成现有分组的填写");
- // 触发表单验证,显示验证错误
- nextTick(() => {
- if (packageFormRef.value) {
- packageFormRef.value.validate(() => {});
- }
- });
- return;
- }
- // 验证数量格式
- const quantityNum = Number(dish.qty);
- if (isNaN(quantityNum) || quantityNum <= 0 || !Number.isInteger(quantityNum)) {
- ElMessage.warning("请先完成现有分组的填写");
- // 触发表单验证,显示验证错误
- nextTick(() => {
- if (packageFormRef.value) {
- packageFormRef.value.validate(() => {});
- }
- });
- return;
- }
- }
- }
- // 添加新分组
- lifeGroupBuyThalis.value.push({
- groupName: "",
- dishes: [
- {
- detailId: "",
- dishName: "",
- dishPrice: "",
- dishImage: "",
- qty: "",
- dishesUnit: ""
- }
- ]
- });
- // 初始化新分组的收起状态为展开
- groupCollapsedStates.value.push(false);
- // 清除表单验证状态,避免新分组显示验证错误
- // 使用延迟清除,确保在验证规则更新和 DOM 渲染完成后再清除
- nextTick(() => {
- requestAnimationFrame(() => {
- setTimeout(() => {
- if (packageFormRef.value) {
- // 只清除新添加分组的验证状态
- const newGroupIndex = lifeGroupBuyThalis.value.length - 1;
- const propsToClear = [
- `groups.${newGroupIndex}.groupName`,
- `groups.${newGroupIndex}.dishes.0.detailId`,
- `groups.${newGroupIndex}.dishes.0.qty`
- ];
- // Element Plus 的 clearValidate 可以接受字符串数组
- propsToClear.forEach(prop => {
- packageFormRef.value?.clearValidate(prop);
- });
- }
- }, 150);
- });
- });
- };
- /**
- * 删除套餐分组
- * @param groupIndex 分组索引
- */
- const removeGroup = (groupIndex: number) => {
- if (lifeGroupBuyThalis.value.length <= 1) {
- ElMessage.warning("至少需要保留一个分组");
- return;
- }
- ElMessageBox.confirm("确定要删除这个分组吗?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- })
- .then(() => {
- lifeGroupBuyThalis.value.splice(groupIndex, 1);
- // 同步删除收起状态数组中的对应项
- if (groupCollapsedStates.value.length > groupIndex) {
- groupCollapsedStates.value.splice(groupIndex, 1);
- }
- ElMessage.success("删除成功");
- })
- .catch(() => {});
- };
- /**
- * 判断分组是否收起
- * @param groupIndex 分组索引
- * @returns 是否收起(收起时只显示类别和第一行菜品,隐藏其他菜品行)
- */
- const isGroupCollapsed = (groupIndex: number): boolean => {
- // 如果"收起全部"状态为true,第一个分组应该展开(显示所有菜品),其他分组收起
- if (allGroupsCollapsed.value) {
- return groupIndex !== 0;
- }
- // 否则根据分组的收起状态判断
- return groupCollapsedStates.value[groupIndex] === true;
- };
- /**
- * 切换单个分组的收起/展开状态
- * @param groupIndex 分组索引
- */
- const toggleGroupCollapse = (groupIndex: number) => {
- // 如果当前是"收起全部"状态,先取消该状态
- if (allGroupsCollapsed.value) {
- allGroupsCollapsed.value = false;
- // 设置所有分组状态:第一个分组当前是展开的,其他分组当前是收起的
- // 所以第一个分组应该设置为收起,其他分组应该设置为展开
- groupCollapsedStates.value = new Array(lifeGroupBuyThalis.value.length).fill(true);
- groupCollapsedStates.value[0] = false; // 第一个分组原本是展开的
- // 然后切换当前分组的状态
- groupCollapsedStates.value[groupIndex] = !groupCollapsedStates.value[groupIndex];
- } else {
- // 确保数组长度足够
- while (groupCollapsedStates.value.length <= groupIndex) {
- groupCollapsedStates.value.push(false);
- }
- groupCollapsedStates.value[groupIndex] = !groupCollapsedStates.value[groupIndex];
- }
- };
- /**
- * 切换所有分组的收起/展开状态
- * 收起全部时保留第一个分组展开
- */
- const toggleAllGroupsCollapse = () => {
- if (allGroupsCollapsed.value) {
- // 展开全部:将所有分组设置为展开状态
- allGroupsCollapsed.value = false;
- groupCollapsedStates.value = groupCollapsedStates.value.map(() => false);
- } else {
- // 收起全部:收起除第一个分组外的所有分组
- allGroupsCollapsed.value = true;
- groupCollapsedStates.value = groupCollapsedStates.value.map((_, index) => index !== 0);
- // 确保数组长度足够
- while (groupCollapsedStates.value.length < lifeGroupBuyThalis.value.length) {
- groupCollapsedStates.value.push(true);
- }
- }
- };
- /**
- * 添加菜品
- * @param groupIndex 分组索引
- */
- const addDish = (groupIndex: number) => {
- const group = lifeGroupBuyThalis.value[groupIndex];
- // 检查菜品数量限制(每个分组最多20个菜品)
- if (group.dishes && group.dishes.length >= 20) {
- ElMessage.warning("每个分组最多只能添加20个菜品");
- return;
- }
- // 验证当前分组是否填写完整
- // 验证类别
- if (!group.groupName || group.groupName.trim() === "") {
- ElMessage.warning("请先完成现有菜品的填写");
- // 触发表单验证,显示验证错误
- nextTick(() => {
- if (packageFormRef.value) {
- packageFormRef.value.validate(() => {});
- }
- });
- return;
- }
- // 验证是否有菜品
- if (!group.dishes || group.dishes.length === 0) {
- ElMessage.warning("请先完成现有菜品的填写");
- // 触发表单验证,显示验证错误
- nextTick(() => {
- if (packageFormRef.value) {
- packageFormRef.value.validate(() => {});
- }
- });
- return;
- }
- // 验证当前分组中每个菜品是否填写完整
- for (let j = 0; j < group.dishes.length; j++) {
- const dish = group.dishes[j];
- // 验证菜品是否已选择
- if (!dish.detailId) {
- ElMessage.warning("请先完成现有菜品的填写");
- // 触发表单验证,显示验证错误
- nextTick(() => {
- if (packageFormRef.value) {
- packageFormRef.value.validate(() => {});
- }
- });
- return;
- }
- // 验证数量是否已填写
- if (!dish.qty || dish.qty.toString().trim() === "") {
- ElMessage.warning("请先完成现有菜品的填写");
- // 触发表单验证,显示验证错误
- nextTick(() => {
- if (packageFormRef.value) {
- packageFormRef.value.validate(() => {});
- }
- });
- return;
- }
- // 验证数量格式
- const quantityNum = Number(dish.qty);
- if (isNaN(quantityNum) || quantityNum <= 0 || !Number.isInteger(quantityNum)) {
- ElMessage.warning("请先完成现有菜品的填写");
- // 触发表单验证,显示验证错误
- nextTick(() => {
- if (packageFormRef.value) {
- packageFormRef.value.validate(() => {});
- }
- });
- return;
- }
- }
- // 所有验证通过,添加新菜品
- if (!group.dishes) {
- group.dishes = [];
- }
- group.dishes.push({
- detailId: "",
- dishName: "",
- dishPrice: "",
- dishImage: "",
- qty: "",
- dishesUnit: ""
- });
- // 清除新添加菜品的验证状态,避免立即显示验证错误
- // 使用延迟清除,确保在验证规则更新和 DOM 渲染完成后再清除
- nextTick(() => {
- requestAnimationFrame(() => {
- setTimeout(() => {
- if (packageFormRef.value) {
- // 只清除新添加菜品的验证状态
- const newDishIndex = group.dishes.length - 1;
- const propsToClear = [
- `groups.${groupIndex}.dishes.${newDishIndex}.detailId`,
- `groups.${groupIndex}.dishes.${newDishIndex}.qty`
- ];
- // Element Plus 的 clearValidate 可以接受字符串
- propsToClear.forEach(prop => {
- packageFormRef.value?.clearValidate(prop);
- });
- }
- }, 150);
- });
- });
- };
- /**
- * 删除菜品
- * @param groupIndex 分组索引
- * @param dishIndex 菜品索引
- */
- const removeDish = (groupIndex: number, dishIndex: number) => {
- const dishes = lifeGroupBuyThalis.value[groupIndex].dishes;
- if (dishes.length <= 1) {
- ElMessage.warning("至少需要保留一个菜品");
- return;
- }
- dishes.splice(dishIndex, 1);
- };
- /**
- * 打开菜品选择对话框
- * @param groupIndex 分组索引
- * @param dishIndex 菜品索引
- */
- const openDishDialog = async (groupIndex: number, dishIndex: number) => {
- currentDishGroupIndex.value = groupIndex;
- currentDishIndex.value = dishIndex;
- dishSearchKeyword.value = "";
- const params = {
- storeId: 104,
- phoneId: 18641153170,
- dishType: 0
- };
- const res = await getMenuByStoreId(params);
- if (res && res.code == 200) {
- dishOptions.value = res.data;
- }
- // 如果已有选中的菜品,设置选中状态
- const currentDish = lifeGroupBuyThalis.value[groupIndex].dishes[dishIndex];
- selectedDishId.value = currentDish?.detailId || null;
- filterDishList();
- dishDialogVisible.value = true;
- };
- /**
- * 选择菜品
- * @param dish 菜品对象
- */
- const selectDish = (dish: any) => {
- selectedDishId.value = dish.id;
- };
- /**
- * 确认菜品选择
- */
- const confirmDishSelection = () => {
- if (selectedDishId.value === null) {
- ElMessage.warning("请选择一个菜品");
- return;
- }
- const selectedDish: any = dishOptions.value.find(dish => dish.id === selectedDishId.value);
- if (selectedDish && currentDishGroupIndex.value >= 0 && currentDishIndex.value >= 0) {
- const dish = lifeGroupBuyThalis.value[currentDishGroupIndex.value].dishes[currentDishIndex.value];
- dish.detailId = selectedDish.id;
- dish.dishName = selectedDish.dishName;
- dish.dishPrice = selectedDish.dishPrice;
- dish.dishImage = selectedDish.imgUrl;
- dish.dishesUnit = selectedDish.dishesUnit;
- dishDialogVisible.value = false;
- // 重新验证对应的字段,如果验证通过,错误提示会消失
- nextTick(() => {
- if (packageFormRef.value) {
- const prop = `groups.${currentDishGroupIndex.value}.dishes.${currentDishIndex.value}.detailId`;
- packageFormRef.value.validateField(prop, () => {});
- }
- });
- }
- };
- /**
- * 过滤菜品列表
- * 排除已经在其他分组中被选择的菜品(当前正在编辑的菜品除外)
- */
- const filterDishList = () => {
- // 获取当前正在编辑的菜品ID(如果有)
- const currentDishId = selectedDishId.value;
- // 收集所有其他分组中已选择的菜品ID
- const selectedDishIds = new Set<number | string>();
- lifeGroupBuyThalis.value.forEach((group, groupIndex) => {
- if (group.dishes && group.dishes.length > 0) {
- group.dishes.forEach((dish, dishIndex) => {
- // 排除当前正在编辑的菜品
- if (dish.detailId && !(groupIndex === currentDishGroupIndex.value && dishIndex === currentDishIndex.value)) {
- selectedDishIds.add(dish.detailId);
- }
- });
- }
- });
- // 先根据搜索关键词过滤
- let filtered = dishOptions.value;
- if (dishSearchKeyword.value && dishSearchKeyword.value.trim() !== "") {
- const keyword = dishSearchKeyword.value.trim().toLowerCase();
- filtered = dishOptions.value.filter(dish => dish.dishName.toLowerCase().includes(keyword));
- }
- // 再排除已在其他分组中被选择的菜品(但保留当前正在编辑的菜品)
- filteredDishList.value = filtered.filter(dish => {
- // 如果是当前正在编辑的菜品,保留
- if (currentDishId && dish.id === currentDishId) {
- return true;
- }
- // 如果菜品已在其他分组中被选择,排除
- return !selectedDishIds.has(dish.id);
- });
- };
- // ==================== 表单引用 ====================
- const ruleFormRef = ref<FormInstance>(); // 表单引用
- const packageFormRef = ref<FormInstance>(); // 套餐内容表单引用
- // 套餐内容表单模型(用于验证)
- const packageFormModel = computed(() => {
- return {
- groups: lifeGroupBuyThalis.value
- };
- });
- // 套餐内容验证规则
- const packageFormRules = computed(() => {
- const rules: any = {};
- lifeGroupBuyThalis.value.forEach((group, groupIndex) => {
- // 类别验证规则 - 使用与 prop 相同的路径格式
- rules[`groups.${groupIndex}.groupName`] = [
- {
- required: true,
- message: `第${groupIndex + 1}个分组的类别不能为空`,
- trigger: "blur"
- }
- ];
- // 每个菜品的验证规则
- if (group.dishes) {
- group.dishes.forEach((dish, dishIndex) => {
- // 菜品选择验证
- rules[`groups.${groupIndex}.dishes.${dishIndex}.detailId`] = [
- {
- required: true,
- message: `第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品未选择`,
- trigger: "change"
- }
- ];
- // 菜品数量验证
- rules[`groups.${groupIndex}.dishes.${dishIndex}.qty`] = [
- {
- required: true,
- message: `第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品数量不能为空`,
- trigger: "blur"
- },
- {
- validator: (rule: any, value: any, callback: any) => {
- if (!value || value.toString().trim() === "") {
- callback();
- return;
- }
- const num = Number(value);
- if (isNaN(num) || num <= 0) {
- callback(new Error(`第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品数量必须为正整数`));
- return;
- }
- if (!Number.isInteger(num)) {
- callback(new Error(`第${groupIndex + 1}个分组的第${dishIndex + 1}个菜品数量必须为正整数`));
- return;
- }
- callback();
- },
- trigger: "blur"
- }
- ];
- });
- }
- });
- return rules;
- });
- /**
- * 提交数据(新增/编辑)
- * 验证表单,通过后调用相应的API接口
- */
- const handleSubmit = (type?) => {
- let params: any = { ...storeInfoModel.value };
- if (params.effectiveDateType == 0) {
- // params.couponCompDate = `用户购买${params.expirationDate}天内有效`;
- } else {
- params.expirationDateList = params.expirationDateList.join(",");
- }
- if (params.disableDateType == 1) {
- params.disableDateValue = params.unavailableWeekdays.join(",") + ";" + params.unavailableHolidays.join(",");
- // params.disableDateValue = [params.unavailableWeekdays, params.unavailableHolidays];
- delete params.unavailableWeekdays;
- delete params.unavailableHolidays;
- } else if (params.disableDateType == 2) {
- // params.disableDateValue = params.disableDateList.map(subArray => subArray.join(",")).join(";");
- }
- params.invoiceType = params.invoiceInformation.join(",");
- const output = lifeGroupBuyThalis.value.flatMap(group =>
- group.dishes.map(dish => ({
- groupName: group.groupName,
- detailId: dish.detailId,
- qty: dish.qty,
- dishPrice: dish.dishPrice
- }))
- );
- const paramsObj = {
- lifeGroupBuyMain: params,
- lifeGroupBuyThalis: output
- };
- console.log(paramsObj);
- if (type) {
- return;
- }
- // 验证表单
- ruleFormRef.value!.validate(async valid => {
- if (!valid) return;
- // 验证套餐内容表单
- if (packageFormRef.value) {
- let packageValid = false;
- await new Promise<void>(resolve => {
- packageFormRef.value!.validate(valid => {
- packageValid = valid;
- if (!valid) {
- ElMessage.error("请完善套餐内容信息");
- }
- resolve();
- });
- });
- if (!packageValid) {
- return;
- }
- }
- // 组装提交参数
- let params: any = { ...storeInfoModel.value };
- params.lifeGroupBuyThalis = lifeGroupBuyThalis.value;
- });
- };
- // ==================== 工具函数 ====================
- /**
- * 禁用开始售卖时间的日期
- * 不能选择早于当前时间的日期
- * @param time 日期对象
- * @returns 是否禁用该日期
- */
- const disabledStartDate = (time: Date) => {
- const today = new Date();
- today.setHours(0, 0, 0, 0);
- return time.getTime() < today.getTime();
- };
- /**
- * 禁用结束售卖时间的日期
- * 不能选择早于当前时间的日期,也不能选择早于或等于开始售卖时间的日期
- * @param time 日期对象
- * @returns 是否禁用该日期
- */
- const disabledEndDate = (time: Date) => {
- const today = new Date();
- today.setHours(0, 0, 0, 0);
- // 不能早于当前时间
- if (time.getTime() < today.getTime()) {
- return true;
- }
- // 如果开始售卖时间已设置,不能早于或等于开始时间
- if (storeInfoModel.value.startTimeType === 1 && storeInfoModel.value.saleTimeStr) {
- const startDate = new Date(storeInfoModel.value.saleTimeStr);
- startDate.setHours(0, 0, 0, 0);
- return time.getTime() <= startDate.getTime();
- }
- return false;
- };
- /**
- * 禁用指定时间段内可用的日期
- * 不能选择早于当前时间的日期
- * @param time 日期对象
- * @returns 是否禁用该日期
- */
- const disabledEffectiveDate = (time: Date) => {
- const today = new Date();
- today.setHours(0, 0, 0, 0);
- return time.getTime() < today.getTime();
- };
- /**
- * 禁用自定义不可用日期的日期
- * 不能选择早于当前时间的日期
- * @param time 日期对象
- * @returns 是否禁用该日期
- */
- const disabledCustomUnavailableDate = (time: Date) => {
- const today = new Date();
- today.setHours(0, 0, 0, 0);
- return time.getTime() < today.getTime();
- };
- /**
- * 处理图片结果
- * 将上传组件的文件对象或URL字符串转换为URL数组
- * @param list 图片列表(可能是文件对象或URL字符串)
- * @returns URL字符串数组
- */
- const handleImageResult = (list: any[]): string[] => {
- let result: string[] = [];
- (list || []).forEach((item: any) => {
- if (item.uid) {
- // 如果是上传组件的文件对象,取url属性
- result.push(item.url);
- } else {
- // 如果是URL字符串,直接添加
- result.push(item);
- }
- });
- return result;
- };
- //图片list 转换为upload 组件的参数
- const handleImageParam = (list: any[], result: any[]) => {
- (list || []).forEach((item: any) => {
- // 使用split方法以'/'为分隔符将URL拆分成数组
- const parts = item.split("/");
- // 取数组的最后一项,即图片名称
- const imageName = parts[parts.length - 1];
- result.push({
- name: imageName,
- percentage: 100,
- url: item
- });
- });
- };
- </script>
- <style scoped lang="scss">
- /* 页面容器 */
- .table-box {
- display: flex;
- flex-direction: column;
- height: auto !important;
- min-height: 100%;
- }
- /* 头部区域 */
- .header {
- display: flex;
- align-items: center;
- padding: 20px;
- border-bottom: 1px solid #e4e7ed;
- }
- .title {
- flex: 1;
- margin: 0;
- font-size: 18px;
- font-weight: bold;
- text-align: center;
- }
- /* 内容区域布局 */
- .content {
- display: flex;
- flex: 1;
- column-gap: 20px;
- width: 98%;
- margin: 20px auto;
- /* 左侧内容区域 */
- .contentLeft {
- width: 50%;
- }
- /* 右侧内容区域 */
- .contentRight {
- width: 50%;
- }
- }
- /* 模块容器 */
- .model {
- margin-bottom: 50px;
- }
- /* 表单容器 */
- .formBox {
- display: flex;
- flex-direction: column;
- width: 100%;
- min-height: 100%;
- }
- /* 底部按钮容器 - 居中显示 */
- .button-container {
- display: flex;
- gap: 12px;
- align-items: center;
- justify-content: center;
- padding: 20px 0;
- margin-top: 20px;
- }
- /* 日期选择器容器 */
- .date-picker-container {
- display: flex;
- flex-direction: column;
- gap: 12px;
- width: 100%;
- }
- /* 添加日期按钮 */
- .add-date-btn {
- width: fit-content;
- margin-bottom: 8px;
- }
- /* 日期项容器 */
- .date-item {
- display: flex;
- gap: 12px;
- align-items: center;
- padding: 8px;
- // background-color: #f5f7fa;
- border-radius: 4px;
- transition: background-color 0.1s;
- &:hover {
- background-color: #ecf5ff;
- }
- }
- /* 日期选择器 */
- .date-item .date-picker {
- flex: 1;
- max-width: 500px;
- }
- /* 删除按钮 */
- .date-item .delete-btn {
- flex-shrink: 0;
- }
- /* 有效期天数容器 */
- .expiration-date-container {
- display: flex;
- gap: 12px;
- align-items: center;
- width: fit-content;
- padding: 8px 12px;
- // background-color: #f5f7fa;
- border-radius: 4px;
- }
- /* 有效期标签文字 */
- .expiration-label {
- font-size: 14px;
- color: #606266;
- white-space: nowrap;
- }
- /* 有效期输入框 */
- .expiration-input {
- width: 150px;
- }
- /* 不可用日期容器 */
- .unavailable-dates-container {
- display: flex;
- flex-direction: column;
- gap: 20px;
- width: 100%;
- }
- /* 日期选择区块 */
- .date-select-section {
- display: flex;
- flex-direction: column;
- gap: 12px;
- }
- /* 区块标题 */
- .section-title {
- font-size: 14px;
- font-weight: 500;
- color: #606266;
- }
- /* 按钮组 */
- .button-group {
- display: flex;
- flex-wrap: wrap;
- gap: 10px;
- }
- /* 日期选择按钮 */
- .date-select-btn {
- min-width: 80px;
- height: 36px;
- padding: 8px 16px;
- margin: 0;
- font-size: 14px;
- border-radius: 4px;
- transition: all 0.1s;
- }
- /* 套餐内容相关样式 */
- .package-content-item {
- width: 100%;
- }
- .package-content-form {
- width: 100%;
- }
- /* 表单项基础样式 */
- .package-content-form :deep(.el-form-item) {
- margin-bottom: 0;
- }
- .package-content-form :deep(.el-form-item__label) {
- display: none;
- }
- /* 类别表单项样式 */
- .category-form-item {
- width: 100%;
- margin-bottom: 16px;
- }
- .category-form-item :deep(.el-form-item__content) {
- display: flex;
- flex-wrap: wrap;
- align-items: flex-start;
- width: 100%;
- }
- .category-form-item :deep(.el-form-item__error) {
- position: static;
- width: 100%;
- padding-top: 4px;
- padding-left: 62px;
- margin-top: 0;
- font-size: 12px;
- line-height: 1.5;
- color: #f56c6c;
- }
- .category-row .el-input {
- flex: 1;
- max-width: 400px;
- }
- /* 菜品表单项样式 */
- .dish-form-item {
- position: relative;
- flex: 1;
- margin-bottom: 0;
- }
- .dish-form-item :deep(.el-form-item__content) {
- display: flex;
- flex-wrap: wrap;
- gap: 12px;
- align-items: center;
- }
- .dish-form-item :deep(.el-form-item__error) {
- position: absolute;
- top: 100%;
- left: 0;
- z-index: 1;
- padding-top: 4px;
- padding-right: 4px;
- font-size: 12px;
- line-height: 1.5;
- color: #f56c6c;
- white-space: nowrap;
- background-color: #ffffff;
- }
- .package-content-wrapper {
- display: flex;
- flex-direction: column;
- gap: 12px;
- width: 100%;
- }
- .package-content-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- width: 100%;
- }
- .add-group-btn {
- width: fit-content;
- }
- .package-content-container {
- display: flex;
- flex-direction: column;
- gap: 16px;
- width: 100%;
- }
- .package-group {
- overflow: hidden;
- background-color: white;
- border: 1px solid #e4e7ed;
- border-radius: 4px;
- }
- .package-group-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- height: 50px;
- padding: 12px 16px;
- background-color: #f5f7fa;
- border-bottom: 1px solid #e4e7ed;
- }
- .group-index {
- flex: 1;
- overflow: hidden;
- font-size: 14px;
- font-weight: 500;
- color: #303133;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .header-right {
- display: flex;
- flex-shrink: 0;
- gap: 12px;
- align-items: center;
- }
- .package-group-content {
- display: flex;
- flex-direction: column;
- gap: 16px;
- min-height: 60px;
- padding: 16px;
- }
- .extra-dishes-container {
- display: flex;
- flex-direction: column;
- gap: 16px;
- margin-top: 0;
- }
- .extra-dishes-container .dish-row {
- padding-bottom: 22px;
- margin-bottom: 4px;
- }
- .extra-dishes-container .dish-row:last-child {
- padding-bottom: 0;
- margin-bottom: 0;
- }
- .package-group-collapsed {
- padding: 16px;
- background-color: #fafafa;
- border-top: 1px solid #e4e7ed;
- }
- .collapsed-dish-row {
- display: flex;
- gap: 12px;
- align-items: center;
- }
- .dish-info-text {
- font-size: 14px;
- color: #606266;
- white-space: nowrap;
- }
- .dish-info-text.empty-text {
- color: #c0c4cc;
- }
- .category-row {
- display: flex;
- gap: 12px;
- align-items: center;
- width: 100%;
- }
- .dish-row {
- position: relative;
- display: flex;
- gap: 12px;
- align-items: flex-start;
- width: 100%;
- margin-bottom: 4px;
- }
- .dish-row:last-child {
- padding-bottom: 0;
- margin-bottom: 0;
- }
- /* 当表单项有错误时,增加底部间距 */
- .dish-row .dish-form-item.is-error {
- margin-bottom: 0;
- }
- .label {
- min-width: 50px;
- font-size: 14px;
- color: #606266;
- white-space: nowrap;
- }
- .dish-select-block {
- position: relative;
- display: flex;
- flex: 1;
- align-items: center;
- max-width: 300px;
- min-height: 32px;
- padding: 0 11px;
- cursor: pointer;
- background-color: #ffffff;
- border: 1px solid #dcdfe6;
- border-radius: 4px;
- transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
- }
- .dish-select-block:hover {
- border-color: #c0c4cc;
- }
- .dish-select-block:focus-within {
- border-color: #409eff;
- }
- /* 当菜品选择有验证错误时,显示错误边框 */
- .dish-form-item.is-error .dish-select-block {
- border-color: #f56c6c;
- }
- .dish-form-item.is-error .dish-select-block:hover {
- border-color: #f56c6c;
- }
- .dish-form-item.is-error .dish-select-block:focus-within {
- border-color: #f56c6c;
- }
- /* 优化表单项的错误状态 */
- .package-content-form :deep(.el-form-item.is-error .el-input__wrapper) {
- box-shadow: 0 0 0 1px #f56c6c inset;
- }
- .package-content-form :deep(.el-form-item.is-error .el-input__wrapper:hover) {
- box-shadow: 0 0 0 1px #f56c6c inset;
- }
- .package-content-form :deep(.el-form-item.is-error .el-input__wrapper.is-focus) {
- box-shadow: 0 0 0 1px #f56c6c inset;
- }
- .dish-selected-name {
- font-size: 14px;
- color: #606266;
- }
- .dish-placeholder {
- font-size: 14px;
- color: #c0c4cc;
- }
- .quantity-input {
- flex-shrink: 0;
- width: 150px;
- }
- .delete-dish-btn {
- flex-shrink: 0;
- margin-left: 8px;
- }
- .add-dish-btn {
- width: fit-content;
- margin-top: 8px;
- }
- /* 优化菜品行的布局,确保在有验证错误时也能正确显示 */
- .dish-row .dish-form-item {
- min-width: 0;
- }
- .dish-row .dish-form-item:first-child {
- flex: 1;
- min-width: 200px;
- max-width: 350px;
- }
- .dish-row .dish-form-item:last-child {
- display: flex;
- flex: 0 0 auto;
- gap: 8px;
- align-items: center;
- }
- /* 确保数量输入框和删除按钮在同一行 */
- .dish-form-item:last-child :deep(.el-form-item__content) {
- display: flex;
- flex-wrap: nowrap;
- gap: 8px;
- align-items: center;
- }
- /* 响应式布局优化 */
- @media (width <= 768px) {
- .dish-row {
- flex-direction: column;
- align-items: stretch;
- }
- .dish-row .dish-form-item {
- width: 100%;
- max-width: 100%;
- }
- .dish-row .dish-form-item:first-child {
- max-width: 100%;
- }
- .category-row {
- flex-direction: column;
- align-items: stretch;
- }
- .category-row .el-input {
- max-width: 100%;
- }
- }
- /* 菜品选择对话框样式 */
- .dish-dialog-content {
- display: flex;
- flex-direction: column;
- gap: 16px;
- }
- .dish-search-input {
- width: 100%;
- }
- .dish-list-container {
- :deep(.el-scrollbar__wrap) {
- overflow-x: hidden;
- }
- :deep(.el-scrollbar__view) {
- display: flex;
- flex-direction: column;
- gap: 12px;
- }
- }
- .dish-empty-state {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 60px 20px;
- text-align: center;
- }
- .empty-text {
- margin-bottom: 8px;
- font-size: 16px;
- color: #909399;
- }
- .empty-hint {
- font-size: 14px;
- color: #c0c4cc;
- }
- .dish-item {
- position: relative;
- display: flex;
- gap: 12px;
- align-items: center;
- padding: 12px;
- cursor: pointer;
- border: 1px solid #e4e7ed;
- border-radius: 4px;
- transition: all 0.1s;
- }
- .dish-item:hover {
- background-color: #f5f7fa;
- border-color: #409eff;
- }
- .dish-item-selected {
- background-color: #ecf5ff;
- border-color: #409eff;
- border-width: 1px;
- }
- .dish-item-selected:hover {
- background-color: #d9ecff;
- }
- .dish-image {
- flex-shrink: 0;
- width: 60px;
- height: 60px;
- overflow: hidden;
- background-color: #f5f7fa;
- border-radius: 4px;
- }
- .dish-img {
- width: 100%;
- height: 100%;
- }
- .dish-image-placeholder {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 100%;
- font-size: 24px;
- color: #c0c4cc;
- }
- .dish-info {
- display: flex;
- flex: 1;
- flex-direction: column;
- gap: 4px;
- }
- .dish-name {
- font-size: 14px;
- font-weight: 500;
- color: #606266;
- }
- .dish-price {
- font-size: 14px;
- color: #909399;
- }
- .dish-selected-icon {
- display: flex;
- flex-shrink: 0;
- align-items: center;
- justify-content: center;
- width: 24px;
- height: 24px;
- font-size: 16px;
- color: #ffffff;
- background-color: #409eff;
- border-radius: 50%;
- }
- .dialog-footer {
- display: flex;
- justify-content: center;
- }
- /* 展开收起动画 - 高度过渡 */
- .slide-fade-enter-active {
- overflow: hidden;
- transition:
- max-height 0.1s ease-out,
- opacity 0.1s ease-out;
- }
- .slide-fade-leave-active {
- overflow: hidden;
- transition:
- max-height 0.1s ease-in,
- opacity 0.1s ease-in;
- }
- .slide-fade-enter-from {
- max-height: 0;
- opacity: 0;
- }
- .slide-fade-leave-to {
- max-height: 0;
- opacity: 0;
- }
- .slide-fade-enter-to,
- .slide-fade-leave-from {
- max-height: 2000px;
- opacity: 1;
- }
- /* 分组收起全部动画 */
- .group-fade-enter-active {
- transition: all 0.1s ease-out;
- }
- .group-fade-leave-active {
- transition: all 0.1s ease-in;
- }
- .group-fade-enter-from {
- opacity: 0;
- transform: translateY(-10px);
- }
- .group-fade-leave-to {
- opacity: 0;
- transform: translateY(-10px);
- }
- .group-fade-move {
- transition: transform 0.1s linear;
- }
- </style>
|