浏览代码

行情修改二级分类查询列表

刘浩男 1 年之前
父节点
当前提交
8880e9bfbf
共有 1 个文件被更改,包括 57 次插入41 次删除
  1. 57 41
      pages/quotations/quotationsSecond.vue

+ 57 - 41
pages/quotations/quotationsSecond.vue

@@ -1,17 +1,5 @@
 <template>
   <view>
-    <view>
-      <scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll" scroll-left="120">
-        <uni-grid :column="5" @change="change" showBorder="false" square="false">
-          <uni-grid-item v-for="item in categories" :index="item.id">
-            <view class="grid-item-box">
-              <image class="image" :src="loadImgSrcLocalhost(item.icon)" mode="aspectFit"></image>
-              <text class="text">{{ item.productName }}</text>
-            </view>
-          </uni-grid-item>
-        </uni-grid>
-      </scroll-view>
-    </view>
     <view class="uni-container">
       <uni-table>
         <uni-tr>
@@ -37,7 +25,7 @@
 </template>
 
 <script>
-import {listConfig,QuotationsList, listQuotations} from "@/api/quotations/quotations";
+import {listConfig, QuotationsList, listQuotations} from "@/api/quotations/quotations";
 import upload from '../../components/upload/index.vue'
 
 export default {
@@ -67,11 +55,13 @@ export default {
         pageSize: 15,
         id: null,
         type: null,
+        types: [],
       },
       //表单数据
       form: {},
+
       //分类树列表
-      forms:{},
+      forms: {},
       imageList: []
     }
   },
@@ -93,47 +83,73 @@ export default {
     this.getList();
   },
   methods: {
-    getList(row) {
-      // 这里是获取列表的方法
-      this.queryParams.type = this.FatherType
-      listQuotations(this.queryParams).then(response => {
-        if (this.queryParams.pageNum === 1) {
-          this.quotationsList = this.dataFormat(response.rows)
-        } else {
-          this.quotationsList = this.quotationsList.concat(this.dataFormat(response.rows));
-        }
-        // 判断是否还有更多数据
-        if (response.rows.length < this.queryParams.pageSize) {
-          this.status = 'noMore'; // 没有更多数据
-        } else {
-          this.status = 'more'; // 还有更多数据
-        }
-      });
-      this.forms.parentId = this.FatherType
+     getList() {
       //获取分类树的方法
-      QuotationsList(this.forms).then(response => {
-        //取出response.rows中所有homeDisplay为1的数据
-        this.categories = response.rows
-      });
+       listConfig().then(response => {
+            this.categories = this.findNodes(response.data.quotations, this.FatherType)
+            //categories是一个数组,把他数组中的每一个id属性都取出来并添加到this.queryParams.types中
+            this.queryParams.types = this.categories.map(item => item.id);
+         listQuotations(this.queryParams).then(response => {
+           if (this.queryParams.pageNum === 1) {
+             this.quotationsList = this.dataFormat(response.rows)
+           } else {
+             this.quotationsList = this.quotationsList.concat(this.dataFormat(response.rows));
+           }
+           // 判断是否还有更多数据
+           if (response.rows.length < this.queryParams.pageSize) {
+             this.status = 'noMore'; // 没有更多数据
+           } else {
+             this.status = 'more'; // 还有更多数据
+           }
+         })
+          }
+      );
+      // 这里是获取列表的方法
+
       uni.stopPullDownRefresh();
     },
+    findNodes(tree, id) {
+      let result = [];
+      for (let v in tree) {
+        let node = tree[v];
+        if (node.id == id || node.parentId == id) {
+          result.push(node)
+        };
+        if (node.children) {
+          result = result.concat(this.findNodes(node.children, id));
+        }
+      }
+      return result;
+    },
     //格式化时间
     dataFormat(rows) {
+      // 创建一个映射对象,键是id,值是productName
+      const idToProductName = this.categories.reduce((acc, cur) => {
+        acc[cur.id] = cur.productName;
+        return acc;
+      }, {});
       return rows.map(item => {
         let date = new Date(item.createTime);
         item.createTime = date.toLocaleDateString('zh-CN', {dateStyle: 'short'});
+        // 使用映射对象将type的值从id转换为productName
+        item.type = idToProductName[item.type] || item.type;
         return item;
       });
     },
     //根据分类id查询列表
     change(e) {
-      this.queryParams.type = e.detail.index;
       listQuotations(this.queryParams).then(response => {
-        this.quotationsList = response.rows.map(item => {
-          let date = new Date(item.createTime);
-          item.createTime = date.toLocaleDateString('zh-CN', {dateStyle: 'short'});
-          return item;
-        });
+        if (this.queryParams.pageNum === 1) {
+          this.quotationsList = this.dataFormat(response.rows)
+        } else {
+          this.quotationsList = this.quotationsList.concat(this.dataFormat(response.rows));
+        }
+        // 判断是否还有更多数据
+        if (response.rows.length < this.queryParams.pageSize) {
+          this.status = 'noMore'; // 没有更多数据
+        } else {
+          this.status = 'more'; // 还有更多数据
+        }
       });
     },
     updateImg(imgList) {