d***@gmail.com
d***@gmail.com
  • 发布:2022-04-03 14:52
  • 更新:2022-04-03 14:52
  • 阅读:457

请问我要怎么实现 查询表格按照设置好的日期排序

分类:uniCloud

求大佬给点建议 卡在这好久了 一直不知道怎么舍得搜索排序

<template>
<view class="container">
<uni-datetime-picker placeholder="请选择查询日期" v-model="querytime" />
<!-- <button type="primary" @click="onQueryTime"> 按日期排序</button> -->
<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" :where="create_date >= '{querytime}'" orderby="nextTime asc" :collection="collectionList" field="username,gender,mobile,email,comment,nextTime,create_date,querytime">
<view v-if="error">{{error.message}}</view>
<view v-else-if="data">

    <uni-list >  
      <uni-list-item  v-for="(item, index) in data" :key="index" showArrow :clickable="true" @click="handleItemClick(item._id)">  
        <template v-slot:body>  
          <view class="text">  
            <!-- 此处默认显示为_id,请根据需要自行修改为其他字段 -->  
            <!-- 如果使用了联表查询,请参考生成的 admin 项目中 list.vue 页面的绑定字段的写法 -->  
            {{index+1}}. 姓名:{{item.username}}   
              <view style="margin-left: 30rpx;">性别:{{options.gender_valuetotext[item.gender]}} </view>  
          </view>  
          <view style="margin-left: 20rpx;color: #b3b3b3;">  
            <uni-dateformat :threshold="[0, 0]" :date="item.nextTime"> </uni-dateformat>  
          </view>  
        </template>  
      </uni-list-item>  
    </uni-list>  
  </view>  
  <uni-load-more :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more>  
  <uni-pagination show-icon :page-size="pagination.size" total="pagination.count" @change="onpagination" />  
</unicloud-db>  
<uni-fab ref="fab" horizontal="right" vertical="bottom" :pop-menu="false" @fabClick="fabClick" />  

</view>
</template>

<script>
const dbOrderBy = 'nextTime asc' // 排序字段,asc(升序)、desc(降序)
const dbSearchFields = ['nextTime', 'create_date', 'mobile', 'email'] // 模糊搜索字段,支持模糊搜索的字段列表
const db = uniCloud.database()
// 由schema2code生成,包含校验规则和enum静态数据
import { enumConverter } from '../../js_sdk/validator/opendb-contacts.js';
export default {
data() {

  return {  
    collectionList: "opendb-contacts",  
    querytime:'2003-02-1',  
    loadMore: {  
      contentdown: '',  
      contentrefresh: '',  
      contentnomore: ''  
    },  
    options: {  
      // 将scheme enum 属性静态数据中的value转成text  
      ...enumConverter  
    }  
  }  
},  
onLoad() {  
  console.log('显示',this.querytime)  
},  

//下拉刷新  
onPullDownRefresh() {  
  this.$refs.udb.loadData({  
    clear: true  
  }, () => {  
    uni.stopPullDownRefresh()  
  })  
},  
onReachBottom() {  
  this.$refs.udb.loadMore()  
},  
methods: {  
    change(e){  
              this.querytime = e  
                            console.log('change事件:', this.querytime = e);  
                        },  
                        changeLog(e) {  
                            console.log('change事件:', e);  
                        },  
                        maskClick(e){  
                            console.log('maskClick事件:', e);  
    },  
  handleItemClick(id) {  
    uni.navigateTo({  
      url: './detail?id=' + id  
    })  
  },  

  fabClick() {  
    // 打开新增页面  
    uni.navigateTo({  
      url: './add',  
      events: {  
        // 监听新增数据成功后, 刷新当前页面数据  
        refreshData: () => {  
          this.$refs.udb.loadData({  
            clear: true  
          })  
        }  
      }  
    })  
  }  
},  
 onqueryload(data, ended) {  
        // 可在此处预处理数据,然后再渲染界面  
      },  
      onqueryerror(e) {  
        // 加载数据失败  
      },  
onpagination(e) {  
        this.$refs.udb.loadData({  
          current: e.current  
        })  
      }  

}
</script>

<style>
.text{
width: 50%;
font-size: 30rpx;
color: #666;

    box-sizing: border-box;  
}  

</style>

2022-04-03 14:52 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复