合伙人运营小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. // pages/createorder/index.js
  2. const api = require('../../api/index.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. cartype:1,
  9. index:0,
  10. objectArray: [],
  11. objdriver: [],
  12. driverindex:0,
  13. date: '',
  14. time: '', // 初始时间
  15. userdata:[],
  16. userindex:0,
  17. addressindex:'',
  18. address: [],
  19. items: [
  20. {value: 1, name: '光伏'},
  21. {value: 2, name: '风电'},
  22. {value: 3, name: '网电'},
  23. ],
  24. greenelectricity:0,
  25. workorderpower:'',
  26. orderdata:[],
  27. orderid:'',
  28. createtype:false,
  29. workorderindex:0,
  30. // 充放电记录列表,初始包含一行默认数据
  31. putDischargeList: [
  32. {
  33. type: '充电',
  34. power: '200',
  35. startTime: '9:00',
  36. endTime: '12:00'
  37. }
  38. ],
  39. chargeDischargeList: [
  40. {
  41. type: '放电',
  42. power: '200',
  43. startTime: '9:00',
  44. endTime: '12:00'
  45. }
  46. ]
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad(options) {
  52. console.log(options);
  53. this.setData({
  54. userdata: wx.getStorageSync('user') || {},
  55. });
  56. this.getaddress()
  57. if (options.order!='') {
  58. this.setData({
  59. orderid:options.order
  60. })
  61. this.getoneworkorder()
  62. }
  63. // this.getdriver()
  64. // this.getvehicle()
  65. },
  66. workordertype(e){
  67. console.log(e);
  68. this.setData({
  69. workorderindex:e.currentTarget.dataset.index
  70. })
  71. },
  72. // 工单详情
  73. getoneworkorder() {
  74. const data = {
  75. workorderId: this.data.orderid
  76. };
  77. api.request(`/sysworkorder/selectworkorderId`, 'post', data, { isPublic: false })
  78. .then((data) => {
  79. if (data.code == 200) {
  80. this.setData({
  81. workorderElectricity:data.data.workorderElectricity,
  82. workorderpower:data.data.workorderPower,
  83. greenelectricity:data.data.greenelectricity,
  84. date:data.data.workorderStarttime.slice(0,10),
  85. time:data.data.workorderStarttime.slice(11,16),
  86. })
  87. for (let index = 0; index < this.data.address.length; index++) {
  88. if (data.data.addressId==this.data.address[index].addressId) {
  89. this.setData({
  90. addressindex:index
  91. })
  92. }
  93. }
  94. }
  95. })
  96. .catch((err) => {
  97. console.error('获取工单信息失败:', err);
  98. this.showInfo('获取工单信息失败');
  99. });
  100. },
  101. // 司机
  102. getdriver(){
  103. let data ={
  104. }
  105. api.request(`/sysdriver/selectdriverall`, 'post',data,{ isPublic: false })
  106. .then((data) => {
  107. console.log(data.data);
  108. let obj = []
  109. for (let index = 0; index < data.data.length; index++) {
  110. let carType = ''
  111. if (data.data[index].operationType==1) {
  112. carType = '空闲'
  113. }else if(data.data[index].operationType==2){
  114. carType = '工作中'
  115. }else if(data.data[index].operationType==3){
  116. carType = '维护中'
  117. }
  118. obj.push({
  119. id:data.data[index].operationId,
  120. name:data.data[index].operationName,
  121. subtitle:data.data[index].operationName + ' / ' + carType
  122. })
  123. }
  124. this.setData({
  125. objdriver:obj
  126. })
  127. })
  128. .catch((err) => {
  129. console.error('请求失败:', err);
  130. });
  131. },
  132. // 车型
  133. getvehicle(){
  134. let data ={}
  135. api.request(`/syscar/selectcarall`, 'post',data,{ isPublic: false })
  136. .then((data) => {
  137. let obj = []
  138. for (let index = 0; index < data.data.length; index++) {
  139. let carType = ''
  140. if (data.data[index].carType==1) {
  141. carType = '空闲'
  142. }else if(data.data[index].carType==2){
  143. carType = '工作中'
  144. }else if(data.data[index].carType==3){
  145. carType = '维护中'
  146. }
  147. obj.push({
  148. id:data.data[index].carId,
  149. name:data.data[index].carId + ' / ' + data.data[index].carMondel,
  150. subtitle:data.data[index].carId + ' / ' + data.data[index].carMondel + ' / ' + carType
  151. })
  152. }
  153. this.setData({
  154. objectArray:obj
  155. })
  156. console.log(this.data.objectArray);
  157. })
  158. .catch((err) => {
  159. console.error('请求失败:', err);
  160. });
  161. },
  162. // 地址
  163. getaddress(){
  164. let data ={
  165. operationId:''
  166. }
  167. api.request(`/sysaddress/selectaddress`, 'post',data,{ isPublic: false })
  168. .then((data) => {
  169. console.log(data.data);
  170. for (let index = 0; index < data.data.length; index++) {
  171. if (data.data[index].isDefault) {
  172. this.setData({
  173. addressindex:index
  174. })
  175. }
  176. }
  177. this.setData({
  178. address:data.data
  179. })
  180. })
  181. .catch((err) => {
  182. console.error('请求失败:', err);
  183. });
  184. },
  185. oncar(e){
  186. console.log(e.currentTarget.dataset.index);
  187. this.setData({
  188. cartype:e.currentTarget.dataset.index
  189. })
  190. },
  191. bindDateChange(e) {
  192. console.log('picker发送选择改变,携带值为', e.detail.value)
  193. this.setData({
  194. date: e.detail.value
  195. })
  196. },
  197. // 时间选择变化
  198. bindTimeChange(e) {
  199. this.setData({ time: e.detail.value });
  200. },
  201. // 需求电量
  202. bindKeyInput (e) {
  203. this.setData({
  204. workorderElectricity: e.detail.value
  205. })
  206. },
  207. bindintentionInput (e) {
  208. this.setData({
  209. workorderpower: e.detail.value
  210. })
  211. },
  212. details(){
  213. if (this.data.createtype) {
  214. return
  215. }
  216. this.setData({
  217. createtype:true
  218. })
  219. if (this.data.workorderElectricity==''||this.data.date==''||this.data.time==''||this.data.workorderpower=='') {
  220. wx.showToast({
  221. title: '请填写完整消息',
  222. icon: 'none'
  223. });
  224. return
  225. }
  226. let data ={
  227. addressId:this.data.address[this.data.addressindex].addressId,
  228. workorderElectricity:this.data.workorderElectricity,
  229. greenelectricity:this.data.greenelectricity,
  230. workorderStarttime:this.data.date+' '+this.data.time,
  231. workorderpower:this.data.workorderpower
  232. }
  233. api.request(`/sysworkorder/addworkorder`, 'post',data,{ isPublic: false })
  234. .then((data) => {
  235. console.log(data);
  236. wx.switchTab({
  237. url: '/pages/tool/index',
  238. })
  239. this.setData({
  240. createtype:false
  241. })
  242. })
  243. .catch((err) => {
  244. this.setData({
  245. createtype:false
  246. })
  247. console.error('请求失败:', err);
  248. });
  249. },
  250. // 编辑
  251. editdetails(){
  252. if (this.data.workorderElectricity==''||this.data.date==''||this.data.time==''||this.data.workorderpower=='') {
  253. wx.showToast({
  254. title: '请填写完整消息',
  255. icon: 'none'
  256. });
  257. return
  258. }
  259. let data ={
  260. workorderId:this.data.orderid,
  261. addressId:this.data.address[this.data.addressindex].addressId,
  262. workorderElectricity:this.data.workorderElectricity,
  263. greenelectricity:this.data.greenelectricity,
  264. workorderStarttime:this.data.date+' '+this.data.time,
  265. workorderpower:this.data.workorderpower
  266. }
  267. api.request(`/sysworkorder/updateworkorder`, 'post',data,{ isPublic: false })
  268. .then((data) => {
  269. console.log(data);
  270. wx.switchTab({
  271. url: '/pages/tool/index',
  272. })
  273. })
  274. .catch((err) => {
  275. console.error('请求失败:', err);
  276. });
  277. },
  278. // 司机
  279. bindectArrayChange(e){
  280. console.log(e.detail.value);
  281. this.setData({
  282. index:e.detail.value
  283. })
  284. },
  285. // 车型
  286. binddriverChange(e){
  287. console.log(e.detail.value);
  288. this.setData({
  289. driverindex:e.detail.value
  290. })
  291. },
  292. // 用户
  293. binduserChange(e){
  294. console.log(e);
  295. this.setData({
  296. userindex:e.detail.value
  297. })
  298. },
  299. // 地址
  300. bindPickerChange(e){
  301. console.log(e);
  302. this.setData({
  303. addressindex:e.detail.value
  304. })
  305. },
  306. radioChange(e) {
  307. console.log('radio发生change事件,携带value值为:', e.detail.value)
  308. // const items = this.data.items
  309. // for (let i = 0, len = items.length; i < len; ++i) {
  310. // items[i].checked = items[i].value === e.detail.value
  311. // }
  312. this.setData({
  313. greenelectricity:e.detail.value
  314. })
  315. console.log(this.data.greenelectricity);
  316. },
  317. toconfigure(){
  318. wx.navigateTo({
  319. url: '/package-order/pages/address/index',
  320. });
  321. },
  322. /**
  323. * 添加新的时间段行
  324. */
  325. addRow(e) {
  326. if (e.currentTarget.dataset.name == 'put') {
  327. // 新增行的默认值(时间为空,引导用户选择)
  328. const newRow = {
  329. type: '放电',
  330. power: '',
  331. startTime: '',
  332. endTime: ''
  333. };
  334. const newList = [...this.data.putDischargeList, newRow];
  335. this.setData({
  336. putDischargeList: newList
  337. });
  338. }else{
  339. // 新增行的默认值(时间为空,引导用户选择)
  340. const newRow = {
  341. type: '充电',
  342. power: '',
  343. startTime: '',
  344. endTime: ''
  345. };
  346. const newList = [...this.data.chargeDischargeList, newRow];
  347. this.setData({
  348. chargeDischargeList: newList
  349. });
  350. }
  351. },
  352. /**
  353. * 删除指定行
  354. */
  355. deleteRow(e) {
  356. if (e.currentTarget.dataset.name= 'put') {
  357. const index = e.currentTarget.dataset.index;
  358. const list = [...this.data.putDischargeList];
  359. if (list.length <= 1) {
  360. wx.showToast({
  361. title: '至少保留一条记录',
  362. icon: 'none'
  363. });
  364. return;
  365. }
  366. list.splice(index, 1);
  367. this.setData({
  368. putDischargeList: list
  369. });
  370. }else{
  371. const index = e.currentTarget.dataset.index;
  372. const list = [...this.data.chargeDischargeList];
  373. if (list.length <= 1) {
  374. wx.showToast({
  375. title: '至少保留一条记录',
  376. icon: 'none'
  377. });
  378. return;
  379. }
  380. list.splice(index, 1);
  381. this.setData({
  382. chargeDischargeList: list
  383. });
  384. }
  385. },
  386. /**
  387. * 修改充放电类型
  388. */
  389. changeType(e) {
  390. const index = e.currentTarget.dataset.index;
  391. const typeIndex = e.detail.value;
  392. const type = typeIndex === '0' ? '充电' : '放电';
  393. const list = [...this.data.putDischargeList];
  394. list[index].type = type;
  395. this.setData({
  396. putDischargeList: list
  397. });
  398. },
  399. /**
  400. * 更新电量
  401. */
  402. updatePower(e) {
  403. if (e.currentTarget.dataset.name=='put') {
  404. console.log(e);
  405. const index = e.currentTarget.dataset.index;
  406. const value = e.detail.value;
  407. const list = [...this.data.putDischargeList];
  408. list[index].power = value;
  409. this.setData({
  410. putDischargeList: list
  411. });
  412. }else{
  413. const index = e.currentTarget.dataset.index;
  414. const value = e.detail.value;
  415. const list = [...this.data.chargeDischargeList];
  416. list[index].power = value;
  417. this.setData({
  418. chargeDischargeList: list
  419. });
  420. }
  421. },
  422. /**
  423. * 更新开始时间(选择器版)
  424. */
  425. updateStartTime(e) {
  426. console.log(e);
  427. if (e.currentTarget.dataset.name=='put') {
  428. const index = e.currentTarget.dataset.index;
  429. const value = e.detail.value; // 格式为 HH:MM
  430. const list = [...this.data.putDischargeList];
  431. list[index].startTime = value;
  432. this.setData({
  433. putDischargeList: list
  434. });
  435. }else{
  436. const index = e.currentTarget.dataset.index;
  437. const value = e.detail.value; // 格式为 HH:MM
  438. const list = [...this.data.chargeDischargeList];
  439. list[index].startTime = value;
  440. this.setData({
  441. chargeDischargeList: list
  442. });
  443. }
  444. },
  445. /**
  446. * 更新结束时间(选择器版)
  447. */
  448. updateEndTime(e) {
  449. if (e.currentTarget.dataset.name=='put') {
  450. const index = e.currentTarget.dataset.index;
  451. const value = e.detail.value; // 格式为 HH:MM
  452. const list = [...this.data.putDischargeList];
  453. // 简单校验:结束时间不能早于开始时间
  454. if (list[index].startTime && value) {
  455. const start = new Date(`2000-01-01 ${list[index].startTime}`);
  456. const end = new Date(`2000-01-01 ${value}`);
  457. if (end < start) {
  458. wx.showToast({
  459. title: '结束时间不能早于开始时间',
  460. icon: 'none'
  461. });
  462. return;
  463. }
  464. }
  465. list[index].endTime = value;
  466. this.setData({
  467. putDischargeList: list
  468. });
  469. }else{
  470. const index = e.currentTarget.dataset.index;
  471. const value = e.detail.value; // 格式为 HH:MM
  472. const list = [...this.data.chargeDischargeList];
  473. // 简单校验:结束时间不能早于开始时间
  474. if (list[index].startTime && value) {
  475. const start = new Date(`2000-01-01 ${list[index].startTime}`);
  476. const end = new Date(`2000-01-01 ${value}`);
  477. if (end < start) {
  478. wx.showToast({
  479. title: '结束时间不能早于开始时间',
  480. icon: 'none'
  481. });
  482. return;
  483. }
  484. }
  485. list[index].endTime = value;
  486. this.setData({
  487. chargeDischargeList: list
  488. });
  489. }
  490. },
  491. /**
  492. * 获取所有充放电数据(提交时调用)
  493. */
  494. getAllData() {
  495. const data = this.data.putDischargeList;
  496. // 数据验证
  497. for (let i = 0; i < data.length; i++) {
  498. const item = data[i];
  499. if (!item.power) {
  500. wx.showToast({
  501. title: `第${i+1}行电量不能为空`,
  502. icon: 'none'
  503. });
  504. return null;
  505. }
  506. if (!item.startTime) {
  507. wx.showToast({
  508. title: `第${i+1}行请选择开始时间`,
  509. icon: 'none'
  510. });
  511. return null;
  512. }
  513. if (!item.endTime) {
  514. wx.showToast({
  515. title: `第${i+1}行请选择结束时间`,
  516. icon: 'none'
  517. });
  518. return null;
  519. }
  520. }
  521. return data;
  522. },
  523. /**
  524. * 生命周期函数--监听页面初次渲染完成
  525. */
  526. onReady() {
  527. },
  528. /**
  529. * 生命周期函数--监听页面显示
  530. */
  531. onShow() {
  532. this.getaddress()
  533. },
  534. /**
  535. * 生命周期函数--监听页面隐藏
  536. */
  537. onHide() {
  538. },
  539. /**
  540. * 生命周期函数--监听页面卸载
  541. */
  542. onUnload() {
  543. },
  544. /**
  545. * 页面相关事件处理函数--监听用户下拉动作
  546. */
  547. onPullDownRefresh() {
  548. },
  549. /**
  550. * 页面上拉触底事件的处理函数
  551. */
  552. onReachBottom() {
  553. },
  554. /**
  555. * 用户点击右上角分享
  556. */
  557. onShareAppMessage() {
  558. }
  559. })
  560. //