123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- // dispatcher/pages/sweeped_books/sweeped_books.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
- import { GetSweepedBooks, DeleteSweepedBooks, DispatcherScanning, ConfirmToLib, ConfirmToZb } from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData } = getApp()
- const { baseImgUrl, thumbnail, qrcodeInvalidToastText } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- thumbnail,
- isLoaded: false,
- isAllCheck: 0,
- isManage: 0,
- totalNum: 0,
- ids: [],
- pageNo: 1,
- pageSize: 10,
- isAll: 0,
- totalNumbers: 0,
- list: [
- // {
- // "order_num": "1",
- // "username": "12154545",
- // "title": "福建师大雷锋精神连接方式精神连接方式垃圾精神连接方式垃圾精神连接接方式精神连接方式垃圾精神连接方式垃圾精神连接方式垃圾垃圾分方式垃圾垃圾分类是就发了是家乐福",
- // "reg_time": "1436864169",
- // parent_name: '地方就是到了封精神连接方式垃圾精神连接方式垃圾精神连接方式垃圾建士大夫的',
- // child_name: 'sdfsfsf',
- // color: '#ff5050',
- // "wish_num": "0",
- // },
- // {
- // "order_num": "1",
- // "username": "12154545",
- // "title": "福建师大雷锋精神连接方式垃圾分类是就发了是家乐福",
- // "reg_time": "1436864169",
- // parent_name: '地方就是到了封建士大夫的',
- // child_name: 'sdfsfsf',
- // color: '#000',
- // "wish_num": "0",
- // },
- // {
- // "order_num": "1",
- // "username": "12154545",
- // "title": "福建师大乐福",
- // "reg_time": "1436864169",
- // parent_name: '地方就是到了封建士大夫的',
- // child_name: 'sdfsfsf',
- // "wish_num": "0",
- // },
- // {
- // "order_num": "1",
- // "username": "12154545",
- // "title": "福建师大雷锋精神连接方式垃圾分类是就发了是家乐福",
- // "reg_time": "1436864169",
- // parent_name: '地方就是到了封建士大夫的',
- // child_name: 'sdfsfsf',
- // "wish_num": "0",
- // },
- // {
- // "order_num": "1",
- // "username": "12154545",
- // "title": "福建师大雷锋精神连接方式垃圾分类是就发了是家乐福",
- // "reg_time": "1436864169",
- // parent_name: '地方就是到了封建士大夫的',
- // child_name: 'sdfsfsf',
- // "wish_num": "0",
- // },
- // {
- // "order_num": "1",
- // "username": "12154545",
- // "title": "福建师大雷锋精神连接方式垃圾分类是就发了是家乐福",
- // "reg_time": "1436864169",
- // parent_name: '地方就是到了封建士大夫的',
- // child_name: 'sdfsfsf',
- // "wish_num": "0",
- // },
- ],
- nodataArray: {
- text: "暂无图书",
- image: '../../../assets/nodata_1.png',
- margin: '400rpx auto'
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const titles = ['', '带书离馆', '调配中', '待调配']
- const btnText = ['', '离馆', '送达', '']
- const { type = 0 } = options
- options.type = ~~type
- options.title = titles[type]
- options.btnText = btnText[type]
- options.userId = getGlobalVal('userId')
- options.libId = (options.libId ? options.libId : getGlobalVal(`dispatchLibId_${options.userId}`) ? getGlobalVal(`dispatchLibId_${options.userId}`) : '')
- this.setData({ options })
- this.getData(res => {
- this.setData({ isLoaded: true })
- })
- wx.setNavigationBarTitle({
- title: titles[type],
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- const obj = { navigateTo, redirectTo, navigateBack, viewImage }
- for (const i in obj) {
- this[i] = obj[i]
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.setData({ pageNo: 1 })
- this.getData(res => {
- wx.stopPullDownRefresh()
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- const { isAll = false } = this.data
- if (isAll) return
- this.getData()
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 获取数据
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getData, param: { ...arguments } }
- const { list = [], pageNo = 1, pageSize = 10, options = {} } = this.data
- const { libId = '', type = 0 } = options
- if (!libId) {
- wx.showToast({
- title: '请先选择馆',
- icon: 'none'
- })
- cb && cb()
- return
- }
- if (!type) {
- wx.showToast({
- title: '出了点小问题',
- icon: 'none'
- })
- cb && cb()
- return
- }
- GetSweepedBooks({ data: { type, libId, pageNo, pageSize }, continuousFn }).then(res => {
- const newList = res.data.list
- const totalNumbers = res.data.pages || 0
- let listTemp = []
- if (pageNo == 1) {
- listTemp = [].concat(newList)
- } else {
- listTemp = [].concat(list, newList)
- }
- const temp = {}
- temp['list'] = listTemp
- temp['pageNo'] = newList.length == pageSize ? pageNo + 1 : pageNo
- temp['isAll'] = newList.length < pageSize
- temp['totalNumbers'] = totalNumbers
- this.setData(temp)
- this.caclulateBook()
- cb && cb(res)
- }).catch(res => {
- cb && cb(res)
- })
- },
- /**
- * 切换管理和取消按钮
- */
- toggleManageCtl: function () {
- const { isManage = false } = this.data
- this.setData({ isManage: !isManage })
- },
- /**
- * 选择图书
- */
- toggleSelectLiCtl: function (e) {
- const { index = -1 } = e.currentTarget.dataset
- const { list = [] } = this.data
- const { isCheck } = list[index]
- list[index].isCheck = isCheck != 1 ? 1 : 0
- this.setData({ list })
- this.caclulateBook()
- },
- /**
- * 选择全部图书
- */
- checkAllCtl: function () {
- const { isAllCheck, list = [] } = this.data
- for (let i in list) {
- list[i]['isCheck'] = isAllCheck != 1 ? 1 : 0
- }
- this.setData({ list })
- this.caclulateBook()
- },
- /**
- * 计算书籍
- */
- caclulateBook: function () {
- const { list } = this.data
- let num = 0
- let ids = []
- for (let v of list) {
- if (v['isCheck'] == 1) {
- num++
- ids.push(v['id'])
- }
- }
- this.setData({ totalNum: num, ids, isAllCheck: ids.length == list.length })
- },
- /**
- * 删除
- */
- delCtl: function () {
- const continuousFn = { fn: this.delCtl, param: { ...arguments } }
- const { ids = [], options = {} } = this.data
- const { libId = '', type = 0 } = options
- if (!ids.length) {
- wx.showToast({
- title: '请先选中要删除的图书',
- icon: 'none'
- })
- return
- }
- DeleteSweepedBooks({ data: { ids, libId, type }, continuousFn }).then(res => {
- this.setData({ pageNo: 1 })
- this.getData()
- })
- },
- /**
- * 到达提交
- */
- submitCtl: function () {
- const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
- const { options = {} } = this.data
- const { libId = '', type = 0 } = options
-
- if (!libId) {
- wx.showToast({
- title: '请先选择馆',
- icon: 'none'
- })
- return
- }
- const titles = ['', '离馆成功', '到达成功']
- const fn = [null, ConfirmToZb, ConfirmToLib]
- if (isFn(fn[type])) {
- wx.showLoading({
- title: '提交中...',
- })
- fn[type]({ data: { libId }, continuousFn }).then(res => {
- wx.hideLoading()
- wx.showToast({
- title: titles[type]
- })
- setTimeout(() => {
- navigateBack()
- }, 2000)
- }).catch(() => {
- wx.hideLoading()
- })
- }
- }
- })
|