worksheetinfo.js 16 KB

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