worksheetinfo.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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. // worksheetinfo.chargStationId = (worksheetinfo.chargStationId==0?null:worksheetinfo.chargStationId)
  264. worksheetinfo.chargStationId = (worksheetinfo.chargStationId==0?null:worksheetinfo.chargStationId)
  265. let signs = this.data.signs;
  266. console.log(signs.length == 0);
  267. var signString = [];
  268. if (signs.length == 0) {
  269. //2021-1-1撤销校验
  270. // wx.showToast({
  271. // title: '请设置签名',
  272. // icon: 'loading',
  273. // duration: 2000,
  274. // mask: true,
  275. // success: function() {}
  276. // });
  277. // return;
  278. } else {
  279. signs.forEach((item, index) => {
  280. wx.uploadFile({
  281. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/editWorkSheetImg',
  282. filePath: signs[index],
  283. name: 'imageFileName',
  284. success: function(res) {
  285. let result = JSON.parse(res.data);
  286. if (result.code == 500) {
  287. wx.showModal({
  288. showCancel: false,
  289. content: result.msg,
  290. confirmColor:'#00AADD',
  291. });
  292. } else {
  293. signString.push(result.msg);
  294. console.log(signString);
  295. }
  296. }
  297. });
  298. });
  299. }
  300. var uploadSignOverFlag = setInterval(function() {
  301. if (signString.length == signs.length) {
  302. clearInterval(uploadSignOverFlag);
  303. if (images.length == 0) {
  304. if (worksheetinfo.pciture) {
  305. console.log(worksheetinfo.pciture);
  306. worksheetinfo.pciture = (pciString.concat(imgString).concat(signString)).join(",");
  307. //worksheetinfo.pciture = ((worksheetinfo.pciture.split(",")).concat(signString)).join(",");
  308. console.log(worksheetinfo.pciture);
  309. }
  310. wx.request({
  311. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/editWorkSheet',
  312. data: worksheetinfo,
  313. method: 'POST',
  314. success(res) {
  315. //console.log(res);
  316. if (res.data.code == 500) {
  317. wx.showModal({
  318. showCancel: false,
  319. content: res.data.msg,
  320. confirmColor:'#00AADD',
  321. });
  322. } else {
  323. wx.navigateBack();
  324. }
  325. }
  326. });
  327. } else {
  328. images.forEach((item, index) => {
  329. wx.uploadFile({
  330. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/editWorkSheetImg',
  331. filePath: images[index],
  332. name: 'imageFileName',
  333. success: function(res) {
  334. let result = JSON.parse(res.data);
  335. if (result.code == 500) {
  336. wx.showModal({
  337. showCancel: false,
  338. content: result.msg,
  339. confirmColor:'#00AADD',
  340. });
  341. } else {
  342. imgString.push(result.msg);
  343. console.log(imgString);
  344. if (index == (images.length - 1)) {
  345. var uploadImgOverFlag = setInterval(function() {
  346. if (imgString.length == images.length) {
  347. clearInterval(uploadImgOverFlag);
  348. //worksheetinfo.pciture = ((worksheetinfo.pciture.split(",")).concat(signString)).join(",");
  349. worksheetinfo.pciture = (pciString.concat(imgString).concat(signString)).join(",");
  350. //var images = this.data.images.concat(res.tempFilePaths);
  351. wx.request({
  352. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/editWorkSheet',
  353. data: worksheetinfo,
  354. method: 'POST',
  355. success(res) {
  356. //console.log(res);
  357. if (res.data.code == 500) {
  358. wx.showModal({
  359. showCancel: false,
  360. content: res.data.msg,
  361. confirmColor:'#00AADD',
  362. });
  363. } else {
  364. wx.navigateBack();
  365. }
  366. }
  367. });
  368. }
  369. }, 100);
  370. }
  371. }
  372. },
  373. fail: function(data) {
  374. console.log(data);
  375. }
  376. });
  377. });
  378. }
  379. }
  380. }, 100);
  381. },
  382. openImage(e) {
  383. //var that = this;
  384. var imgCount = (9 - this.data.pcitures.length) < 0 ? 0 : 9 - this.data.pcitures.length;
  385. console.log(imgCount);
  386. wx.chooseImage({
  387. count: 9 - (this.data.pcitures.length + this.data.images.length),
  388. //sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
  389. //sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
  390. success: res => {
  391. //console.log(res);
  392. var images = this.data.images.concat(res.tempFilePaths);
  393. // 限制最多只能留下5张照片
  394. images = images.length <= imgCount ? images : images.slice(0, imgCount);
  395. if (images.length >= imgCount || imgCount<= 0){
  396. wx.showToast({
  397. title: '最多9张图片',
  398. icon:'none'
  399. });
  400. }
  401. this.setData({
  402. //pcitures: [],
  403. images
  404. });
  405. }
  406. });
  407. },
  408. removeImage(e) {
  409. //console.log(e);
  410. //console.log(this.data.images);
  411. let idx = e.currentTarget.dataset.idx;
  412. var images = this.data.images;
  413. images.splice(idx, 1);
  414. this.setData({
  415. images
  416. });
  417. },
  418. removePciture(e) {
  419. //console.log(e);
  420. //console.log(this.data.images);
  421. let idx = e.currentTarget.dataset.idx;
  422. var pcitures = this.data.pcitures;
  423. pcitures.splice(idx, 1);
  424. this.setData({
  425. pcitures
  426. });
  427. },
  428. removeSign(e) {
  429. //console.log(e);
  430. //console.log(this.data.images);
  431. let idx = e.currentTarget.dataset.idx;
  432. var signs = this.data.signs;
  433. signs.splice(idx, 1);
  434. this.setData({
  435. signs
  436. });
  437. },
  438. handleImagePreview(e) {
  439. const idx = e.target.dataset.idx
  440. const images = this.data.images
  441. wx.previewImage({
  442. current: images[idx], //当前预览的图片
  443. urls: images, //所有要预览的图片
  444. })
  445. },
  446. handleSignPreview(e) {
  447. const idx = e.target.dataset.idx
  448. const signs = this.data.signs
  449. //console.log(idx);
  450. //console.log(signs);
  451. //console.log(signs[idx]);
  452. wx.previewImage({
  453. current: signs[idx], //当前预览的图片
  454. urls: signs, //所有要预览的图片
  455. })
  456. },
  457. clear_chargStationName(e){
  458. let worksheetinfo = this.data.worksheetinfo;
  459. worksheetinfo.chargStationId = 0;
  460. worksheetinfo.pams = [];
  461. worksheetinfo.accendant = '';
  462. worksheetinfo.mainLocation = '';
  463. this.setData({
  464. worksheetinfo,
  465. chargStationNameClearFlag: true
  466. });
  467. },
  468. bindworkEndtimeParamsChange(e){
  469. let workEndtimeParams = this.data.workEndtimeParams;
  470. workEndtimeParams.pText = e.detail
  471. this.setData({
  472. workEndtimeParams:workEndtimeParams
  473. })
  474. console.info("workEndtimeParams " + workEndtimeParams.pText)
  475. },
  476. bindFinishparamsChange(e){
  477. let finishparams = this.data.finishparams;
  478. finishparams.pText = e.detail
  479. this.setData({
  480. finishparams:finishparams
  481. })
  482. console.info("finishparams " + finishparams.pText)
  483. },
  484. bindExceptparamsChange(e){
  485. let exceptparams = this.data.exceptparams;
  486. exceptparams.pText = e.detail
  487. this.setData({
  488. exceptparams:exceptparams
  489. })
  490. console.info("exceptparams " + exceptparams.pText)
  491. },
  492. /**
  493. * 生命周期函数--监听页面加载
  494. */
  495. onLoad: function(options) {
  496. //console.log(options);
  497. let {
  498. worksheet
  499. } = options;
  500. //console.log(worksheet);
  501. let worksheetinfo = JSON.parse(worksheet);
  502. //worksheetinfo.breakdownType = 2;
  503. this.setData({
  504. worksheetinfo
  505. });
  506. this.data.workstatus.forEach((item, index) => {
  507. if (item.value == worksheetinfo.workStatus) {
  508. this.setData({
  509. workstatusindex: index
  510. });
  511. }
  512. });
  513. this.data.workBigclass.forEach((item, index) => {
  514. if (item.value == worksheetinfo.workBigclass) {
  515. this.setData({
  516. workBigclassindex: index
  517. });
  518. }
  519. });
  520. this.data.wokSmallclass.forEach((item, index) => {
  521. if (item.value == worksheetinfo.wokSmallclass) {
  522. this.setData({
  523. wokSmallclassindex: index
  524. });
  525. }
  526. });
  527. if (worksheetinfo.exceptTime) {
  528. // let datetime = worksheetinfo.exceptTime.split(" ");
  529. // this.setData({
  530. // exceptdate: datetime[0],
  531. // excepttime: datetime[1].substr(0, 5)
  532. // });
  533. let exceptparams = this.data.exceptparams;
  534. exceptparams['pText'] = worksheetinfo.exceptTime.substr(0,16)
  535. console.info(exceptparams['pText'])
  536. this.setData({
  537. exceptparams: exceptparams
  538. });
  539. }
  540. if (worksheetinfo.workEndtime) {
  541. let workEndtimeParams = this.data.workEndtimeParams;
  542. workEndtimeParams['pText'] = worksheetinfo.workEndtime.substr(0,16)
  543. console.info(workEndtimeParams['pText'])
  544. this.setData({
  545. workEndtimeParams: workEndtimeParams
  546. });
  547. }else{
  548. let workEndtimeParams = this.data.workEndtimeParams;
  549. workEndtimeParams['pText'] = '0000-00-00 00:00'
  550. console.info(workEndtimeParams['pText'])
  551. this.setData({
  552. workEndtimeParams: workEndtimeParams
  553. });
  554. }
  555. if (worksheetinfo.finishTime) {
  556. // let datetime = worksheetinfo.finishTime.split(" ");
  557. // this.setData({
  558. // finishdate: datetime[0],
  559. // finishtime: datetime[1].substr(0, 5)
  560. // });
  561. let finishparams = this.data.finishparams;
  562. finishparams['pText'] = worksheetinfo.finishTime.substr(0,16)
  563. console.info(finishparams['pText'])
  564. this.setData({
  565. finishparams: finishparams
  566. });
  567. }else{
  568. let finishparams = this.data.finishparams;
  569. finishparams['pText'] = '0000-00-00 00:00'
  570. console.info(finishparams['pText'])
  571. this.setData({
  572. finishparams: finishparams
  573. });
  574. }
  575. this.data.breakdownType.forEach((item, index) => {
  576. if (item.value == worksheetinfo.breakdownType) {
  577. this.setData({
  578. breakdownTypeindex: index
  579. });
  580. }
  581. });
  582. if (worksheetinfo.pciture) {
  583. let pcitures_src = worksheetinfo.pciture.split(",");
  584. var pcitures = [];
  585. pcitures_src.forEach((item, index) => {
  586. // pcitures[index] = { src: item, flag: item.indexOf('https://cdgl.pjnes.com/profile/station/') != -1};
  587. let url = getApp().globalData.postHeadAgreement
  588. url = url.replace("cloud/chargapi","") + "web/profile/station/" + item
  589. console.info(url)
  590. pcitures[index] = { url:url, src: item, flag: item.indexOf(getApp().globalData.postHeadAgreement) != -1};
  591. });
  592. this.setData({
  593. pcitures
  594. });
  595. }
  596. //console.log(worksheetinfo);
  597. if(worksheetinfo.workStatus==7){
  598. this.setData({
  599. workstatusFinished: true
  600. })
  601. }
  602. let userInfo = wx.getStorageSync('userInfo');
  603. let isLogin = wx.getStorageSync('isLogin');
  604. let that = this;
  605. //console.log(12345);
  606. if (userInfo && isLogin) {
  607. that.setData({
  608. chargStationName:worksheetinfo.chargStationName,
  609. worksheetinfo
  610. });
  611. console.info(worksheetinfo.chargStationName)
  612. if(!worksheetinfo.chargStationName){
  613. that.setData({
  614. chargStationNameClearFlag:true,
  615. });
  616. }
  617. }
  618. wx.request({
  619. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/getuserworksheet',
  620. data: worksheetinfo.id,
  621. method: 'POST',
  622. success(res) {
  623. //console.log(res);
  624. let accendantids = [];
  625. let userNames = [];
  626. res.data.forEach((item, index) => {
  627. accendantids.push(item.userId);
  628. userNames.push(item.userName);
  629. });
  630. that.setData({
  631. accendantids,
  632. userNames
  633. });
  634. }
  635. });
  636. },
  637. openSign(e) {
  638. let url = `/pages/sign/sign`;
  639. wx.navigateTo({
  640. url
  641. });
  642. },
  643. /**
  644. * 生命周期函数--监听页面初次渲染完成
  645. */
  646. onReady: function() {
  647. },
  648. /**
  649. * 生命周期函数--监听页面显示
  650. */
  651. onShow: function() {
  652. },
  653. /**
  654. * 生命周期函数--监听页面隐藏
  655. */
  656. onHide: function() {
  657. },
  658. /**
  659. * 生命周期函数--监听页面卸载
  660. */
  661. onUnload: function() {
  662. },
  663. /**
  664. * 页面相关事件处理函数--监听用户下拉动作
  665. */
  666. onPullDownRefresh: function() {
  667. },
  668. /**
  669. * 页面上拉触底事件的处理函数
  670. */
  671. onReachBottom: function() {
  672. },
  673. /**
  674. * 用户点击右上角分享
  675. */
  676. onShareAppMessage: function() {
  677. }
  678. })