wzp
2022-02-21 2667d6931e0f85f3dda26238330d9c45385025cf
assetMgtH5/pages/assets/use.vue
@@ -1,27 +1,32 @@
<!-- 资产领用 -->
<template>
   <!-- mescroll-body本质是原生page的滚动,无法像mescroll-uni那样用flex布局嵌在某个view中使用局部区域滚动, 但是可以通过fixed定位其他元素来实现"局部区域滚动"-->
   <view>
      <!-- 顶部 fixed定位 -->
      <view class="top-warp">
      <view class="">
         <cu-custom bgColor="bg-gradual-blue" :isBack="true">
            <block slot="backText">返回</block>
            <block slot="content">资产领用</block>
         </cu-custom>
      </view>
      <view class="">
         <view class="cu-bar bg-white solid-bottom ">
            <view class="action">
               <text class="cuIcon-title text-orange"></text> 可领用资产列表
      </view>
      <view class="search-box">
         <view class="item">
            <u-search placeholder="请输入关键字搜索" v-model="keyword" :clearabled="true" :show-action="false"
               @search="onSearch">
            </u-search>
            </view>
         </view>
         <view class="" v-if="listFlag">
            <u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png">
            </u-empty>
         </view>
      <!-- mescroll-body跟随page滚动, 不可fixed定位, 可设置 top, bottom, topbar, bottombar, safearea的偏移量-->
      <mescroll-body ref="mescrollRef" top="176" bottom="300" @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>
@@ -45,23 +50,19 @@
                     <view class="text-cut">规格:{{item.model?item.model:'无'}} 编码:{{item.serialNumber}}</view>
                  </view>
               </view>
               <!-- <view class="action"> -->
               <!-- <view class="text-grey text-xs">22:20</view> -->
               <!-- <view class="cu-tag round bg-red sm">删除</view> -->
               <!-- </view> -->
            </view>
         </view>
      </mescroll-body>
         <!-- 申请理由 -->
      <!-- 底部 fixed定位 -->
      <view class="bottom-warp">
         <view class="margin-top">
            <view class="margin-left border-title">
               申请理由
            </view>
            <view class="flex justify-center align-center" style="margin-top: 10rpx;">
               <view class="" style="width: 95%; ">
                  <u--textarea v-model="reason" placeholder="请输入内容" placeholderStyle="font-size: 15rpx;">
                  <u--textarea height="50" v-model="reason" placeholder="请输入内容" placeholderStyle="font-size: 15rpx;">
                  </u--textarea>
               </view>
@@ -78,83 +79,102 @@
               <view class="">
                  申请人: {{applicant}}
               </view>
               <view class="" style="margin-top: 5rpx;">
                  职务: {{jobTitle}}
               </view>
               <view class="" style="margin-top: 5rpx;">
                  申请单位: {{applicationUnit}}
               </view>
               <view class="" style="margin-top: 5rpx;">
                  申请时间: {{applicationTime}}
               </view>
            </view>
         </view>
      </view>
      <view class="margin-top">
         <view class="margin-top" style="margin-bottom: 30rpx;">
         <u-button style="width: 40%;" type="primary" text="提交申请" @click="submit" :disabled="isDisabled"></u-button>
      </view>
      <u-toast ref="uToast"></u-toast>
   </view>
   </view>
</template>
<script>
   import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
   export default {
      mixins: [MescrollMixin], // 使用mixin
      data() {
         return {
            keyword: '',
            value: 0,
            reason: '',
            total:0,
            assetsList: [],
            listFlag: false,
            valueList: [],
            applicant: "", //申请人
            jobTitle: "", //职务
            applicationUnit: '', //申请单位
            applicationTime: '', //申请时间
            templateId: '', //模板ID
            isDisabled:false
            isDisabled: false,
            page: 1,
            pageSize: 10,
            status: 'loadmore',
            user:null
         }
      },
      onLoad() {
         this.user =uni.getStorageSync('user');
         this.applicant = this.user.userName;
         this.applicationTime = this.$dayjs().format("YYYY-MM-DD HH:mm:ss")
      },
      onShow() {
         console.log(this.$dayjs().format("YYYY-MM-DD"));
         this.initUseListData();
         this.initTemplateData();
      },
      methods: {
         valChange(e) {
            console.log('当前值为: ' + e.value)
         /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
         onSearch(e) {
            console.log("搜索:" + this.keyword)
            this.page = 1;
            let page ={};
            page.num =1;
            this.upCallback(page);
         },
         //获取可领用设备
         initUseListData() {
         upCallback(page) {
            let pageNum = page.num; //页码,默认从1开始
            let pageSize = 10; //页长,默认每页10条
            console.log(pageNum)
            this.$http.get('/assets/approval/search', {
                  params: {
                     pageNum: "1",
                     pageSize: "5",
                     keyStr: '',
                     pageNum: pageNum,
                     pageSize: pageSize,
                     keyStr: this.keyword,
                     state: "2"
                  }
               })
               .then(res => {
                  // debugger;
                  if (res.statusCode === 200) {
                     if (res.data.code === 0) {
                        let data = res.data.rows;
                        this.assetsList = data;
                        // console.log(data.length)
                     console.log(res.data.total)
                     if (page.num == 1) this.assetsList = []; //如果是第一页,需手动置空列表
                     this.assetsList = this.assetsList.concat(data); //追加新数据
                     console.log(this.assetsList.length)
                     this.mescroll.endBySize(this.assetsList.length, res.data.total);
                     }
                  } else {
                     this.listFlag = true;
                  else{
                     this.mescroll.endBySize(0, 0);
                  }
               }).catch(err => {
                  this.listFlag = true;
                  console.log(err.data)
               })
               .catch(err => {
                  this.mescroll.endErr();
                  console.log('异常', err);
               });
         },
         //获取领用的模板
@@ -162,14 +182,9 @@
            this.$http.get('/assets/approval/getTemplate')
               .then(res => {
                  // debugger;
                  if (res.statusCode === 200) {
                     if (res.data.code === 0) {
                        let data = res.data.data;
                        // this.assetsList = data;
                        // console.log(JSON.stringify(data.data))
                        // let tt = data.data;
                        console.log(data.length)
                        //获取领用的模板ID
                        for (let i = 0; i < data.length; i++) {
                           if (data[i].type === 1) {
@@ -177,8 +192,9 @@
                              break;
                           }
                        }
                     console.log('模板ID=' + this.templateId)
                     }
                  }
               }).catch(err => {
@@ -223,7 +239,7 @@
               }
            }
            console.log(assets);
            // console.log(assets);
            let data = {
               "assets": assets,
               "templateId": this.templateId,
@@ -234,13 +250,13 @@
               .then(res => {
                  // debugger;
                  if (res.data.code === 0) {
                     console.log("成功了")
                     console.log("成功了");
                     this.reason="";
                     this.$refs.uToast.show({
                        type: 'success',
                        message: "提交成功"
                     });
                  }
                  else{
                  } else {
                     this.$refs.uToast.show({
                        type: 'error',
                        message: res.data.msg
@@ -257,7 +273,73 @@
   }
</script>
<style lang="scss">
   /* 顶部 fixed定位*/
   .top-warp{
      z-index: 200;
      position: fixed;
      top: var(--window-top);
      left: 0;
      width: 100%;
      height: 88rpx;
      padding-top: 10rpx;
      font-size: 28rpx;
      text-align: center;
      background-color: #CFE0DA;
   }
   // 设置padding
   .mescroll-body,
   /deep/.mescroll-body{
      padding-left: 0rpx;
   }
   /* 底部 fixed定位*/
   .bottom-warp{
      z-index: 200;
      position: fixed;
      left: 0;
      bottom: 0;
      width: 100%;
      background-color: #FFFFFF;
   }
   .itembox {
      /* 父容器设置宽度, 并超出部分不显示 */
      width: 100%;
      height: 100%;
      overflow: scroll;
      .item {
         /* 子容器比父容器的宽度多 17 px, 经测正好是滚动条的默认宽度 */
         // width: 5517px;
         // height: 100%;
         // line-height: 30px;
         text-align: center;
         overflow-y: scroll;
      }
   }
   .content-box {
      position: relative;
      // border: 1rpx red solid;
      height: 50vh;
   }
   .search-box {
      background-color: #FFFFFF;
      // margin-top: 88rpx;
      z-index: 200;
      top:88rpx;
      width: 100%;
      position: fixed;
      padding: 10rpx 30rpx 0rpx 30rpx;
      // border: 1rpx red solid;
   }
   .numbox {
      margin-left: 20rpx;
   }