priceTable.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div class="farm-table">
  3. <div class="new-wrap" v-if="(isArrList && prescriptionData?.length) || prescriptionData?.pesticideFertilizerList?.length">
  4. <div class="new-title">
  5. <div class="title-2"><div class="table-name">药肥名称</div></div>
  6. <div class="title-3"><div class="table-name">药肥品牌</div></div>
  7. <div class="title-4"><div class="table-name">药肥单价</div></div>
  8. <div class="title-5"><div class="table-name">单亩用量</div></div>
  9. <div class="title-6" v-if="area"><div class="table-name">总价</div></div>
  10. </div>
  11. <template v-if="isArrList && prescriptionData?.length">
  12. <div
  13. class="new-table-wrap"
  14. v-for="(prescriptionItem, prescriptionI) in prescriptionData || []"
  15. :key="prescriptionI"
  16. >
  17. <div
  18. class="new-prescription"
  19. v-for="(subP, subI) in prescriptionItem?.pesticideFertilizerList || []"
  20. :key="subI"
  21. >
  22. <div class="new-table">
  23. <div class="line-l">
  24. <div class="line-2">{{ subP.defaultName || subP.pesticideFertilizerName }}</div>
  25. <div class="title-3">{{ subP.brand }}</div>
  26. <div class="title-4">{{ subP.price }}</div>
  27. <div class="title-5">{{ subP.dosage }}</div>
  28. <div class="title-6" v-if="area">¥{{ subP.total }}</div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <template v-else-if="prescriptionData?.pesticideFertilizerList?.length">
  35. <div
  36. class="new-prescription"
  37. v-for="(subP, subI) in prescriptionData?.pesticideFertilizerList || []"
  38. :key="subI"
  39. >
  40. <div class="new-table">
  41. <div class="line-l">
  42. <div class="line-2">{{ subP.name || subP.defaultName || subP.pesticideFertilizerName }}</div>
  43. <div class="title-3">{{ subP.brand ? subP.brand : '--' }}</div>
  44. <div class="title-4">{{ subP.price ? (subP.price + '元/' + subP.unit) : '--' }}</div>
  45. <div class="title-5">{{ subP.dosage ? (subP.dosage + subP.unit) : '--' }}</div>
  46. <div class="title-6" v-if="area">¥{{ getTotal(subP) }}</div>
  47. </div>
  48. </div>
  49. </div>
  50. </template>
  51. </div>
  52. <slot name="bottomContent"></slot>
  53. </div>
  54. </template>
  55. <script setup>
  56. const props = defineProps({
  57. prescriptionData: {
  58. default: () => ({}),
  59. },
  60. // 面积(亩数),用于计算总价:单价 * 用量 * 面积
  61. area: {
  62. type: [Number, String],
  63. default: null,
  64. },
  65. isArrList: {
  66. type: Boolean,
  67. default: false,
  68. },
  69. });
  70. // 计算单个药肥的总价:单价 * 用量 * 面积
  71. const getTotal = (item) => {
  72. const price = Number(item?.price ?? 0);
  73. const dosage = Number(item?.dosage ?? 0);
  74. const area = props.area != null ? Number(props.area) : Number(item?.area ?? 0);
  75. // 如果有现成的 total 字段且无法计算,则退回使用 total
  76. if (!price || !dosage || !area) {
  77. return item?.total ?? "--";
  78. }
  79. return (price * dosage * area).toFixed(2);
  80. };
  81. </script>
  82. <style lang="scss" scoped>
  83. .box-wrap {
  84. background: #fff;
  85. padding: 10px;
  86. border-radius: 8px;
  87. }
  88. .card-title {
  89. font-size: 16px;
  90. font-weight: bold;
  91. color: #000;
  92. display: flex;
  93. align-items: center;
  94. .type-tag {
  95. margin-left: 5px;
  96. font-size: 12px;
  97. color: #000000;
  98. padding: 0 10px;
  99. background: rgba(119, 119, 119, 0.1);
  100. border-radius: 20px;
  101. font-weight: normal;
  102. height: 26px;
  103. line-height: 26px;
  104. }
  105. }
  106. .farm-table {
  107. .table-item {
  108. padding: 10px 0 12px 0;
  109. }
  110. .form-item {
  111. display: flex;
  112. align-items: center;
  113. font-size: 14px;
  114. color: #767676;
  115. height: 24px;
  116. .item-name {
  117. width: 80px;
  118. color: rgba(0, 0, 0, 0.2);
  119. }
  120. }
  121. }
  122. .new-wrap {
  123. border-radius: 5px;
  124. text-align: center;
  125. border: 1px solid rgba(225, 225, 225, 0.5);
  126. .new-title {
  127. background: rgba(241, 241, 241, 0.4);
  128. border-radius: 5px 5px 0 0;
  129. border-bottom: 1px solid rgba(225, 225, 225, 0.5);
  130. display: flex;
  131. color: #767676;
  132. // justify-content: space-around;
  133. padding: 3px 0px;
  134. font-size: 12px;
  135. .table-name {
  136. width: 24px;
  137. font-size: 12px;
  138. margin: 0 auto;
  139. }
  140. }
  141. .title-1 {
  142. width: 40px;
  143. }
  144. .title-2 {
  145. flex: 1;
  146. }
  147. .title-3 {
  148. width: 52px;
  149. }
  150. .title-4 {
  151. width: 66px;
  152. }
  153. .title-5 {
  154. width: 52px;
  155. }
  156. .title-6 {
  157. width: 52px;
  158. }
  159. .new-table-wrap {
  160. padding: 5px;
  161. }
  162. .new-prescription {
  163. .new-table {
  164. display: flex;
  165. align-items: center;
  166. background: #fff;
  167. border-radius: 5px;
  168. color: rgba(0, 0, 0, 0.6);
  169. font-size: 11px;
  170. min-height: 45px;
  171. .line-l {
  172. display: flex;
  173. align-items: center;
  174. flex: 1;
  175. .line-2 {
  176. flex: 1;
  177. padding: 0 2px;
  178. }
  179. }
  180. .line-r {
  181. &.has-border {
  182. border-left: 1px solid rgba(225, 225, 225, 0.8);
  183. }
  184. .line-3 {
  185. display: flex;
  186. align-items: center;
  187. }
  188. .sub-line {
  189. padding: 10px 0;
  190. }
  191. .line-4 {
  192. display: flex;
  193. align-items: center;
  194. border-top: 1px solid rgba(225, 225, 225, 0.8);
  195. }
  196. .execute-line {
  197. border-right: 1px solid rgba(225, 225, 225, 0.8);
  198. }
  199. }
  200. }
  201. .note-text {
  202. margin: 8px 0 4px 0;
  203. color: rgba(0, 0, 0, 0.4);
  204. background: #fff;
  205. padding: 6px 8px;
  206. border-radius: 5px;
  207. text-align: left;
  208. font-size: 11px;
  209. }
  210. }
  211. .new-prescription + .new-prescription {
  212. // padding-top: 8px;
  213. .new-table {
  214. border-top: 1px solid rgba(0, 0, 0, 0.08);
  215. }
  216. }
  217. .new-table-wrap + .new-table-wrap {
  218. border-top: 1px solid rgba(0, 0, 0, 0.08);
  219. }
  220. }
  221. </style>