// pages/sorting/choice.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { inputval: '', fileList: [ ], fenid:0, tagnum:0, rgb: 'rgb(0,154,97)',//初始值 pick: false, color: "", col: '333333', title: "请选择衣物分类", cateid:0, show: false, flaws: [], standard: [], shows: false, results: 0, result: "", str: ['请选择'], rustr:"请选择", string:"", isshows:false, isworkstr:'a', iswork:['不加工','加工','需用户确认'], meoth:"save", ispick:"", iscolor:"", type:0, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.data.tagnum = options.seal_no var type= options.type this.data.fenid = options.fenid?options.fenid:0 if(options.fenid && options.fenid>0 && type!='parent'){ this.data.fenid = options.fenid this.data.meoth = "edit" this.data.type ="" this.getdata(); } if(type=='parent'){ this.data.type =1} }, onShow() { var pages = getCurrentPages(); var currPage = pages[pages.length - 1]; this.data.title = currPage.data.title this.data.cateid = currPage.data.id }, getdata(){ var that = this; app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/entry/FlawReport", { id:that.data.fenid }, "get").then(function (res) { console.log(res); if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading(); }, 1000); } else { wx.hideLoading(); var data = res.message.data var result=[]; for(var i in data.flaw){ result[i]=data.flaw[i].id } const { fileList = [] } = that.data; for(var i in data.images){ console.log(data.images[i]) fileList.push({url: data.images[i]}); } that.setData({ inputval:data.wash_code, title:data.cat_title, ispick:data.color, rustr:data.flaw[0].name, results:data.standard_id, isworkstr:data.is_machining, fileList, cateid:data.cate_id, result:result }) } }).catch(function (err) { console.log(err); }) }, // 显示取色器 toPick: function () { this.setData({ pick: !this.data.pick }) var that = this; app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/entry/SelectColor", { }, "get").then(function (res) { console.log(res); if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading(); }, 1000); } else { wx.hideLoading(); let color = res.message.data that.setData({ color }) } }).catch(function (err) { console.log(err); }) }, toShow() { this.setData({ show: !this.data.show }) if (this.data.show) { this.getwehre() } }, toShows() { this.setData({ shows: !this.data.shows }) if (this.data.shows) { this.getwehre() } }, isshows() { this.setData({ isshows: !this.data.isshows }) }, //取色结果回调 pickColor(e) { console.log(e) this.setData({ ispick: e.detail, }); }, onClickColor(event) { const { name } = event.currentTarget.dataset; console.log(name); this.setData({ ispick: name, }); }, toEnter() { wx.navigateTo({ url: '../enter/enter', }) }, bindinput(e) { this.setData({ inputval: e.detail.value }) }, inputw(e){ console.log(); //this.data.color=e.detail.value this.setData({ color: e.detail }) }, getScancode: function () { var _this = this; // 允许从相机和相册扫码 wx.scanCode({ onlyFromCamera: true, scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'], success: (res) => { console.log(res); var result = res.result; _this.setData({ inputval: result, }) }, fail: (err) => { console.log(err); } }) }, delete(e) { console.log(e) var filelist=this.data.fileList filelist.splice(e.detail.index,1); this.setData({ fileList:filelist }) }, clos(){ wx.navigateBack({ delta: 1 //想要返回的层级 }) }, checknum: function (seal_no) { var that = this; app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/sign", { seal_no: seal_no }, "post").then(function (res) { console.log(res); if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading(); }, 1000); } else { wx.hideLoading(); var data = res.message.data wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading(); }, 1000); } }).catch(function (err) { console.log(222); }) }, afterRead(event) { var that=this; const { file } = event.detail; // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式 wx.uploadFile({ url: app.globalData.baseAppUrl + 'api/common/uploadImg', // 仅为示例,非真实的接口地址 filePath: file.url, header: { "Content-Type": "multipart/form-data", 'accept': 'application/json', }, name: 'file', formData: { user: 'test' }, success(res) { var datas = JSON.parse(res.data) console.log(datas); if(datas.code==200){ // 上传完成需要更新 fileList const { fileList = [] } = that.data; fileList.push({ ...file, url: datas.message.data.path }); that.setData({ fileList }); }else{ wx.showLoading({ title: datas.message.msg, }) setTimeout(function () { wx.hideLoading(); }, 1000); } }, }); }, noop(e){ console.log(e) }, onChange(event) { console.log(event) var detail=event.detail if(!event.detail || event.detail=="" || event.detail==undefined){ detail=false; } var rustr=detail?this.data.string[event.detail]:"" this.setData({ result:detail , rustr:rustr }); }, Change(event) { console.log(event.detail) this.setData({ results: event.detail, }); }, isChange(event){ console.log(event.detail) this.setData({ isworkstr: event.detail, }); }, toggle(event) { const { index } = event.currentTarget.dataset; const checkbox = this.selectComponent(`.checkboxes-${index}`); console.log(checkbox); checkbox.toggle(); }, noop() { }, getwehre() { var that = this; app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/flaw", { }, "get").then(function (res) { console.log(res); if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading(); }, 1000); } else { wx.hideLoading(); var data = res.message.data var str=[]; var string =[]; for (var index in data.standard) { str[data.standard[index].id] = data.standard[index].title } for (var index in data.flaws) { string[data.flaws[index].id] = data.flaws[index].name } that.setData({ flaws: data.flaws, standard: data.standard, str: str, string:string }) } }).catch(function (err) { console.log(err); }) }, addSoting(){ var that = this; var fileList=this.data.fileList; var images=[] fileList.map((item, index) => { images[index]=item.url }) if(this.data.cateid==0){ wx.showLoading({ title: "衣物分类必须选择", }) setTimeout(function () { wx.hideLoading(); }, 1000); return false; } if(this.data.tagnum==0){ wx.showLoading({ title: "数据错误请返回重试", }) setTimeout(function () { wx.hideLoading(); }, 1000); return false; } if(this.data.inputval==""){ wx.showLoading({ title: "水洗码必填", }) setTimeout(function () { wx.hideLoading(); }, 1000); return false; } // if(images=="" || images==[]){ // wx.showLoading({ // title: "你忘记拍照了", // }) // setTimeout(function () { // wx.hideLoading(); // }, 1000); // return false; // } if(this.data.isworkstr=='a'){ wx.showLoading({ title: "是否加工请选择", }) setTimeout(function () { wx.hideLoading(); }, 1000); return false; } if(this.data.ispick==''){ wx.showLoading({ title: "颜色必选", }) setTimeout(function () { wx.hideLoading(); }, 1000); return false; } app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/entry/"+that.data.meoth, { cate_id:that.data.cateid, color:that.data.ispick, standard_id:that.data.results, is_machining:that.data.isworkstr, images:images, flaw_id:that.data.result, wash_code:that.data.inputval, id:that.data.fenid, seal_no:that.data.tagnum, type:that.data.type }, "post").then(function (res) { console.log(res); if (res.code != 200) { wx.showModal({ title: '错误', content: res.message.msg }) } else { wx.hideLoading(); wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading(); wx.navigateBack({ delta: 1 //想要返回的层级 }) }, 1000); } }).catch(function (err) { console.log(err); }) }, })