addworksheetinfo.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. ],
  39. workstatusindex: 1,
  40. workBigclass: [{
  41. value: 1,
  42. text: '售后服务'
  43. }, {
  44. value: 2,
  45. text: '工程实施'
  46. }],
  47. workBigclassindex: 1,
  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: 0,
  88. exceptdate: null,
  89. excepttime: '00:00',
  90. exceptparams:{
  91. placeholder: '请选择时间',
  92. startDateTime: '2020-01-01 00:00',
  93. endDateTime: '2040-01-01 00:00',
  94. pText: Util.formatTimePicker(new Date()) //'2022-04-30 00:00'
  95. },
  96. workEndtimeParams:{
  97. placeholder: '请选择时间',
  98. startDateTime: '2020-01-01 00:00',
  99. endDateTime: '2040-01-01 00:00',
  100. // pText: Util.formatTimePicker(new Date()) //'2022-04-30 00:00'
  101. pText: '0000-00-00 00:00' //'2022-04-30 00:00'
  102. },
  103. finishdate: null,
  104. finishtime: '00:00',
  105. accendantids: [],
  106. userNames:[],
  107. chargStationName:'',
  108. chargStationNameClearFlag: true
  109. },
  110. bindChargstationsChange: function(e) {
  111. if (this.data.chargstationsindex != e.detail.value) {
  112. console.log('picker发送选择改变,携带值为', e.detail.value)
  113. let chargstationid = this.data.chargstations[e.detail.value].id;
  114. let worksheetinfo = this.data.worksheetinfo;
  115. worksheetinfo.accendant = null;
  116. worksheetinfo.chargStationId = chargstationid;
  117. this.setData({
  118. chargstationsindex: e.detail.value,
  119. worksheetinfo
  120. })
  121. }
  122. },
  123. bindWorkstatusChange: function(e) {
  124. //console.log('picker发送选择改变,携带值为', e.detail.value)
  125. let workStatus = this.data.workstatus[e.detail.value].value;
  126. let worksheetinfo = this.data.worksheetinfo;
  127. worksheetinfo.workStatus = workStatus;
  128. this.setData({
  129. workstatusindex: e.detail.value,
  130. worksheetinfo
  131. });
  132. },
  133. bindWorkBigclassChange: function(e) {
  134. //console.log('picker发送选择改变,携带值为', e.detail.value)
  135. let workBigclass = this.data.workBigclass[e.detail.value].value;
  136. let worksheetinfo = this.data.worksheetinfo;
  137. worksheetinfo.workBigclass = workBigclass;
  138. this.setData({
  139. workBigclassindex: e.detail.value,
  140. worksheetinfo
  141. });
  142. },
  143. bindwokSmallclassChange: function(e) {
  144. //console.log('picker发送选择改变,携带值为', e.detail.value)
  145. let wokSmallclass = this.data.wokSmallclass[e.detail.value].value;
  146. let worksheetinfo = this.data.worksheetinfo;
  147. worksheetinfo.wokSmallclass = wokSmallclass;
  148. this.setData({
  149. wokSmallclassindex: e.detail.value,
  150. worksheetinfo
  151. });
  152. },
  153. bindBreakdownType(e) {
  154. //console.log('picker发送选择改变,携带值为', e.detail.value)
  155. let breakdownType = this.data.breakdownType[e.detail.value].value;
  156. let worksheetinfo = this.data.worksheetinfo;
  157. worksheetinfo.breakdownType = breakdownType;
  158. this.setData({
  159. breakdownTypeindex: e.detail.value,
  160. worksheetinfo
  161. });
  162. },
  163. chargStationNameSelect:function(e){
  164. let url = `/pages/worksheetinfo/findstation`;
  165. wx.navigateTo({
  166. url
  167. });
  168. },
  169. bindAccendantChange: function(e) {
  170. let accendant = this.data.worksheetinfo.accendant;
  171. let chargStationId = this.data.worksheetinfo.chargStationId==null?0:this.data.worksheetinfo.chargStationId;
  172. let url = `/pages/worksheetinfo/accendant?chargstationid=${chargStationId}&accendant=${accendant}`;
  173. wx.navigateTo({
  174. url
  175. });
  176. },
  177. // bindExceptdateChange(e) {
  178. // this.setData({
  179. // exceptdate: e.detail.value
  180. // })
  181. // },
  182. // bindExcepttimeChange(e) {
  183. // this.setData({
  184. // excepttime: e.detail.value
  185. // })
  186. // },
  187. bindFinishdateChange(e) {
  188. this.setData({
  189. finishdate: e.detail.value
  190. })
  191. },
  192. bindFinishtimeChange(e) {
  193. this.setData({
  194. finishtime: e.detail.value
  195. })
  196. },
  197. bindMainLocationInput(e) {
  198. let mainLocation = e.detail.value;
  199. let worksheetinfo = this.data.worksheetinfo;
  200. worksheetinfo.mainLocation = mainLocation;
  201. this.setData({
  202. worksheetinfo
  203. });
  204. },
  205. bindContentInput(e) {
  206. let content = e.detail.value;
  207. // let worksheetinfo = this.data.worksheetinfo;
  208. // worksheetinfo.content = content;
  209. this.setData({
  210. "worksheetinfo.content":content
  211. });
  212. },
  213. bindWorkSheetSubmit(e) {
  214. let worksheetinfo = this.data.worksheetinfo;
  215. worksheetinfo.operatorName = this.data.userNames.length>0?this.data.userNames[0]:"";
  216. worksheetinfo.pams = this.data.accendantids;
  217. console.info(this.data.accendantids)
  218. // worksheetinfo.accendant = null;
  219. // if (this.data.exceptdate ) {
  220. // // if (this.data.exceptdate && this.data.excepttime) {
  221. // worksheetinfo.exceptTime = this.data.exceptdate + " " + this.data.excepttime + ":00";
  222. // }
  223. worksheetinfo.exceptTime = this.data.exceptparams.pText + ":00";
  224. // if (this.data.finishdate){
  225. // // if (this.data.finishdate && this.data.finishtime){
  226. // worksheetinfo.finishTime = this.data.finishdate + " " + this.data.finishtime + ":00";
  227. // }
  228. worksheetinfo.workEndtime = this.data.workEndtimeParams.pText == '0000-00-00 00:00'? null : this.data.workEndtimeParams.pText + ":00";
  229. console.info(worksheetinfo.exceptTime + ":00")
  230. console.info(worksheetinfo.finishTime + ":00")
  231. let images = this.data.images;
  232. var imgString = [];
  233. var pciString = [];
  234. this.data.pcitures.forEach((item, index) =>{
  235. pciString.push(item.src);
  236. });
  237. if(worksheetinfo.mainLocation == '' || worksheetinfo.mainLocation == undefined){
  238. wx.showModal({
  239. showCancel: false,
  240. content: '地址不能为空,请填写!',
  241. confirmColor:'#00AADD',
  242. });
  243. return;
  244. }
  245. if(worksheetinfo.pams.length == 0){
  246. wx.showModal({
  247. showCancel: false,
  248. content: '运维人员不能为空,请填写!',
  249. confirmColor:'#00AADD',
  250. });
  251. return;
  252. }
  253. if(worksheetinfo.content == '' || worksheetinfo.content == undefined){
  254. wx.showModal({
  255. showCancel: false,
  256. content: '工作内容不能为空,请填写!',
  257. confirmColor:'#00AADD',
  258. });
  259. return;
  260. }
  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 = null;
  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: null,
  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=null;
  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. })