quotationsSecond.vue 4.8 KB

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