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