dailyFill.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. var util = require('../../../utils/util.js')
  2. const app = getApp()
  3. Page({
  4. data: {
  5. orderId: null,
  6. selectedDate: {},
  7. selectedDateArray: [],
  8. datas: [],
  9. customerId: null,
  10. orderDetail: {},
  11. records: [],
  12. },
  13. onLoad(options) {
  14. const id = options.id
  15. this.setData({
  16. orderId: id,
  17. })
  18. this.initdatas()
  19. this.getDetail()
  20. this.getDailyFillList()
  21. },
  22. // 获取服务工单基本信息 和 工单记录进度
  23. getDetail() {
  24. var send_data = [
  25. { name: 'getInstallationOrderById', returntype: 'Map', parammaps: { id: this.data.orderId } },
  26. ]
  27. util.getDataByNames(send_data, this.handleDetail)
  28. },
  29. handleDetail(res) {
  30. var data = res.data
  31. this.setData({
  32. orderDetail: data.getInstallationOrderById.list[0],
  33. customerId: data.getInstallationOrderById.list[0].customerId,
  34. })
  35. },
  36. // 初始化日期数组
  37. initdatas: function () {
  38. const dates = []
  39. const today = new Date()
  40. // 添加今天和前两天的日期
  41. for (let i = 0; i < 3; i++) {
  42. const date = new Date(today)
  43. date.setDate(today.getDate() - i)
  44. const formatDate = this.formatDate(date)
  45. dates.push(formatDate)
  46. }
  47. this.setData({
  48. datas: dates,
  49. selectedDates: { [dates[0]]: true }, // 默认选中今天
  50. selectedDateArray: [dates[0]],
  51. })
  52. },
  53. // 格式化日期为 YYYY-MM-DD
  54. formatDate: function (date) {
  55. const year = date.getFullYear()
  56. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  57. const day = date.getDate().toString().padStart(2, '0')
  58. return `${year}-${month}-${day}`
  59. },
  60. // 日期选择
  61. selectDate(e) {
  62. const date = e.currentTarget.dataset.date
  63. const selectedDates = { ...this.data.selectedDates }
  64. let selectedDateArray = [...this.data.selectedDateArray]
  65. // 切换选中状态
  66. if (selectedDates[date]) {
  67. // 如果当前只有一个选中的日期,不允许取消
  68. if (selectedDateArray.length === 1) {
  69. wx.showToast({
  70. title: '至少需要选择一个日期',
  71. icon: 'none',
  72. })
  73. return
  74. }
  75. delete selectedDates[date]
  76. selectedDateArray = selectedDateArray.filter((item) => item !== date)
  77. } else {
  78. selectedDates[date] = true
  79. selectedDateArray.push(date)
  80. }
  81. this.setData({
  82. selectedDates: selectedDates,
  83. selectedDateArray: selectedDateArray,
  84. })
  85. console.log(selectedDateArray, 'selectedDates')
  86. this.getDailyFillList()
  87. },
  88. getDailyFillList() {
  89. var send_data = [
  90. {
  91. name: 'getInstallationDailyData',
  92. returntype: 'Map',
  93. parammaps: { orderId: this.data.orderId, dates: this.data.selectedDateArray.join(',') },
  94. },
  95. ]
  96. util.getDataByNames(send_data, this.handleDailyFill)
  97. },
  98. handleDailyFill(res) {
  99. if (res.data.getInstallationDailyData.list) {
  100. res.data.getInstallationDailyData.list.map((item) => {
  101. item.installDate = ''
  102. item.todayQuantity = 0
  103. item.remark = ''
  104. })
  105. this.setData({
  106. records: res.data.getInstallationDailyData.list,
  107. })
  108. } else {
  109. this.setData({
  110. records: [],
  111. })
  112. }
  113. },
  114. onRemarkChange(e) {
  115. var index = e.target.dataset.index
  116. let records = this.data.records
  117. records[index].remark = e.detail.value
  118. this.setData({
  119. records: records,
  120. })
  121. console.log(this.data.records, 'remark')
  122. },
  123. onQuantityChange(e) {
  124. console.log(e, 'ee')
  125. var index = e.target.dataset.index
  126. let records = this.data.records
  127. records[index].todayQuantity = e.detail.value
  128. this.setData({
  129. records: records,
  130. })
  131. console.log(this.data.records, '数量')
  132. },
  133. // 提交每日填写
  134. posttDailyFill() {
  135. // 检查每条记录的必填项
  136. for (let i = 0; i < this.data.records.length; i++) {
  137. const record = this.data.records[i]
  138. record.installDate = record.date
  139. if (record.todayQuantity < 0) {
  140. wx.showToast({
  141. title: '请正确填写今日完成量',
  142. icon: 'none',
  143. })
  144. return
  145. }
  146. if (record.remark == '' || !record.remark) {
  147. wx.showToast({
  148. title: '请填写备注',
  149. icon: 'none',
  150. })
  151. return
  152. }
  153. }
  154. console.log(this.data.records, 'this.data.records')
  155. var send_data = {
  156. common: { returnmap: '0' },
  157. data: [
  158. {
  159. name: 'deleteInstallationDailyWriteByDates',
  160. type: 'e',
  161. parammaps: {
  162. datas: this.data.selectedDateArray.join(','),
  163. userId: app.globalData.g_userId,
  164. orderId: this.data.orderId,
  165. },
  166. },
  167. {
  168. name: 'submitInstallationDailyWrite',
  169. resultmaps: {
  170. list: this.data.records,
  171. },
  172. children: [
  173. {
  174. name: 'insertInstallationDailyWrite',
  175. type: 'e',
  176. parammaps: {
  177. orderId: this.data.orderId,
  178. installUserId: app.globalData.g_userId,
  179. installUserName: app.globalData.g_lgName,
  180. goodsName: '@submitInstallationDailyWrite.goodsName',
  181. installDate: '@submitInstallationDailyWrite.installDate',
  182. goodsId: '@submitInstallationDailyWrite.goodsId',
  183. todayQuantity: '@submitInstallationDailyWrite.todayQuantity',
  184. remark: '@submitInstallationDailyWrite.remark',
  185. projectId: '@submitInstallationDailyWrite.projectId',
  186. projectName: '@submitInstallationDailyWrite.projectName',
  187. },
  188. },
  189. ],
  190. },
  191. {
  192. name: 'refreshInstallationOrderDetailQuantity',
  193. type: 'e',
  194. parammaps: {
  195. orderId: this.data.orderId,
  196. },
  197. },
  198. {
  199. name: 'refreshInstallationOrderProcessByOrderId',
  200. type: 'e',
  201. parammaps: {
  202. orderId: this.data.orderId,
  203. },
  204. },
  205. {
  206. name: 'insertInstallationOrderProcessLog',
  207. type: 'e',
  208. parammaps: {
  209. orderId: this.data.orderId,
  210. operationType: 'write',
  211. operationUserId: app.globalData.g_userId,
  212. operationUserName: app.globalData.g_lgName,
  213. beforeStatus: '处理中',
  214. afterStatus: '处理中',
  215. operationContent: '',
  216. },
  217. },
  218. {
  219. name: 'updateDailyDetailYesterdayAndBeforeQuantity',
  220. type: 'e',
  221. parammaps: {
  222. orderId: this.data.orderId,
  223. },
  224. },
  225. ],
  226. }
  227. util.execDataByConfig(send_data, this.handleAccept)
  228. },
  229. handleAccept: function (res) {
  230. console.log(res, 'res')
  231. if (res.msg !== 'fail') {
  232. wx.showToast({
  233. title: '保存成功',
  234. icon: 'success',
  235. duration: 3000,
  236. success: function () {
  237. // wx.redirectTo() 会关闭当前页面,返回时不会刷新
  238. // wx.navigateBack() 返回上一页时会触发onShow生命周期,可以在onShow中刷新数据
  239. setTimeout(function () {
  240. // wx.navigateBack()
  241. wx.redirectTo({ url: '../serviceTicket/serviceTicket' })
  242. }, 1000)
  243. },
  244. })
  245. } else {
  246. wx.showToast({
  247. title: '保存失败' + res.data,
  248. icon: 'error',
  249. duration: 2000,
  250. })
  251. }
  252. },
  253. handleReject() {
  254. wx.navigateBack()
  255. },
  256. goBack() {
  257. wx.navigateBack()
  258. },
  259. viewHistory() {
  260. var id = this.data.orderId
  261. wx.navigateTo({
  262. url: `/pages/workbench/historyFill/historyFill?id=${id}`,
  263. })
  264. },
  265. // 更新今日完成量
  266. updateTodayQuantity(e) {
  267. const value = parseInt(e.detail.value) || 0
  268. const remaining = this.data.totalQuantity - this.data.completedQuantity - value
  269. this.setData({
  270. todayQuantity: value,
  271. remainingQuantity: remaining >= 0 ? remaining : 0,
  272. })
  273. },
  274. // 保存记录
  275. saveRecord() {
  276. wx.showLoading({
  277. title: '保存中...',
  278. })
  279. // 这里添加保存逻辑
  280. setTimeout(() => {
  281. wx.hideLoading()
  282. wx.showToast({
  283. title: '保存成功',
  284. icon: 'success',
  285. })
  286. }, 1500)
  287. },
  288. })