quotations.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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.categories = [];
  90. this.getList()
  91. },
  92. //上拉加载
  93. onReachBottom(){
  94. let pageNum = this.queryParams.pageNum
  95. let pageSize = this.queryParams.pageSize
  96. let total = this.total
  97. if(pageNum*pageSize >= total){
  98. uni.showToast({
  99. title:'暂无更多数据'
  100. })
  101. return
  102. } else {
  103. this.queryParams.pageNum += 1;
  104. this.getList()
  105. }
  106. },
  107. onLoad() {
  108. this.getList();
  109. },
  110. methods: {
  111. getList(row) {
  112. // 这里是获取列表的方法
  113. listQuotations(this.queryParams).then(response => {
  114. if (this.queryParams.pageNum === 1) {
  115. this.quotationsList = this.dataFormat(response.rows)
  116. } else {
  117. this.quotationsList = this.quotationsList.concat(this.dataFormat(response.rows));
  118. }
  119. // 判断是否还有更多数据
  120. if (response.rows.length < this.queryParams.pageSize) {
  121. this.status = 'noMore'; // 没有更多数据
  122. } else {
  123. this.status = 'more'; // 还有更多数据
  124. }
  125. });
  126. //获取分类树的方法
  127. listConfig().then(response => {
  128. this.categories = response.data.quotations.filter(item => item.homeDisplay === "1");
  129. });
  130. uni.stopPullDownRefresh();
  131. },
  132. dataFormat(rows) {
  133. // 创建一个映射对象,键是id,值是productName
  134. const idToProductName = this.categories.reduce((acc, cur) => {
  135. acc[cur.id] = cur.productName;
  136. return acc;
  137. }, {});
  138. return rows.map(item => {
  139. let date = new Date(item.createTime);
  140. item.createTime = date.toLocaleDateString('zh-CN', {dateStyle: 'short'});
  141. // 使用映射对象将type的值从id转换为productName
  142. item.type = idToProductName[item.type] || item.type;
  143. return item;
  144. });
  145. },
  146. //根据分类id查询列表
  147. change(e) {
  148. console.log(e)
  149. const type = e.detail.index;
  150. uni.navigateTo({
  151. url: `../quotations/quotationsSecond?type=${type}`
  152. });
  153. },
  154. //悬浮按钮点击事件
  155. fabClick() {
  156. uni.navigateTo({
  157. url: '../quotations/quotationsForm'
  158. });
  159. },
  160. updateImg(imgList) {
  161. this.imageList = imgList;
  162. }
  163. }
  164. }
  165. </script>
  166. <style>
  167. .grid-item-box {
  168. flex: 1;
  169. // position: relative;
  170. /* #ifndef APP-NVUE */
  171. display: flex;
  172. /* #endif */
  173. flex-direction: column;
  174. align-items: center;
  175. justify-content: center;
  176. padding: 0 0;
  177. }
  178. .image {
  179. height: 100%;
  180. width: 100%;
  181. }
  182. .uni-container{
  183. align-items: center;
  184. }
  185. </style>