worksheetinfo.js 15 KB

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