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