worksheetinfo.js 20 KB

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