recordindex.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <a-card>
  3. <a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
  4. <a-row :gutter="24">
  5. <a-col :span="6">
  6. <a-form-item label="日期" name="times">
  7. <a-range-picker
  8. v-model:value="searchFormState.times"
  9. :disabled-date="disabledDate"
  10. format="YYYY-MM-DD"
  11. @change="onChange"
  12. @openChange="onOpenChange"
  13. @calendarChange="onCalendarChange"
  14. />
  15. </a-form-item>
  16. </a-col>
  17. <a-col :span="6">
  18. <a-form-item label="车牌号" name="licensePlate">
  19. <a-input v-model:value="searchFormState.licensePlate" placeholder="请输入车牌号" />
  20. </a-form-item>
  21. </a-col>
  22. <a-col :span="6">
  23. <a-form-item label="货品" name="goodsName">
  24. <a-input v-model:value="searchFormState.goodsName" placeholder="请输入货品" />
  25. </a-form-item>
  26. </a-col>
  27. <!-- <a-col :span="6" v-show="advanced">
  28. <a-form-item label="客户名称" name="receiptCompany">
  29. <a-input v-model:value="searchFormState.receiptCompany" placeholder="请输入客户名称" />
  30. </a-form-item>
  31. </a-col>-->
  32. <!-- <a-col :span="6" v-show="advanced">
  33. <a-form-item label="发货单位" name="shippingCompany">
  34. <a-input v-model:value="searchFormState.shippingCompany" placeholder="请输入发货单位" />
  35. </a-form-item>
  36. </a-col>
  37. <a-col :span="6" v-show="advanced">
  38. <a-form-item label="运输单位" name="transportCompany">
  39. <a-input v-model:value="searchFormState.transportCompany" placeholder="请输入运输单位" />
  40. </a-form-item>
  41. </a-col>-->
  42. <a-col :span="6">
  43. <a-button type="primary" @click="query()">查询</a-button>
  44. <a-button style="margin: 0 8px" @click="reset">重置</a-button>
  45. <!-- <a @click="toggleAdvanced" style="margin-left: 8px">
  46. {{ advanced ? '收起' : '展开' }}
  47. <component :is="advanced ? 'up-outlined' : 'down-outlined'" />
  48. </a>-->
  49. </a-col>
  50. </a-row>
  51. </a-form>
  52. </a-card>
  53. <div style="margin-top: 5px">
  54. <a-row :gutter="24">
  55. <a-col :span="6">
  56. <a-card>
  57. <a-statistic title="总车次" :value="totalCar" />
  58. </a-card>
  59. </a-col>
  60. <a-col :span="6">
  61. <a-card>
  62. <a-statistic title="总毛重" :value="totalGrossWeight">
  63. <template #suffix>
  64. <span>吨</span>
  65. </template>
  66. </a-statistic>
  67. </a-card>
  68. </a-col>
  69. <a-col :span="6">
  70. <a-card>
  71. <a-statistic title="总皮重" :value="totalTareWeight">
  72. <template #suffix>
  73. <span>吨</span>
  74. </template>
  75. </a-statistic>
  76. </a-card>
  77. </a-col>
  78. <a-col :span="6">
  79. <a-card>
  80. <a-statistic title="总净重" :value="totalNetWeight">
  81. <template #suffix>
  82. <span>吨</span>
  83. </template>
  84. </a-statistic>
  85. </a-card>
  86. </a-col>
  87. </a-row>
  88. </div>
  89. <div style="margin-top: 5px">
  90. <a-card title="近七日过磅统计" :bordered="false">
  91. <div id="SevenDays"></div>
  92. </a-card>
  93. </div>
  94. </template>
  95. <script setup name="recordcount">
  96. import { ref } from 'vue'
  97. import { onMounted } from 'vue'
  98. import { Column } from '@antv/g2plot'
  99. import bizRecordApi from '@/api/biz/bizRecordApi'
  100. import {cloneDeep} from "lodash-es";
  101. const searchFormState = ref({
  102. times: [],
  103. licensePlate: '',
  104. goodsName: '',
  105. receiptCompany: '',
  106. shippingCompany: '',
  107. transportCompany: ''
  108. })
  109. const totalCar = ref(0)
  110. const totalGrossWeight = ref(0)
  111. const totalNetWeight = ref(0)
  112. const totalTareWeight = ref(0)
  113. const searchFormRef = ref()
  114. // 查询区域显示更多控制
  115. const advanced = ref(false)
  116. const toggleAdvanced = () => {
  117. advanced.value = !advanced.value
  118. }
  119. // 统计
  120. const sevenData = ref([])
  121. const loading = ref(true)
  122. let stackedColumnPlot = null // 声明图表实例
  123. onMounted(() => {
  124. loadData()
  125. })
  126. //日期选择
  127. const dates = ref()
  128. const value = ref()
  129. const hackValue = ref()
  130. const disabledDate = (current) => {
  131. if (!dates.value || dates.value.length === 0) {
  132. return false
  133. }
  134. const tooLate = dates.value[0] && current.diff(dates.value[0], 'days') > 7
  135. const tooEarly = dates.value[1] && dates.value[1].diff(current, 'days') > 7
  136. return tooEarly || tooLate
  137. }
  138. const onOpenChange = (open) => {
  139. if (open) {
  140. dates.value = []
  141. hackValue.value = []
  142. } else {
  143. hackValue.value = undefined
  144. }
  145. }
  146. const onChange = (val) => {
  147. console.log(val)
  148. value.value = val
  149. }
  150. const onCalendarChange = (val) => {
  151. dates.value = val
  152. }
  153. // 重置
  154. const reset = () => {
  155. searchFormRef.value.resetFields()
  156. searchFormState.value.startDay = null
  157. searchFormState.value.endDay = null
  158. }
  159. const query = () => {
  160. const searchFormParam = cloneDeep(searchFormState.value)
  161. if (Array.isArray(searchFormParam.times) && searchFormParam.times.length > 0) {
  162. searchFormParam.times = searchFormParam.times.map((item) => item.format('YYYY-MM-DD'))
  163. searchFormParam.startDay = searchFormParam.times[0]
  164. searchFormParam.endDay = searchFormParam.times[1]
  165. delete searchFormParam.times
  166. }
  167. countData(searchFormParam)
  168. return bizRecordApi
  169. .bizRecordSevenDaysList(Object.assign(searchFormParam))
  170. .then((res) => {
  171. sevenData.value = res || []
  172. renderChart() // 查询成功后重新渲染图表
  173. //searchFormState.value.startDay = null
  174. //searchFormState.value.endDay = null
  175. })
  176. .catch((err) => {
  177. console.error('查询失败:', err)
  178. sevenData.value = [] // 如果请求失败,清空数据
  179. })
  180. }
  181. const loadData = () => {
  182. query().finally(() => {
  183. loading.value = false
  184. renderChart()
  185. })
  186. }
  187. const renderChart = () => {
  188. if (stackedColumnPlot) {
  189. stackedColumnPlot.destroy() // 销毁旧的图表实例
  190. }
  191. stackedColumnPlot = new Column('SevenDays', {
  192. data: sevenData.value, // 使用 sevenData.value
  193. isGroup: true,
  194. xField: 'day',
  195. yField: 'num',
  196. seriesField: 'name',
  197. label: {
  198. position: 'middle',
  199. layout: [{ type: 'interval-adjust-position' }, { type: 'interval-hide-overlap' }, { type: 'adjust-color' }]
  200. }
  201. })
  202. stackedColumnPlot.render()
  203. }
  204. // 统计
  205. const countData = (param) => {
  206. bizRecordApi.bizRecordCountWeight(param).then((res) => {
  207. if (res) {
  208. totalCar.value = res.totalCar
  209. totalGrossWeight.value = res.totalGrossWeight
  210. totalNetWeight.value = res.totalNetWeight
  211. totalTareWeight.value = res.totalTareWeight
  212. }
  213. })
  214. }
  215. </script>