addworksheetinfo.js 18 KB

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