123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import {
- visiteeList,
- } from '../../../utils/api/api'
- import {
- getWaterDrop
- } from '../../../utils/index/index'
- const app = getApp()
- Page({
- data: {
- formPath: null, //从哪个页面来
- searchList: [{
- name: '姓名',
- val: 'name'
- },
- {
- name: '手机号',
- val: 'phone'
- },
- {
- name: '身份证',
- val: 'idNumber'
- },
- {
- name: '单位',
- val: 'company'
- },
- {
- name: '部门',
- val: 'unitName'
- },
- {
- name: '楼层',
- val: 'floor'
- },
- {
- name: '房间号',
- val: 'room'
- },
- ],
- searchForm: {
- name: '',
- phone: '',
- company: '',
- unitName: '',
- floor: '',
- room: '',
- },
- allList: [],
- allListCopy: [],
- tableList: [],
- total: 0,
- pageNum: 0, //总页数
- pageSize: 0, //当前页数
- sliceStart: 0, //截取数组开始
- sliceEnd: 8, //截取数组结束
- },
- onLoad(e) {
- my.hideBackHome();
- this.setData({
- formPath: e.formPath || null
- })
- this.data.searchFormCopy = JSON.parse(JSON.stringify(this.data.searchForm));
- this.getTable()
- },
- async getTable(e) {
- my.showLoading()
- try {
- let dto = {
- sn: app.globalData.sn,
- }
- let res = await visiteeList(app.globalData.snDisposition.visiteeUrl, dto)
- if (res.data) {
- var pageNum = Math.ceil(res.data.length / 8);
- let {
- sliceEnd,
- sliceStart
- } = this.data
- this.setData({
- allList: res.data,
- allListCopy: res.data,
- tableList: res.data.slice(sliceStart, sliceEnd),
- total: res.data.length,
- pageNum,
- pageSize: res.data.length > 0 ? 1 : 0,
- })
- }
- } catch (error) {
- console.log(error);
- } finally {
- my.hideLoading()
- }
- },
- clickAudio() {
- getWaterDrop()
- },
- getVal(e) {
- let key = e.currentTarget.dataset.key
- let key1 = `searchForm[${key}]`
- this.setData({
- [key1]: e.detail.value
- })
- },
- // 查询
- inquireFun() {
- let {
- searchForm,
- allList,
- allListCopy
- } = this.data
- allList = JSON.parse(JSON.stringify(allListCopy))
- // 根据条件过滤数据
- let result = this.filterData(searchForm, allList)
- var pageNum = Math.ceil(result.length / 8);
- let sliceStart = 0
- let sliceEnd = 8
- this.setData({
- allList: result,
- tableList: result.slice(sliceStart, sliceEnd),
- sliceEnd,
- sliceStart,
- total: result.length,
- pageNum,
- pageSize: result.length > 0 ? 1 : 0,
- })
- },
- // 多条件过滤,参数queryObj(过滤条件对象),list(需要过滤的数组)
- filterData(queryObj, list) {
- let arr = list
- Object.keys(queryObj).forEach(key => {
- if (queryObj[key] == undefined || queryObj[key] == '') return arr
- arr = arr.filter(p => p[key] !== null && (p[key].indexOf(queryObj[key]) > -1))
- })
- return arr
- },
- //清空
- clearFun() {
- let searchForm = JSON.parse(JSON.stringify(this.data.searchFormCopy));
- this.setData({
- searchForm
- })
- this.getTable()
- },
- // 上一页
- previousFun() {
- let {
- allList,
- pageSize,
- sliceEnd,
- sliceStart
- } = this.data
- if (pageSize <= 1) {
- return
- }
- this.setData({
- tableList: allList.slice(sliceStart - 8, sliceEnd - 8),
- sliceStart: sliceStart - 8,
- sliceEnd: sliceEnd - 8,
- pageSize: pageSize - 1
- })
- },
- // 下一页
- nextFun() {
- let {
- allList,
- pageSize,
- pageNum,
- sliceEnd,
- sliceStart
- } = this.data
- if (pageSize >= pageNum) {
- return
- }
- this.setData({
- tableList: allList.slice(sliceStart + 8, sliceEnd + 8),
- sliceStart: sliceStart + 8,
- sliceEnd: sliceEnd + 8,
- pageSize: pageSize + 1
- })
- },
- });
|