daily-inspection.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. onShareAppMessage: function () {
  87. },
  88. /**
  89. * 历史记录
  90. */
  91. history: function () {
  92. wx.navigateTo({
  93. url: '../meeting-inspection-history/meeting-inspection-history?inspectionType=10&meetingId=',
  94. });
  95. },
  96. /**
  97. * 巡检结果不正常
  98. * @param {*} e
  99. */
  100. abnormal: function (e) {
  101. this.setData({
  102. abnormalIndex: e.currentTarget.dataset.index
  103. });
  104. wx.navigateTo({
  105. url: '../meeting-inspection-abnormal/meeting-inspection-abnormal?inspectionProjectId=' + e.currentTarget.dataset.id,
  106. })
  107. },
  108. /**
  109. * 巡检结果正常
  110. * @param {*} e
  111. */
  112. normal: function (e) {
  113. let that = this;
  114. // 修改巡检结果为正常(10)
  115. that.data.inspectionProjectList[e.currentTarget.dataset.index].result = 10;
  116. that.data.inspectionProjectList[e.currentTarget.dataset.index].color = '#2EC3CD';
  117. that.data.inspectionProjectList[e.currentTarget.dataset.index].results = '正常';
  118. let list = that.data.inspectionResultList;
  119. list.push({
  120. inspectionProjectId: e.currentTarget.dataset.id,
  121. result: 10
  122. });
  123. that.setData({
  124. inspectionProjectList: that.data.inspectionProjectList,
  125. inspectionResultList: list
  126. });
  127. },
  128. /**
  129. * 提交巡检结果
  130. */
  131. submitInspection: function () {
  132. let that = this;
  133. let inspectionResultList = that.data.inspectionResultList;
  134. if (!inspectionResultList || inspectionResultList.length < 1) {
  135. util.toast('请选择巡检结果');
  136. return;
  137. }
  138. wx.showModal({
  139. cancelColor: 'cancelColor',
  140. title: '巡检工程师',
  141. showCancel: false,
  142. editable: true,
  143. placeholderText: '请输入姓名',
  144. success: (res) => {
  145. if (!res.content) {
  146. util.toast('请输入姓名');
  147. return;
  148. } else {
  149. util.post({
  150. url: '/api/inspection/record/addBean',
  151. data: {
  152. inspectionType: that.data.inspectionType,
  153. inspectionResultList: inspectionResultList,
  154. inspectionPersonnel: res.content
  155. },
  156. success: (res) => {
  157. wx.hideLoading();
  158. if (res.data.code != 200) {
  159. util.toast(res.data.msg);
  160. } else {
  161. util.toast(res.data.msg);
  162. setTimeout(() => {
  163. wx.navigateBack({
  164. delta: -1,
  165. });
  166. }, 1000);
  167. }
  168. }
  169. });
  170. }
  171. }
  172. });
  173. }
  174. })