priceSheetPopup.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. <template>
  2. <popup class="price-sheet-popup" :overlay-style="{'z-index': 9999}" v-model:show="showPopup" teleport="body">
  3. <div class="price-sheet-content">
  4. <div class="price-sheet-content-inner" ref="contentEl">
  5. <!-- 顶部标题区域 -->
  6. <div class="header-section">
  7. <div class="header-left">
  8. <div class="main-title">服务报价单</div>
  9. </div>
  10. <div class="header-right">
  11. <div class="qr-icon">
  12. <img src="@/assets/img/home/qrcode.png" alt="" />
  13. </div>
  14. <div class="qr-text">扫码查看详情</div>
  15. </div>
  16. </div>
  17. <div class="sheet-content" v-loading="loading">
  18. <!-- 报价详情区域 -->
  19. <div class="quotation-info">
  20. <div class="info-item">
  21. <span class="info-label">报价组织</span>
  22. <span class="info-value">{{ quotationData.serviceMain || '--' }}</span>
  23. </div>
  24. <div class="info-item">
  25. <span class="info-label">报价农事</span>
  26. <span class="info-value">{{ quotationData?.farmWorkName || '--' }}</span>
  27. </div>
  28. <div class="info-item">
  29. <span class="info-label">执行时间</span>
  30. <span class="info-value">{{ quotationData?.executeDate || '--' }}</span>
  31. </div>
  32. <div class="info-item catalog-label">
  33. <span class="info-label">报价目录</span>
  34. <div class="edit-btn-box">
  35. <div class="edit-btn" @click="handleEdit">编辑报价</div>
  36. </div>
  37. </div>
  38. <div class="total-bar">
  39. <span class="total-label">报价合计:</span>
  40. <span class="total-value">{{ priceData?.totalCost ? formatArea(priceData.totalCost) : '--' }}</span>
  41. <span class="total-unit">元</span>
  42. </div>
  43. </div>
  44. <!-- 肥药费用区域 -->
  45. <div class="fertilizer-cost-section">
  46. <div class="section-header">
  47. <div class="section-title">肥药费用</div>
  48. <div class="section-total">{{ priceData?.pesticideFertilizerCost ? formatArea(priceData.pesticideFertilizerCost) : '--' }}<span class="unit-text">元</span></div>
  49. </div>
  50. <div class="cost-table">
  51. <div class="table-header">
  52. <div class="col-1">功效</div>
  53. <div class="col-2">名称</div>
  54. <div class="col-3">品牌</div>
  55. <div class="col-4">单价</div>
  56. <div class="col-5">用量</div>
  57. <div class="col-6">总价</div>
  58. </div>
  59. <div
  60. class="table-row"
  61. v-for="(item, index) in processedPrescriptionList"
  62. :key="index"
  63. >
  64. <div class="col-1">{{ item.typeName || '--' }}</div>
  65. <div class="col-2">{{ item.defaultName || item.pesticideFertilizerName || '--' }}</div>
  66. <div class="col-3">{{ item.brand || '--' }}</div>
  67. <div class="col-4">{{ item.price || '--' }}</div>
  68. <div class="col-5">{{ item.usageDisplay || '--' }}</div>
  69. <div class="col-6">{{ item.totalDisplay === '--' ? '--' : (item.totalDisplay + '元') }}</div>
  70. </div>
  71. </div>
  72. </div>
  73. <!-- 服务费用区域 -->
  74. <div class="service-cost-section">
  75. <div class="section-header">
  76. <div class="section-title">服务费用</div>
  77. <div class="section-total">{{ priceData?.farmWorkServiceCost ? getServiceCost(priceData.farmWorkServiceCost, quotationData.area) : '--' }}<span class="unit-text">元</span></div>
  78. </div>
  79. <div class="service-details">
  80. <div class="detail-item">
  81. <div class="detail-value">{{ priceData?.executionMethodName || '--' }}</div>
  82. <div class="detail-label">执行方式</div>
  83. </div>
  84. <div class="detail-item">
  85. <div class="detail-value">{{ (priceData?.farmWorkServiceCost ? priceData.farmWorkServiceCost + '元/亩' : '--') }}</div>
  86. <div class="detail-label">亩单价</div>
  87. </div>
  88. <div class="detail-item">
  89. <div class="detail-value">{{ quotationData?.area ? (formatArea(quotationData?.area) + '亩') : '--' }}</div>
  90. <div class="detail-label">亩数</div>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. <!-- 底部操作按钮 -->
  97. <div class="bottom-actions" @click.stop="showPopup = false">
  98. <div class="action-buttons">
  99. <div class="action-btn blue-btn" @click.stop="handleShare">
  100. <div class="icon-circle">
  101. <img src="@/assets/img/home/bird.png" alt="" />
  102. </div>
  103. <span class="btn-label">飞鸟用户</span>
  104. </div>
  105. <div class="action-btn green-btn" @click.stop="handleWechat">
  106. <div class="icon-circle">
  107. <img src="@/assets/img/home/wechat.png" alt="" />
  108. </div>
  109. <span class="btn-label">微信</span>
  110. </div>
  111. <div class="action-btn orange-btn">
  112. <div class="icon-circle">
  113. <el-icon :size="24"><Download /></el-icon>
  114. </div>
  115. <span class="btn-label">保存图片</span>
  116. </div>
  117. </div>
  118. <div class="cancel-btn" @click="handleCancel">取消</div>
  119. </div>
  120. </div>
  121. </popup>
  122. </template>
  123. <script setup>
  124. import { Popup } from "vant";
  125. import { ref, computed, onActivated, watch } from "vue";
  126. import { useRouter } from "vue-router";
  127. import { ElMessage } from "element-plus";
  128. import wx from "weixin-js-sdk";
  129. import html2canvas from "html2canvas";
  130. import { formatArea } from "@/common/commonFun";
  131. const router = useRouter();
  132. const showPopup = ref(false);
  133. const contentEl = ref(null);
  134. // 报价数据
  135. const quotationData = ref({});
  136. const priceData = ref({});
  137. onActivated(() => {
  138. console.log('onActivated')
  139. fetchPriceData()
  140. })
  141. // 处理后的处方列表(展平并匹配价格)
  142. const processedPrescriptionList = computed(() => {
  143. if (!quotationData.value?.prescriptionList || !Array.isArray(quotationData.value.prescriptionList)) {
  144. return [];
  145. }
  146. // 创建价格映射表,方便快速查找
  147. const priceMap = new Map();
  148. if (priceData.value?.itemsList && Array.isArray(priceData.value.itemsList)) {
  149. priceData.value.itemsList.forEach(item => {
  150. priceMap.set(String(item.pesticideFertilizerId), { price: item.price, brand: item.brand, totalPrice: item.totalPrice });
  151. });
  152. }
  153. // 展平 prescriptionList 中的所有 pesticideFertilizerList
  154. const result = [];
  155. quotationData.value.prescriptionList.forEach(prescription => {
  156. if (prescription.pesticideFertilizerList && Array.isArray(prescription.pesticideFertilizerList)) {
  157. prescription.pesticideFertilizerList.forEach(item => {
  158. const pesticideFertilizerId = String(item.pesticideFertilizerId || '');
  159. const mapped = priceMap.get(pesticideFertilizerId) || {};
  160. const price = mapped.price || 0;
  161. const brand = mapped.brand || item.brand || '';
  162. const total = mapped.totalPrice || item.total || '';
  163. const muUsage = quotationData.value.usageMode === "叶面施" ? (item.muUsage2 || item.muUsage) : item.muUsage
  164. const unit = item.unit || '';
  165. result.push({
  166. typeName: item.typeName || item.pesticideFertilizerTypeName || '--',
  167. defaultName: item.defaultName || item.pesticideFertilizerName || '--',
  168. brand: brand,
  169. price: price ? `${price}元` : '--',
  170. unit: unit,
  171. muUsage: muUsage,
  172. // total: total,
  173. // 显示的格式化字符串
  174. priceDisplay: price > 0 ? `${price}元/${unit}` : '--',
  175. usageDisplay: muUsage > 0 ? `${muUsage}${unit}` : '--',
  176. totalDisplay: total > 0 ? `${total.toFixed(2)}` : '--'
  177. });
  178. });
  179. }
  180. });
  181. return result;
  182. });
  183. function getServiceCost(cost, area) {
  184. if (!cost || !area) return '--';
  185. return (parseFloat(cost) * parseFloat(area)).toFixed(2);
  186. }
  187. const handleShowPopup = (data) => {
  188. if (data) {
  189. quotationData.value = data;
  190. fetchPriceData();
  191. }
  192. showPopup.value = true;
  193. };
  194. const loading = ref(false);
  195. function fetchPriceData() {
  196. if (!quotationData.value?.id) {
  197. return;
  198. }
  199. loading.value = true;
  200. VE_API.z_farm_work_record_cost.getByRecordId({ farmWorkRecordId: quotationData.value.id }).then(({ data }) => {
  201. priceData.value = data;
  202. }).catch(() => {
  203. // 获取价格数据失败
  204. }).finally(() => {
  205. loading.value = false;
  206. });
  207. }
  208. const handleShare = () => {
  209. if (!priceData.value?.id || !priceData.value?.itemsList || priceData.value?.itemsList?.length === 0) {
  210. ElMessage.warning('请补全报价数据')
  211. return;
  212. }
  213. const userId = quotationData.value.farmMiniUserId;
  214. const parmasPage = {
  215. farmWorkOrderId:quotationData.value.orderId,
  216. farmMiniUserId:userId,
  217. farmMiniUserName:quotationData.value.farmMiniUserName,
  218. farmId:quotationData.value.farmId,
  219. farmWorkName:quotationData.value.farmWorkName,
  220. id:quotationData.value.id,
  221. type:'quotation'
  222. }
  223. if(userId){
  224. router.push(`/chat_frame?userId=${userId}&farmId=${parmasPage.farmId}&pageParams=${JSON.stringify(parmasPage)}`);
  225. }else{
  226. ElMessage.warning('尚未绑定用户,暂时无法分享')
  227. }
  228. };
  229. const handleWechat = () => {
  230. if (!priceData.value?.id || !priceData.value?.itemsList || priceData.value?.itemsList?.length === 0) {
  231. ElMessage.warning('请补全报价数据')
  232. return;
  233. }
  234. // router.push({
  235. // path: "/completed_work",
  236. // query: { id: quotationData.value.id, farmWorkOrderId: quotationData.value.orderId, isAssign: true },
  237. // });
  238. const query = { askInfo: {title: "服务报价单", content: "是否分享该服务报价单给好友"}, shareText: "向您发送了一张 服务报价单", id: quotationData.value.id, farmWorkOrderId: quotationData.value.orderId, isAssign: true }
  239. wx.miniProgram.navigateTo({
  240. url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=priceSheet`,
  241. });
  242. };
  243. const handleSaveImage = async () => {
  244. try {
  245. if (!contentEl.value) return;
  246. const element = contentEl.value;
  247. const scroller = element.querySelector('.sheet-content');
  248. // 记录原样式
  249. const prev = {
  250. elementOverflow: element.style.overflow,
  251. elementMaxHeight: element.style.maxHeight,
  252. elementHeight: element.style.height,
  253. scrollerOverflow: scroller ? scroller.style.overflow : undefined,
  254. scrollerMaxHeight: scroller ? scroller.style.maxHeight : undefined,
  255. scrollerHeight: scroller ? scroller.style.height : undefined,
  256. };
  257. // 展开内容,去除滚动限制,确保截图包含全部内容
  258. element.style.overflow = 'visible';
  259. element.style.maxHeight = 'none';
  260. element.style.height = 'auto';
  261. if (scroller) {
  262. scroller.style.overflow = 'visible';
  263. scroller.style.maxHeight = 'none';
  264. scroller.style.height = 'auto';
  265. }
  266. // 计算完整尺寸
  267. const width = element.scrollWidth;
  268. const height = element.scrollHeight;
  269. const canvas = await html2canvas(element, {
  270. backgroundColor: '#ffffff',
  271. useCORS: true,
  272. allowTaint: true,
  273. scale: Math.min(2, window.devicePixelRatio || 2),
  274. width,
  275. height,
  276. windowWidth: width,
  277. windowHeight: height,
  278. scrollX: 0,
  279. scrollY: 0,
  280. });
  281. const dataUrl = canvas.toDataURL('image/png');
  282. const link = document.createElement('a');
  283. link.href = dataUrl;
  284. link.download = '服务报价单.png';
  285. document.body.appendChild(link);
  286. link.click();
  287. document.body.removeChild(link);
  288. // 还原样式
  289. element.style.overflow = prev.elementOverflow;
  290. element.style.maxHeight = prev.elementMaxHeight;
  291. element.style.height = prev.elementHeight;
  292. if (scroller) {
  293. scroller.style.overflow = prev.scrollerOverflow;
  294. scroller.style.maxHeight = prev.scrollerMaxHeight;
  295. scroller.style.height = prev.scrollerHeight;
  296. }
  297. } catch (e) {
  298. console.error('保存图片失败', e);
  299. }
  300. };
  301. const handleEdit = () => {
  302. // 编辑报价逻辑
  303. // 可以触发编辑事件或打开编辑页面
  304. router.push({
  305. path: "/price_detail",
  306. query: { data: JSON.stringify(quotationData.value), priceData: JSON.stringify(priceData.value) },
  307. });
  308. };
  309. // 清空数据
  310. const clearData = () => {
  311. // quotationData.value = {};
  312. // priceData.value = {};
  313. };
  314. // 监听弹窗关闭,清空数据
  315. // watch(showPopup, (newVal) => {
  316. // if (!newVal) {
  317. // clearData();
  318. // }
  319. // });
  320. const handleCancel = () => {
  321. showPopup.value = false;
  322. };
  323. defineExpose({
  324. handleShowPopup,
  325. });
  326. </script>
  327. <style lang="scss" scoped>
  328. .price-sheet-popup {
  329. z-index: 9999 !important;
  330. width: 90%;
  331. max-height: 90vh;
  332. background: none;
  333. border-radius: 12px;
  334. overflow: hidden;
  335. display: flex;
  336. flex-direction: column;
  337. backdrop-filter: 4px;
  338. ::v-deep {
  339. .van-popup__close-icon {
  340. color: #000;
  341. font-size: 18px;
  342. top: 12px;
  343. right: 12px;
  344. }
  345. }
  346. }
  347. .price-sheet-content {
  348. display: flex;
  349. flex-direction: column;
  350. max-height: 90vh;
  351. // height: 95vh;
  352. .price-sheet-content-inner {
  353. background: #fff;
  354. border-radius: 12px;
  355. display: flex;
  356. flex-direction: column;
  357. height: 100%;
  358. overflow: hidden;
  359. }
  360. }
  361. // 顶部标题区域
  362. .header-section {
  363. display: flex;
  364. justify-content: space-between;
  365. align-items: center;
  366. padding: 16px 10px 12px 16px;
  367. // background: linear-gradient(180deg, rgba(33, 153, 248, 0) 8%, rgba(139, 199, 252, 0.519) 94%, rgba(237, 241, 255, 1) 100%);
  368. background: linear-gradient(180deg, rgba(33, 153, 248, 0) 2%, rgba(139, 199, 252, 0.519) 50%, #c4e3fd);
  369. flex-shrink: 0;
  370. .header-left {
  371. flex: 1;
  372. .main-title {
  373. font-family: "PangMenZhengDao";
  374. font-size: 28px;
  375. color: #0387EF;
  376. }
  377. }
  378. .header-right {
  379. display: flex;
  380. flex-direction: column;
  381. align-items: center;
  382. margin-left: 16px;
  383. .qr-icon {
  384. color: #2199F8;
  385. margin-bottom: 4px;
  386. img {
  387. width: 40px;
  388. height: 40px;
  389. }
  390. }
  391. .qr-text {
  392. font-size: 12px;
  393. color: #171717;
  394. }
  395. }
  396. }
  397. .sheet-content {
  398. padding: 24px 16px 12px 16px;
  399. flex: 1;
  400. overflow-y: auto;
  401. overflow-x: hidden;
  402. position: relative;
  403. }
  404. // 报价详情区域
  405. .quotation-info {
  406. margin-bottom: 12px;
  407. .info-item {
  408. font-size: 16px;
  409. color: #000;
  410. margin-bottom: 8px;
  411. .info-label {
  412. padding-right: 8px;
  413. color: rgba(0, 0, 0, 0.5);
  414. }
  415. .info-value {
  416. color: #000;
  417. }
  418. &.catalog-label {
  419. font-weight: bold;
  420. margin-top: 10px;
  421. margin-bottom: 10px;
  422. position: relative;
  423. .info-label {
  424. color: #000;
  425. }
  426. }
  427. }
  428. .total-bar {
  429. display: flex;
  430. align-items: center;
  431. justify-content: center;
  432. background: rgba(33, 153, 248, 0.1);
  433. border: 1px solid rgba(33, 153, 248, 0.5);
  434. height: 38px;
  435. border-radius: 4px;
  436. .total-label {
  437. font-size: 14px;
  438. color: #000000;
  439. }
  440. .total-value {
  441. font-size: 22px;
  442. font-weight: bold;
  443. color: #2199F8;
  444. }
  445. .total-unit {
  446. font-size: 14px;
  447. color: #000;
  448. margin-left: 4px;
  449. }
  450. }
  451. }
  452. // 肥药费用区域
  453. .fertilizer-cost-section {
  454. margin-bottom: 10px;
  455. .section-header {
  456. display: flex;
  457. justify-content: space-between;
  458. align-items: center;
  459. margin-bottom: 8px;
  460. .section-title {
  461. font-size: 14px;
  462. color: #000;
  463. }
  464. .section-total {
  465. font-size: 16px;
  466. font-weight: bold;
  467. color: #000;
  468. .unit-text {
  469. padding-left: 2px;
  470. font-size: 12px;
  471. font-weight: normal;
  472. }
  473. }
  474. }
  475. .cost-table {
  476. border: 1px solid rgba(225, 225, 225, 0.5);
  477. border-radius: 5px;
  478. overflow: hidden;
  479. .table-header {
  480. display: flex;
  481. background: rgba(241, 241, 241, 0.4);
  482. padding: 8px 6px;
  483. font-size: 12px;
  484. color: #767676;
  485. border-bottom: 1px solid rgba(225, 225, 225, 0.5);
  486. .col-1 {
  487. width: 40px;
  488. text-align: center;
  489. }
  490. .col-2 {
  491. flex: 1;
  492. text-align: center;
  493. }
  494. .col-3 {
  495. width: 52px;
  496. text-align: center;
  497. }
  498. .col-4 {
  499. width: 56px;
  500. text-align: center;
  501. }
  502. .col-5 {
  503. width: 52px;
  504. text-align: center;
  505. }
  506. .col-6 {
  507. width: 52px;
  508. text-align: center;
  509. }
  510. }
  511. .table-row {
  512. display: flex;
  513. padding: 8px 6px;
  514. font-size: 11px;
  515. color: rgba(0, 0, 0, 0.6);
  516. background: #fff;
  517. border-bottom: 1px solid rgba(225, 225, 225, 0.3);
  518. &:last-child {
  519. border-bottom: none;
  520. }
  521. .col-1,
  522. .col-2,
  523. .col-3,
  524. .col-4,
  525. .col-5,
  526. .col-6 {
  527. display: flex;
  528. align-items: center;
  529. justify-content: center;
  530. }
  531. .col-1 {
  532. width: 40px;
  533. }
  534. .col-2 {
  535. flex: 1;
  536. }
  537. .col-3 {
  538. width: 52px;
  539. }
  540. .col-4 {
  541. width: 56px;
  542. }
  543. .col-5 {
  544. width: 52px;
  545. }
  546. .col-6 {
  547. width: 52px;
  548. }
  549. }
  550. }
  551. }
  552. // 服务费用区域
  553. .service-cost-section {
  554. position: relative;
  555. .section-header {
  556. display: flex;
  557. justify-content: space-between;
  558. align-items: center;
  559. margin-bottom: 12px;
  560. .section-title {
  561. font-size: 14px;
  562. color: #000;
  563. }
  564. .section-total {
  565. font-size: 16px;
  566. font-weight: bold;
  567. color: #000;
  568. .unit-text {
  569. padding-left: 2px;
  570. font-size: 12px;
  571. font-weight: normal;
  572. }
  573. }
  574. }
  575. .service-details {
  576. display: flex;
  577. align-items: center;
  578. border: 1px solid rgba(206, 206, 206, 0.5);
  579. padding: 8px 0;
  580. border-radius: 4px;
  581. margin-bottom: 10px;
  582. .detail-item {
  583. font-size: 14px;
  584. flex: 1;
  585. text-align: center;
  586. .detail-label {
  587. color: rgba(0, 0, 0, 0.2);
  588. margin-top: 6px;
  589. }
  590. .detail-value {
  591. color: rgba(0, 0, 0, 0.8);
  592. }
  593. }
  594. .detail-item + .detail-item {
  595. position: relative;
  596. &::before {
  597. content: '';
  598. position: absolute;
  599. left: 0;
  600. top: 50%;
  601. transform: translateY(-50%);
  602. width: 1px;
  603. height: 20px;
  604. background: rgba(0, 0, 0, 0.1);
  605. }
  606. }
  607. }
  608. }
  609. .edit-btn-box {
  610. display: flex;
  611. justify-content: end;
  612. position: absolute;
  613. right: 0;
  614. top: -8px;
  615. z-index: 10;
  616. }
  617. .edit-btn {
  618. background: rgba(33, 153, 248, 0.1);
  619. color: #2199F8;
  620. padding: 6px 16px;
  621. border-radius: 20px;
  622. font-size: 14px;
  623. width: fit-content;
  624. cursor: pointer;
  625. }
  626. // 底部操作按钮
  627. .bottom-actions {
  628. flex-shrink: 0;
  629. .action-buttons {
  630. padding: 16px;
  631. display: flex;
  632. justify-content: space-around;
  633. .action-btn {
  634. display: flex;
  635. flex-direction: column;
  636. align-items: center;
  637. cursor: pointer;
  638. .icon-circle {
  639. width: 48px;
  640. height: 48px;
  641. border-radius: 50%;
  642. display: flex;
  643. align-items: center;
  644. justify-content: center;
  645. color: #fff;
  646. margin-bottom: 4px;
  647. .el-icon {
  648. color: #fff;
  649. }
  650. img {
  651. width: 50px;
  652. }
  653. }
  654. &.blue-btn .icon-circle {
  655. background: #2199F8;
  656. }
  657. &.green-btn .icon-circle {
  658. background: #07C160;
  659. }
  660. &.orange-btn .icon-circle {
  661. background: #FF790B;
  662. }
  663. .btn-label {
  664. font-size: 12px;
  665. color: #fff;
  666. }
  667. }
  668. }
  669. .cancel-btn {
  670. text-align: center;
  671. font-size: 18px;
  672. color: #fff;
  673. cursor: pointer;
  674. }
  675. }
  676. </style>