add.js 10 KB

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