addworksheetinfo.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. // pages/worksheetinfo/worksheetinfo.js
  2. let Util = require("../../utils/util");
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. images: [],
  9. signs: [],
  10. submitting:false,
  11. worksheetinfo: {},
  12. chargstations: [],
  13. chargstationsindex: 0,
  14. pcitures: [],
  15. workstatus: [{
  16. value: 1,
  17. text: '新建'
  18. }, {
  19. value: 2,
  20. text: '指派人员'
  21. }, {
  22. value: 3,
  23. text: '指派确认'
  24. }, {
  25. value: 4,
  26. text: '施工前安全准备'
  27. }, {
  28. value: 5,
  29. text: '进行中'
  30. }
  31. , {
  32. value: 6,
  33. text: '完成工作内容'
  34. }
  35. // , {
  36. // value: 7,
  37. // text: '完成工单'
  38. // }
  39. ],
  40. workstatusindex: 1,
  41. workBigclass: [{
  42. value: 1,
  43. text: '售后服务'
  44. }, {
  45. value: 2,
  46. text: '工程实施'
  47. }],
  48. workBigclassindex: 1,
  49. wokSmallclass:[{
  50. value: 1,
  51. text: '日常巡站'
  52. }, {
  53. value: 2,
  54. text: '紧急维修'
  55. }, {
  56. value: 3,
  57. text: '施工准备'
  58. }, {
  59. value: 4,
  60. text: '工程进程'
  61. }, {
  62. value: 5,
  63. text: '施工过程'
  64. }, {
  65. value: 6,
  66. text: '工程竣工'
  67. }, {
  68. value: 7,
  69. text: '工程验收'
  70. },{
  71. value: 8,
  72. text: '其他'
  73. }],
  74. wokSmallclassIndex: 1,
  75. breakdownType: [{
  76. value: 1,
  77. text: '车辆导致'
  78. }, {
  79. value: 2,
  80. text: '桩体导致'
  81. }, {
  82. value: 3,
  83. text: '人为导致'
  84. }, {
  85. value: 4,
  86. text: '基础设施问题'
  87. }, {
  88. value: 5,
  89. text: '其他'
  90. }],
  91. breakdownTypeindex: 0,
  92. exceptdate: null,
  93. excepttime: '00:00',
  94. exceptparams:{
  95. placeholder: '请选择时间',
  96. startDateTime: '2020-01-01 00:00',
  97. endDateTime: '2040-01-01 00:00',
  98. pText: Util.formatTimePicker(new Date()) //'2022-04-30 00:00'
  99. },
  100. workEndtimeParams:{
  101. placeholder: '请选择时间',
  102. startDateTime: '2020-01-01 00:00',
  103. endDateTime: '2040-01-01 00:00',
  104. pText: Util.formatTimePicker(new Date()) //'2022-04-30 00:00'
  105. //pText: '0000-00-00 00:00' //'2022-04-30 00:00'
  106. },
  107. finishdate: null,
  108. finishtime: '00:00',
  109. accendantids: [],
  110. userNames:[],
  111. chargStationName:'',
  112. chargStationNameClearFlag: true,
  113. brandName:''
  114. },
  115. bindChargstationsChange: function(e) {
  116. if (this.data.chargstationsindex != e.detail.value) {
  117. console.log('picker发送选择改变,携带值为', e.detail.value)
  118. let chargstationid = this.data.chargstations[e.detail.value].id;
  119. let worksheetinfo = this.data.worksheetinfo;
  120. worksheetinfo.accendant = null;
  121. worksheetinfo.chargStationId = chargstationid;
  122. this.setData({
  123. chargstationsindex: e.detail.value,
  124. worksheetinfo
  125. })
  126. }
  127. },
  128. bindWorkstatusChange: function(e) {
  129. //console.log('picker发送选择改变,携带值为', e.detail.value)
  130. let workStatus = this.data.workstatus[e.detail.value].value;
  131. let worksheetinfo = this.data.worksheetinfo;
  132. worksheetinfo.workStatus = workStatus;
  133. this.setData({
  134. workstatusindex: e.detail.value,
  135. worksheetinfo
  136. });
  137. },
  138. bindWorkBigclassChange: function(e) {
  139. //console.log('picker发送选择改变,携带值为', e.detail.value)
  140. let workBigclass = this.data.workBigclass[e.detail.value].value;
  141. let worksheetinfo = this.data.worksheetinfo;
  142. worksheetinfo.workBigclass = workBigclass;
  143. this.setData({
  144. workBigclassindex: e.detail.value,
  145. worksheetinfo
  146. });
  147. },
  148. bindwokSmallclassChange: function(e) {
  149. //console.log('picker发送选择改变,携带值为', e.detail.value)
  150. let wokSmallclass = this.data.wokSmallclass[e.detail.value].value;
  151. let worksheetinfo = this.data.worksheetinfo;
  152. worksheetinfo.wokSmallclass = wokSmallclass;
  153. this.setData({
  154. wokSmallclassindex: e.detail.value,
  155. worksheetinfo
  156. });
  157. },
  158. bindBreakdownType(e) {
  159. //console.log('picker发送选择改变,携带值为', e.detail.value)
  160. let breakdownType = this.data.breakdownType[e.detail.value].value;
  161. let worksheetinfo = this.data.worksheetinfo;
  162. worksheetinfo.breakdownType = breakdownType;
  163. this.setData({
  164. breakdownTypeindex: e.detail.value,
  165. worksheetinfo
  166. });
  167. },
  168. chargStationNameSelect:function(e){
  169. let url = `/pages/worksheetinfo/findstation`;
  170. wx.navigateTo({
  171. url
  172. });
  173. },
  174. bindAccendantChange: function(e) {
  175. let accendant = this.data.worksheetinfo.accendant;
  176. let chargStationId = this.data.worksheetinfo.chargStationId==null?0:this.data.worksheetinfo.chargStationId;
  177. let url = `/pages/worksheetinfo/accendant?chargstationid=${chargStationId}&accendant=${accendant}`;
  178. wx.navigateTo({
  179. url
  180. });
  181. },
  182. // bindExceptdateChange(e) {
  183. // this.setData({
  184. // exceptdate: e.detail.value
  185. // })
  186. // },
  187. // bindExcepttimeChange(e) {
  188. // this.setData({
  189. // excepttime: e.detail.value
  190. // })
  191. // },
  192. bindFinishdateChange(e) {
  193. this.setData({
  194. finishdate: e.detail.value
  195. })
  196. },
  197. bindFinishtimeChange(e) {
  198. this.setData({
  199. finishtime: e.detail.value
  200. })
  201. },
  202. bindMainLocationInput(e) {
  203. console.log(e);
  204. let mainLocation = e.detail.value;
  205. let worksheetinfo = this.data.worksheetinfo;
  206. worksheetinfo.mainLocation = mainLocation;
  207. this.setData({
  208. worksheetinfo
  209. });
  210. },
  211. bindAccendantInput(e){
  212. let accendant = e.detail.value;
  213. this.setData({
  214. "worksheetinfo.accendant":accendant
  215. });
  216. },
  217. bindContentInput(e) {
  218. let content = e.detail.value;
  219. // let worksheetinfo = this.data.worksheetinfo;
  220. // worksheetinfo.content = content;
  221. this.setData({
  222. "worksheetinfo.content":content
  223. });
  224. },
  225. bindWorkSheetSubmit(e) {
  226. let worksheetinfo = this.data.worksheetinfo;
  227. worksheetinfo.operatorName = this.data.userNames.length>0?this.data.userNames[0]:"";
  228. worksheetinfo.pams = this.data.accendantids;
  229. console.info(this.data.accendantids)
  230. console.log("783756349857235");
  231. // 如果正在提交,则不执行重复操作
  232. if (this.data.submitting) {
  233. return;
  234. }
  235. // worksheetinfo.accendant = null;
  236. // if (this.data.exceptdate ) {
  237. // // if (this.data.exceptdate && this.data.excepttime) {
  238. // worksheetinfo.exceptTime = this.data.exceptdate + " " + this.data.excepttime + ":00";
  239. // }
  240. worksheetinfo.exceptTime = this.data.exceptparams.pText + ":00";
  241. // if (this.data.finishdate){
  242. // // if (this.data.finishdate && this.data.finishtime){
  243. // worksheetinfo.finishTime = this.data.finishdate + " " + this.data.finishtime + ":00";
  244. // }
  245. worksheetinfo.workEndtime = this.data.workEndtimeParams.pText == '0000-00-00 00:00'? null : this.data.workEndtimeParams.pText + ":00";
  246. console.info(worksheetinfo.exceptTime + ":00")
  247. console.info(worksheetinfo.finishTime + ":00")
  248. let images = this.data.images;
  249. var imgString = [];
  250. var pciString = [];
  251. this.data.pcitures.forEach((item, index) =>{
  252. pciString.push(item.src);
  253. });
  254. if(worksheetinfo.mainLocation == '' || worksheetinfo.mainLocation == undefined){
  255. wx.showModal({
  256. showCancel: false,
  257. content: '地址不能为空,请填写!',
  258. confirmColor:'#00AADD',
  259. });
  260. return;
  261. }
  262. // if(worksheetinfo.pams.length == 0){
  263. // wx.showModal({
  264. // showCancel: false,
  265. // content: '运维人员不能为空,请填写!',
  266. // confirmColor:'#00AADD',
  267. // });
  268. // return;
  269. // }
  270. if(worksheetinfo.accendant == '' || worksheetinfo.accendant == undefined){
  271. wx.showModal({
  272. showCancel: false,
  273. content: '运维人员不能为空,请填写!',
  274. confirmColor:'#00AADD',
  275. });
  276. return;
  277. }
  278. if(worksheetinfo.content == '' || worksheetinfo.content == undefined){
  279. wx.showModal({
  280. showCancel: false,
  281. content: '工作内容不能为空,请填写!',
  282. confirmColor:'#00AADD',
  283. });
  284. return;
  285. }
  286. let signs = this.data.signs;
  287. console.log(signs.length == 0);
  288. let that = this
  289. var signString = [];
  290. if (signs.length == 0) {
  291. //2021-1-1撤销校验
  292. // wx.showToast({
  293. // title: '请设置签名',
  294. // icon: 'loading',
  295. // duration: 2000,
  296. // mask: true,
  297. // success: function() {}
  298. // });
  299. // return;
  300. } else {
  301. signs.forEach((item, index) => {
  302. wx.uploadFile({
  303. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/editWorkSheetImg',
  304. filePath: signs[index],
  305. name: 'imageFileName',
  306. success: function(res) {
  307. let result = JSON.parse(res.data);
  308. if (result.code == 500) {
  309. wx.showModal({
  310. showCancel: false,
  311. content: result.msg,
  312. confirmColor:'#00AADD',
  313. });
  314. } else {
  315. signString.push(result.msg);
  316. console.log(signString);
  317. }
  318. }
  319. });
  320. });
  321. }
  322. var uploadSignOverFlag = setInterval(function() {
  323. if (signString.length == signs.length) {
  324. clearInterval(uploadSignOverFlag);
  325. // 设置提交状态为 true
  326. that.setData({
  327. submitting: true
  328. });
  329. console.log("1111");
  330. console.log(that.data.submitting);
  331. if (images.length == 0) {
  332. if (worksheetinfo.pciture) {
  333. console.log(worksheetinfo.pciture);
  334. worksheetinfo.pciture = (pciString.concat(imgString).concat(signString)).join(",");
  335. //worksheetinfo.pciture = ((worksheetinfo.pciture.split(",")).concat(signString)).join(",");
  336. console.log(worksheetinfo.pciture);
  337. }
  338. wx.showLoading({
  339. title: '提交中...',
  340. })
  341. wx.request({
  342. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/saveWorkSheet',
  343. data: worksheetinfo,
  344. method: 'POST',
  345. success(res) {
  346. //console.log(res);
  347. if (res.data.code == 500) {
  348. wx.showModal({
  349. showCancel: false,
  350. content: res.data.msg,
  351. confirmColor:'#00AADD',
  352. });
  353. } else {
  354. wx.navigateBack();
  355. wx.hideLoading()
  356. //提交完成重置按钮
  357. that.setData({
  358. submitting: false
  359. });
  360. }
  361. }
  362. });
  363. } else {
  364. images.forEach((item, index) => {
  365. wx.uploadFile({
  366. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/editWorkSheetImg',
  367. filePath: images[index],
  368. name: 'imageFileName',
  369. success: function(res) {
  370. let result = JSON.parse(res.data);
  371. if (result.code == 500) {
  372. wx.showModal({
  373. showCancel: false,
  374. content: result.msg,
  375. confirmColor:'#00AADD',
  376. });
  377. } else {
  378. imgString.push(result.msg);
  379. console.log(imgString);
  380. if (index == (images.length - 1)) {
  381. var uploadImgOverFlag = setInterval(function() {
  382. if (imgString.length == images.length) {
  383. clearInterval(uploadImgOverFlag);
  384. //worksheetinfo.pciture = ((worksheetinfo.pciture.split(",")).concat(signString)).join(",");
  385. worksheetinfo.pciture = (pciString.concat(imgString).concat(signString)).join(",");
  386. //var images = this.data.images.concat(res.tempFilePaths);
  387. wx.showLoading({title: "提交中...."})
  388. wx.request({
  389. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/saveWorkSheet',
  390. data: worksheetinfo,
  391. method: 'POST',
  392. success(res) {
  393. //console.log(res);
  394. if (res.data.code == 500) {
  395. wx.showModal({
  396. showCancel: false,
  397. content: res.data.msg,
  398. confirmColor:'#00AADD',
  399. });
  400. } else {
  401. wx.navigateBack();
  402. wx.hideLoading()
  403. //提交完成重置按钮
  404. that.setData({
  405. submitting: false
  406. });
  407. }
  408. }
  409. });
  410. }
  411. }, 100);
  412. }
  413. }
  414. },
  415. fail: function(data) {
  416. console.log(data);
  417. }
  418. });
  419. });
  420. }
  421. }
  422. }, 100);
  423. },
  424. openImage(e) {
  425. //var that = this;
  426. var imgCount = (9 - this.data.pcitures.length) < 0 ? 0 : 9 - this.data.pcitures.length;
  427. console.log(imgCount);
  428. wx.chooseImage({
  429. count: 9 - (this.data.pcitures.length + this.data.images.length),
  430. //sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
  431. //sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
  432. success: res => {
  433. //console.log(res);
  434. var images = this.data.images.concat(res.tempFilePaths);
  435. // 限制最多只能留下5张照片
  436. images = images.length <= imgCount ? images : images.slice(0, imgCount);
  437. if (images.length >= imgCount || imgCount<= 0){
  438. wx.showToast({
  439. title: '最多9张图片',
  440. icon:'none'
  441. });
  442. }
  443. this.setData({
  444. //pcitures: [],
  445. images
  446. });
  447. }
  448. });
  449. },
  450. removeImage(e) {
  451. //console.log(e);
  452. //console.log(this.data.images);
  453. let idx = e.currentTarget.dataset.idx;
  454. var images = this.data.images;
  455. images.splice(idx, 1);
  456. this.setData({
  457. images
  458. });
  459. },
  460. removePciture(e) {
  461. //console.log(e);
  462. //console.log(this.data.images);
  463. let idx = e.currentTarget.dataset.idx;
  464. var pcitures = this.data.pcitures;
  465. pcitures.splice(idx, 1);
  466. this.setData({
  467. pcitures
  468. });
  469. },
  470. removeSign(e) {
  471. //console.log(e);
  472. //console.log(this.data.images);
  473. let idx = e.currentTarget.dataset.idx;
  474. var signs = this.data.signs;
  475. signs.splice(idx, 1);
  476. this.setData({
  477. signs
  478. });
  479. },
  480. handleImagePreview(e) {
  481. const idx = e.target.dataset.idx
  482. const images = this.data.images
  483. wx.previewImage({
  484. current: images[idx], //当前预览的图片
  485. urls: images, //所有要预览的图片
  486. })
  487. },
  488. handleSignPreview(e) {
  489. const idx = e.target.dataset.idx
  490. const signs = this.data.signs
  491. //console.log(idx);
  492. //console.log(signs);
  493. //console.log(signs[idx]);
  494. wx.previewImage({
  495. current: signs[idx], //当前预览的图片
  496. urls: signs, //所有要预览的图片
  497. })
  498. },
  499. clear_chargStationName(e){
  500. let worksheetinfo = this.data.worksheetinfo;
  501. worksheetinfo.chargStationId = null;
  502. worksheetinfo.pams = [];
  503. worksheetinfo.accendant = '';
  504. worksheetinfo.mainLocation = '';
  505. this.setData({
  506. worksheetinfo,
  507. chargStationNameClearFlag: true
  508. });
  509. },
  510. bindworkEndtimeParamsChange(e){
  511. let workEndtimeParams = this.data.workEndtimeParams;
  512. workEndtimeParams.pText = e.detail
  513. this.setData({
  514. workEndtimeParams:workEndtimeParams
  515. })
  516. console.info("workEndtimeParams " + workEndtimeParams.pText)
  517. },
  518. bindExceptparamsChange(e){
  519. let exceptparams = this.data.exceptparams;
  520. exceptparams.pText = e.detail
  521. this.setData({
  522. exceptparams:exceptparams
  523. })
  524. console.info("exceptparams " + exceptparams.pText)
  525. },
  526. /**
  527. * 生命周期函数--监听页面加载
  528. */
  529. onLoad: function(options) {
  530. //console.log(options);
  531. // let {
  532. // worksheet
  533. // } = options;
  534. // //console.log(worksheet);
  535. // let worksheetinfo = JSON.parse(worksheet);
  536. // //worksheetinfo.breakdownType = 2;
  537. // this.setData({
  538. // worksheetinfo
  539. // });
  540. console.info('sdfsdf')
  541. this.setData({
  542. 'exceptparams.pText' : Util.formatTimePicker(new Date()),
  543. // 'finishparams.pText' : Util.formatTimePicker(new Date()),
  544. })
  545. let worksheetinfo = {
  546. workStatus: 1,
  547. workBigclass: 1,
  548. wokSmallclass: 1,
  549. breakdownType: 1,
  550. chargStationId: null,
  551. }
  552. this.setData({
  553. worksheetinfo: worksheetinfo
  554. });
  555. this.setData({
  556. workstatusindex: 0,
  557. workBigclassindex: 0,
  558. wokSmallclassindex: 0,
  559. chargstationsindex: 0,
  560. });
  561. // if (worksheetinfo.exceptTime) {
  562. // let datetime = worksheetinfo.exceptTime.split(" ");
  563. // this.setData({
  564. // exceptdate: datetime[0],
  565. // excepttime: datetime[1].substr(0, 5)
  566. // });
  567. // }
  568. // if (worksheetinfo.finishTime) {
  569. // let datetime = worksheetinfo.finishTime.split(" ");
  570. // this.setData({
  571. // finishdate: datetime[0],
  572. // finishtime: datetime[1].substr(0, 5)
  573. // });
  574. // }
  575. this.setData({
  576. breakdownTypeindex: 0
  577. });
  578. //console.log(worksheetinfo);
  579. let userInfo = wx.getStorageSync('userInfo');
  580. let isLogin = wx.getStorageSync('isLogin');
  581. let that = this;
  582. if (userInfo && isLogin) {
  583. wx.request({
  584. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/userChargStationsWeb',
  585. data: {
  586. userId: userInfo.userId,
  587. pagenum: 1,
  588. pagesize: 1,
  589. },
  590. method: 'POST',
  591. success(res) {
  592. //console.log(res);
  593. let {
  594. rows: chargstations
  595. } = res.data;
  596. let chargStationName='';
  597. let chargStationId=null;
  598. chargstations.forEach((item, index) => {
  599. chargStationName = item.chargStationName
  600. // chargStationId = item.id
  601. });
  602. let worksheetinfo = that.data.worksheetinfo;
  603. worksheetinfo.chargStationId = chargStationId;
  604. worksheetinfo.accendant = userInfo.userName
  605. that.data.accendantids.push(userInfo.userId);//解决初始页面未给pams赋值
  606. that.setData({
  607. // chargStationName:that.data.chargStationNameNullValue,
  608. worksheetinfo,
  609. });
  610. }
  611. });
  612. }
  613. // wx.request({
  614. // url: getApp().globalData.postHeadAgreement + '/restapi/wechat/getuserworksheet',
  615. // data: worksheetinfo.id,
  616. // method: 'POST',
  617. // success(res) {
  618. // //console.log(res);
  619. // let accendantids = [];
  620. // let userNames = [];
  621. // res.data.forEach((item, index) => {
  622. // accendantids.push(item.userId);
  623. // userNames.push(item.userName);
  624. // });
  625. // that.setData({
  626. // accendantids,
  627. // userNames
  628. // });
  629. // }
  630. // });
  631. },
  632. openSign(e) {
  633. let url = `/pages/sign/sign`;
  634. wx.navigateTo({
  635. url
  636. });
  637. },
  638. /**
  639. * 生命周期函数--监听页面初次渲染完成
  640. */
  641. onReady: function() {
  642. },
  643. /**
  644. * 生命周期函数--监听页面显示
  645. */
  646. onShow: function() {
  647. // 页面显示时获取的数据
  648. console.log('PageA shown with data:', this.data);
  649. },
  650. /**
  651. * 生命周期函数--监听页面隐藏
  652. */
  653. onHide: function() {
  654. },
  655. /**
  656. * 生命周期函数--监听页面卸载
  657. */
  658. onUnload: function() {
  659. },
  660. /**
  661. * 页面相关事件处理函数--监听用户下拉动作
  662. */
  663. onPullDownRefresh: function() {
  664. },
  665. /**
  666. * 页面上拉触底事件的处理函数
  667. */
  668. onReachBottom: function() {
  669. },
  670. /**
  671. * 用户点击右上角分享
  672. */
  673. onShareAppMessage: function() {
  674. }
  675. })