quotations.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view>
  3. <view>
  4. <scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll" scroll-left="120">
  5. <uni-grid :column="5" @change="change" showBorder="false" square="false">
  6. <uni-grid-item v-for="item in categories" :index="item.id">
  7. <view class="grid-item-box">
  8. <image class="image" :src="loadImgSrc(item.icon)" mode="aspectFit"></image>
  9. <text class="text">{{ item.productName }}</text>
  10. </view>
  11. </uni-grid-item>
  12. </uni-grid>
  13. </scroll-view>
  14. </view>
  15. <view class="uni-container">
  16. <uni-table>
  17. <uni-tr>
  18. <uni-th width="80" align="center">地区</uni-th>
  19. <uni-th width="80" align="center">名称</uni-th>
  20. <uni-th width="80" align="center">类型</uni-th>
  21. <uni-th width="80" align="center">价格</uni-th>
  22. <uni-th width="100" align="center">时间</uni-th>
  23. </uni-tr>
  24. <uni-tr v-for="(item, index) in quotationsList" :key="index">
  25. <uni-td align="center">{{ item.area+item.address }}
  26. </uni-td>
  27. <uni-td align="center">{{ item.productName }}
  28. </uni-td>
  29. <uni-td align="center">
  30. <view class="name">{{ item.type}}</view>
  31. </uni-td>
  32. <uni-td align="center">{{ item.price }}
  33. </uni-td>
  34. <uni-td align="center">{{ item.createTime }}
  35. </uni-td>
  36. </uni-tr>
  37. </uni-table>
  38. <uni-load-more :status="status" :content-text="contentText"/>
  39. <uni-fab ref="fab" :horizontal="right" :vertical="bottom"
  40. @fabClick="fabClick()"/>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import {listConfig, listQuotations} from "@/api/quotations/quotations";
  46. import upload from '../../components/upload/index.vue'
  47. export default {
  48. components: {
  49. upload
  50. },
  51. data() {
  52. return {
  53. //是否显示弹出层
  54. open: false,
  55. //悬浮按钮右对齐
  56. right: 'right',
  57. //悬浮按钮下对齐
  58. bottom: 'bottom',
  59. //分类列表
  60. categories: [
  61. // 这里是一级分类的数据
  62. ],
  63. // 行情列表
  64. quotationsList: [
  65. // 这里是列表的数据
  66. ],
  67. //查询参数
  68. queryParams: {
  69. pageNum: 1,
  70. pageSize: 15,
  71. id: null,
  72. status:"1",
  73. },
  74. //加载更多
  75. status: 'more',
  76. contentText: {
  77. contentdown: '查看更多',
  78. contentrefresh: '加载中',
  79. contentnomore: '没有更多'
  80. },
  81. //表单数据
  82. form: {},
  83. imageList: []
  84. }
  85. },
  86. onPullDownRefresh() {
  87. this.queryParams.pageNum = 1;
  88. this.quotationsList = [];
  89. this.getList()
  90. },
  91. //上拉加载
  92. onReachBottom(){
  93. let pageNum = this.queryParams.pageNum
  94. let pageSize = this.queryParams.pageSize
  95. let total = this.total
  96. if(pageNum*pageSize >= total){
  97. uni.showToast({
  98. title:'暂无更多数据'
  99. })
  100. return
  101. } else {
  102. this.queryParams.pageNum += 1;
  103. this.getList()
  104. }
  105. },
  106. onLoad() {
  107. this.getList();
  108. },
  109. methods: {
  110. getList(row) {
  111. // 这里是获取列表的方法
  112. listQuotations(this.queryParams).then(response => {
  113. if (this.queryParams.pageNum === 1) {
  114. this.quotationsList = this.dataFormat(response.rows)
  115. } else {
  116. this.quotationsList = this.quotationsList.concat(this.dataFormat(response.rows));
  117. }
  118. // 判断是否还有更多数据
  119. if (response.rows.length < this.queryParams.pageSize) {
  120. this.status = 'noMore'; // 没有更多数据
  121. } else {
  122. this.status = 'more'; // 还有更多数据
  123. }
  124. });
  125. //获取分类树的方法
  126. listConfig().then(response => {
  127. this.categories = response.data.quotations.filter(item => item.homeDisplay === "1");
  128. });
  129. uni.stopPullDownRefresh();
  130. },
  131. dataFormat(rows) {
  132. // 创建一个映射对象,键是id,值是productName
  133. const idToProductName = this.categories.reduce((acc, cur) => {
  134. acc[cur.id] = cur.productName;
  135. return acc;
  136. }, {});
  137. return rows.map(item => {
  138. let date = new Date(item.createTime);
  139. item.createTime = date.toLocaleDateString('zh-CN', {dateStyle: 'short'});
  140. // 使用映射对象将type的值从id转换为productName
  141. item.type = idToProductName[item.type] || item.type;
  142. return item;
  143. });
  144. },
  145. //根据分类id查询列表
  146. change(e) {
  147. console.log(e)
  148. const type = e.detail.index;
  149. uni.navigateTo({
  150. url: `../quotations/quotationsSecond?type=${type}`
  151. });
  152. },
  153. //悬浮按钮点击事件
  154. fabClick() {
  155. uni.navigateTo({
  156. url: '../quotations/quotationsForm'
  157. });
  158. },
  159. updateImg(imgList) {
  160. this.imageList = imgList;
  161. }
  162. }
  163. }
  164. </script>
  165. <style>
  166. .grid-item-box {
  167. flex: 1;
  168. // position: relative;
  169. /* #ifndef APP-NVUE */
  170. display: flex;
  171. /* #endif */
  172. flex-direction: column;
  173. align-items: center;
  174. justify-content: center;
  175. padding: 0 0;
  176. }
  177. .image {
  178. height: 100%;
  179. width: 100%;
  180. }
  181. .uni-container{
  182. align-items: center;
  183. }
  184. </style>