worksheetinfo.js 16 KB

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