daily-inspection.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // pages/daily-inspection/daily-inspection.js
  2. const util = require('../../utils/util.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. inspectionProjectList: [],
  9. inspectionType: 10,//10:日常巡检,20:会议巡检
  10. inspectionResultList: [],
  11. abnormalIndex: null,
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. let that = this;
  18. util.get({
  19. url: '/api/inspection/template/getDailyInspectionProject',
  20. header: {
  21. 'Content-Type': 'application/x-www-form-urlencoded'
  22. },
  23. success: (res) => {
  24. wx.hideLoading();
  25. console.info(res)
  26. if (res.data.code != 200) {
  27. util.toast(res.data.msg);
  28. } else {
  29. that.setData({
  30. inspectionProjectList: res.data.data
  31. });
  32. }
  33. }
  34. });
  35. },
  36. /**
  37. * 生命周期函数--监听页面初次渲染完成
  38. */
  39. onReady: function () {
  40. },
  41. /**
  42. * 生命周期函数--监听页面显示
  43. */
  44. onShow: function () {
  45. let that = this;
  46. let item = wx.getStorageSync('inspectionResultItem');
  47. if (item) {
  48. let obj = JSON.parse(item);
  49. let index = that.data.abnormalIndex;
  50. that.data.inspectionProjectList[index].result = 20;
  51. that.data.inspectionProjectList[index].color = '#E95543';
  52. that.data.inspectionProjectList[index].results = '不正常';
  53. let list = that.data.inspectionResultList;
  54. list.push(obj);
  55. that.setData({
  56. inspectionProjectList: that.data.inspectionProjectList,
  57. inspectionResultList: list,
  58. abnormalIndex: null
  59. });
  60. wx.removeStorageSync('inspectionResultItem');
  61. }
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function () {
  72. },
  73. /**
  74. * 页面相关事件处理函数--监听用户下拉动作
  75. */
  76. onPullDownRefresh: function () {
  77. },
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom: function () {
  82. },
  83. /**
  84. * 历史记录
  85. */
  86. history: function () {
  87. wx.navigateTo({
  88. url: '../meeting-inspection-history/meeting-inspection-history?inspectionType=10&meetingId=',
  89. });
  90. },
  91. /**
  92. * 巡检结果不正常
  93. * @param {*} e
  94. */
  95. abnormal: function (e) {
  96. this.setData({
  97. abnormalIndex: e.currentTarget.dataset.index
  98. });
  99. wx.navigateTo({
  100. url: '../meeting-inspection-abnormal/meeting-inspection-abnormal?inspectionProjectId=' + e.currentTarget.dataset.id,
  101. })
  102. },
  103. /**
  104. * 巡检结果正常
  105. * @param {*} e
  106. */
  107. normal: function (e) {
  108. let that = this;
  109. // 修改巡检结果为正常(10)
  110. that.data.inspectionProjectList[e.currentTarget.dataset.index].result = 10;
  111. that.data.inspectionProjectList[e.currentTarget.dataset.index].color = '#2EC3CD';
  112. that.data.inspectionProjectList[e.currentTarget.dataset.index].results = '正常';
  113. let list = that.data.inspectionResultList;
  114. list.push({
  115. inspectionProjectId: e.currentTarget.dataset.id,
  116. result: 10
  117. });
  118. that.setData({
  119. inspectionProjectList: that.data.inspectionProjectList,
  120. inspectionResultList: list
  121. });
  122. },
  123. /**
  124. * 提交巡检结果
  125. */
  126. submitInspection: function () {
  127. let that = this;
  128. let inspectionResultList = that.data.inspectionResultList;
  129. if (!inspectionResultList || inspectionResultList.length < 1) {
  130. util.toast('请选择巡检结果');
  131. return;
  132. }
  133. wx.showModal({
  134. cancelColor: 'cancelColor',
  135. title: '巡检工程师',
  136. showCancel: false,
  137. editable: true,
  138. placeholderText: '请输入姓名',
  139. success: (res) => {
  140. if (!res.content) {
  141. util.toast('请输入姓名');
  142. return;
  143. } else {
  144. util.post({
  145. url: '/api/inspection/record/addBean',
  146. data: {
  147. inspectionType: that.data.inspectionType,
  148. inspectionResultList: inspectionResultList,
  149. inspectionPersonnel: res.content
  150. },
  151. success: (res) => {
  152. wx.hideLoading();
  153. if (res.data.code != 200) {
  154. util.toast(res.data.msg);
  155. } else {
  156. util.toast(res.data.msg);
  157. setTimeout(() => {
  158. wx.navigateBack({
  159. delta: -1,
  160. });
  161. }, 1000);
  162. }
  163. }
  164. });
  165. }
  166. }
  167. });
  168. }
  169. })