You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

434 lines
11 KiB

  1. var app = getApp();
  2. const config = require('../../../config/config.js')
  3. const util = require('../../../utils/util.js')
  4. const Http = require('../../../utils/HttpBasics.js')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. actions: [
  11. // { name: "抄电", id: 1 },
  12. // { name: "抄水", id: 2 },
  13. // { name: "抄燃气", id: 3 }
  14. ],
  15. actionID: 1,
  16. timeIndex: 0,
  17. typeIndex: 0,
  18. searchIndex: 0,
  19. timeArr: ['区间1', '区间2', '区间3', '区间4'],
  20. typeArr: ['用户表', '公共表'],
  21. searchArr: ['按表号查询', '按店铺查询'],
  22. shopNumber: "",
  23. searchKey: "",
  24. buildIndex: 0,
  25. floorIndex: 0,
  26. shopIndex: 0,
  27. isShowBuilding: false,
  28. isShowfloor: false,
  29. isShowshop: false,
  30. buildArr: [],
  31. floorArr: [],
  32. shopArr: [],
  33. building: "",
  34. floor: "",
  35. preShopReadingList: [],
  36. date: "2024-08-28", //默认起始时间
  37. date2: "2024-08-28", //默认结束时间
  38. },
  39. goAction(e) {
  40. const id = e.target.dataset.id
  41. this.setData({
  42. actionID: id
  43. })
  44. },
  45. bindSelectChange(e) {
  46. const index = e.target.dataset.index
  47. const value = e.detail.value
  48. console.log(value, 'value');
  49. this.setData({
  50. searchKey: ""
  51. })
  52. if (index == "timeIndex") {
  53. this.setData({
  54. timeIndex: value
  55. })
  56. } else if (index == "typeIndex") {
  57. this.setData({
  58. typeIndex: value,
  59. })
  60. } else if (index == "searchIndex") {
  61. this.setData({
  62. searchIndex: value,
  63. })
  64. } else if (index == "buildIndex") {
  65. this.setData({
  66. building: this.data.buildArr[value].id,
  67. buildIndex: value,
  68. isShowBuilding: true,
  69. floorArr: this.data.buildArr[value].floors
  70. })
  71. } else if (index == "floorIndex") {
  72. // wx.showLoading({
  73. // title: '请稍等',
  74. // })
  75. // this.getShopList(this.data.floorArr[value].id)
  76. this.setData({
  77. floor: this.data.floorArr[value].id,
  78. floorIndex: value,
  79. isShowfloor: true,
  80. })
  81. } else if (index == "shopIndex") {
  82. this.setData({
  83. shopIndex: value,
  84. isShowshop: true,
  85. })
  86. }
  87. },
  88. changeShopNumber(e) {
  89. const value = e.detail.value
  90. this.setData({
  91. shopNumber: value
  92. })
  93. },
  94. changeSearchKey(e) {
  95. const value = e.detail.value
  96. this.setData({
  97. searchKey: value
  98. })
  99. },
  100. getbuildingfloorlist() {
  101. Http.get({
  102. url: config.api.getbuildingfloorlist
  103. })
  104. .then(res => {
  105. console.log(res.data)
  106. this.setData({
  107. buildArr: res.data
  108. })
  109. })
  110. .catch(err => {
  111. });
  112. },
  113. getShopList(floor) {
  114. Http.get({
  115. url: config.api.getShopList + floor
  116. })
  117. .then(res => {
  118. console.log(res.data.list)
  119. this.setData({
  120. shopArr: res.data.list
  121. })
  122. wx.hideLoading()
  123. })
  124. .catch(err => {
  125. });
  126. },
  127. getShopMeterList() {
  128. let type = this.data.actionID
  129. // let shopNumber = this.data.shopNumber
  130. // let shopId = this.data.shopArr[this.data.shopIndex].id
  131. // if (!shopId) shopId = ""
  132. // const physicsType = this.data.typeIndex * 1 + 1
  133. const searchKey = this.data.searchKey
  134. const building = this.data.building
  135. const floor = this.data.floor
  136. console.log(building, floor);
  137. Http.get({
  138. // url: config.api.getShopMeterList +
  139. // "physicsType=" + physicsType +
  140. // "&type=" + type +
  141. // "&shopId=" + shopId +
  142. // "&shopNumber=" + shopNumber
  143. url: config.api.getShopMeterList +
  144. "searchKey=" + searchKey +
  145. "&type=" + type +
  146. "&building=" + building +
  147. "&floor=" + floor
  148. })
  149. .then(res => {
  150. console.log(res.data)
  151. this.setData({
  152. preShopReadingList: res.data.list
  153. })
  154. res.data.list.forEach((item, index) => {
  155. this.getPreShopReadingList(item.id, index)
  156. })
  157. if (!res.data.list.length) {
  158. wx.showToast({
  159. title: "该店铺暂无数据!",
  160. icon: 'error',
  161. duration: 2000,
  162. mask: false
  163. });
  164. }
  165. })
  166. .catch(err => {
  167. });
  168. },
  169. getPreShopReadingList(id, index) {
  170. Http.get({
  171. url: config.api.preShopReadingList + id
  172. })
  173. .then(res => {
  174. try {
  175. console.log(res, 'res', index);
  176. const preShopReadingList = [...this.data.preShopReadingList]
  177. if (res.data) {
  178. res.data.formatTime = this.timestampToTime(res.data.preTime, "YYYY-MM-DD")
  179. preShopReadingList[index].meterData = res.data
  180. console.log(index, 'index1');
  181. } else {
  182. const obj = {
  183. meterId: id,
  184. preNumber: "",
  185. curNumber: "",
  186. formatTime: "",
  187. preByName: ""
  188. }
  189. preShopReadingList[index].meterData = obj
  190. console.log(index, 'index2');
  191. }
  192. this.setData({
  193. preShopReadingList
  194. })
  195. console.log(preShopReadingList, 'preShopReadingList');
  196. } catch (error) {
  197. console.log(error, 'err');
  198. }
  199. })
  200. .catch(err => {
  201. });
  202. },
  203. getMeterList() {
  204. Http.get({
  205. url: config.api.meterList
  206. })
  207. .then(res => {
  208. const valus = Object.values(res.data)
  209. const keys = Object.keys(res.data)
  210. const arr = []
  211. valus.forEach((item, index) => {
  212. const obj = {
  213. id: keys[index] * 1,
  214. name: item
  215. }
  216. arr.push(obj)
  217. })
  218. this.setData({
  219. actions: arr
  220. })
  221. console.log(this.data.actions, 'this.data.actions')
  222. })
  223. .catch(err => {
  224. });
  225. },
  226. getTimeList() {
  227. Http.get({
  228. url: config.api.timeList + "?type=" + this.data.actionID
  229. })
  230. .then(res => {
  231. console.log(res.data)
  232. res.data.list.forEach(item => {
  233. item.period = item.period ? item.period : "*"
  234. })
  235. this.setData({
  236. timeArr: res.data.list
  237. })
  238. })
  239. .catch(err => {
  240. });
  241. },
  242. numberInput(e) {
  243. console.log(e, 'e');
  244. const index = e.currentTarget.dataset.index
  245. const value = e.detail.value
  246. const preShopReadingList = [...this.data.preShopReadingList]
  247. preShopReadingList[index].meterData.curNumber = value
  248. this.setData({
  249. preShopReadingList
  250. })
  251. },
  252. bindDateChange(e) {
  253. let that = this;
  254. that.setData({
  255. date: e.detail.value,
  256. })
  257. console.log(that.data.date)
  258. },
  259. bindDateChange2(e) {
  260. let that = this;
  261. that.setData({
  262. date2: e.detail.value,
  263. })
  264. console.log(that.data.date2)
  265. },
  266. isConfirmTouched() {
  267. wx.showToast({
  268. icon: "none",
  269. title: "该表已确认,无法更改!",
  270. })
  271. },
  272. save() {
  273. const meterReadingList = this.data.preShopReadingList.map(item => {
  274. const obj = {
  275. meterId: item.id,
  276. curNumber: item.meterData.curNumber,
  277. }
  278. if (item.meterData.id) {
  279. obj.id = item.meterData.id
  280. }
  281. return obj
  282. })
  283. Http.post({
  284. url: config.api.commitEnergyReading,
  285. data: {
  286. startTime: this.data.date + " 00:00:00",
  287. endTime: this.data.date2 + " 23:59:59",
  288. meterReadingList
  289. }
  290. }).then(res => {
  291. wx.showToast({
  292. title: "保存成功!",
  293. icon: 'none',
  294. duration: 2000,
  295. mask: false,
  296. });
  297. this.getShopMeterList()
  298. }).catch(err => {
  299. wx.showToast({
  300. title: err.message ? err.message : "保存失败!",
  301. icon: 'none',
  302. duration: 2000,
  303. mask: false
  304. });
  305. })
  306. },
  307. /**
  308. * @description 根据时间戳获取时间
  309. * @param {*} timestamp 必传,number类型,时间戳数据(10位及以下,10位至13位);若不传,则返回:“无时间戳”
  310. * @param {*} format 选传,string类型,提供以下时间格式:YYYY-MM-DD hh:mm:ss、YYYY/MM/DD hh:mm:ss、YYYY.MM.DD hh:mm:ss、YYYY MM DD hh:mm:ss、YYYY年MM月DD日 hh:mm:ss、YYYY-MM-DD、YYYY/MM/DD、YYYY.MM.DD、YYYY MM DD、YYYY年MM月DD日;若不传,则默认为:YYYY-MM-DD
  311. * @returns 根据要求的时间格式
  312. * @version V 1.0, Created by YWQ, 2022.10.20
  313. */
  314. timestampToTime(timestamp, format) {
  315. //时间戳为10位需*1000,时间戳为13位不需乘1000
  316. if (!timestamp) return
  317. const length = timestamp.length
  318. if (length <= 10) {
  319. var date = new Date(timestamp * 1000)
  320. } else {
  321. var date = new Date(timestamp)
  322. }
  323. let Y = String(date.getFullYear())
  324. let M = String(date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
  325. let D = String(date.getDate() + 1 < 10 ? '0' + (date.getDate()) : date.getDate())
  326. let h = String(date.getHours() + 1 < 10 ? '0' + (date.getHours()) : date.getHours())
  327. let m = String(date.getMinutes() + 1 < 10 ? '0' + (date.getMinutes()) : date.getMinutes())
  328. let s = String(date.getSeconds() + 1 < 10 ? '0' + (date.getSeconds()) : date.getSeconds())
  329. // return Y + M + D + h + m + s
  330. if (format == "YYYY-MM-DD hh:mm:ss") {
  331. return Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s
  332. } else if (format == "YYYY/MM/DD hh:mm:ss") {
  333. return Y + "/" + M + "/" + D + " " + h + ":" + m + ":" + s
  334. } else if (format == "YYYY.MM.DD hh:mm:ss") {
  335. return Y + "." + M + "." + D + " " + h + ":" + m + ":" + s
  336. } else if (format == "YYYY MM DD hh:mm:ss") {
  337. return Y + " " + M + " " + D + " " + h + ":" + m + ":" + s
  338. } else if (format == "YYYY年MM月DD日 hh:mm:ss") {
  339. return Y + "年" + M + "月" + D + "日" + " " + h + ":" + m + ":" + s
  340. } else if (format == "YYYY-MM-DD") {
  341. return Y + "-" + M + "-" + D
  342. } else if (format == "YYYY/MM/DD") {
  343. return Y + "/" + M + "/" + D
  344. } else if (format == "YYYY.MM.DD") {
  345. return Y + "." + M + "." + D
  346. } else if (format == "YYYY MM DD") {
  347. return Y + " " + M + " " + D
  348. } else if (format == "YYYY年MM月DD日") {
  349. return Y + "年" + M + "月" + D + "日"
  350. } else {
  351. return Y + "-" + M + "-" + D
  352. }
  353. },
  354. /**
  355. * 生命周期函数--监听页面加载
  356. */
  357. onLoad(options) {
  358. },
  359. /**
  360. * 生命周期函数--监听页面初次渲染完成
  361. */
  362. onReady() {
  363. },
  364. /**
  365. * 生命周期函数--监听页面显示
  366. */
  367. onShow() {
  368. Http.setToken(app.globalData.token)
  369. this.getbuildingfloorlist()
  370. this.getTimeList()
  371. this.getMeterList()
  372. },
  373. /**
  374. * 生命周期函数--监听页面隐藏
  375. */
  376. onHide() {
  377. },
  378. /**
  379. * 生命周期函数--监听页面卸载
  380. */
  381. onUnload() {
  382. },
  383. /**
  384. * 页面相关事件处理函数--监听用户下拉动作
  385. */
  386. onPullDownRefresh() {
  387. },
  388. /**
  389. * 页面上拉触底事件的处理函数
  390. */
  391. onReachBottom() {
  392. },
  393. /**
  394. * 用户点击右上角分享
  395. */
  396. onShareAppMessage() {
  397. }
  398. })