worksheetinfo.js 14 KB

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