addworksheetinfo.js 18 KB

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