123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- // 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,
- is_sub:1,
-
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- // if(options.seal_no){
-
- // }
- 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.length>0?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) {
- console.log(e.detail.value);
- var that = this;
- app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/entry/check_code", {
- wash_code: e.detail.value
- }, "get").then(function (res) {
- console.log(res);
- if (res.code != 200) {
-
- that.setData({
- is_sub: 0
- })
- wx.showLoading({
- title: res.message.msg,
- })
- setTimeout(function () {
- wx.hideLoading();
- }, 1000);
- } else {
- wx.hideLoading();
- that.setData({
- inputval: e.detail.value
- })
- }
- }).catch(function (err) {
- console.log(err);
- })
- },
- 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;
- }
- if(this.data.is_sub==0){
- 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);
- })
- },
- })
|