worksheetinfo.js 18 KB

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