123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583 |
- // parents/pages/information/information.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
- import { CheckBookCard, GetBookInfoByIsbn, AddBook, BookCase, SaveBookcase, UploadFile} from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData, hasLibraryService, hasVipService } = getApp()
- const { baseImgUrl, qrcodeInvalidToastText } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- isLoaded: 1,
- bookInfo: {
- author: "",
- childTheme: "",
- csIndex: "",
- isbn13: "",
- localImage: "",
- price: "",
- section: "",
- summary: "",
- title: ""
- },
- value:[2,1],
- pickerABShow:false,
- pickerCDShow: false,
- abValue:[0,0],
- cdValue: [0,0],
- isFirst:true,
- isTwo: false,
- isScan:false,
- isOperation:false,
- isFerfect:false,
- isBtn: false,
- isDetail:false,
- user_vipId:"",
- gradeArray: ['学前段', '低年段', '中年段', '高年段'],
- gradeIndex: 0,
- themeListIndex: 0,
- list: [
- {
- "csIndex": "8",
- "title": ""
- },
- {
- "csIndex": "9",
- "title": ""
- },
- {
- "csIndex": "10",
- "title": ""
- },
- {
- "csIndex": "11",
- "title": ""
- },
- {
- "csIndex": "12",
- "title": ""
- },
- {
- "csIndex": "13",
- "title": ""
- },
- {
- "csIndex": "14",
- "title": ""
- },
- {
- "csIndex": "15",
- "title": ""
- }
- ],
- A: [
- {
- "code": "A01",
- "isCheck": 0
- },
- {
- "code": "A02",
- "isCheck":1
- },
- {
- "code": "A03",
- "isCheck": 0
- },
- {
- "code": "A04",
- "isCheck": 0
- }
- ],
- B: [
- {
- "code": "B01",
- "isCheck": 0
- },
- {
- "code": "B02",
- "isCheck": 1
- },
- {
- "code": "B03",
- "isCheck": 0
- }
- ],
- C: [
- {
- "code": "C01",
- "isCheck": 0
- },
- {
- "code": "C02",
- "isCheck": 1
- },
- {
- "code": "C03",
- "isCheck": 0
- }
- ],
- D: [
- {
- "code": "D01",
- "isCheck": 0
- },
- {
- "code": "D02",
- "isCheck": 1
- },
- {
- "code": "D03",
- "isCheck": 0
- }
- ],
- numIndex:0,
- bookInfo: {},
- themeList: [],
- serialType: "1",
- footerArray: [
- {
- type: 1,
- text: '取消'
- },
- {
- type: 2,
- text: '保存'
- }
- ]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
- options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
- this.setData(options)
- // const user_vipId = wx.getStorageSync("vipId")
- // this.setData({
- // user_vipId: user_vipId
- // });
- // options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
- // this.setData({ options })
- // this.getData(res => {
- // this.setData({ isLoaded: 1 })
- // })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- 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 () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 获取个人资料
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getData, param: { ...arguments } }
- const { user_vipId } = this.data
- VipInfo({ data: { vipId: user_vipId }, continuousFn }).then(res => {
- this.setData({ signList: { ...res.data } })
- cb && cb(res)
- }).catch(res => {
- cb && cb(res)
- })
- },
- /**
- * 上传头像
- */
- uploadImgCtl: function () {
- const continuousFn = { fn: this.uploadImgCtl, param: { ...arguments } }
- const { bookInfo } = this.data
- wx.chooseImage({
- count: 1,
- success: res => {
- UploadFile({ file: res.tempFilePaths, continuousFn }).then(res => {
- bookInfo.localImage = res[0]
- this.setData({ bookInfo })
- })
- }
- })
- },
-
- /**
- * 保存输入值
- */
- inputCtl: function (e) {
- const { value } = e.detail
- const { type } = e.currentTarget.dataset
- const { bookInfo } = this.data
- bookInfo[type] = value
- this.setData({ bookInfo })
- },
- /**
- * 手动输入isbn13
- */
- isbn13Ctl:function(e){
- const { value } = e.detail
- this.setData({ isbn13: value})
- },
- /**
- * 改变年级
- */
- pickerGradeCtl: function (e) {
- const { value } = e.detail
- const { gradeArray, gradeIndex, bookInfo } = this.data
- if (value == gradeIndex) {
- return
- }
- bookInfo.section = gradeArray[value]
- this.setData({ bookInfo, gradeIndex: value })
- },
- /**
- * 改变主题
- */
- pickerThemeCtl: function (e) {
- const { value } = e.detail
- const { themeList, themeListIndex, bookInfo, themeOldList } = this.data
- bookInfo.childTheme = themeOldList[value].code
- this.setData({ bookInfo, themeListIndex: value, childTheme: themeOldList[value].name })
- },
- /**
- * 提交按钮
- */
- operationCtl:function(e){
- const { type } = e.currentTarget.dataset
- if (type == 1) {
- wx.navigateBack({
- delta: 1
- })
- } else if (type == 2) {
- this.setBookInfoByIsbn()
- }
- },
- /**
- * 提交按钮
- */
- submitCtl: function (e) {
- const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
- const { type } = e.currentTarget.dataset
- const { bookInfo, libId, detailsId} = this.data
- if (type == 1) {
- wx.navigateBack({
- delta: 1
- })
- } else if (type == 2) {
- AddBook({ data: { ...bookInfo, libId, id:detailsId}, continuousFn }).then(res => {
- wx.showToast({
- title: '保存成功',
- })
- setTimeout(() => {
- navigateBack()
- }, 2000)
- })
- }
- },
- /**
- * 扫一扫书籍标签二维码
- */
- codeScanCtl: function () {
- wx.scanCode({
- success: res => {
- const url = res.result
- const detailsId = url.split('_')[1].split('.')[0]
- console.log(res)
- if (!detailsId) {
- wx.showToast({
- title: qrcodeInvalidToastText,
- icon: 'none'
- })
- return
- }
- this.setData({ detailsId })
- this.setValid()
- }
- })
- },
- /**
- * 是否有效二维码
- */
- setValid: function () {
- const continuousFn = { fn: this.setValid, param: { ...arguments } }
- const { libId, detailsId } = this.data
- CheckBookCard({ data: { libId, detailsId }, continuousFn }).then(res => {
- const { isValid}=res.data;
- if (isValid==1){
- wx.showToast({
- title: '此二维码有效',
- duration:1500,
- icon:'none'
- })
- this.setData({ isScan:true})
- }else{
- wx.showToast({
- title: '此二维码无效',
- icon: 'none'
- })
- }
- })
- },
- getOperation:function(){
- this.setData({ isOperation: true, isFirst:false})
- },
- /**
- * 调用微信扫一扫
- */
- scanFn: function () {
- wx.scanCode({
- success: res => {
- const url = res.result
- const type = res.scanType
- console.log(res)
- if (type != 'EAN_13'&&type != 'EAN_10') {
- wx.showToast({
- title: qrcodeInvalidToastText,
- icon: 'none'
- })
- return
- }
- this.setData({ isbn13: url })
- this.setBookInfoByIsbn()
- }
- })
- },
- /**
- * 扫一扫---图书录入-完善货架
- */
- ferfectScanCtl:function(){
- wx.scanCode({
- success: res => {
- const url = res.result
- const detailsId = url.split('_')[1].split('.')[0]
- console.log(res.result)
- if (!detailsId) {
- wx.showToast({
- title: qrcodeInvalidToastText,
- icon: 'none'
- })
- return
- }
- this.setData({ isFerfect: true, isTwo: false, detailsId })
- this.setBookCase()
- }
- })
- },
- /**
- * 根据isbn13查询书籍信息
- */
- setBookCase: function() {
- const continuousFn = { fn: this.setBookCase, param: { ...arguments } }
- const that = this
- const { A, B, C, D, detailsId}=this.data
- const abValue=[]
- const cdValue = []
- BookCase({ data: { detailsId }, continuousFn }).then(res => {
- const { title, localImage, detailId, price,A,B,C,D } = res.data;
- if (A.length>0){
- for (var i in A) {
- if (A[i].isCheck == 1) {
- abValue[0] = i
- } else {
- abValue[0] = 0
- }
- }
- }
- if (B.length > 0) {
- for (var i in B) {
- if (B[i].isCheck == 1) {
- abValue[1] = i
- } else {
- abValue[1] = 0
- }
- }
- }
- if (C.length > 0) {
- for (var i in C) {
- if (C[i].isCheck == 1) {
- cdValue[0] = i
- } else {
- cdValue[0] = 0
- }
- }
- }
- if (D.length > 0) {
- for (var i in D) {
- if (D[i].isCheck == 1) {
- cdValue[1] = i
- } else {
- cdValue[1] = 0
- }
- }
- }
- const abNumber = A[abValue[0]].code + ';' + B[abValue[1]].code
- const cdNumber = C[cdValue[0]].code + ';' + C[cdValue[1]].code
- that.setData({ title, localImage, detailId, price, A, B, C, D, abValue, cdValue, abNumber, cdNumber})
- })
- },
- /**
- * 填写价格
- */
- priceInputCtl: function (e) {
- const { value } = e.detail
- this.setData({ price: value })
- },
- /**
- * 显示货架AB
- */
- clickAB:function(){
- this.setData({ pickerABShow: true, pickerCDShow:false})
- },
- /**
- * 显示货架CD
- */
- clickCD: function () {
- this.setData({ pickerCDShow: true, pickerABShow:false })
- },
- /**
- * 选择货架AB
- */
- bindChangeAB: function (e) {
- console.log(e)
- const { value } = e.detail
- this.setData({ abValue: value })
- },
- /**
- * 选择货架CD
- */
- bindChangeCD: function (e) {
- const { value } = e.detail
- this.setData({ cdValue: value })
- },
- /**
- * 完成选择货架
- */
- finish:function(e){
- const { type } = e.currentTarget.dataset;
- const { abValue, cdValue,A,B,C,D}=this.data;
- // console.log(abValue, cdValue, A, B, C, D)
- if(type==0){
- const abNumber = A[abValue[0]].code + ';' + B[abValue[1]].code
- this.setData({ abNumber, pickerABShow:false})
- }else{
- const cdNumber = C[cdValue[0]].code + ';' + C[cdValue[1]].code
- this.setData({ cdNumber, pickerCDShow: false })
- }
- },
- /**
- * 完成选择货架
- */
- saveGoods:function(e){
- const continuousFn = { fn: this.saveGoods, param: { ...arguments } }
- const { type } = e.currentTarget.dataset
- const { abValue, cdValue, A, B, C, D, detailsId,price } = this.data
- const bookcase = A[abValue[0]].code + '-' + B[abValue[1]].code +'-'+ C[cdValue[0]].code + '-' + C[cdValue[1]].code
- if (type == 1) {
- wx.navigateBack({
- delta: 1
- })
- } else if (type == 2) {
- if (!price) {
- wx.showToast({
- title: '请填写价格',
- icon: 'none'
- })
- return
- }
- SaveBookcase({ data: { detailsId, price, bookcase }, continuousFn }).then(res => {
- wx.showToast({
- title: '保存成功',
- })
- setTimeout(() => {
- navigateBack()
- }, 2000)
- })
- }
- },
- /**
- * 根据isbn13查询书籍信息
- */
- setBookInfoByIsbn: function () {
- const continuousFn = { fn: this.setBookInfoByIsbn, param: { ...arguments } }
- const { isbn13, csIndex } = this.data
- const that=this
- GetBookInfoByIsbn({ data: { isbn13, csIndex }, continuousFn }).then(res => {
- const { serialType, list, bookInfo, themeList } = res.data;
- const { childTheme } = bookInfo
- if (list){
- const data = (res => {
- const arr = []
- for (const i in res) {
- arr.push(res[i].csIndex)
- }
- return arr
- })(list)
- that.setData({ list:data})
- }
- if (themeList) {
- // console.log(themeList)
- const themedata = (res => {
- const themearr = []
- // console.log(res)
- for (const i in res) {
- themearr.push(res[i].name)
- }
- return themearr
- })(themeList)
- that.setData({ themeList: themedata, themeOldList: themeList })
- }
-
- that.setData({ serialType, bookInfo, childTheme, isDetail: true, isFirst: false, isOperation:false,isBtn:true})
- })
- }
- })
|