quotations.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view>
  3. <view class="nactive">
  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="true">
  6. <uni-grid-item v-for="item in categories" :index="item.id">
  7. <view class="grid-item-box">
  8. <image class="image" :src="loadImgSrcLocalhost(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. book: false,
  54. total:0,
  55. //是否显示弹出层
  56. open: false,
  57. //悬浮按钮右对齐
  58. right: 'right',
  59. //悬浮按钮下对齐
  60. bottom: 'bottom',
  61. //分类列表
  62. categories: [
  63. // 这里是一级分类的数据
  64. ],
  65. // 行情列表
  66. quotationsList: [
  67. // 这里是列表的数据
  68. ],
  69. //查询参数
  70. queryParams: {
  71. pageNum: 1,
  72. pageSize: 15,
  73. id: null,
  74. status: "1",
  75. },
  76. //加载更多
  77. status: 'more',
  78. contentText: {
  79. contentdown: '查看更多',
  80. contentrefresh: '加载中',
  81. contentnomore: '没有更多'
  82. },
  83. //表单数据
  84. form: {},
  85. imageList: []
  86. }
  87. },
  88. onPullDownRefresh() {
  89. this.queryParams.pageNum = 1;
  90. this.quotationsList = [];
  91. this.categories = [];
  92. this.getList()
  93. },
  94. //上拉加载
  95. onReachBottom() {
  96. let pageNum = this.queryParams.pageNum
  97. let pageSize = this.queryParams.pageSize
  98. let total = this.total
  99. if (pageNum * pageSize >= total) {
  100. uni.showToast({
  101. title: '暂无更多数据'
  102. })
  103. return
  104. } else {
  105. this.queryParams.pageNum += 1;
  106. this.getList()
  107. }
  108. },
  109. onLoad() {
  110. this.getList();
  111. },
  112. methods: {
  113. getList(row) {
  114. // 这里是获取列表的方法
  115. listQuotations(this.queryParams).then(response => {
  116. this.total=response.total
  117. if (this.queryParams.pageNum === 1) {
  118. this.quotationsList = this.dataFormat(response.rows)
  119. } else {
  120. this.quotationsList = this.quotationsList.concat(this.dataFormat(response.rows));
  121. }
  122. // 判断是否还有更多数据
  123. if (response.rows.length < this.queryParams.pageSize) {
  124. this.status = 'noMore'; // 没有更多数据
  125. } else {
  126. this.status = 'more'; // 还有更多数据
  127. }
  128. });
  129. //获取分类树的方法
  130. listConfig().then(response => {
  131. this.categories = response.data.quotations.filter(item => item.homeDisplay === "1");
  132. });
  133. uni.stopPullDownRefresh();
  134. },
  135. dataFormat(rows) {
  136. // 创建一个映射对象,键是id,值是productName
  137. const idToProductName = this.categories.reduce((acc, cur) => {
  138. acc[cur.id] = cur.productName;
  139. return acc;
  140. }, {});
  141. return rows.map(item => {
  142. let date = new Date(item.createTime);
  143. item.createTime = date.toLocaleDateString('zh-CN', {dateStyle: 'short'});
  144. // 使用映射对象将type的值从id转换为productName
  145. item.type = idToProductName[item.type] || item.type;
  146. return item;
  147. });
  148. },
  149. //根据分类id查询列表
  150. change(e) {
  151. console.log(e)
  152. const type = e.detail.index;
  153. uni.navigateTo({
  154. url: '/pages/quotations/quotationsSecond?type=${type}'
  155. });
  156. },
  157. //悬浮按钮点击事件
  158. fabClick() {
  159. uni.navigateTo({
  160. url: '/pages/quotations/quotationsForm'
  161. });
  162. },
  163. updateImg(imgList) {
  164. this.imageList = imgList;
  165. }
  166. }
  167. }
  168. </script>
  169. <style>
  170. .nactive {
  171. padding: 10px 0 10px 0;
  172. }
  173. .container {
  174. backgroud-color: #f5f5f5;
  175. }
  176. .grid-item-box {
  177. flex: 1;
  178. // position: relative;
  179. /* #ifndef APP-NVUE */
  180. display: flex;
  181. /* #endif */
  182. flex-direction: column;
  183. align-items: center;
  184. justify-content: center;
  185. padding: 0 0;
  186. }
  187. .image {
  188. height: 100%;
  189. width: 100%;
  190. }
  191. .uni-container {
  192. align-items: center;
  193. }
  194. .gray-background {
  195. background-color: gray;
  196. }
  197. .uni-table-tr:first-child {
  198. background-color: #E8E8E8 !important;
  199. color: #7F818A;
  200. }
  201. </style>