addworksheetinfo.js 16 KB

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