123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- // dispatcher/pages/withdraw/withdraw.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
- import { GetRecoveryListHeadInfo, GetRecoveryList, DispatcherRecovery, ConfirmRecovery } from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData } = getApp()
- const { baseImgUrl, qrcodeInvalidToastText } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- isLoaded: false,
- league_name: '',
- league_address: '',
- itemIndex: 0,
- items: [
- {
- icon: '../../../assets/dispatch_icon_1_gray.png',
- actIcon: '../../../assets/dispatch_icon_1_blue.png',
- text: '开始撤馆',
- name: '',
- },
- {
- icon: '../../../assets/dispatch_icon_2_gray.png',
- actIcon: '../../../assets/dispatch_icon_2_blue.png',
- text: '书籍回收',
- name: '',
- },
- {
- icon: '../../../assets/dispatch_icon_3_gray.png',
- actIcon: '../../../assets/dispatch_icon_3_blue.png',
- text: '盘点归库',
- name: '',
- },
- ],
- navIndex: 0,
- navList: [
- {
- text: '',
- stat: 1,
- pageNo: 1,
- pageSize: 10,
- isAll: false,
- list: [
- // {
- // detailsId: 1,
- // },
- // {
- // detailsId: 2,
- // },
- // {
- // detailsId: 3,
- // },
- // {
- // detailsId: 4,
- // },
- // {
- // detailsId: 5,
- // },
- // {
- // detailsId: 6,
- // },
- ],
- number: 0,
- nodataArray: {
- text: '暂无书籍',
- image: '../../../assets/nodata_1.png',
- // hasNodataBtn: 1,
- // btnText: '扫码收书'
- }
- },
- {
- text: '',
- stat: 2,
- pageNo: 1,
- pageSize: 10,
- isAll: false,
- list: [],
- number: 0,
- nodataArray: {
- text: '暂无书籍',
- image: '../../../assets/nodata_1.png',
- // hasNodataBtn: 1,
- // btnText: '扫码收书'
- }
- },
- {
- text: '',
- stat: 3,
- pageNo: 1,
- pageSize: 10,
- isAll: false,
- list: [],
- number: 0,
- nodataArray: {
- text: '暂无书籍',
- image: '../../../assets/nodata_1.png',
- // hasNodataBtn: 1,
- // btnText: '扫码收书'
- }
- },
- ],
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({ options })
- this.getHeaderData()
- this.getData(() => {
- this.setData({ isLoaded: true })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- const obj = { navigateTo, redirectTo, navigateBack, viewImage }
- for (const i in obj) {
- this[i] = obj[i]
- }
- const { options, navList } = this.data
- const { type = 1 } = options
- const arr = [
- ['仍在馆', '已回收', '非馆目标'],
- ['已回收', '已入库', '非馆目标'],
- ]
- const temp = {}
- for (const i in navList) {
- temp[`navList[${i}].text`] = arr[type - 1][i]
- }
- temp['itemIndex'] = ~~type
- this.setData(temp)
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- const { navIndex, navList } = this.data
- const temp = {}
- temp[`navList[${navIndex}].pageNo`] = 1
- this.setData(temp)
- this.getData(() => {
- wx.stopPullDownRefresh()
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- const { navIndex, navList } = this.data
- const { isAll } = navList[navIndex]
- if (isAll) return
- this.getData()
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 获取头部信息
- */
- getHeaderData: function () {
- const continuousFn = { fn: this.getHeaderData, param: { ...arguments } }
- const { options, navList, items } = this.data
- const { libId, type } = options
- GetRecoveryListHeadInfo({ data: { libId, type }, continuousFn }).then(res => {
- const { league_name, league_address, tabcount = [], operUserList = [] } = res.data
- const temp = { league_name, league_address }
- if (tabcount.length > 0) {
- for (const [k, v] of tabcount.entries()) {
- temp[`navList[${k}].number`] = v
- }
- }
- if (operUserList.length > 0) {
- for (const [k, v] of operUserList.entries()) {
- temp[`items[${k}].name`] = v
- }
- }
- this.setData(temp)
- })
- },
- /**
- * 获取书籍列表
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getData, param: { ...arguments } }
- const { options, navIndex, navList } = this.data
- const { libId, type } = options
- const { list, pageNo, pageSize, stat } = navList[navIndex]
- GetRecoveryList({ data: { libId, type, stat, pageNo, pageSize }, continuousFn }).then(res => {
- const newList = res.data.list
- let tempList = []
- if (pageNo == 1) {
- tempList = newList
- } else {
- tempList = [...list, ...newList]
- }
- const temp = {}
- temp[`navList[${navIndex}].list`] = tempList
- temp[`navList[${navIndex}].pageNo`] = newList.length == pageSize ? ~~pageNo + 1 : pageNo
- temp[`navList[${navIndex}].isAll`] = newList.length < pageSize
- this.setData(temp)
- if (isFn(cb)) cb()
- }).catch(res => {
- if (isFn(cb)) cb()
- })
- },
- /**
- * 选择导航栏
- */
- selectNavCtl: function (e) {
- const { index } = e.currentTarget.dataset
- const { navIndex, navList } = this.data
- if (navIndex == index) return
- const temp = {}
- temp['navIndex'] = index
- temp[`navList[${index}].pageNo`] = 1
- this.setData(temp)
- this.getData()
- },
- /**
- * 扫书
- */
- scanCtl: function () {
- wx.scanCode({
- success: res => {
- const url = res.result
- const detailsId = url.split('_')[1].split('.')[0]
- if (!detailsId) {
- wx.showToast({
- title: qrcodeInvalidToastText,
- icon: 'none'
- })
- return
- }
- this.scanningFn(detailsId)
- }
- })
- },
- /**
- * 扫描获取详情
- */
- scanningFn: function (detailsId) {
- const continuousFn = { fn: this.scanningFn, param: { ...arguments } }
- const { options, navList, navIndex } = this.data
- const { list = [], number } = navList[navIndex]
- const { type, libId } = options
- DispatcherRecovery({ data: { detailsId, type, libId }, continuousFn }).then(res => {
- const temp = {}
- temp[`navList[${res.data.type - 1}].number`] = ~~navList[res.data.type - 1].number + 1
- temp[`navList[${navIndex}].number`] = number - 1
- this.setData(temp)
- wx.showToast({
- title: '扫描成功',
- })
- // if (detailsId) {
- // for (const [k, v] of list.entries()) {
- // if (v['detailsId'] == detailsId) {
- // list.splice(k, 1)
- // const temp = {}
- // temp[`navList[${res.data.type - 1}].number`] = ~~navList[res.data.type - 1].number + 1
- // temp[`navList[${navIndex}].number`] = number - 1
- // temp[`navList[${navIndex}].list`] = list
- // this.setData(temp)
- // wx.showToast({
- // title: '扫描成功',
- // })
- // break
- // }
- // }
- // }
- }).catch(res => {
- wx.showToast({
- title: res.msg,
- icon: 'none'
- })
- })
- },
- /**
- * 确认收书或者入库弹框
- */
- submitCtl: function () {
- const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
- const { options, navList, navIndex } = this.data
- const { libId, type } = options
- const { number } = navList[0]
- if (number > 0) {
- wx.showModal({
- title: '',
- content: type == 1 ? `目前回收仍差${number}本,是否确定结束盘点,一旦确定则视为书籍已丢失,请谨慎操作` : type == 2 ? `目前仍有${number}本书没有入库,一旦确定视为该书已丢失,并且完成撤馆操作,请谨慎选择` : '',
- success: res => {
- if (res.confirm) this.confirmFn()
- }
- })
- } else {
- this.confirmFn()
- }
- },
- /**
- * 确认收书或者入库
- */
- confirmFn: function () {
- const continuousFn = { fn: this.confirmFn, param: { ...arguments } }
- const { options } = this.data
- const { libId, type } = options
- ConfirmRecovery({ data: { libId, type }, continuousFn }).then(res => {
- wx.showToast({
- title: `${type == 1 ? '收书' : '入库'}成功`,
- duration: 2000
- })
- setTimeout(() => {
- navigateBack()
- }, 2000)
- })
- }
- })
|