quotations.vue 5.4 KB

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