withdraw.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. // dispatcher/pages/withdraw/withdraw.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { GetRecoveryListHeadInfo, GetRecoveryList, DispatcherRecovery, ConfirmRecovery } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isLoaded: false,
  14. league_name: '',
  15. league_address: '',
  16. itemIndex: 0,
  17. items: [
  18. {
  19. icon: '../../../assets/dispatch_icon_1_gray.png',
  20. actIcon: '../../../assets/dispatch_icon_1_blue.png',
  21. text: '开始撤馆',
  22. name: '',
  23. },
  24. {
  25. icon: '../../../assets/dispatch_icon_2_gray.png',
  26. actIcon: '../../../assets/dispatch_icon_2_blue.png',
  27. text: '书籍回收',
  28. name: '',
  29. },
  30. {
  31. icon: '../../../assets/dispatch_icon_3_gray.png',
  32. actIcon: '../../../assets/dispatch_icon_3_blue.png',
  33. text: '盘点归库',
  34. name: '',
  35. },
  36. ],
  37. navIndex: 0,
  38. navList: [
  39. {
  40. text: '',
  41. stat: 1,
  42. pageNo: 1,
  43. pageSize: 10,
  44. isAll: false,
  45. list: [
  46. // {
  47. // detailsId: 1,
  48. // },
  49. // {
  50. // detailsId: 2,
  51. // },
  52. // {
  53. // detailsId: 3,
  54. // },
  55. // {
  56. // detailsId: 4,
  57. // },
  58. // {
  59. // detailsId: 5,
  60. // },
  61. // {
  62. // detailsId: 6,
  63. // },
  64. ],
  65. number: 0,
  66. nodataArray: {
  67. text: '暂无书籍',
  68. image: '../../../assets/nodata_1.png',
  69. // hasNodataBtn: 1,
  70. // btnText: '扫码收书'
  71. }
  72. },
  73. {
  74. text: '',
  75. stat: 2,
  76. pageNo: 1,
  77. pageSize: 10,
  78. isAll: false,
  79. list: [],
  80. number: 0,
  81. nodataArray: {
  82. text: '暂无书籍',
  83. image: '../../../assets/nodata_1.png',
  84. // hasNodataBtn: 1,
  85. // btnText: '扫码收书'
  86. }
  87. },
  88. {
  89. text: '',
  90. stat: 3,
  91. pageNo: 1,
  92. pageSize: 10,
  93. isAll: false,
  94. list: [],
  95. number: 0,
  96. nodataArray: {
  97. text: '暂无书籍',
  98. image: '../../../assets/nodata_1.png',
  99. // hasNodataBtn: 1,
  100. // btnText: '扫码收书'
  101. }
  102. },
  103. ],
  104. },
  105. /**
  106. * 生命周期函数--监听页面加载
  107. */
  108. onLoad: function (options) {
  109. this.setData({ options })
  110. this.getHeaderData()
  111. this.getData(() => {
  112. this.setData({ isLoaded: true })
  113. })
  114. },
  115. /**
  116. * 生命周期函数--监听页面初次渲染完成
  117. */
  118. onReady: function () {
  119. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  120. for (const i in obj) {
  121. this[i] = obj[i]
  122. }
  123. const { options, navList } = this.data
  124. const { type = 1 } = options
  125. const arr = [
  126. ['仍在馆', '已回收', '非馆目标'],
  127. ['已回收', '已入库', '非馆目标'],
  128. ]
  129. const temp = {}
  130. for (const i in navList) {
  131. temp[`navList[${i}].text`] = arr[type - 1][i]
  132. }
  133. temp['itemIndex'] = ~~type
  134. this.setData(temp)
  135. },
  136. /**
  137. * 生命周期函数--监听页面显示
  138. */
  139. onShow: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面隐藏
  143. */
  144. onHide: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面卸载
  148. */
  149. onUnload: function () {
  150. },
  151. /**
  152. * 页面相关事件处理函数--监听用户下拉动作
  153. */
  154. onPullDownRefresh: function () {
  155. const { navIndex, navList } = this.data
  156. const temp = {}
  157. temp[`navList[${navIndex}].pageNo`] = 1
  158. this.setData(temp)
  159. this.getData(() => {
  160. wx.stopPullDownRefresh()
  161. })
  162. },
  163. /**
  164. * 页面上拉触底事件的处理函数
  165. */
  166. onReachBottom: function () {
  167. const { navIndex, navList } = this.data
  168. const { isAll } = navList[navIndex]
  169. if (isAll) return
  170. this.getData()
  171. },
  172. /**
  173. * 用户点击右上角分享
  174. */
  175. onShareAppMessage: function () {
  176. if (isFn(sharePage)) return sharePage()
  177. },
  178. /**
  179. * 获取头部信息
  180. */
  181. getHeaderData: function () {
  182. const continuousFn = { fn: this.getHeaderData, param: { ...arguments } }
  183. const { options, navList, items } = this.data
  184. const { libId, type } = options
  185. GetRecoveryListHeadInfo({ data: { libId, type }, continuousFn }).then(res => {
  186. const { league_name, league_address, tabcount = [], operUserList = [] } = res.data
  187. const temp = { league_name, league_address }
  188. if (tabcount.length > 0) {
  189. for (const [k, v] of tabcount.entries()) {
  190. temp[`navList[${k}].number`] = v
  191. }
  192. }
  193. if (operUserList.length > 0) {
  194. for (const [k, v] of operUserList.entries()) {
  195. temp[`items[${k}].name`] = v
  196. }
  197. }
  198. this.setData(temp)
  199. })
  200. },
  201. /**
  202. * 获取书籍列表
  203. */
  204. getData: function (cb) {
  205. const continuousFn = { fn: this.getData, param: { ...arguments } }
  206. const { options, navIndex, navList } = this.data
  207. const { libId, type } = options
  208. const { list, pageNo, pageSize, stat } = navList[navIndex]
  209. GetRecoveryList({ data: { libId, type, stat, pageNo, pageSize }, continuousFn }).then(res => {
  210. const newList = res.data.list
  211. let tempList = []
  212. if (pageNo == 1) {
  213. tempList = newList
  214. } else {
  215. tempList = [...list, ...newList]
  216. }
  217. const temp = {}
  218. temp[`navList[${navIndex}].list`] = tempList
  219. temp[`navList[${navIndex}].pageNo`] = newList.length == pageSize ? ~~pageNo + 1 : pageNo
  220. temp[`navList[${navIndex}].isAll`] = newList.length < pageSize
  221. this.setData(temp)
  222. if (isFn(cb)) cb()
  223. }).catch(res => {
  224. if (isFn(cb)) cb()
  225. })
  226. },
  227. /**
  228. * 选择导航栏
  229. */
  230. selectNavCtl: function (e) {
  231. const { index } = e.currentTarget.dataset
  232. const { navIndex, navList } = this.data
  233. if (navIndex == index) return
  234. const temp = {}
  235. temp['navIndex'] = index
  236. temp[`navList[${index}].pageNo`] = 1
  237. this.setData(temp)
  238. this.getData()
  239. },
  240. /**
  241. * 扫书
  242. */
  243. scanCtl: function () {
  244. wx.scanCode({
  245. success: res => {
  246. const url = res.result
  247. const detailsId = url.split('_')[1].split('.')[0]
  248. if (!detailsId) {
  249. wx.showToast({
  250. title: qrcodeInvalidToastText,
  251. icon: 'none'
  252. })
  253. return
  254. }
  255. this.scanningFn(detailsId)
  256. }
  257. })
  258. },
  259. /**
  260. * 扫描获取详情
  261. */
  262. scanningFn: function (detailsId) {
  263. const continuousFn = { fn: this.scanningFn, param: { ...arguments } }
  264. const { options, navList, navIndex } = this.data
  265. const { list = [], number } = navList[navIndex]
  266. const { type, libId } = options
  267. DispatcherRecovery({ data: { detailsId, type, libId }, continuousFn }).then(res => {
  268. const temp = {}
  269. temp[`navList[${res.data.type - 1}].number`] = ~~navList[res.data.type - 1].number + 1
  270. temp[`navList[${navIndex}].number`] = number - 1
  271. this.setData(temp)
  272. wx.showToast({
  273. title: '扫描成功',
  274. })
  275. // if (detailsId) {
  276. // for (const [k, v] of list.entries()) {
  277. // if (v['detailsId'] == detailsId) {
  278. // list.splice(k, 1)
  279. // const temp = {}
  280. // temp[`navList[${res.data.type - 1}].number`] = ~~navList[res.data.type - 1].number + 1
  281. // temp[`navList[${navIndex}].number`] = number - 1
  282. // temp[`navList[${navIndex}].list`] = list
  283. // this.setData(temp)
  284. // wx.showToast({
  285. // title: '扫描成功',
  286. // })
  287. // break
  288. // }
  289. // }
  290. // }
  291. }).catch(res => {
  292. wx.showToast({
  293. title: res.msg,
  294. icon: 'none'
  295. })
  296. })
  297. },
  298. /**
  299. * 确认收书或者入库弹框
  300. */
  301. submitCtl: function () {
  302. const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
  303. const { options, navList, navIndex } = this.data
  304. const { libId, type } = options
  305. const { number } = navList[0]
  306. if (number > 0) {
  307. wx.showModal({
  308. title: '',
  309. content: type == 1 ? `目前回收仍差${number}本,是否确定结束盘点,一旦确定则视为书籍已丢失,请谨慎操作` : type == 2 ? `目前仍有${number}本书没有入库,一旦确定视为该书已丢失,并且完成撤馆操作,请谨慎选择` : '',
  310. success: res => {
  311. if (res.confirm) this.confirmFn()
  312. }
  313. })
  314. } else {
  315. this.confirmFn()
  316. }
  317. },
  318. /**
  319. * 确认收书或者入库
  320. */
  321. confirmFn: function () {
  322. const continuousFn = { fn: this.confirmFn, param: { ...arguments } }
  323. const { options } = this.data
  324. const { libId, type } = options
  325. ConfirmRecovery({ data: { libId, type }, continuousFn }).then(res => {
  326. wx.showToast({
  327. title: `${type == 1 ? '收书' : '入库'}成功`,
  328. duration: 2000
  329. })
  330. setTimeout(() => {
  331. navigateBack()
  332. }, 2000)
  333. })
  334. }
  335. })