worksheetinfo.js 15 KB

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