addworksheetinfo.js 20 KB

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