add.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. // pages/sorting/choice.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. inputval: '',
  9. fileList: [
  10. ],
  11. fenid:0,
  12. tagnum:0,
  13. rgb: 'rgb(0,154,97)',//初始值
  14. pick: false,
  15. color: "",
  16. col: '333333',
  17. title: "请选择衣物分类",
  18. cateid:0,
  19. show: false,
  20. flaws: [],
  21. standard: [],
  22. shows: false,
  23. results: 0,
  24. result: "",
  25. str: ['请选择'],
  26. rustr:"请选择",
  27. string:"",
  28. isshows:false,
  29. isworkstr:'a',
  30. iswork:['不加工','加工','需用户确认'],
  31. meoth:"save",
  32. ispick:"",
  33. iscolor:"",
  34. type:0,
  35. is_sub:1,
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: function (options) {
  41. // if(options.seal_no){
  42. // }
  43. this.data.tagnum = options.seal_no
  44. var type= options.type
  45. this.data.fenid = options.fenid?options.fenid:0
  46. if(options.fenid && options.fenid>0 && type!='parent'){
  47. this.data.fenid = options.fenid
  48. this.data.meoth = "edit"
  49. this.data.type =""
  50. this.getdata();
  51. }
  52. if(type=='parent'){ this.data.type =1}
  53. },
  54. onShow() {
  55. var pages = getCurrentPages();
  56. var currPage = pages[pages.length - 1];
  57. this.data.title = currPage.data.title
  58. this.data.cateid = currPage.data.id
  59. },
  60. getdata(){
  61. var that = this;
  62. app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/entry/FlawReport", {
  63. id:that.data.fenid
  64. }, "get").then(function (res) {
  65. console.log(res);
  66. if (res.code != 200) {
  67. wx.showLoading({
  68. title: res.message.msg,
  69. })
  70. setTimeout(function () {
  71. wx.hideLoading();
  72. }, 1000);
  73. } else {
  74. wx.hideLoading();
  75. var data = res.message.data
  76. var result=[];
  77. for(var i in data.flaw){
  78. result[i]=data.flaw[i].id
  79. }
  80. const { fileList = [] } = that.data;
  81. for(var i in data.images){
  82. console.log(data.images[i])
  83. fileList.push({url: data.images[i]});
  84. }
  85. that.setData({
  86. inputval:data.wash_code,
  87. title:data.cat_title,
  88. ispick:data.color,
  89. rustr:data.flaw.length>0?data.flaw[0].name:'',
  90. results:data.standard_id,
  91. isworkstr:data.is_machining,
  92. fileList,
  93. cateid:data.cate_id,
  94. result:result,
  95. })
  96. }
  97. }).catch(function (err) {
  98. console.log(err);
  99. })
  100. },
  101. // 显示取色器
  102. toPick: function () {
  103. this.setData({
  104. pick: !this.data.pick
  105. })
  106. var that = this;
  107. app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/entry/SelectColor", {
  108. }, "get").then(function (res) {
  109. console.log(res);
  110. if (res.code != 200) {
  111. wx.showLoading({
  112. title: res.message.msg,
  113. })
  114. setTimeout(function () {
  115. wx.hideLoading();
  116. }, 1000);
  117. } else {
  118. wx.hideLoading();
  119. let color = res.message.data
  120. that.setData({
  121. color
  122. })
  123. }
  124. }).catch(function (err) {
  125. console.log(err);
  126. })
  127. },
  128. toShow() {
  129. this.setData({
  130. show: !this.data.show
  131. })
  132. if (this.data.show) {
  133. this.getwehre()
  134. }
  135. },
  136. toShows() {
  137. this.setData({
  138. shows: !this.data.shows
  139. })
  140. if (this.data.shows) {
  141. this.getwehre()
  142. }
  143. },
  144. isshows() {
  145. this.setData({
  146. isshows: !this.data.isshows
  147. })
  148. },
  149. //取色结果回调
  150. pickColor(e) {
  151. console.log(e)
  152. this.setData({
  153. ispick: e.detail,
  154. });
  155. },
  156. onClickColor(event) {
  157. const { name } = event.currentTarget.dataset;
  158. console.log(name);
  159. this.setData({
  160. ispick: name,
  161. });
  162. },
  163. toEnter() {
  164. wx.navigateTo({
  165. url: '../enter/enter',
  166. })
  167. },
  168. bindinput(e) {
  169. console.log(e.detail.value);
  170. var that = this;
  171. app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/entry/check_code", {
  172. wash_code: e.detail.value
  173. }, "get").then(function (res) {
  174. console.log(res);
  175. if (res.code != 200) {
  176. that.setData({
  177. is_sub: 0
  178. })
  179. wx.showLoading({
  180. title: res.message.msg,
  181. })
  182. setTimeout(function () {
  183. wx.hideLoading();
  184. }, 1000);
  185. } else {
  186. wx.hideLoading();
  187. that.setData({
  188. inputval: e.detail.value
  189. })
  190. }
  191. }).catch(function (err) {
  192. console.log(err);
  193. })
  194. },
  195. inputw(e){
  196. console.log();
  197. //this.data.color=e.detail.value
  198. this.setData({
  199. color: e.detail
  200. })
  201. },
  202. getScancode: function () {
  203. var _this = this;
  204. // 允许从相机和相册扫码
  205. wx.scanCode({
  206. onlyFromCamera: true,
  207. scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
  208. success: (res) => {
  209. console.log(res);
  210. var result = res.result;
  211. _this.setData({
  212. inputval: result,
  213. })
  214. },
  215. fail: (err) => {
  216. console.log(err);
  217. }
  218. })
  219. },
  220. delete(e) {
  221. console.log(e)
  222. var filelist=this.data.fileList
  223. filelist.splice(e.detail.index,1);
  224. this.setData({
  225. fileList:filelist
  226. })
  227. },
  228. clos(){
  229. wx.navigateBack({
  230. delta: 1 //想要返回的层级
  231. })
  232. },
  233. checknum: function (seal_no) {
  234. var that = this;
  235. app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/sign", {
  236. seal_no: seal_no
  237. }, "post").then(function (res) {
  238. console.log(res);
  239. if (res.code != 200) {
  240. wx.showLoading({
  241. title: res.message.msg,
  242. })
  243. setTimeout(function () {
  244. wx.hideLoading();
  245. }, 1000);
  246. } else {
  247. wx.hideLoading();
  248. var data = res.message.data
  249. wx.showLoading({
  250. title: res.message.msg,
  251. })
  252. setTimeout(function () {
  253. wx.hideLoading();
  254. }, 1000);
  255. }
  256. }).catch(function (err) {
  257. console.log(222);
  258. })
  259. },
  260. afterRead(event) {
  261. var that=this;
  262. const { file } = event.detail;
  263. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  264. wx.uploadFile({
  265. url: app.globalData.baseAppUrl + 'api/common/uploadImg', // 仅为示例,非真实的接口地址
  266. filePath: file.url,
  267. header: {
  268. "Content-Type": "multipart/form-data",
  269. 'accept': 'application/json',
  270. },
  271. name: 'file',
  272. formData: { user: 'test' },
  273. success(res) {
  274. var datas = JSON.parse(res.data)
  275. console.log(datas);
  276. if(datas.code==200){
  277. // 上传完成需要更新 fileList
  278. const { fileList = [] } = that.data;
  279. fileList.push({ ...file, url: datas.message.data.path });
  280. that.setData({ fileList });
  281. }else{
  282. wx.showLoading({
  283. title: datas.message.msg,
  284. })
  285. setTimeout(function () {
  286. wx.hideLoading();
  287. }, 1000);
  288. }
  289. },
  290. });
  291. },
  292. noop(e){
  293. console.log(e)
  294. },
  295. onChange(event) {
  296. console.log(event)
  297. var detail=event.detail
  298. if(!event.detail || event.detail=="" || event.detail==undefined){
  299. detail=false;
  300. }
  301. var rustr=detail?this.data.string[event.detail]:""
  302. this.setData({
  303. result:detail ,
  304. rustr:rustr
  305. });
  306. },
  307. Change(event) {
  308. console.log(event.detail)
  309. this.setData({
  310. results: event.detail,
  311. });
  312. },
  313. isChange(event){
  314. console.log(event.detail)
  315. this.setData({
  316. isworkstr: event.detail,
  317. });
  318. },
  319. toggle(event) {
  320. const { index } = event.currentTarget.dataset;
  321. const checkbox = this.selectComponent(`.checkboxes-${index}`);
  322. console.log(checkbox);
  323. checkbox.toggle();
  324. },
  325. noop() { },
  326. getwehre() {
  327. var that = this;
  328. app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/flaw", {
  329. }, "get").then(function (res) {
  330. console.log(res);
  331. if (res.code != 200) {
  332. wx.showLoading({
  333. title: res.message.msg,
  334. })
  335. setTimeout(function () {
  336. wx.hideLoading();
  337. }, 1000);
  338. } else {
  339. wx.hideLoading();
  340. var data = res.message.data
  341. var str=[];
  342. var string =[];
  343. for (var index in data.standard) {
  344. str[data.standard[index].id] = data.standard[index].title
  345. }
  346. for (var index in data.flaws) {
  347. string[data.flaws[index].id] = data.flaws[index].name
  348. }
  349. that.setData({
  350. flaws: data.flaws,
  351. standard: data.standard,
  352. str: str,
  353. string:string
  354. })
  355. }
  356. }).catch(function (err) {
  357. console.log(err);
  358. })
  359. },
  360. addSoting(){
  361. var that = this;
  362. var fileList=this.data.fileList;
  363. var images=[]
  364. fileList.map((item, index) => {
  365. images[index]=item.url
  366. })
  367. if(this.data.cateid==0){
  368. wx.showLoading({
  369. title: "衣物分类必须选择",
  370. })
  371. setTimeout(function () {
  372. wx.hideLoading();
  373. }, 1000);
  374. return false;
  375. }
  376. if(this.data.tagnum==0){
  377. wx.showLoading({
  378. title: "数据错误请返回重试",
  379. })
  380. setTimeout(function () {
  381. wx.hideLoading();
  382. }, 1000);
  383. return false;
  384. }
  385. if(this.data.inputval==""){
  386. wx.showLoading({
  387. title: "水洗码必填",
  388. })
  389. setTimeout(function () {
  390. wx.hideLoading();
  391. }, 1000);
  392. return false;
  393. }
  394. // if(images=="" || images==[]){
  395. // wx.showLoading({
  396. // title: "你忘记拍照了",
  397. // })
  398. // setTimeout(function () {
  399. // wx.hideLoading();
  400. // }, 1000);
  401. // return false;
  402. // }
  403. if(this.data.isworkstr=='a'){
  404. wx.showLoading({
  405. title: "是否加工请选择",
  406. })
  407. setTimeout(function () {
  408. wx.hideLoading();
  409. }, 1000);
  410. return false;
  411. }
  412. if(this.data.ispick==''){
  413. wx.showLoading({
  414. title: "颜色必选",
  415. })
  416. setTimeout(function () {
  417. wx.hideLoading();
  418. }, 1000);
  419. return false;
  420. }
  421. if(this.data.is_sub==0){
  422. wx.showLoading({
  423. title: "水洗码重复",
  424. })
  425. setTimeout(function () {
  426. wx.hideLoading();
  427. }, 1000);
  428. return false;
  429. }
  430. app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/entry/"+that.data.meoth, {
  431. cate_id:that.data.cateid,
  432. color:that.data.ispick,
  433. standard_id:that.data.results,
  434. is_machining:that.data.isworkstr,
  435. images:images,
  436. flaw_id:that.data.result,
  437. wash_code:that.data.inputval,
  438. id:that.data.fenid,
  439. seal_no:that.data.tagnum,
  440. type:that.data.type
  441. }, "post").then(function (res) {
  442. console.log(res);
  443. if (res.code != 200) {
  444. wx.showModal({
  445. title: '错误',
  446. content: res.message.msg
  447. })
  448. } else {
  449. wx.hideLoading();
  450. wx.showLoading({
  451. title: res.message.msg,
  452. })
  453. setTimeout(function () {
  454. wx.hideLoading();
  455. wx.navigateBack({
  456. delta: 1 //想要返回的层级
  457. })
  458. }, 1000);
  459. }
  460. }).catch(function (err) {
  461. console.log(err);
  462. })
  463. },
  464. })