addworksheetinfo.js 20 KB

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