trend.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <u-modal :show="trendModal" title="价格趋势" @confirm="closeTrendModal" confirmText="关闭弹窗" height="80%">
  3. <view class="trend_modal">
  4. <u-search placeholder="请输入型号" v-model="model" @blur="searchTrend" @custom="searchTrend"></u-search>
  5. <view class="charts_box" v-if="chartShow">
  6. <u--text type="primary" :text="`最大价格:${Math.max(...maxPrice)}元`"></u--text>
  7. <u--text type="warning" :text="`最小价格:${Math.min(...minPrice)}元`"></u--text>
  8. <qiun-data-charts type="line" :chartData="chartData" canvasId="trendChart" :opts="opts" :ontouch="true"
  9. tooltipFormat="tooltipFormatPrice" width="700rpx" height="500rpx" backgroundColor="#ffffff"
  10. @getIndex="handleChartClick" />
  11. </view>
  12. <!-- <u--text v-if="cardData.length > 0" :text="'日期:' + date"></u--text> -->
  13. <view class="card-container" v-if="cardData.length > 0">
  14. <view class="card-item" v-for="(item, index) in cardData" :key="index">
  15. <view class="card-row">
  16. <span class="card-label">型号:</span>
  17. <span class="card-value">{{ item.model }}</span>
  18. </view>
  19. <view class="card-row">
  20. <span class="card-label">日期:</span>
  21. <span class="card-value">{{ formatTime(item.recycleTime) }}</span>
  22. </view>
  23. <view class="card-row">
  24. <span class="card-label">价格:</span>
  25. <span class="card-value">{{ item.price }}元</span>
  26. </view>
  27. <view class="card-row">
  28. <span class="card-label">回收情况:</span>
  29. <span class="card-value">{{ formatRecycleSituation(item.recycleSituation) }}</span>
  30. </view>
  31. <view class="card-row">
  32. <span class="card-label">备注:</span>
  33. <span class="card-value">{{ item.remark || '-' }}</span>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </u-modal>
  39. </template>
  40. <script>
  41. import { recycleSituationList } from '@/pages/wareHouse/js/public.js'
  42. export default {
  43. name: 'ComponentName',
  44. data() {
  45. return {
  46. trendModal: false,
  47. chartData: {},
  48. color: [],
  49. opts: {
  50. color: this.color,
  51. padding: [20, 10, 20, 0],
  52. dataLabel: true,
  53. dataPointShape: true,
  54. enableScroll: true,
  55. xAxis: {
  56. disableGrid: true,
  57. scrollShow: true,
  58. itemCount: 10,
  59. rotateLabel: true,
  60. rotateAngle: 45,
  61. },
  62. yAxis: {
  63. gridType: "dash",
  64. dashLength: 7,
  65. },
  66. legend: {
  67. show: false,
  68. type: 'scroll',
  69. orient: 'horizontal',
  70. pageSize: 3,
  71. pageIconSize: 12,
  72. pageIconColor: '#666',
  73. pageIconInactiveColor: '#ccc',
  74. pageTextStyle: {
  75. color: '#666',
  76. fontSize: 12
  77. },
  78. bottom: 0
  79. },
  80. extra: {
  81. line: {
  82. type: "curve",
  83. width: 3,
  84. activeType: "hollow",
  85. linearType: "custom",
  86. onShadow: true,
  87. animation: "horizontal"
  88. },
  89. tooltip: {
  90. legendShow: false,
  91. bgOpacity: 0.6,
  92. }
  93. }
  94. },
  95. model: "",
  96. maxPrice: [],
  97. minPrice: [],
  98. chartShow: false,
  99. cardData: [],
  100. date: '',
  101. recycleSituationList: recycleSituationList,
  102. }
  103. },
  104. props: {
  105. },
  106. emits: [],
  107. methods: {
  108. openTrendModal() {
  109. this.trendModal = true;
  110. },
  111. closeTrendModal() {
  112. this.model = ""
  113. this.date = ""
  114. this.cardData = []
  115. this.chartShow = false
  116. this.trendModal = false;
  117. },
  118. searchTrend(val) {
  119. if (val !== '') {
  120. uni.$u.api.inquiryChart({
  121. model: val,
  122. }).then(res => {
  123. if (res.data.length == 0) {
  124. uni.$u.toast("暂无数据")
  125. this.minPrice = []
  126. this.maxPrice = []
  127. this.chartShow = false
  128. return
  129. }
  130. const response = res.data
  131. this.maxPrice = []
  132. this.minPrice = []
  133. this.color = []
  134. const categories = []
  135. const dateMap = {}
  136. response.forEach(item => {
  137. this.maxPrice.push(item.max)
  138. this.minPrice.push(item.min)
  139. item.list.forEach(i => {
  140. i.recycleTime = this.formatTime(i.recycleTime)
  141. if (!dateMap[i.recycleTime]) {
  142. dateMap[i.recycleTime] = true
  143. categories.push(i.recycleTime)
  144. }
  145. })
  146. })
  147. const series = response.map((item) => {
  148. const color = this.getRandomColor()
  149. this.color.push(color)
  150. const data = categories.map(date => {
  151. const itemData = item.list.find(i => this.formatTime(i.recycleTime) == date)
  152. return itemData ? itemData.price : null
  153. })
  154. return {
  155. name: item.model,
  156. data: data,
  157. list: item.list,
  158. setShadow: [
  159. 3,
  160. 8,
  161. 15,
  162. color
  163. ],
  164. }
  165. })
  166. this.opts.color = this.color
  167. const chartData = {
  168. categories: categories,
  169. series: series
  170. }
  171. this.chartData = JSON.parse(JSON.stringify(chartData))
  172. this.cardData = []
  173. this.chartShow = true
  174. }).catch((err) => {
  175. uni.$u.toast(err)
  176. })
  177. }
  178. },
  179. formatTime(date){
  180. return this.$dayjs(date).format('YYYY-MM-DD')
  181. },
  182. formatRecycleSituation(situation) {
  183. const item = this.recycleSituationList.find(i => i.value == situation)
  184. return item ? item.name : '-'
  185. },
  186. handleChartClick(event) {
  187. const index = event.currentIndex.index;
  188. // 获取点击的日期
  189. const date = this.chartData.categories[index];
  190. this.date = date;
  191. // 构建该日期的所有型号价格数据
  192. const cardData = [];
  193. this.chartData.series.forEach(series => {
  194. const price = series.data[index];
  195. if (price !== null) {
  196. // 查找对应日期的完整数据
  197. const itemData = series.list.find(i => i.recycleTime === date);
  198. cardData.push({
  199. model: series.name,
  200. price: price,
  201. recycleSituation: itemData?.recycleSituation || '',
  202. remark: itemData?.remark || ''
  203. });
  204. }
  205. });
  206. this.cardData = cardData;
  207. },
  208. getRandomColor() {
  209. var letters = '0123456789ABCDEF';
  210. var color = '#';
  211. for (var i = 0; i < 6; i++) {
  212. color += letters[Math.floor(Math.random() * 16)];
  213. }
  214. return color;
  215. },
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. .trend_modal {
  221. width: 100%;
  222. display: flex;
  223. flex-direction: column;
  224. gap: 20rpx;
  225. }
  226. .card-container {
  227. display: flex;
  228. flex-direction: column;
  229. gap: 16rpx;
  230. max-height: 500rpx;
  231. overflow-y: auto;
  232. font-size:26rpx;
  233. &::-webkit-scrollbar {
  234. width: 6rpx;
  235. }
  236. &::-webkit-scrollbar-track {
  237. background: #f1f1f1;
  238. border-radius: 3rpx;
  239. }
  240. &::-webkit-scrollbar-thumb {
  241. background: #c1c1c1;
  242. border-radius: 3rpx;
  243. &:hover {
  244. background: #a8a8a8;
  245. }
  246. }
  247. }
  248. .card-item {
  249. background-color: #f5f5f5;
  250. border-radius: 8rpx;
  251. padding: 16rpx;
  252. box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
  253. }
  254. .card-row {
  255. display: flex;
  256. margin-bottom: 10rpx;
  257. align-items: flex-start;
  258. .card-label {
  259. flex-shrink: 0;
  260. }
  261. .card-value {
  262. flex: 1;
  263. word-break: break-all;
  264. }
  265. }
  266. </style>