addworksheetinfo.js 16 KB

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