wzp
2022-03-08 1f478b4b033d518f6de21f931d828d2a175b2a3e
assetMgtH5/pages/assets/list.vue
@@ -9,7 +9,8 @@
      </view>
      <view class="search-box">
         <view class="item">
            <u-search placeholder="请输入关键字" v-model="keyword" :clearabled="true" :show-action="false" @search="onSearch"></u-search>
            <u-search placeholder="请输入关键字" v-model="keyword" :clearabled="true" :show-action="false"
               @search="onSearch"></u-search>
         </view>
      </view>
      <view class="">
@@ -24,18 +25,17 @@
         </u-picker>
      </view>
      <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
         <view class="cu-list menu-avatar ">
            <view class="cu-item" v-for="(item,index) in assetsList" :key="index">
               <view class="cu-avatar radius lg bg-white"
                  style="background-image:url(../../static/device.png)">
               <view class="cu-avatar radius lg bg-white" style="background-image:url(../../static/device.png)">
               </view>
               <view class="content">
                  <view>
                     <view class="text-cut text-bold text-xl">{{item.assets.name}}</view>
                     <view class="cu-tag radius bg-orange sm">已申请数量:{{item.quantity}}</view>
                  </view>
                  <view class="text-gray text-sm flex">
                     <view class="text-cut">规格:{{item.model?item.model:'无'}} 编码:{{item.serialNumber}}</view>
@@ -49,12 +49,13 @@
         <u-empty mode="search" icon="http://cdn.uviewui.com/uview/empty/search.png">
         </u-empty>
      </view> -->
      <u-toast ref="uToast"></u-toast>
   </view>
</template>
<script>
   import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
   export default {
      mixins: [MescrollMixin], // 使用mixin
      data() {
@@ -62,19 +63,20 @@
            keyword: '',
            show: false,
            columns: [],
            columnData: [
            ],
            newColumnData:[],
            columnData: [],
            newColumnData: [],
            assetsList: [],
            flag:false
            flag: false,
            category: null,
            type: null,
            resData:[]
         }
      },
      async onLoad() {
         await this.getAssetsCategoryList();
      onLoad() {
         this.getAssetsCategoryList();
      },
      onReady() {
      },
      onReady() {},
      methods: {
         changeHandler(e) {
            const {
@@ -85,6 +87,7 @@
               // 微信小程序无法将picker实例传出来,只能通过ref操作
               picker = this.$refs.uPicker
            } = e
            // console.log(e)
            // 当第一列值发生变化时,变化第二列(后一列)对应的选项
            if (columnIndex === 0) {
               // picker为选择器this实例,变化第二列对应的选项
@@ -93,8 +96,26 @@
         },
         // 回调参数为包含columnIndex、value、values
         confirm(e) {
            console.log('confirm', e)
            this.show = false
            const index0 = e.indexs[0]; //第一列
            const index1 = e.indexs[1]; //第二列
            console.log('confirm1', index0)
            console.log('confirm2', index1)
            let item1 = index0;
            let item2 = 0;
            if (index1 !== undefined) {
               item2 = index1;
            }
            this.show = false;
            this.category = this.columns[0][item1].id;
            this.type = this.columnData[item1][item2].id;
            this.page = 1;
            let page = {};
            page.num = 1;
            this.upCallback(page);
         },
         cancel() {
            // console.log('cancel');
@@ -103,110 +124,188 @@
         showPicker() {
            this.show = true;
         },
         onSearch(e) {
            console.log("搜索:" + this.keyword)
            this.page = 1;
            let page ={};
            page.num =1;
            let page = {};
            page.num = 1;
            this.upCallback(page);
         },
         upCallback(page) {
            let pageNum = page.num; //页码,默认从1开始
            let pageSize = 10; //页长,默认每页10条
            
            console.log(pageNum)
            this.$http.get('/assets/approval/myAssets', {
                  params: {
                     pageNum: pageNum,
                     pageSize: pageSize,
                     keyStr: this.keyword
                     keyStr: this.keyword,
                     category: this.category,
                     type: this.type
                  }
               })
               .then(res => {
                  // debugger;
                  if (res.data.code === 0) {
                     let data = res.data.data;
                     console.log('总资产'+ data.length)
                     // console.log('总资产' + data.length)
                     if (page.num == 1) this.assetsList = []; //如果是第一页,需手动置空列表
                     this.assetsList = this.assetsList.concat(data); //追加新数据
                     console.log(this.assetsList.length)
                     // console.log(this.assetsList.length)
                     this.mescroll.endBySize(this.assetsList.length, res.data.total);
                  }
                  else{
                  } else {
                     this.mescroll.endBySize(0, 0);
                  }
               })
               .catch(err => {
                  this.mescroll.endErr();
                  console.log('异常', err);
               });
         },
         //资产类别
         async getAssetsCategoryList() {
            await this.$http.get('/assets/approval/getAssetsCategory')
               .then(res => {
         getAssetsCategoryList() {
             // await this.getTest(22);
            this.$http.get('/assets/approval/getAssetsCategory')
               .then(async res => {
                  // debugger;
                  let tt=[]
                  if(res.data.code===0){
                  let tt = []
                  if (res.data.code === 0) {
                     let data = res.data.data;
                     for(let i=0;i<data.length;i++){
                        let jsonData={
                           id:data[i].id,
                           name:data[i].name
                        }
                        tt.push(jsonData);
                        this.getAssetsTypes(data[i].id);
                     }
                     this.resData = data;
                     // for (let i = 0; i < data.length; i++) {
                     //    let jsonData = {
                     //       id: data[i].id,
                     //       name: data[i].name
                     //    }
                     //    tt.push(jsonData);
                     //     await this.getTest(data[i].id);
                     // }
                     tt = data.map(item => ({id: item.id, name: item.name}));
                     // await Promise.all(data.map(item => this.getTest(item.id)))
                     this.dealth();
                  }
                  // this.dealth();
                  
                  let newCloumns=[];
                  newCloumns.push(tt);
                  // newCloumns.push(this.newColumnData[0]);
                  this.columns = newCloumns;
                  this.columns.push(tt);
                  console.log(this.columns);
                  console.log(this.columnData)
               }).catch(err => {
                  console.log(err.data)
               })
         },
         
         async getAssetsTypes(id) {
            await this.$http.get('/assets/approval/getAssetsTypes',{params:{parentId:id}})
         async dealth(){
            let data = this.resData;
            for (let i = 0; i < data.length; i++) {
                await this.getTest(data[i].id);
            }
         },
          getTest(id) {
             console.log("传参"+id)
             // let Authorization="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDYzNjY4NDgsInVzZXJuYW1lIjoiMTM2MTE0NTIxNzUifQ.3QLykIpMBJ__R2s5ReJp53mmPp3WLEWF0xZgvi0rL_I";
             let Authorization=""
             try {
                Authorization = uni.getStorageSync('token')
            } catch (e) {}
            return new Promise((resolve, reject) => {
               // 封装主体:网络请求
                uni.request({
                  url: this.$ApiUrl+ '/assets/approval/getAssetsTypes', //仅为示例,并非真实接口地址。
                  data: {
                     parentId: id
                  },
                  header: {
                     'Authorization': Authorization //自定义请求头信息
                  },
                  success: (res) => {
                     console.log('返还:',id); // 控制台显示数据信息
                     // this.$refs.uToast.show({
                     //    type: 'success',
                     //    message: "获取成功"
                     // });
                     let typeData = []
                     if (res.data.code === 0) {
                        let data = res.data.data;
                        for (let i = 0; i < data.length; i++) {
                           let jsonData = {
                              id: data[i].id,
                              name: data[i].name
                           }
                           typeData.push(jsonData);
                        }
                     }
                     // console.log('typeData=',typeData)
                     this.columnData.push(typeData);
                     if (!this.flag) {
                        this.columns.push(typeData);
                        this.flag = true;
                     }
                     // debugger;
                     resolve(res.data.data)
                  },
                  fail: (err) => {
                     this.$refs.uToast.show({
                        type: 'error',
                        message: "失败!"+err
                     });
                     // 返回错误消息
                     reject(err)
                  }
               })
            })
         },
         //作废
         getAssetsTypes(id) {
            console.log("传参=" + id)
            this.$http.get('/assets/approval/getAssetsTypes', {
                  params: {
                     parentId: id
                  }
               })
               .then(res => {
                  console.log('返回:',id);
                  // debugger;
                  let typeData=[]
                  if(res.data.code===0){
                  let typeData = []
                  if (res.data.code === 0) {
                     let data = res.data.data;
                     for(let i=0;i<data.length;i++){
                        let jsonData={
                           id:data[i].id,
                           name:data[i].name
                     for (let i = 0; i < data.length; i++) {
                        let jsonData = {
                           id: data[i].id,
                           name: data[i].name
                        }
                        typeData.push(jsonData);
                     }
                  }
                  // console.log('typeData=',typeData)
                  this.columnData.push(typeData);
                  if(!this.flag){
                  if (!this.flag) {
                     this.columns.push(typeData);
                     this.flag=true;
                     this.flag = true;
                  }
               }).catch(err => {
                  console.log('错误',err)
                  console.log('错误', err)
               })
         }
      }