FootprintReportDialog.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <el-dialog :visible.sync="visible" width="550px" :title="'Carbon Footprint Report'" :before-close="handleClose" :lock-scroll="false">
  3. <div>
  4. <el-form label-width="70px">
  5. <el-form-item label="Model">
  6. <el-select v-model="form.model" placeholder="Please select" style="width:100%;" clearable filterable>
  7. <el-option
  8. :label="item.accountName.replace(/\s*[\(\(][^)\)]*[\)\)]$/, '')"
  9. v-for="(item, idx) in carbon"
  10. :value="idx"
  11. :key="idx"
  12. />
  13. </el-select>
  14. </el-form-item>
  15. <div class="form-row">
  16. <el-form-item label="Quantity" style="flex:1;">
  17. <el-input v-model="form.quantity" type="number" :min="1" :step="1" :controls="false"
  18. placeholder="Please input" class="left-input-number" />
  19. </el-form-item>
  20. <el-form-item label="Transport" style="flex:1;margin-left:10px;">
  21. <el-select v-model="form.transport" placeholder="Please select" style="width:100%;" clearable>
  22. <el-option label="AU-Sea" value="AU-Sea" />
  23. <el-option label="AU-Air" value="AU-Air" />
  24. </el-select>
  25. </el-form-item>
  26. </div>
  27. </el-form>
  28. <div class="carbon-report-card">
  29. <div class="carbon-report-main">
  30. <div class="carbon-report-header">
  31. <span>Product Carbon Footprint</span>
  32. </div>
  33. <div class="carbon-report-value">{{ comEmissionTotal }}</div>
  34. <div class="carbon-report-date">kgCO₂e per product unit</div>
  35. <div class="carbon-report-date">Accounting Period:{{ this.carbon[this.form.model]?.accountTime }}</div>
  36. <img src="@/assets/img/esg/bg_city.png" alt="bg" class="carbon-bg" />
  37. <div class="carbon-report-equal">
  38. <div class="equal-title">Equivalent to</div>
  39. <div class="equal-list">
  40. <div class="equal-item">
  41. <img src="@/assets/img/esg/tree.png" alt="tree" />
  42. <div>{{ multiply(comEquallist.equallist[0]?.amount, form.quantity) || 0 }} <span>tree</span></div>
  43. <div class="equal-desc">CO₂ uptake by 1 ammodendron tree</div>
  44. </div>
  45. <div class="equal-item">
  46. <img src="@/assets/img/esg/electricity.png" alt="electricity" />
  47. <div>{{ multiply(comEquallist.equallist[1]?.amount, form.quantity) || 0 }} <span>kWh</span></div>
  48. <div class="equal-desc">Household electricity consumption</div>
  49. </div>
  50. <div class="equal-item">
  51. <img src="@/assets/img/esg/iphone.png" alt="iphone" />
  52. <div>{{ multiply(comEquallist.equallist[2]?.amount, form.quantity) || 0 }} <span>day</span></div>
  53. <div class="equal-desc">The number of days an iPhone is used</div>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. <div style="text-align:right;margin-top:20px;">
  60. <el-button type="primary" class="report-btn"
  61. @click="download(comEquallist?.url)">Download</el-button>
  62. </div>
  63. </div>
  64. </el-dialog>
  65. </template>
  66. <script>
  67. import { times as npTimes } from 'number-precision';
  68. export default {
  69. props: {
  70. visible: { type: Boolean, default: false },
  71. carbon: { type: Array, default: () => [] }
  72. },
  73. data() {
  74. return {
  75. form: {
  76. model: '',
  77. quantity: 1,
  78. transport: ''
  79. }
  80. }
  81. },
  82. computed: {
  83. comEquallist() {
  84. return this.carbon[this.form.model]?.accountlist?.find(item => item.code === this.form.transport) || { equallist: [], emissionTotal: 0 };
  85. },
  86. comEmissionTotal() {
  87. return this.multiply(this.comEquallist.emissionTotal, this.form.quantity).toFixed(2) || 0;
  88. }
  89. },
  90. methods: {
  91. handleClose() {
  92. this.$emit('update:visible', false);
  93. },
  94. multiply(a, b) {
  95. return npTimes(Number(a), b);
  96. },
  97. download(url) {
  98. if (!url) {
  99. this.$message.error('No report available for download');
  100. return
  101. }
  102. var urlStr = url.match('[^/]+(?!.*/)')[0]
  103. this.$utils.downloadBlob(url, urlStr)
  104. },
  105. },
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. $green: #006D28;
  110. $blue-dark: #15395A;
  111. $white: #fff;
  112. $gray: #666;
  113. $radius-lg: 16px;
  114. $shadow-green: 0 2px 8px rgba($green, 0.08);
  115. :deep(.el-dialog__header) {
  116. padding: 20px;
  117. border-bottom: 1px solid #eee;
  118. }
  119. .form-row {
  120. display: flex;
  121. gap: 10px;
  122. }
  123. .carbon-report-card {
  124. background: transparent;
  125. .carbon-report-main {
  126. background: $green;
  127. border-radius: 10px;
  128. color: $white;
  129. padding: 18px;
  130. position: relative;
  131. overflow: hidden;
  132. min-height: 120px;
  133. .carbon-report-header {
  134. font-size: 20px;
  135. font-weight: bold;
  136. margin-bottom: 8px;
  137. }
  138. .carbon-report-value {
  139. font-size: 32px;
  140. font-weight: bold;
  141. .unit {
  142. font-size: 18px;
  143. font-weight: normal;
  144. }
  145. }
  146. .carbon-report-date {
  147. font-size: 14px;
  148. margin-bottom: 10px;
  149. }
  150. }
  151. .carbon-bg {
  152. position: absolute;
  153. right: 20PX;
  154. top: 20PX;
  155. width: 232px;
  156. height: 126px;
  157. opacity: 0.7;
  158. pointer-events: none;
  159. }
  160. .carbon-report-equal {
  161. background: $white;
  162. color: $green;
  163. border-radius: 10px;
  164. padding: 18px;
  165. position: relative;
  166. z-index: 2;
  167. box-shadow: $shadow-green;
  168. .equal-title {
  169. font-size: 14px;
  170. font-weight: 600;
  171. margin-bottom: 8px;
  172. color: #000;
  173. }
  174. .equal-list {
  175. display: flex;
  176. justify-content: space-around;
  177. align-items: flex-start;
  178. margin-top: 20px;
  179. .equal-item {
  180. text-align: center;
  181. width: 130px;
  182. img {
  183. width: 32px;
  184. height: 32px;
  185. margin-bottom: 4px;
  186. }
  187. div {
  188. &:nth-child(2) {
  189. font-size: 14px;
  190. font-weight: 600;
  191. color: #000;
  192. }
  193. }
  194. .equal-desc {
  195. font-size: 12px;
  196. color: $gray;
  197. margin-top: 2px;
  198. word-break: break-word;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. .report-btn {
  205. background: $blue-dark !important;
  206. border: none !important;
  207. height: 40px;
  208. font-size: 16px;
  209. font-weight: 500;
  210. }
  211. :deep(.el-input__inner) {
  212. padding-right: 0;
  213. }
  214. </style>