book_entry.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. // parents/pages/information/information.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { CheckBookCard, GetBookInfoByIsbn, AddBook, BookCase, SaveBookcase, UploadFile} from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService } = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isLoaded: 1,
  14. bookInfo: {
  15. author: "",
  16. childTheme: "",
  17. csIndex: "",
  18. isbn13: "",
  19. localImage: "",
  20. price: "",
  21. section: "",
  22. summary: "",
  23. title: ""
  24. },
  25. value:[2,1],
  26. pickerABShow:false,
  27. pickerCDShow: false,
  28. abValue:[0,0],
  29. cdValue: [0,0],
  30. isFirst:true,
  31. isTwo: false,
  32. isScan:false,
  33. isOperation:false,
  34. isFerfect:false,
  35. isBtn: false,
  36. isDetail:false,
  37. user_vipId:"",
  38. gradeArray: ['学前段', '低年段', '中年段', '高年段'],
  39. gradeIndex: 0,
  40. themeListIndex: 0,
  41. list: [
  42. {
  43. "csIndex": "8",
  44. "title": ""
  45. },
  46. {
  47. "csIndex": "9",
  48. "title": ""
  49. },
  50. {
  51. "csIndex": "10",
  52. "title": ""
  53. },
  54. {
  55. "csIndex": "11",
  56. "title": ""
  57. },
  58. {
  59. "csIndex": "12",
  60. "title": ""
  61. },
  62. {
  63. "csIndex": "13",
  64. "title": ""
  65. },
  66. {
  67. "csIndex": "14",
  68. "title": ""
  69. },
  70. {
  71. "csIndex": "15",
  72. "title": ""
  73. }
  74. ],
  75. A: [
  76. {
  77. "code": "A01",
  78. "isCheck": 0
  79. },
  80. {
  81. "code": "A02",
  82. "isCheck":1
  83. },
  84. {
  85. "code": "A03",
  86. "isCheck": 0
  87. },
  88. {
  89. "code": "A04",
  90. "isCheck": 0
  91. }
  92. ],
  93. B: [
  94. {
  95. "code": "B01",
  96. "isCheck": 0
  97. },
  98. {
  99. "code": "B02",
  100. "isCheck": 1
  101. },
  102. {
  103. "code": "B03",
  104. "isCheck": 0
  105. }
  106. ],
  107. C: [
  108. {
  109. "code": "C01",
  110. "isCheck": 0
  111. },
  112. {
  113. "code": "C02",
  114. "isCheck": 1
  115. },
  116. {
  117. "code": "C03",
  118. "isCheck": 0
  119. }
  120. ],
  121. D: [
  122. {
  123. "code": "D01",
  124. "isCheck": 0
  125. },
  126. {
  127. "code": "D02",
  128. "isCheck": 1
  129. },
  130. {
  131. "code": "D03",
  132. "isCheck": 0
  133. }
  134. ],
  135. numIndex:0,
  136. bookInfo: {},
  137. themeList: [],
  138. serialType: "1",
  139. footerArray: [
  140. {
  141. type: 1,
  142. text: '取消'
  143. },
  144. {
  145. type: 2,
  146. text: '保存'
  147. }
  148. ]
  149. },
  150. /**
  151. * 生命周期函数--监听页面加载
  152. */
  153. onLoad: function (options) {
  154. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  155. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  156. this.setData(options)
  157. // const user_vipId = wx.getStorageSync("vipId")
  158. // this.setData({
  159. // user_vipId: user_vipId
  160. // });
  161. // options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
  162. // this.setData({ options })
  163. // this.getData(res => {
  164. // this.setData({ isLoaded: 1 })
  165. // })
  166. },
  167. /**
  168. * 生命周期函数--监听页面初次渲染完成
  169. */
  170. onReady: function () {
  171. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  172. for (const i in obj) {
  173. this[i] = obj[i]
  174. }
  175. },
  176. /**
  177. * 生命周期函数--监听页面显示
  178. */
  179. onShow: function () {
  180. },
  181. /**
  182. * 生命周期函数--监听页面隐藏
  183. */
  184. onHide: function () {
  185. },
  186. /**
  187. * 生命周期函数--监听页面卸载
  188. */
  189. onUnload: function () {
  190. },
  191. /**
  192. * 页面相关事件处理函数--监听用户下拉动作
  193. */
  194. onPullDownRefresh: function () {
  195. },
  196. /**
  197. * 页面上拉触底事件的处理函数
  198. */
  199. onReachBottom: function () {
  200. },
  201. /**
  202. * 用户点击右上角分享
  203. */
  204. onShareAppMessage: function () {
  205. if (isFn(sharePage)) return sharePage()
  206. },
  207. /**
  208. * 获取个人资料
  209. */
  210. getData: function (cb) {
  211. const continuousFn = { fn: this.getData, param: { ...arguments } }
  212. const { user_vipId } = this.data
  213. VipInfo({ data: { vipId: user_vipId }, continuousFn }).then(res => {
  214. this.setData({ signList: { ...res.data } })
  215. cb && cb(res)
  216. }).catch(res => {
  217. cb && cb(res)
  218. })
  219. },
  220. /**
  221. * 上传头像
  222. */
  223. uploadImgCtl: function () {
  224. const continuousFn = { fn: this.uploadImgCtl, param: { ...arguments } }
  225. const { bookInfo } = this.data
  226. wx.chooseImage({
  227. count: 1,
  228. success: res => {
  229. UploadFile({ file: res.tempFilePaths, continuousFn }).then(res => {
  230. bookInfo.localImage = res[0]
  231. this.setData({ bookInfo })
  232. })
  233. }
  234. })
  235. },
  236. /**
  237. * 保存输入值
  238. */
  239. inputCtl: function (e) {
  240. const { value } = e.detail
  241. const { type } = e.currentTarget.dataset
  242. const { bookInfo } = this.data
  243. bookInfo[type] = value
  244. this.setData({ bookInfo })
  245. },
  246. /**
  247. * 手动输入isbn13
  248. */
  249. isbn13Ctl:function(e){
  250. const { value } = e.detail
  251. this.setData({ isbn13: value})
  252. },
  253. /**
  254. * 改变年级
  255. */
  256. pickerGradeCtl: function (e) {
  257. const { value } = e.detail
  258. const { gradeArray, gradeIndex, bookInfo } = this.data
  259. if (value == gradeIndex) {
  260. return
  261. }
  262. bookInfo.section = gradeArray[value]
  263. this.setData({ bookInfo, gradeIndex: value })
  264. },
  265. /**
  266. * 改变主题
  267. */
  268. pickerThemeCtl: function (e) {
  269. const { value } = e.detail
  270. const { themeList, themeListIndex, bookInfo, themeOldList } = this.data
  271. bookInfo.childTheme = themeOldList[value].code
  272. this.setData({ bookInfo, themeListIndex: value, childTheme: themeOldList[value].name })
  273. },
  274. /**
  275. * 提交按钮
  276. */
  277. operationCtl:function(e){
  278. const { type } = e.currentTarget.dataset
  279. if (type == 1) {
  280. wx.navigateBack({
  281. delta: 1
  282. })
  283. } else if (type == 2) {
  284. this.setBookInfoByIsbn()
  285. }
  286. },
  287. /**
  288. * 提交按钮
  289. */
  290. submitCtl: function (e) {
  291. const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
  292. const { type } = e.currentTarget.dataset
  293. const { bookInfo, libId, detailsId} = this.data
  294. if (type == 1) {
  295. wx.navigateBack({
  296. delta: 1
  297. })
  298. } else if (type == 2) {
  299. AddBook({ data: { ...bookInfo, libId, id:detailsId}, continuousFn }).then(res => {
  300. wx.showToast({
  301. title: '保存成功',
  302. })
  303. setTimeout(() => {
  304. navigateBack()
  305. }, 2000)
  306. })
  307. }
  308. },
  309. /**
  310. * 扫一扫书籍标签二维码
  311. */
  312. codeScanCtl: function () {
  313. wx.scanCode({
  314. success: res => {
  315. const url = res.result
  316. const detailsId = url.split('_')[1].split('.')[0]
  317. console.log(res)
  318. if (!detailsId) {
  319. wx.showToast({
  320. title: qrcodeInvalidToastText,
  321. icon: 'none'
  322. })
  323. return
  324. }
  325. this.setData({ detailsId })
  326. this.setValid()
  327. }
  328. })
  329. },
  330. /**
  331. * 是否有效二维码
  332. */
  333. setValid: function () {
  334. const continuousFn = { fn: this.setValid, param: { ...arguments } }
  335. const { libId, detailsId } = this.data
  336. CheckBookCard({ data: { libId, detailsId }, continuousFn }).then(res => {
  337. const { isValid}=res.data;
  338. if (isValid==1){
  339. wx.showToast({
  340. title: '此二维码有效',
  341. duration:1500,
  342. icon:'none'
  343. })
  344. this.setData({ isScan:true})
  345. }else{
  346. wx.showToast({
  347. title: '此二维码无效',
  348. icon: 'none'
  349. })
  350. }
  351. })
  352. },
  353. getOperation:function(){
  354. this.setData({ isOperation: true, isFirst:false})
  355. },
  356. /**
  357. * 调用微信扫一扫
  358. */
  359. scanFn: function () {
  360. wx.scanCode({
  361. success: res => {
  362. const url = res.result
  363. const type = res.scanType
  364. console.log(res)
  365. if (type != 'EAN_13'&&type != 'EAN_10') {
  366. wx.showToast({
  367. title: qrcodeInvalidToastText,
  368. icon: 'none'
  369. })
  370. return
  371. }
  372. this.setData({ isbn13: url })
  373. this.setBookInfoByIsbn()
  374. }
  375. })
  376. },
  377. /**
  378. * 扫一扫---图书录入-完善货架
  379. */
  380. ferfectScanCtl:function(){
  381. wx.scanCode({
  382. success: res => {
  383. const url = res.result
  384. const detailsId = url.split('_')[1].split('.')[0]
  385. console.log(res.result)
  386. if (!detailsId) {
  387. wx.showToast({
  388. title: qrcodeInvalidToastText,
  389. icon: 'none'
  390. })
  391. return
  392. }
  393. this.setData({ isFerfect: true, isTwo: false, detailsId })
  394. this.setBookCase()
  395. }
  396. })
  397. },
  398. /**
  399. * 根据isbn13查询书籍信息
  400. */
  401. setBookCase: function() {
  402. const continuousFn = { fn: this.setBookCase, param: { ...arguments } }
  403. const that = this
  404. const { A, B, C, D, detailsId}=this.data
  405. const abValue=[]
  406. const cdValue = []
  407. BookCase({ data: { detailsId }, continuousFn }).then(res => {
  408. const { title, localImage, detailId, price,A,B,C,D } = res.data;
  409. if (A.length>0){
  410. for (var i in A) {
  411. if (A[i].isCheck == 1) {
  412. abValue[0] = i
  413. } else {
  414. abValue[0] = 0
  415. }
  416. }
  417. }
  418. if (B.length > 0) {
  419. for (var i in B) {
  420. if (B[i].isCheck == 1) {
  421. abValue[1] = i
  422. } else {
  423. abValue[1] = 0
  424. }
  425. }
  426. }
  427. if (C.length > 0) {
  428. for (var i in C) {
  429. if (C[i].isCheck == 1) {
  430. cdValue[0] = i
  431. } else {
  432. cdValue[0] = 0
  433. }
  434. }
  435. }
  436. if (D.length > 0) {
  437. for (var i in D) {
  438. if (D[i].isCheck == 1) {
  439. cdValue[1] = i
  440. } else {
  441. cdValue[1] = 0
  442. }
  443. }
  444. }
  445. const abNumber = A[abValue[0]].code + ';' + B[abValue[1]].code
  446. const cdNumber = C[cdValue[0]].code + ';' + C[cdValue[1]].code
  447. that.setData({ title, localImage, detailId, price, A, B, C, D, abValue, cdValue, abNumber, cdNumber})
  448. })
  449. },
  450. /**
  451. * 填写价格
  452. */
  453. priceInputCtl: function (e) {
  454. const { value } = e.detail
  455. this.setData({ price: value })
  456. },
  457. /**
  458. * 显示货架AB
  459. */
  460. clickAB:function(){
  461. this.setData({ pickerABShow: true, pickerCDShow:false})
  462. },
  463. /**
  464. * 显示货架CD
  465. */
  466. clickCD: function () {
  467. this.setData({ pickerCDShow: true, pickerABShow:false })
  468. },
  469. /**
  470. * 选择货架AB
  471. */
  472. bindChangeAB: function (e) {
  473. console.log(e)
  474. const { value } = e.detail
  475. this.setData({ abValue: value })
  476. },
  477. /**
  478. * 选择货架CD
  479. */
  480. bindChangeCD: function (e) {
  481. const { value } = e.detail
  482. this.setData({ cdValue: value })
  483. },
  484. /**
  485. * 完成选择货架
  486. */
  487. finish:function(e){
  488. const { type } = e.currentTarget.dataset;
  489. const { abValue, cdValue,A,B,C,D}=this.data;
  490. // console.log(abValue, cdValue, A, B, C, D)
  491. if(type==0){
  492. const abNumber = A[abValue[0]].code + ';' + B[abValue[1]].code
  493. this.setData({ abNumber, pickerABShow:false})
  494. }else{
  495. const cdNumber = C[cdValue[0]].code + ';' + C[cdValue[1]].code
  496. this.setData({ cdNumber, pickerCDShow: false })
  497. }
  498. },
  499. /**
  500. * 完成选择货架
  501. */
  502. saveGoods:function(e){
  503. const continuousFn = { fn: this.saveGoods, param: { ...arguments } }
  504. const { type } = e.currentTarget.dataset
  505. const { abValue, cdValue, A, B, C, D, detailsId,price } = this.data
  506. const bookcase = A[abValue[0]].code + '-' + B[abValue[1]].code +'-'+ C[cdValue[0]].code + '-' + C[cdValue[1]].code
  507. if (type == 1) {
  508. wx.navigateBack({
  509. delta: 1
  510. })
  511. } else if (type == 2) {
  512. if (!price) {
  513. wx.showToast({
  514. title: '请填写价格',
  515. icon: 'none'
  516. })
  517. return
  518. }
  519. SaveBookcase({ data: { detailsId, price, bookcase }, continuousFn }).then(res => {
  520. wx.showToast({
  521. title: '保存成功',
  522. })
  523. setTimeout(() => {
  524. navigateBack()
  525. }, 2000)
  526. })
  527. }
  528. },
  529. /**
  530. * 根据isbn13查询书籍信息
  531. */
  532. setBookInfoByIsbn: function () {
  533. const continuousFn = { fn: this.setBookInfoByIsbn, param: { ...arguments } }
  534. const { isbn13, csIndex } = this.data
  535. const that=this
  536. GetBookInfoByIsbn({ data: { isbn13, csIndex }, continuousFn }).then(res => {
  537. const { serialType, list, bookInfo, themeList } = res.data;
  538. const { childTheme } = bookInfo
  539. if (list){
  540. const data = (res => {
  541. const arr = []
  542. for (const i in res) {
  543. arr.push(res[i].csIndex)
  544. }
  545. return arr
  546. })(list)
  547. that.setData({ list:data})
  548. }
  549. if (themeList) {
  550. // console.log(themeList)
  551. const themedata = (res => {
  552. const themearr = []
  553. // console.log(res)
  554. for (const i in res) {
  555. themearr.push(res[i].name)
  556. }
  557. return themearr
  558. })(themeList)
  559. that.setData({ themeList: themedata, themeOldList: themeList })
  560. }
  561. that.setData({ serialType, bookInfo, childTheme, isDetail: true, isFirst: false, isOperation:false,isBtn:true})
  562. })
  563. }
  564. })