add.js 10 KB

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