priceSheetPopup.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. <template>
  2. <popup class="price-sheet-popup" v-model:show="showPopup">
  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">
  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 || '--' }}</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. fetchPriceData()
  139. })
  140. // 处理后的处方列表(展平并匹配价格)
  141. const processedPrescriptionList = computed(() => {
  142. if (!quotationData.value?.prescriptionList || !Array.isArray(quotationData.value.prescriptionList)) {
  143. return [];
  144. }
  145. // 创建价格映射表,方便快速查找
  146. const priceMap = new Map();
  147. console.log('priceData.value',priceData.value )
  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 = item.muUsage || 0;
  164. const unit = item.unit || '';
  165. result.push({
  166. typeName: item.typeName || '--',
  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. function fetchPriceData() {
  195. if (!quotationData.value?.id) {
  196. return;
  197. }
  198. VE_API.z_farm_work_record_cost.getByRecordId({ farmWorkRecordId: quotationData.value.id }).then(({ data }) => {
  199. priceData.value = data;
  200. }).catch(() => {
  201. // 获取价格数据失败
  202. });
  203. }
  204. const handleShare = () => {
  205. if (!priceData.value?.id || !priceData.value?.itemsList || priceData.value?.itemsList?.length === 0) {
  206. ElMessage.warning('请补全报价数据')
  207. return;
  208. }
  209. const userId = quotationData.value.users[0]?.userId;
  210. const parmasPage = {
  211. farmWorkOrderId:quotationData.value.orderId,
  212. farmMiniUserId:userId,
  213. farmMiniUserName:quotationData.value.expertUserName,
  214. farmId:quotationData.value.farmId,
  215. farmWorkName:quotationData.value.farmWorkName,
  216. id:quotationData.value.id,
  217. type:'quotation'
  218. }
  219. if(userId){
  220. router.push(`/chat_frame?userId=${userId}&name=${parmasPage.farmMiniUserName}&farmId=${parmasPage.farmId}&pageParams=${JSON.stringify(parmasPage)}`);
  221. }else{
  222. ElMessage.warning('尚未绑定用户,暂时无法分享')
  223. }
  224. };
  225. const handleWechat = () => {
  226. console.log("handleWechat", quotationData.value, priceData.value);
  227. if (!priceData.value?.id || !priceData.value?.itemsList || priceData.value?.itemsList?.length === 0) {
  228. ElMessage.warning('请补全报价数据')
  229. return;
  230. }
  231. // router.push({
  232. // path: "/completed_work",
  233. // query: { id: quotationData.value.id, farmWorkOrderId: quotationData.value.orderId, isAssign: true },
  234. // });
  235. const query = { askInfo: {title: "服务报价单", content: "是否分享该服务报价单给好友"}, shareText: "向您发送了一张 服务报价单", id: quotationData.value.id, farmWorkOrderId: quotationData.value.orderId, isAssign: true }
  236. wx.miniProgram.navigateTo({
  237. url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=priceSheet`,
  238. });
  239. };
  240. const handleSaveImage = async () => {
  241. try {
  242. if (!contentEl.value) return;
  243. const element = contentEl.value;
  244. const scroller = element.querySelector('.sheet-content');
  245. // 记录原样式
  246. const prev = {
  247. elementOverflow: element.style.overflow,
  248. elementMaxHeight: element.style.maxHeight,
  249. elementHeight: element.style.height,
  250. scrollerOverflow: scroller ? scroller.style.overflow : undefined,
  251. scrollerMaxHeight: scroller ? scroller.style.maxHeight : undefined,
  252. scrollerHeight: scroller ? scroller.style.height : undefined,
  253. };
  254. // 展开内容,去除滚动限制,确保截图包含全部内容
  255. element.style.overflow = 'visible';
  256. element.style.maxHeight = 'none';
  257. element.style.height = 'auto';
  258. if (scroller) {
  259. scroller.style.overflow = 'visible';
  260. scroller.style.maxHeight = 'none';
  261. scroller.style.height = 'auto';
  262. }
  263. // 计算完整尺寸
  264. const width = element.scrollWidth;
  265. const height = element.scrollHeight;
  266. const canvas = await html2canvas(element, {
  267. backgroundColor: '#ffffff',
  268. useCORS: true,
  269. allowTaint: true,
  270. scale: Math.min(2, window.devicePixelRatio || 2),
  271. width,
  272. height,
  273. windowWidth: width,
  274. windowHeight: height,
  275. scrollX: 0,
  276. scrollY: 0,
  277. });
  278. const dataUrl = canvas.toDataURL('image/png');
  279. const link = document.createElement('a');
  280. link.href = dataUrl;
  281. link.download = '服务报价单.png';
  282. document.body.appendChild(link);
  283. link.click();
  284. document.body.removeChild(link);
  285. // 还原样式
  286. element.style.overflow = prev.elementOverflow;
  287. element.style.maxHeight = prev.elementMaxHeight;
  288. element.style.height = prev.elementHeight;
  289. if (scroller) {
  290. scroller.style.overflow = prev.scrollerOverflow;
  291. scroller.style.maxHeight = prev.scrollerMaxHeight;
  292. scroller.style.height = prev.scrollerHeight;
  293. }
  294. } catch (e) {
  295. console.error('保存图片失败', e);
  296. }
  297. };
  298. const handleEdit = () => {
  299. // 编辑报价逻辑
  300. // 可以触发编辑事件或打开编辑页面
  301. router.push({
  302. path: "/price_detail",
  303. query: { data: JSON.stringify(quotationData.value), priceData: JSON.stringify(priceData.value) },
  304. });
  305. };
  306. // 清空数据
  307. const clearData = () => {
  308. quotationData.value = {};
  309. priceData.value = {};
  310. };
  311. // 监听弹窗关闭,清空数据
  312. watch(showPopup, (newVal) => {
  313. if (!newVal) {
  314. clearData();
  315. }
  316. });
  317. const handleCancel = () => {
  318. showPopup.value = false;
  319. };
  320. defineExpose({
  321. handleShowPopup,
  322. });
  323. </script>
  324. <style lang="scss" scoped>
  325. .price-sheet-popup {
  326. width: 90%;
  327. max-height: 82vh;
  328. background: none;
  329. border-radius: 12px;
  330. overflow: hidden;
  331. display: flex;
  332. flex-direction: column;
  333. backdrop-filter: 4px;
  334. ::v-deep {
  335. .van-popup__close-icon {
  336. color: #000;
  337. font-size: 18px;
  338. top: 12px;
  339. right: 12px;
  340. }
  341. }
  342. }
  343. .price-sheet-content {
  344. display: flex;
  345. flex-direction: column;
  346. max-height: 82vh;
  347. // height: 95vh;
  348. .price-sheet-content-inner {
  349. background: #fff;
  350. border-radius: 12px;
  351. display: flex;
  352. flex-direction: column;
  353. height: 100%;
  354. overflow: hidden;
  355. }
  356. }
  357. // 顶部标题区域
  358. .header-section {
  359. display: flex;
  360. justify-content: space-between;
  361. align-items: center;
  362. padding: 16px 10px 12px 16px;
  363. // background: linear-gradient(180deg, rgba(33, 153, 248, 0) 8%, rgba(139, 199, 252, 0.519) 94%, rgba(237, 241, 255, 1) 100%);
  364. background: linear-gradient(180deg, rgba(33, 153, 248, 0) 2%, rgba(139, 199, 252, 0.519) 50%, #c4e3fd);
  365. flex-shrink: 0;
  366. .header-left {
  367. flex: 1;
  368. .main-title {
  369. font-family: "PangMenZhengDao";
  370. font-size: 28px;
  371. color: #0387EF;
  372. }
  373. }
  374. .header-right {
  375. display: flex;
  376. flex-direction: column;
  377. align-items: center;
  378. margin-left: 16px;
  379. .qr-icon {
  380. color: #2199F8;
  381. margin-bottom: 4px;
  382. img {
  383. width: 40px;
  384. height: 40px;
  385. }
  386. }
  387. .qr-text {
  388. font-size: 12px;
  389. color: #171717;
  390. }
  391. }
  392. }
  393. .sheet-content {
  394. padding: 24px 16px 12px 16px;
  395. flex: 1;
  396. overflow-y: auto;
  397. overflow-x: hidden;
  398. position: relative;
  399. }
  400. // 报价详情区域
  401. .quotation-info {
  402. margin-bottom: 12px;
  403. .info-item {
  404. font-size: 16px;
  405. color: #000;
  406. margin-bottom: 8px;
  407. .info-label {
  408. padding-right: 8px;
  409. color: rgba(0, 0, 0, 0.5);
  410. }
  411. .info-value {
  412. color: #000;
  413. }
  414. &.catalog-label {
  415. font-weight: bold;
  416. margin-top: 10px;
  417. margin-bottom: 10px;
  418. position: relative;
  419. .info-label {
  420. color: #000;
  421. }
  422. }
  423. }
  424. .total-bar {
  425. display: flex;
  426. align-items: center;
  427. justify-content: center;
  428. background: rgba(33, 153, 248, 0.1);
  429. border: 1px solid rgba(33, 153, 248, 0.5);
  430. height: 38px;
  431. border-radius: 4px;
  432. .total-label {
  433. font-size: 14px;
  434. color: #000000;
  435. }
  436. .total-value {
  437. font-size: 22px;
  438. font-weight: bold;
  439. color: #2199F8;
  440. }
  441. .total-unit {
  442. font-size: 14px;
  443. color: #000;
  444. margin-left: 4px;
  445. }
  446. }
  447. }
  448. // 肥药费用区域
  449. .fertilizer-cost-section {
  450. margin-bottom: 10px;
  451. .section-header {
  452. display: flex;
  453. justify-content: space-between;
  454. align-items: center;
  455. margin-bottom: 8px;
  456. .section-title {
  457. font-size: 14px;
  458. color: #000;
  459. }
  460. .section-total {
  461. font-size: 16px;
  462. font-weight: bold;
  463. color: #000;
  464. .unit-text {
  465. padding-left: 2px;
  466. font-size: 12px;
  467. font-weight: normal;
  468. }
  469. }
  470. }
  471. .cost-table {
  472. border: 1px solid rgba(225, 225, 225, 0.5);
  473. border-radius: 5px;
  474. overflow: hidden;
  475. .table-header {
  476. display: flex;
  477. background: rgba(241, 241, 241, 0.4);
  478. padding: 8px 6px;
  479. font-size: 12px;
  480. color: #767676;
  481. border-bottom: 1px solid rgba(225, 225, 225, 0.5);
  482. .col-1 {
  483. width: 40px;
  484. text-align: center;
  485. }
  486. .col-2 {
  487. flex: 1;
  488. text-align: center;
  489. }
  490. .col-3 {
  491. width: 52px;
  492. text-align: center;
  493. }
  494. .col-4 {
  495. width: 56px;
  496. text-align: center;
  497. }
  498. .col-5 {
  499. width: 52px;
  500. text-align: center;
  501. }
  502. .col-6 {
  503. width: 52px;
  504. text-align: center;
  505. }
  506. }
  507. .table-row {
  508. display: flex;
  509. padding: 8px 6px;
  510. font-size: 11px;
  511. color: rgba(0, 0, 0, 0.6);
  512. background: #fff;
  513. border-bottom: 1px solid rgba(225, 225, 225, 0.3);
  514. &:last-child {
  515. border-bottom: none;
  516. }
  517. .col-1,
  518. .col-2,
  519. .col-3,
  520. .col-4,
  521. .col-5,
  522. .col-6 {
  523. display: flex;
  524. align-items: center;
  525. justify-content: center;
  526. }
  527. .col-1 {
  528. width: 40px;
  529. }
  530. .col-2 {
  531. flex: 1;
  532. }
  533. .col-3 {
  534. width: 52px;
  535. }
  536. .col-4 {
  537. width: 56px;
  538. }
  539. .col-5 {
  540. width: 52px;
  541. }
  542. .col-6 {
  543. width: 52px;
  544. }
  545. }
  546. }
  547. }
  548. // 服务费用区域
  549. .service-cost-section {
  550. position: relative;
  551. .section-header {
  552. display: flex;
  553. justify-content: space-between;
  554. align-items: center;
  555. margin-bottom: 12px;
  556. .section-title {
  557. font-size: 14px;
  558. color: #000;
  559. }
  560. .section-total {
  561. font-size: 16px;
  562. font-weight: bold;
  563. color: #000;
  564. .unit-text {
  565. padding-left: 2px;
  566. font-size: 12px;
  567. font-weight: normal;
  568. }
  569. }
  570. }
  571. .service-details {
  572. display: flex;
  573. align-items: center;
  574. border: 1px solid rgba(206, 206, 206, 0.5);
  575. padding: 8px 0;
  576. border-radius: 4px;
  577. margin-bottom: 10px;
  578. .detail-item {
  579. font-size: 14px;
  580. flex: 1;
  581. text-align: center;
  582. .detail-label {
  583. color: rgba(0, 0, 0, 0.2);
  584. margin-top: 6px;
  585. }
  586. .detail-value {
  587. color: rgba(0, 0, 0, 0.8);
  588. }
  589. }
  590. .detail-item + .detail-item {
  591. position: relative;
  592. &::before {
  593. content: '';
  594. position: absolute;
  595. left: 0;
  596. top: 50%;
  597. transform: translateY(-50%);
  598. width: 1px;
  599. height: 20px;
  600. background: rgba(0, 0, 0, 0.1);
  601. }
  602. }
  603. }
  604. }
  605. .edit-btn-box {
  606. display: flex;
  607. justify-content: end;
  608. position: absolute;
  609. right: 0;
  610. top: -8px;
  611. z-index: 10;
  612. }
  613. .edit-btn {
  614. background: rgba(33, 153, 248, 0.1);
  615. color: #2199F8;
  616. padding: 6px 16px;
  617. border-radius: 20px;
  618. font-size: 14px;
  619. width: fit-content;
  620. cursor: pointer;
  621. }
  622. // 底部操作按钮
  623. .bottom-actions {
  624. flex-shrink: 0;
  625. .action-buttons {
  626. padding: 16px;
  627. display: flex;
  628. justify-content: space-around;
  629. .action-btn {
  630. display: flex;
  631. flex-direction: column;
  632. align-items: center;
  633. cursor: pointer;
  634. .icon-circle {
  635. width: 48px;
  636. height: 48px;
  637. border-radius: 50%;
  638. display: flex;
  639. align-items: center;
  640. justify-content: center;
  641. color: #fff;
  642. margin-bottom: 4px;
  643. .el-icon {
  644. color: #fff;
  645. }
  646. img {
  647. width: 50px;
  648. }
  649. }
  650. &.blue-btn .icon-circle {
  651. background: #2199F8;
  652. }
  653. &.green-btn .icon-circle {
  654. background: #07C160;
  655. }
  656. &.orange-btn .icon-circle {
  657. background: #FF790B;
  658. }
  659. .btn-label {
  660. font-size: 12px;
  661. color: #fff;
  662. }
  663. }
  664. }
  665. .cancel-btn {
  666. text-align: center;
  667. font-size: 18px;
  668. color: #fff;
  669. cursor: pointer;
  670. }
  671. }
  672. </style>