AddItems.vue 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. <script lang="ts" setup>
  2. import { ref, watch, reactive, onMounted, h, computed, nextTick } from 'vue';
  3. import { message } from 'ant-design-vue';
  4. import { PlusOutlined } from '@ant-design/icons-vue'; // 确保导入
  5. import VxeUI from 'vxe-table';
  6. import { useRequest } from 'alova/client';
  7. import { getDictionaryMethod, cpMedicinesMethod } from '@/request/api/dictionary.api';
  8. import { branchMethod } from '@/request/api/system.api';
  9. import { systemCpEditMethod, getAllSupplierMethod, getConditioningSchemeDetailMethod } from '@/request/api/care.api';
  10. import { UploadIFile } from '@/request/api/follow.api';
  11. import type { SystemItemModel } from '@/model/care.model';
  12. import RemoteSelect from '@/libs/v-select-page/RemoteSelect.vue';
  13. import SearchableSelect from '@/components/SearchableSelect.vue';
  14. import type { UploadFile } from 'ant-design-vue/es/upload/interface';
  15. import type { FormInstance } from 'ant-design-vue';
  16. import Derivation from '@/service/Derivation.vue';
  17. type SystemModel = Partial<SystemItemModel>;
  18. const props = defineProps<{ data: SystemModel; institutionId: string | number }>();
  19. const formRef = ref<FormInstance>();
  20. const typeOptionsLoading = ref<boolean>(false);
  21. const typeOptions = ref<{ label: string; value: string }[]>([]);
  22. // 统一提升消息提示层级,避免被弹窗遮挡
  23. message.config({ zIndex: 5000, top: 80, maxCount: 3, duration: 2 });
  24. const supplierOptions = ref<{ label: string; value: string }[]>([]);
  25. const isRequired = ref<boolean>(true);
  26. // 使用单位
  27. const unitOptions = [
  28. { label: '袋', value: '袋' },
  29. { label: '包', value: '包' },
  30. { label: '贴', value: '贴' },
  31. { label: '次', value: '次' },
  32. ];
  33. const herbList = ref<any[]>([]);
  34. // 获取所有的机构
  35. const branch = ref<any[]>([]);
  36. const { loading: branchLoading } = useRequest(branchMethod).onSuccess(({ data }) => {
  37. const to = (data?: any[]): any[] => {
  38. return Array.isArray(data)
  39. ? data.map((item) => {
  40. return {
  41. ...item,
  42. value: item.id,
  43. key: item.id.toString(),
  44. children: to(item.children),
  45. };
  46. })
  47. : [];
  48. };
  49. branch.value = to(data);
  50. });
  51. const form = reactive<SystemItemModel>({
  52. institutionName: '',
  53. conditioningProgramType: '',
  54. conditioningProgramSupplierId: '',
  55. institutionId: '',
  56. cpDynamicPricingRule: [
  57. { min: '', max: '', priceType: '', price: '' },
  58. { min: '', max: '', priceType: '', price: '' },
  59. ],
  60. pricingType: '0',
  61. cpFixedPricingRule: {
  62. unitPrice: '',
  63. pricingUnit: '',
  64. convertDose: '',
  65. convertUnit: '',
  66. },
  67. cpPatientMatchRule: {
  68. sex: '', // 性别
  69. age: '', // 年龄
  70. diagnoseDiseaseNames: [], // 疾病
  71. diagnoseSyndromeNames: [], // 证型
  72. constitutionGroupNames: [], // 体质
  73. willillStateNames: [], // 欲病状态
  74. tabooCrowds: [], // 禁忌
  75. },
  76. cpMedicines: [{ name: '', dosage: '', id: '' }],
  77. isOffline: null,
  78. isDelivery: null,
  79. effect: '', // 功效
  80. photo: '', // 商品图片
  81. itemImgFirst: '', // 操作图片
  82. itemVideoFirst: '', // 操作视频
  83. attrFirst: '', // 特色
  84. attrSeventh: '', //使用注意
  85. attrSixth: '', // 疗程说明
  86. attrFifth: '', // 操作方法
  87. attrFourth: '', // 用法
  88. attrThird: '', // 制法
  89. status: '0', // 状态
  90. isForWrap: null, // 是否服务包项目
  91. isForInfer: null, // 是否调理方案项目
  92. attrEighth: '', // 购买链接
  93. attrNinth: '', // 跳转类型
  94. });
  95. const checkedList = ref<string[]>(['1']); // 默认选中第一个
  96. const onlineArr = ref<string[]>([]);
  97. const deliverArr = ref<string[]>([]);
  98. // 添加推导逻辑编辑状态
  99. const isDerivationModalOpen = ref(false);
  100. const rules = {
  101. name: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
  102. conditioningProgramType: [{ required: true, message: '请选择方案类型', trigger: 'change' }],
  103. institutionId: [{
  104. required: true,
  105. message: '请选择机构名称',
  106. trigger: 'blur',
  107. validator: (rule: any, value: any, callback: any) => {
  108. // 如果推导逻辑弹窗打开,跳过验证
  109. if (isDerivationModalOpen.value) {
  110. callback();
  111. return;
  112. }
  113. if (!value) {
  114. callback(new Error('请选择机构名称'));
  115. } else {
  116. callback();
  117. }
  118. }
  119. }],
  120. isOffline: [{ required: true, message: '请选择线下项目', trigger: 'change' }],
  121. isDelivery: [{ required: true, message: '请选择是否配送', trigger: 'change' }],
  122. };
  123. const isShowOnline = ref<boolean>(false);
  124. const isShowDelivery = ref<boolean>(false);
  125. const supplierArr = ref<any[]>([]);
  126. // 获取所有的供应商
  127. async function getSupplier(params: any) {
  128. supplierOptions.value = [];
  129. const res = await getAllSupplierMethod(params);
  130. if (res && res.length > 0) {
  131. supplierArr.value = res;
  132. supplierOptions.value = res.map((item: any) => ({
  133. label: item.name,
  134. value: item.id,
  135. }));
  136. getisOffline(params.conditioningProgramSupplierId, params.isOffline, params.isDelivery, params.conditioningProgramTypes);
  137. }
  138. }
  139. function getisOffline(e: any, newOffline: any, newDelivery: any, newType: any) {
  140. let filterSupplierArr = supplierArr.value.filter((item: any) => item.id === e);
  141. if (filterSupplierArr.length > 0) {
  142. isShowOnline.value = filterSupplierArr.every((items: any) => {
  143. if (newType.length > 0) {
  144. if (items.offlineCPTypes?.includes(newType[0]) && items.onlineCPTypes?.includes(newType[0])) {
  145. return true;
  146. } else {
  147. if (items.offlineCPTypes?.includes(newType[0])) {
  148. form.isOffline = 'Y';
  149. return false;
  150. } else if (items.onlineCPTypes?.includes(newType[0])) {
  151. form.isOffline = 'N';
  152. // 线上项目 显示配送选项
  153. isShowDelivery.value = true;
  154. return false;
  155. } else {
  156. form.isOffline = null;
  157. return false;
  158. }
  159. }
  160. } else {
  161. return false;
  162. }
  163. });
  164. if (isShowOnline.value) {
  165. if (newOffline) {
  166. onlineArr.value = [newOffline];
  167. if (onlineArr.value.length > 1) {
  168. onlineArr.value = [onlineArr.value[onlineArr.value.length - 1]];
  169. } else if (onlineArr.value.length === 0) {
  170. onlineArr.value = [];
  171. }
  172. // newOffline ==Y 线下项目 不需要配送
  173. if (newOffline === 'Y') {
  174. form.isDelivery = null;
  175. isShowDelivery.value = false;
  176. } else {
  177. isShowDelivery.value = true;
  178. }
  179. } else {
  180. isShowDelivery.value = false;
  181. }
  182. if (newDelivery) {
  183. deliverArr.value = [newDelivery];
  184. if (deliverArr.value.length > 1) {
  185. deliverArr.value = [deliverArr.value[deliverArr.value.length - 1]];
  186. } else if (deliverArr.value.length === 0) {
  187. deliverArr.value = [];
  188. }
  189. }
  190. } else {
  191. // 线上项目 显示配送选项
  192. if (newOffline === 'N') {
  193. isShowDelivery.value = true;
  194. deliverArr.value = [newDelivery];
  195. if (deliverArr.value.length > 1) {
  196. deliverArr.value = [deliverArr.value[deliverArr.value.length - 1]];
  197. } else if (deliverArr.value.length === 0) {
  198. deliverArr.value = [];
  199. }
  200. }
  201. }
  202. } else {
  203. isShowOnline.value = false;
  204. isShowDelivery.value = false;
  205. onlineArr.value = [];
  206. deliverArr.value = [];
  207. }
  208. }
  209. watch(
  210. [() => form.conditioningProgramType, () => form.institutionId, () => form.conditioningProgramSupplierId, () => form.isOffline, () => form.isDelivery],
  211. ([newType, newInstitutionId, newSupplierId, newOffline, newDelivery]) => {
  212. getSupplier({
  213. conditioningProgramTypes: newType ? [newType] : form.conditioningProgramType ? [form.conditioningProgramType] : [],
  214. collaborateDeptId: newInstitutionId ? newInstitutionId : form.institutionId ? form.institutionId : '',
  215. conditioningProgramSupplierId: newSupplierId ? newSupplierId : form.conditioningProgramSupplierId ? form.conditioningProgramSupplierId : '',
  216. isOffline: newOffline,
  217. isDelivery: newDelivery,
  218. });
  219. },
  220. { immediate: true }
  221. );
  222. function addHerb() {
  223. if (!form.cpMedicines) {
  224. form.cpMedicines = [];
  225. }
  226. form.cpMedicines.push({ name: '', dosage: '', id: '' });
  227. }
  228. function removeHerb(idx: number) {
  229. if (form.cpMedicines) {
  230. form.cpMedicines.splice(idx, 1);
  231. }
  232. }
  233. function cancel() {
  234. VxeUI.modal.close(`add-items-modal`);
  235. }
  236. function doSubmit() {
  237. // 手动验证方案类型
  238. if (!form.conditioningProgramType) {
  239. message.error('请选择方案类型');
  240. return;
  241. }
  242. // 自定义验证:检查项目应用是否已选择
  243. if (!checkedList.value || checkedList.value.length === 0) {
  244. message.error('请选择项目应用');
  245. return;
  246. }
  247. form.isForWrap = checkedList.value.includes('1') ? 'Y' : null;
  248. form.isForInfer = checkedList.value.includes('2') ? 'Y' : null;
  249. // 服务包项目相关必填
  250. if ((form.addType === 'itemsList' && checkedList.value.includes('1')) || form.addType === 'system') {
  251. // 计价规则
  252. if (!form.pricingType) {
  253. message.error('请选择计价规则');
  254. return;
  255. }
  256. // 计价规则相关字段校验
  257. if (form.pricingType === '0') {
  258. const { unitPrice, pricingUnit, convertDose, convertUnit } = form.cpFixedPricingRule || {};
  259. const allFilled = (unitPrice !== '' && unitPrice !== null && unitPrice !== undefined) && pricingUnit && (convertDose !== '' && convertDose !== null && convertDose !== undefined) && convertUnit;
  260. if (!allFilled) {
  261. message.error('请将单价、计价单位、相当于、使用单位全部填写');
  262. return;
  263. }
  264. form.cpDynamicPricingRule = undefined;
  265. } else if (form.pricingType === '1') {
  266. const rule1 = form.cpDynamicPricingRule[0] || {};
  267. const rule2 = form.cpDynamicPricingRule[1] || {};
  268. const allFilled1 = rule1.min && typeof rule1.priceType !== 'undefined' && rule1.price;
  269. const allFilled2 = rule2.max && typeof rule2.priceType !== 'undefined' && rule2.price;
  270. rule1.max = 0;
  271. rule2.min = 0;
  272. if (!(allFilled1 && allFilled2)) {
  273. message.error('请将按穴位/经络/部位的所有计价字段全部填写');
  274. return;
  275. }
  276. // 按穴位模式:清空一口价数据
  277. form.cpFixedPricingRule = undefined;
  278. }
  279. // 供应商
  280. // if (form.addType === 'itemsList' && checkedList.value.includes('1')) {
  281. // // if (!form.conditioningProgramSupplierId) {
  282. // // message.error('请选择供应商');
  283. // // return;
  284. // // }
  285. // } else
  286. if (form.addType === 'system') {
  287. form.isOffline = 'N';
  288. form.isDelivery = 'N';
  289. }
  290. // 线下项目
  291. if (isShowOnline.value && !form.isOffline) {
  292. message.error('请选择是否为线下项目');
  293. return;
  294. }
  295. // 配送
  296. if (isShowDelivery.value && (!deliverArr.value || deliverArr.value.length === 0)) {
  297. message.error('请选择配送方式');
  298. return;
  299. }
  300. } else if (form.addType === 'itemsList') {
  301. // 计价规则非必填时,做全填/全空校验
  302. if (form.pricingType === '0') {
  303. const { unitPrice, pricingUnit, convertDose, convertUnit } = form.cpFixedPricingRule || {};
  304. const allFilled = (unitPrice !== '' && unitPrice !== null && unitPrice !== undefined) && pricingUnit && (convertDose !== '' && convertDose !== null && convertDose !== undefined) && convertUnit;
  305. const allEmpty = !unitPrice && !pricingUnit && !convertDose && !convertUnit;
  306. if (!(allFilled || allEmpty)) {
  307. message.error('单价、计价单位、相当于、使用单位要么全部填写,要么全部为空');
  308. return;
  309. }
  310. // 一口价模式:清空按穴位数据
  311. if (allFilled) {
  312. form.cpDynamicPricingRule = undefined;
  313. }
  314. } else if (form.pricingType === '1') {
  315. const rule1 = form.cpDynamicPricingRule[0] || {};
  316. const rule2 = form.cpDynamicPricingRule[1] || {};
  317. const allFilled1 = rule1.min && typeof rule1.priceType !== 'undefined' && rule1.price;
  318. const allEmpty1 = !rule1.min && (typeof rule1.priceType === 'undefined' || rule1.priceType === '' || rule1.priceType === null) && !rule1.price;
  319. const allFilled2 = rule2.max && typeof rule2.priceType !== 'undefined' && rule2.price;
  320. const allEmpty2 = !rule2.max && (typeof rule2.priceType === 'undefined' || rule2.priceType === '' || rule2.priceType === null) && !rule2.price;
  321. if (!((allFilled1 && allFilled2) || (allEmpty1 && allEmpty2))) {
  322. message.error('按穴位/经络/部位的所有计价字段要么全部填写,要么全部为空');
  323. return;
  324. }
  325. // 按穴位模式:清空一口价数据
  326. if (allFilled1 && allFilled2) {
  327. form.cpFixedPricingRule = undefined;
  328. }
  329. }
  330. }
  331. // 调理方案项目相关必填
  332. if (form.addType === 'itemsList' && checkedList.value.includes('2')) {
  333. if (!hasDerivationLogic.value) {
  334. message.error('请设置推导逻辑');
  335. return;
  336. }
  337. }
  338. // 购买链接与跳转类型联动校验:有购买链接则必须选择跳转类型
  339. if (form.addType === 'itemsList') {
  340. const hasBuyUrl = !!(form.attrEighth && String(form.attrEighth).trim());
  341. if (hasBuyUrl && !form.attrNinth) {
  342. message.error('请选择跳转类型');
  343. return;
  344. }
  345. }
  346. formRef.value?.validate().then(() => {
  347. form.photo = fileList.value[0]?.response?.url || fileList.value[0]?.url || '';
  348. form.itemImgFirst = optionsList.value[0]?.response?.url || optionsList.value[0]?.url || '';
  349. // 合并推导逻辑数据到表单数据中
  350. if (hasDerivationLogic.value && derivationData.value.cpPatientMatchRule) {
  351. form.cpPatientMatchRule = { ...derivationData.value.cpPatientMatchRule };
  352. }
  353. if (props.data.isType === 'itemsList') {
  354. delete form.id;
  355. }
  356. submit(form);
  357. });
  358. }
  359. // 获取方案类型
  360. async function getConditioningProgramType() {
  361. typeOptionsLoading.value = true;
  362. try {
  363. const res = await getDictionaryMethod('condition_type');
  364. if (res?.length > 0) {
  365. typeOptions.value = res; // 直接使用返回的数据
  366. }
  367. } catch (error: any) {
  368. message.error(error.message);
  369. } finally {
  370. typeOptionsLoading.value = false;
  371. }
  372. }
  373. const jumpTypeOptionsLoading = ref(false);
  374. const jumpTypeOptions = ref<{ label: string; value: string }[]>([]);
  375. // 获取跳转类型
  376. async function getJumpType() {
  377. jumpTypeOptionsLoading.value = true;
  378. try {
  379. const res = await getDictionaryMethod('fdhb_cpbuy_type');
  380. if (res?.length > 0) {
  381. jumpTypeOptions.value = res;
  382. }
  383. } catch (error: any) {
  384. message.error(error.message);
  385. } finally {
  386. jumpTypeOptionsLoading.value = false;
  387. }
  388. }
  389. // 处理下拉框点击事件
  390. function handleSelectClick() {
  391. // 如果选项为空且不在加载中,尝试重新获取数据
  392. if (typeOptions.value.length === 0 && !typeOptionsLoading.value) {
  393. getConditioningProgramType();
  394. }
  395. }
  396. onMounted(async () => {
  397. const deptId = localStorage.getItem('deptId');
  398. if (props.data.addType === 'system' && deptId) {
  399. form.institutionId = deptId;
  400. }
  401. if (props.data.addType === 'system') {
  402. isRequired.value = false;
  403. }
  404. form.addType = props.data.addType;
  405. if (props.data.id || props.data.sourceId) {
  406. const res: any = await getConditioningSchemeDetailMethod(props.data);
  407. const checked: string[] = [];
  408. if (res.isForWrap === 'Y') checked.push('1');
  409. if (res.isForInfer === 'Y') checked.push('2');
  410. checkedList.value = checked.length > 0 ? checked : ['1', '2'];
  411. Object.assign(form, res);
  412. form.cpMedicines = (res.cpMedicines ?? []).map((item: any) => ({
  413. name: item.name || item.herbName || item.medicineName || '',
  414. dosage: item.dosage,
  415. id: item.id,
  416. }));
  417. // 处理推导逻辑数据回填
  418. if (res.cpPatientMatchRule) {
  419. derivationData.value = { cpPatientMatchRule: res.cpPatientMatchRule };
  420. hasDerivationLogic.value = true;
  421. }
  422. fileList.value = res.photo
  423. ? [
  424. {
  425. uid: '-1',
  426. name: 'image.png',
  427. status: 'done',
  428. url: res.photo,
  429. thumbUrl: res.photo,
  430. },
  431. ]
  432. : [];
  433. optionsList.value = res.itemImgFirst
  434. ? [
  435. {
  436. uid: '-1',
  437. name: 'image.png',
  438. status: 'done',
  439. url: res.itemImgFirst,
  440. thumbUrl: res.itemImgFirst,
  441. },
  442. ]
  443. : [];
  444. // 处理视频数据
  445. if (res.itemVideoFirst) {
  446. videoFileList.value = [
  447. {
  448. uid: '-1',
  449. name: '操作视频',
  450. status: 'done',
  451. url: res.itemVideoFirst,
  452. response: { url: res.itemVideoFirst },
  453. },
  454. ];
  455. }
  456. if (props.data.isType === 'itemsList' && props.data.sourceId) {
  457. form.sourceId = form.id;
  458. // form.institutionId = '';
  459. form.institutionId = props.data.institutionId;
  460. form.institutionName = props.data.institutionName;
  461. }
  462. }
  463. // 获取方案类型
  464. getConditioningProgramType();
  465. // 获取跳转类型
  466. getJumpType();
  467. });
  468. const emits = defineEmits<{
  469. submit: [data?: SystemItemModel];
  470. addSubmit: [data?: SystemItemModel];
  471. }>();
  472. const { loading: submitting, send: submit } = useRequest(systemCpEditMethod, {
  473. immediate: false,
  474. }).onSuccess(({ data }) => {
  475. emits('submit');
  476. });
  477. const visible = ref<boolean>(false);
  478. const setVisible = (value: boolean): void => {
  479. visible.value = value;
  480. };
  481. const previewImg = ref<string>('');
  482. const uploadProps = reactive({ showRemoveIcon: true });
  483. // 商品图片
  484. const fileList = ref<UploadFile[]>([]);
  485. // 操作图片
  486. const optionsList = ref<UploadFile[]>([]);
  487. // 安全挂载弹层,避免 document 不可用或被父层遮挡
  488. function getSafePopupContainer(triggerNode?: HTMLElement) {
  489. try {
  490. // @ts-ignore
  491. if (typeof document !== 'undefined' && document?.body) return document.body;
  492. } catch (e) {}
  493. return (triggerNode?.parentNode as HTMLElement) || undefined;
  494. }
  495. // 统一用 change 处理(避免 @select 改值导致面板被打断)
  496. function onInstitutionChange(val: string | number | undefined) {
  497. form.institutionId = val as any;
  498. }
  499. // 预览图片
  500. const handlePreview = async (file: UploadFile) => {
  501. previewImg.value = file.response?.url ?? file.thumbUrl;
  502. visible.value = true;
  503. };
  504. function customUpload(e: any) {
  505. UploadIFile(e.file)
  506. .then((res) => {
  507. // 调用实例的成功方法通知组件该文件上传成功
  508. e.onSuccess(res, e);
  509. })
  510. .catch((err) => {
  511. // 调用实例的失败方法通知组件该文件上传失败
  512. e.onError(err);
  513. });
  514. }
  515. // 视频上传相关
  516. const accept = 'video/mp4,video/avi,video/mov,video/webm';
  517. const maxSize = 100 * 1024 * 1024; // 100MB
  518. const videoUrl = ref('');
  519. const uploading = ref(false);
  520. const progress = ref(0);
  521. const videoFileList = ref<UploadFile[]>([]);
  522. // 供应商校验规则:仅在"项目应用 勾选 服务包"且"新增项目(itemsList)"时必填
  523. const supplierRules = computed(() => {
  524. const need = checkedList.value.includes('1') && form.addType === 'itemsList';
  525. return need ? [{
  526. required: true,
  527. message: '请选择供应商',
  528. trigger: 'blur',
  529. validator: (rule: any, value: any, callback: any) => {
  530. // 如果推导逻辑弹窗打开,跳过验证
  531. if (isDerivationModalOpen.value) {
  532. callback();
  533. return;
  534. }
  535. if (!value) {
  536. callback(new Error('请选择供应商'));
  537. } else {
  538. callback();
  539. }
  540. }
  541. }] : [];
  542. });
  543. // 上传前校验
  544. function beforeVideoUpload(file: File) {
  545. const isValidType = accept.split(',').includes(file.type);
  546. if (!isValidType) {
  547. message.error('仅支持mp4、avi、mov、webm格式视频');
  548. return false;
  549. }
  550. const isValidSize = file.size <= maxSize;
  551. if (!isValidSize) {
  552. message.error('视频大小不能超过100MB');
  553. return false;
  554. }
  555. return true;
  556. }
  557. // 视频预览
  558. function handleVideoPreview(file: UploadFile) {
  559. const videoUrl = file.response?.url || file.url || form.itemVideoFirst;
  560. if (videoUrl) {
  561. VxeUI.modal.open({
  562. title: '视频预览',
  563. width: 800,
  564. height: 600,
  565. escClosable: true,
  566. destroyOnClose: true,
  567. slots: {
  568. default() {
  569. return h(
  570. 'div',
  571. {
  572. style: {
  573. display: 'flex',
  574. justifyContent: 'center',
  575. alignItems: 'center',
  576. height: '100%',
  577. },
  578. },
  579. [
  580. h('video', {
  581. src: videoUrl,
  582. controls: true,
  583. style: {
  584. maxWidth: '100%',
  585. maxHeight: '100%',
  586. borderRadius: '8px',
  587. },
  588. }),
  589. ]
  590. );
  591. },
  592. },
  593. });
  594. }
  595. }
  596. // 删除视频
  597. function removeVideo() {
  598. form.itemVideoFirst = '';
  599. videoFileList.value = [];
  600. message.success('视频已删除');
  601. }
  602. // 自定义上传
  603. function customVideoRequest(e: any) {
  604. const { file, onSuccess, onError, onProgress } = e;
  605. // 验证文件
  606. if (!beforeVideoUpload(file)) {
  607. onError(new Error('文件验证失败'));
  608. return;
  609. }
  610. uploading.value = true;
  611. progress.value = 0;
  612. // 模拟上传进度
  613. const progressInterval = setInterval(() => {
  614. if (progress.value < 90) {
  615. progress.value += Math.random() * 10;
  616. onProgress({ percent: progress.value });
  617. }
  618. }, 200);
  619. // 上传文件
  620. UploadIFile(file)
  621. .then((res: any) => {
  622. clearInterval(progressInterval);
  623. progress.value = 100;
  624. onProgress({ percent: 100 });
  625. // 设置视频URL
  626. form.itemVideoFirst = res?.url || res?.data?.url;
  627. // 更新文件列表
  628. videoFileList.value = [
  629. {
  630. uid: file.uid,
  631. name: file.name,
  632. status: 'done',
  633. url: form.itemVideoFirst,
  634. response: res,
  635. },
  636. ];
  637. onSuccess(res, e);
  638. uploading.value = false;
  639. message.success('视频上传成功');
  640. })
  641. .catch((err) => {
  642. clearInterval(progressInterval);
  643. uploading.value = false;
  644. progress.value = 0;
  645. onError(err);
  646. message.error('视频上传失败,请重试');
  647. });
  648. }
  649. // 视频上传状态变化
  650. function handleVideoChange(info: any) {
  651. const { file, fileList } = info;
  652. if (file.status === 'uploading') {
  653. uploading.value = true;
  654. } else if (file.status === 'done') {
  655. uploading.value = false;
  656. videoFileList.value = fileList;
  657. } else if (file.status === 'error') {
  658. uploading.value = false;
  659. message.error('视频上传失败');
  660. }
  661. }
  662. watch(
  663. () => form.pricingType,
  664. (val) => {
  665. if (val === '0') {
  666. // 一口价模式:确保 cpFixedPricingRule 存在
  667. if (!form.cpFixedPricingRule) {
  668. form.cpFixedPricingRule = {
  669. unitPrice: '',
  670. pricingUnit: '',
  671. convertDose: '',
  672. convertUnit: '',
  673. };
  674. }
  675. } else if (val === '1') {
  676. // 按穴位模式:确保 cpDynamicPricingRule 存在
  677. if (!form.cpDynamicPricingRule) {
  678. form.cpDynamicPricingRule = [
  679. { min: '', max: '', priceType: '', price: '' },
  680. { min: '', max: '', priceType: '', price: '' },
  681. ];
  682. }
  683. }
  684. }
  685. );
  686. function onlineChange(value: any) {
  687. form.isOffline = value[value.length - 1];
  688. deliverArr.value = [];
  689. form.isDelivery = null;
  690. }
  691. function deliveryChange(value: any) {
  692. form.isDelivery = value[value.length - 1];
  693. }
  694. function getConditioningProgramSupplier(value: any) {
  695. onlineArr.value = [];
  696. deliverArr.value = [];
  697. form.isOffline = null;
  698. form.isDelivery = null;
  699. isShowDelivery.value = false;
  700. }
  701. // 项目应用数据
  702. const plainOptions = [
  703. { id: '1', name: '服务包项目' },
  704. { id: '2', name: '调理方案项目' },
  705. ];
  706. // 推导逻辑
  707. const hasDerivationLogic = ref(false); // 添加推导逻辑状态跟踪
  708. const derivationData = ref<any>({});
  709. // 判断推导逻辑内容是否为空
  710. const isDerivationEmpty = computed(() => {
  711. const rule = derivationData.value.cpPatientMatchRule;
  712. if (!rule) return true;
  713. // 检查所有字段都为空或未填写
  714. const fields = ['sex', 'age', 'diagnoseDiseaseNames', 'diagnoseSyndromeNames', 'constitutionGroupNames', 'willillStateNames', 'tabooCrowds'];
  715. return fields.every((key) => {
  716. const val = rule[key];
  717. if (Array.isArray(val)) return val.length === 0;
  718. return !val;
  719. });
  720. });
  721. function handleDerivation() {
  722. // 设置推导逻辑弹窗打开状态
  723. isDerivationModalOpen.value = true;
  724. VxeUI.modal.open({
  725. title: `推导逻辑`,
  726. height: 750,
  727. width: 750,
  728. escClosable: true,
  729. destroyOnClose: true,
  730. id: `derivation-modal`,
  731. remember: true,
  732. storage: true,
  733. onClose: () => {
  734. // 弹窗关闭时清除验证状态并重置状态
  735. isDerivationModalOpen.value = false;
  736. nextTick(() => {
  737. formRef.value?.clearValidate(['institutionId', 'conditioningProgramSupplierId']);
  738. });
  739. },
  740. slots: {
  741. default() {
  742. return h(Derivation, {
  743. data: {
  744. ...props.data,
  745. // 传递当前的推导逻辑数据
  746. cpPatientMatchRule: derivationData.value.cpPatientMatchRule || form.cpPatientMatchRule,
  747. checkedList: checkedList.value,
  748. },
  749. onSubmit: (data: any) => {
  750. derivationData.value = data;
  751. hasDerivationLogic.value = true; // 设置推导逻辑已编辑
  752. // 重置状态并清除验证状态
  753. isDerivationModalOpen.value = false;
  754. nextTick(() => {
  755. formRef.value?.clearValidate(['institutionId', 'conditioningProgramSupplierId']);
  756. });
  757. },
  758. onCancel: () => {
  759. // 取消时重置状态并清除验证状态
  760. isDerivationModalOpen.value = false;
  761. nextTick(() => {
  762. formRef.value?.clearValidate(['institutionId', 'conditioningProgramSupplierId']);
  763. });
  764. },
  765. });
  766. },
  767. },
  768. });
  769. }
  770. </script>
  771. <template>
  772. <div class="form-container">
  773. <a-form ref="formRef" :model="form" :rules="rules" layout="horizontal">
  774. <a-form-item label="项目名称:" name="name">
  775. <a-input v-model:value="form.name" placeholder="请输入" />
  776. </a-form-item>
  777. <a-form-item label="方案类型:" name="conditioningProgramType" style="width: 100%" required>
  778. <vxe-select
  779. v-model="form.conditioningProgramType"
  780. :options="typeOptions"
  781. placeholder="请选择方案类型"
  782. clearable
  783. filterable
  784. transfer
  785. empty-text="暂无数据"
  786. @focus="handleSelectClick"
  787. style="width: 100%"
  788. />
  789. </a-form-item>
  790. <a-form-item label="项目应用:" required v-if="form.addType === 'itemsList'">
  791. <a-checkbox-group v-model:value="checkedList">
  792. <a-checkbox v-for="option in plainOptions" :key="option.id" :value="option.id">
  793. {{ option.name }}
  794. </a-checkbox>
  795. </a-checkbox-group>
  796. </a-form-item>
  797. <a-form-item label="计价规则:" name="pricingType" :required="checkedList.includes('1')">
  798. <a-radio-group v-model:value="form.pricingType">
  799. <a-radio value="0">一口价</a-radio>
  800. <a-radio value="1">按穴位/经络/部位</a-radio>
  801. </a-radio-group>
  802. </a-form-item>
  803. <div class="price-row" v-if="form.pricingType === '0' && form.cpFixedPricingRule">
  804. <span class="label">单价:</span>
  805. <a-input v-model:value="form.cpFixedPricingRule.unitPrice" placeholder="请输入" style="width: 100px" />
  806. <span style="margin: 0 8px">元</span>
  807. <span class="label" style="margin-left: 32px">计价单位:</span>
  808. <a-input v-model:value="form.cpFixedPricingRule.pricingUnit" placeholder="请输入" style="width: 100px" />
  809. <span style="margin-left: 32px">相当于</span>
  810. <a-input v-model:value="form.cpFixedPricingRule.convertDose" placeholder="请输入" style="width: 100px; margin-left: 8px" />
  811. <vxe-select v-model="form.cpFixedPricingRule.convertUnit" :options="unitOptions" placeholder="请选择" clearable transfer style="width: 100px; margin-left: 8px" />
  812. <span style="color: #aaa; margin-left: 8px">(使用单位)</span>
  813. </div>
  814. <div v-if="form.pricingType === '1'" class="per-rule">
  815. <div class="price-row">
  816. <span>计价1:</span>
  817. <span class="flex items-center"
  818. >当"穴位/经络/部位" ≤
  819. <a-input
  820. placeholder="请输入"
  821. class="w-20 ml-2 mr-2"
  822. v-model:value="form.cpDynamicPricingRule[0].min"
  823. @change="() => (form.cpDynamicPricingRule[1].max = form.cpDynamicPricingRule[0].min)"
  824. />个时,</span
  825. >
  826. <vxe-select
  827. v-model="form.cpDynamicPricingRule[0].priceType"
  828. :options="[
  829. { label: '单价', value: 0, priceType: 0 },
  830. { label: '一口价', value: 1, priceType: 1 },
  831. ]"
  832. placeholder="请选择"
  833. clearable
  834. transfer
  835. style="width: 100px; margin: 0 4px"
  836. />
  837. <span>=</span>
  838. <a-input v-model:value="form.cpDynamicPricingRule[0].price" style="width: 80px; margin: 0 4px" placeholder="请输入" />
  839. <span>元</span>
  840. </div>
  841. <div class="price-row">
  842. <span>计价2:</span>
  843. <span class="flex items-center"
  844. >当"穴位/经络/部位" &gt; <a-input placeholder="请输入" class="w-20 ml-2 mr-2" v-model:value="form.cpDynamicPricingRule[1].max" disabled />个时,</span
  845. >
  846. <vxe-select
  847. v-model="form.cpDynamicPricingRule[1].priceType"
  848. :options="[
  849. { label: '单价', value: 0, priceType: 0 },
  850. { label: '一口价', value: 1, priceType: 1 },
  851. ]"
  852. placeholder="请选择"
  853. clearable
  854. transfer
  855. style="width: 100px; margin: 0 4px"
  856. />
  857. <span>=</span>
  858. <a-input v-model:value="form.cpDynamicPricingRule[1].price" style="width: 80px; margin: 0 4px" placeholder="请输入" />
  859. <span>元</span>
  860. </div>
  861. </div>
  862. <a-form-item label="组成:">
  863. <div class="herb-list">
  864. <template v-for="(herb, idx) in form.cpMedicines" :key="herb.id">
  865. <div class="herb-item">
  866. <button class="herb-remove" v-if="form?.cpMedicines?.length > 1" @click="removeHerb(idx)" type="button">×</button>
  867. <!-- <RemoteSelect :load="cpMedicinesMethod" key-prop="name" v-model:value="herb.name" /> -->
  868. <SearchableSelect
  869. v-model="herb.name"
  870. :options="herbList"
  871. placeholder="请选择"
  872. value-key="name"
  873. label-key="name"
  874. key-key="id"
  875. :fetch-options="cpMedicinesMethod"
  876. style="width: 150px"
  877. :allow-custom-input="true"
  878. />
  879. <a-input v-model:value="herb.dosage" class="herb-dosage" placeholder="剂量" />
  880. <span>g</span>
  881. </div>
  882. </template>
  883. <button style="margin-left: 8px" @click="addHerb" type="button">+</button>
  884. </div>
  885. </a-form-item>
  886. <a-form-item label="特色:" v-if="form.addType === 'itemsList'">
  887. <textarea
  888. v-model="form.attrFirst"
  889. placeholder="请输入"
  890. rows="3"
  891. style="width: 100%; padding: 8px; border: 1px solid #d9d9d9; border-radius: 4px; resize: vertical; font-family: inherit"
  892. />
  893. </a-form-item>
  894. <a-form-item label="功效:">
  895. <a-input v-model:value="form.effect" placeholder="请输入" />
  896. </a-form-item>
  897. <a-form-item label="制法:" v-if="form.addType === 'itemsList'">
  898. <a-input v-model:value="form.attrThird" placeholder="请输入" />
  899. </a-form-item>
  900. <a-form-item label="用法:" v-if="form.addType === 'itemsList'">
  901. <a-input v-model:value="form.attrFourth" placeholder="请输入" />
  902. </a-form-item>
  903. <a-form-item label="操作方法:" v-if="form.addType === 'itemsList'">
  904. <textarea
  905. v-model="form.attrFifth"
  906. placeholder="请输入"
  907. rows="3"
  908. style="width: 100%; padding: 8px; border: 1px solid #d9d9d9; border-radius: 4px; resize: vertical; font-family: inherit"
  909. />
  910. </a-form-item>
  911. <div class="image-row">
  912. <a-form-item label="操作图片:" class="image-form-item" v-if="form.addType === 'itemsList'">
  913. <a-upload :showUploadList="uploadProps" v-model:file-list="optionsList" list-type="picture-card" @preview="handlePreview" :maxCount="1" :customRequest="customUpload">
  914. <div v-if="optionsList.length < 1">
  915. <PlusOutlined />
  916. <div style="margin-top: 8px">上传</div>
  917. </div>
  918. </a-upload>
  919. </a-form-item>
  920. <a-form-item label="商品图片:" class="image-form-item">
  921. <a-upload :showUploadList="uploadProps" v-model:file-list="fileList" list-type="picture-card" @preview="handlePreview" :maxCount="1" :customRequest="customUpload">
  922. <div v-if="fileList.length < 1">
  923. <PlusOutlined />
  924. <div style="margin-top: 8px">上传</div>
  925. </div>
  926. </a-upload>
  927. </a-form-item>
  928. </div>
  929. <a-form-item label="操作视频:" class="image-form-item" v-if="form.addType === 'itemsList'">
  930. <div class="video-upload-wrapper">
  931. <div class="video-upload-container">
  932. <a-upload
  933. :showUploadList="false"
  934. :custom-request="customVideoRequest"
  935. :max-count="1"
  936. :multiple="false"
  937. :before-upload="beforeVideoUpload"
  938. @change="handleVideoChange"
  939. :file-list="videoFileList"
  940. accept="video/mp4,video/avi,video/mov,video/webm"
  941. >
  942. <div v-if="!form.itemVideoFirst && !uploading" class="video-upload-btn">
  943. <PlusOutlined />
  944. <div style="margin-top: 8px">上传视频</div>
  945. <div class="video-upload-tip">mp4/avi/mov/webm<br />最大100MB</div>
  946. </div>
  947. <!-- 上传中状态 -->
  948. <div v-else-if="uploading" class="video-uploading">
  949. <div class="upload-progress">
  950. <a-progress :percent="progress" :show-info="false" size="small" stroke-color="#1890ff" />
  951. <div class="upload-text">上传中... {{ Math.round(progress) }}%</div>
  952. </div>
  953. </div>
  954. <!-- 视频预览 -->
  955. <div v-else class="video-preview-container">
  956. <div class="video-thumbnail">
  957. <video :src="form.itemVideoFirst" preload="metadata" class="video-preview" />
  958. <div class="video-overlay">
  959. <a-button
  960. type="primary"
  961. size="small"
  962. @click.stop="
  963. handleVideoPreview({
  964. uid: 'video-preview',
  965. name: '操作视频',
  966. url: form.itemVideoFirst,
  967. })
  968. "
  969. >
  970. 预览
  971. </a-button>
  972. <a-button danger size="small" @click.stop="removeVideo"> 删除 </a-button>
  973. </div>
  974. </div>
  975. <!-- <div class="video-info">
  976. <div class="video-name">操作视频</div>
  977. <div class="video-size">已上传</div>
  978. </div> -->
  979. </div>
  980. </a-upload>
  981. </div>
  982. </div>
  983. </a-form-item>
  984. <a-form-item label="疗程说明:" v-if="form.addType === 'itemsList'">
  985. <textarea
  986. v-model="form.attrSixth"
  987. placeholder="请输入"
  988. rows="3"
  989. style="width: 100%; padding: 8px; border: 1px solid #d9d9d9; border-radius: 4px; resize: vertical; font-family: inherit"
  990. />
  991. </a-form-item>
  992. <a-form-item label="使用注意:" v-if="form.addType === 'itemsList'">
  993. <textarea
  994. v-model="form.attrSeventh"
  995. placeholder="请输入"
  996. rows="3"
  997. style="width: 100%; padding: 8px; border: 1px solid #d9d9d9; border-radius: 4px; resize: vertical; font-family: inherit"
  998. />
  999. </a-form-item>
  1000. <a-form-item label="推导逻辑:" v-if="form.addType === 'itemsList'" :required="checkedList.includes('2')">
  1001. <button @click="handleDerivation" v-if="!hasDerivationLogic || isDerivationEmpty">编辑</button>
  1002. <div v-else @click="handleDerivation" style="cursor: pointer">
  1003. <div v-if="derivationData.cpPatientMatchRule" class="derivation-container">
  1004. <div v-if="derivationData.cpPatientMatchRule.sex" class="derivation-item">
  1005. <span class="derivation-label">性别限制:</span>
  1006. <span class="derivation-content">{{ derivationData.cpPatientMatchRule.sex }}</span>
  1007. </div>
  1008. <div v-if="derivationData.cpPatientMatchRule.age" class="derivation-item">
  1009. <span class="derivation-label">年龄限制:</span>
  1010. <span class="derivation-content">{{ derivationData.cpPatientMatchRule.age }}</span>
  1011. </div>
  1012. <div v-if="derivationData.cpPatientMatchRule.diagnoseDiseaseNames && derivationData.cpPatientMatchRule.diagnoseDiseaseNames.length > 0" class="derivation-item">
  1013. <span class="derivation-label">专病:</span>
  1014. <span class="derivation-content">{{ derivationData.cpPatientMatchRule.diagnoseDiseaseNames.join('、') }}</span>
  1015. </div>
  1016. <div v-if="derivationData.cpPatientMatchRule.diagnoseSyndromeNames && derivationData.cpPatientMatchRule.diagnoseSyndromeNames.length > 0" class="derivation-item">
  1017. <span class="derivation-label">证型:</span>
  1018. <span class="derivation-content">{{ derivationData.cpPatientMatchRule.diagnoseSyndromeNames.join('、') }}</span>
  1019. </div>
  1020. <div v-if="derivationData.cpPatientMatchRule.constitutionGroupNames && derivationData.cpPatientMatchRule.constitutionGroupNames.length > 0" class="derivation-item">
  1021. <span class="derivation-label">体质:</span>
  1022. <span class="derivation-content">{{ derivationData.cpPatientMatchRule.constitutionGroupNames.join('、') }}</span>
  1023. </div>
  1024. <div v-if="derivationData.cpPatientMatchRule.willillStateNames && derivationData.cpPatientMatchRule.willillStateNames.length > 0" class="derivation-item">
  1025. <span class="derivation-label">欲病状态:</span>
  1026. <span class="derivation-content">{{ derivationData.cpPatientMatchRule.willillStateNames.join('、') }}</span>
  1027. </div>
  1028. <div v-if="derivationData.cpPatientMatchRule.tabooCrowds && derivationData.cpPatientMatchRule.tabooCrowds.length > 0" class="derivation-item">
  1029. <span class="derivation-label">禁忌人群:</span>
  1030. <span class="derivation-content">{{ derivationData.cpPatientMatchRule.tabooCrowds.join('、') }}</span>
  1031. </div>
  1032. </div>
  1033. </div>
  1034. </a-form-item>
  1035. <!-- 购买链接 -->
  1036. <a-form-item label="购买链接:" v-if="form.addType === 'itemsList'">
  1037. <a-input v-model:value="form.attrEighth" placeholder="请输入" />
  1038. </a-form-item>
  1039. <!-- 跳转类型 -->
  1040. <a-form-item label="跳转类型:" v-if="form.addType === 'itemsList'" style="width: 100%">
  1041. <Vxe-select v-model="form.attrNinth" :options="jumpTypeOptions" placeholder="请选择" clearable transfer style="width: 100%" />
  1042. </a-form-item>
  1043. <!-- 机构名称 -->
  1044. <a-form-item label="机构名称:" v-if="form?.addType === 'itemsList'" required name="institutionId">
  1045. <a-tree-select
  1046. :disabled="form.addType === 'itemsList' && !!form.sourceId"
  1047. v-model:value="form.institutionId"
  1048. style="width: 100%"
  1049. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto', zIndex: 4000 }"
  1050. :dropdownMatchSelectWidth="false"
  1051. :getPopupContainer="getSafePopupContainer"
  1052. placeholder="请选择"
  1053. allow-clear
  1054. tree-default-expand-all
  1055. :tree-data="branch"
  1056. :loading="branchLoading"
  1057. @change="onInstitutionChange"
  1058. ></a-tree-select>
  1059. </a-form-item>
  1060. <a-form-item label="供应商:" name="conditioningProgramSupplierId" :rules="supplierRules" style="width: 100%">
  1061. <a-select
  1062. v-model:value="form.conditioningProgramSupplierId"
  1063. :options="supplierOptions"
  1064. placeholder="请选择"
  1065. allow-clear
  1066. show-search
  1067. :getPopupContainer="getSafePopupContainer"
  1068. :dropdownMatchSelectWidth="false"
  1069. :dropdownStyle="{ zIndex: 5000 }"
  1070. style="width: 100%"
  1071. @change="getConditioningProgramSupplier"
  1072. not-found-content="暂无数据"
  1073. />
  1074. </a-form-item>
  1075. <a-form-item label="线下项目:" name="isOffline" v-if="isShowOnline" :required="checkedList.includes('1')">
  1076. <a-checkbox-group v-model:value="onlineArr" @change="onlineChange">
  1077. <a-checkbox value="Y">是</a-checkbox>
  1078. <a-checkbox value="N">否</a-checkbox>
  1079. </a-checkbox-group>
  1080. </a-form-item>
  1081. <a-form-item label="配送:" name="isDelivery" v-if="isShowDelivery" :required="checkedList.includes('1')">
  1082. <a-checkbox-group v-model:value="deliverArr" @change="deliveryChange">
  1083. <a-checkbox value="Y">支持</a-checkbox>
  1084. <a-checkbox value="N">不支持</a-checkbox>
  1085. </a-checkbox-group>
  1086. </a-form-item>
  1087. <a-form-item label="启用状态:" name="status" v-if="form.addType === 'itemsList'" required>
  1088. <a-radio-group v-model:value="form.status">
  1089. <a-radio value="0">启用</a-radio>
  1090. <a-radio value="1">停用</a-radio>
  1091. </a-radio-group>
  1092. </a-form-item>
  1093. <a-image
  1094. :width="200"
  1095. :style="{ display: 'none' }"
  1096. :preview="{
  1097. visible,
  1098. onVisibleChange: setVisible,
  1099. }"
  1100. :src="previewImg"
  1101. />
  1102. <video :src="videoUrl" controls v-if="videoUrl" style="width: 100%; max-width: 500px; border-radius: 6px" preload="metadata" />
  1103. <div class="form-actions-center">
  1104. <a-button @click="cancel">取消</a-button>
  1105. <a-button type="primary" style="background: #faad14; border: none" @click="doSubmit">确定</a-button>
  1106. </div>
  1107. </a-form>
  1108. </div>
  1109. </template>
  1110. <style scoped>
  1111. .form-container {
  1112. width: 95%;
  1113. margin: 0 auto;
  1114. padding: 10px 0px 0 0;
  1115. display: flex;
  1116. flex-direction: column;
  1117. /* max-height: 80vh; */
  1118. }
  1119. .per-rule {
  1120. margin-bottom: 16px;
  1121. }
  1122. .price-row {
  1123. display: flex;
  1124. align-items: center;
  1125. margin-bottom: 10px;
  1126. }
  1127. .label {
  1128. font-weight: 500;
  1129. color: #222;
  1130. margin-right: 8px;
  1131. }
  1132. .herb-list {
  1133. display: flex;
  1134. align-items: center;
  1135. flex-wrap: wrap;
  1136. }
  1137. .herb-item {
  1138. position: relative;
  1139. display: flex;
  1140. align-items: center;
  1141. margin-right: 8px;
  1142. margin-bottom: 8px;
  1143. padding-left: 16px;
  1144. }
  1145. .herb-dosage {
  1146. width: 70px;
  1147. font-size: 14px;
  1148. margin-right: 10px;
  1149. }
  1150. .herb-remove {
  1151. position: absolute;
  1152. left: 0;
  1153. top: 0;
  1154. background: #fff;
  1155. border: none;
  1156. color: #ff4d4f;
  1157. font-size: 14px;
  1158. cursor: pointer;
  1159. line-height: 1;
  1160. width: 16px;
  1161. height: 16px;
  1162. padding: 0;
  1163. display: flex;
  1164. align-items: center;
  1165. justify-content: center;
  1166. }
  1167. .form-actions-center {
  1168. display: flex;
  1169. justify-content: center;
  1170. gap: 16px;
  1171. position: sticky;
  1172. bottom: 0;
  1173. background: #fff;
  1174. padding: 12px 0;
  1175. }
  1176. .form-container .ant-form {
  1177. display: flex;
  1178. flex-direction: column;
  1179. overflow: auto;
  1180. }
  1181. .slider-section {
  1182. margin-bottom: 16px;
  1183. }
  1184. .slider-labels {
  1185. display: flex;
  1186. justify-content: space-between;
  1187. width: 200px;
  1188. margin-left: 230px;
  1189. margin-bottom: 4px;
  1190. font-weight: 500;
  1191. color: #222;
  1192. }
  1193. .slider-row {
  1194. display: flex;
  1195. align-items: center;
  1196. }
  1197. .slider-desc {
  1198. color: #222;
  1199. white-space: nowrap;
  1200. display: flex;
  1201. flex-direction: column;
  1202. align-items: center;
  1203. justify-content: center;
  1204. }
  1205. .slider-value {
  1206. margin-left: 16px;
  1207. color: #faad14;
  1208. font-weight: bold;
  1209. }
  1210. .upload-btn {
  1211. display: flex;
  1212. flex-direction: column;
  1213. align-items: center;
  1214. justify-content: center;
  1215. min-height: 100px;
  1216. border: 1px dashed #d9d9d9;
  1217. border-radius: 6px;
  1218. background: #fafafa;
  1219. cursor: pointer;
  1220. transition: border-color 0.3s;
  1221. width: 100px;
  1222. }
  1223. .upload-btn:hover {
  1224. border-color: #1890ff;
  1225. background: #f0f7ff;
  1226. }
  1227. .upload-btn .anticon {
  1228. font-size: 16px;
  1229. color: #1890ff;
  1230. }
  1231. .upload-btn .upload-text {
  1232. margin-top: 8px;
  1233. color: #666;
  1234. font-size: 15px;
  1235. }
  1236. .video-preview {
  1237. border-radius: 6px;
  1238. background: #000;
  1239. width: 120px !important;
  1240. height: 100px !important;
  1241. }
  1242. .video-preview video {
  1243. border-radius: 6px;
  1244. background: #000;
  1245. width: 120px;
  1246. height: 100px;
  1247. }
  1248. .video-preview .ant-btn-link {
  1249. padding: 0;
  1250. font-size: 14px;
  1251. color: #ff4d4f;
  1252. }
  1253. .image-row {
  1254. display: flex;
  1255. gap: 32px;
  1256. align-items: flex-start;
  1257. margin-bottom: 16px;
  1258. }
  1259. .image-form-item {
  1260. flex: 1;
  1261. margin-bottom: 0 !important;
  1262. }
  1263. .image-form-item .ant-upload-picture-card-wrapper {
  1264. display: flex;
  1265. flex-direction: column;
  1266. align-items: flex-start;
  1267. }
  1268. .derivation-item {
  1269. display: flex;
  1270. align-items: center;
  1271. min-width: 200px;
  1272. max-width: 300px;
  1273. padding: 6px 12px;
  1274. background: #f5f5f5;
  1275. border-radius: 4px;
  1276. border: 1px solid #e8e8e8;
  1277. }
  1278. .derivation-label {
  1279. font-weight: 500;
  1280. color: #222;
  1281. margin-right: 8px;
  1282. white-space: nowrap;
  1283. font-size: 13px;
  1284. }
  1285. .derivation-content {
  1286. color: #555;
  1287. font-size: 13px;
  1288. flex: 1;
  1289. word-break: break-all;
  1290. }
  1291. .derivation-container {
  1292. display: flex;
  1293. flex-wrap: wrap;
  1294. gap: 16px;
  1295. align-items: flex-start;
  1296. }
  1297. .video-upload-wrapper {
  1298. display: flex;
  1299. align-items: flex-start;
  1300. }
  1301. .video-upload-container {
  1302. position: relative;
  1303. width: 130px;
  1304. height: 130px;
  1305. display: flex;
  1306. align-items: center;
  1307. justify-content: center;
  1308. border: 2px dashed #d9d9d9;
  1309. border-radius: 8px;
  1310. background: #fafafa;
  1311. cursor: pointer;
  1312. transition: all 0.3s ease;
  1313. overflow: hidden;
  1314. margin-bottom: 20px;
  1315. }
  1316. .video-upload-container:hover {
  1317. border-color: #1890ff;
  1318. background: #f0f7ff;
  1319. transform: translateY(-1px);
  1320. box-shadow: 0 2px 8px rgba(24, 144, 255, 0.1);
  1321. }
  1322. .video-upload-btn {
  1323. display: flex;
  1324. flex-direction: column;
  1325. align-items: center;
  1326. justify-content: center;
  1327. padding: 16px 12px;
  1328. text-align: center;
  1329. }
  1330. .video-upload-btn .anticon {
  1331. font-size: 20px;
  1332. color: #1890ff;
  1333. margin-bottom: 6px;
  1334. }
  1335. .video-upload-tip {
  1336. font-size: 11px;
  1337. color: #999;
  1338. margin-top: 6px;
  1339. line-height: 1.3;
  1340. }
  1341. .video-uploading {
  1342. position: absolute;
  1343. top: 0;
  1344. left: 0;
  1345. width: 100%;
  1346. height: 100%;
  1347. background: rgba(255, 255, 255, 0.95);
  1348. display: flex;
  1349. flex-direction: column;
  1350. align-items: center;
  1351. justify-content: center;
  1352. z-index: 10;
  1353. backdrop-filter: blur(2px);
  1354. }
  1355. .upload-progress {
  1356. display: flex;
  1357. flex-direction: column;
  1358. align-items: center;
  1359. gap: 8px;
  1360. width: 90%;
  1361. max-width: 160px;
  1362. }
  1363. .upload-text {
  1364. font-size: 12px;
  1365. color: #1890ff;
  1366. font-weight: 500;
  1367. text-align: center;
  1368. }
  1369. .video-preview-container {
  1370. display: flex;
  1371. flex-direction: column;
  1372. align-items: center;
  1373. justify-content: center;
  1374. width: 100%;
  1375. height: 100%;
  1376. padding: 10px;
  1377. background: #fafafa;
  1378. border-radius: 8px;
  1379. }
  1380. .video-thumbnail {
  1381. position: relative;
  1382. width: 100%;
  1383. height: 100px;
  1384. border-radius: 6px;
  1385. overflow: hidden;
  1386. background: #000;
  1387. display: flex;
  1388. align-items: center;
  1389. justify-content: center;
  1390. margin-bottom: 8px;
  1391. }
  1392. .video-thumbnail .video-preview {
  1393. width: 100%;
  1394. height: 100%;
  1395. object-fit: cover;
  1396. }
  1397. .video-overlay {
  1398. position: absolute;
  1399. top: 0;
  1400. left: 0;
  1401. width: 100%;
  1402. height: 100%;
  1403. background: rgba(0, 0, 0, 0.7);
  1404. border-radius: 6px;
  1405. display: flex;
  1406. align-items: center;
  1407. justify-content: center;
  1408. gap: 8px;
  1409. opacity: 0;
  1410. transition: opacity 0.3s ease;
  1411. }
  1412. .video-preview-container:hover .video-overlay {
  1413. opacity: 1;
  1414. }
  1415. .video-overlay .ant-btn {
  1416. background: rgba(255, 255, 255, 0.95);
  1417. border: none;
  1418. color: #333;
  1419. font-size: 11px;
  1420. padding: 3px 8px;
  1421. border-radius: 4px;
  1422. transition: all 0.3s ease;
  1423. min-width: 40px;
  1424. height: 28px;
  1425. line-height: 1.2;
  1426. display: flex;
  1427. align-items: center;
  1428. justify-content: center;
  1429. white-space: nowrap;
  1430. }
  1431. .video-overlay .ant-btn:hover {
  1432. background: rgba(255, 255, 255, 1);
  1433. transform: scale(1.05);
  1434. }
  1435. .video-overlay .ant-btn-danger {
  1436. background: rgba(255, 77, 79, 0.95);
  1437. color: #fff;
  1438. }
  1439. .video-overlay .ant-btn-danger:hover {
  1440. background: rgba(255, 77, 79, 1);
  1441. }
  1442. .video-info {
  1443. text-align: center;
  1444. font-size: 11px;
  1445. color: #666;
  1446. }
  1447. .video-name {
  1448. font-weight: 500;
  1449. color: #333;
  1450. margin-bottom: 2px;
  1451. }
  1452. .video-size {
  1453. color: #999;
  1454. font-size: 10px;
  1455. }
  1456. </style>
  1457. <style>
  1458. /* 提升 AntD Select 下拉层级,避免被弹窗/遮罩遮挡 */
  1459. .ant-select-dropdown {
  1460. z-index: 5000 !important;
  1461. }
  1462. </style>