work-order.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // pagesPublic/pages/work-order/work-order.js
  2. var dateTimePicker = require('../../../utils/dateTimePicker');
  3. const FormData = require('../../pages/menu/formData.js');
  4. import {
  5. baseUrl,
  6. request
  7. } from "../../../pages/api/canteen-request.js"
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. isUser: true,
  14. currentIndex: 0,
  15. date: '2023-10-01',
  16. time: '12:00',
  17. dateTimeArray: null,
  18. dateTime: null,
  19. startYear: 2000,
  20. endYear: 2250,
  21. typeList: ['报修类型一', '报修类型二', '报修类型三'],
  22. list: [{ type: '维修类型一', address: '食堂二楼楼梯地砖', time: '2022-03-15 13:45' }, { type: '维修类型一', address: '食堂二楼楼梯地砖', time: '2022-03-15 13:45' }],
  23. tempFileList: []
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad(options) {
  29. // 获取完整的年月日 时分秒,以及默认显示的数组
  30. var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
  31. // 精确到分的处理,将数组的秒去掉
  32. // var lastArray = obj.dateTimeArray.pop();
  33. // var lastTime = obj.dateTime.pop();
  34. this.setData({
  35. dateTime: obj.dateTime,
  36. dateTimeArray: obj.dateTimeArray
  37. });
  38. // 查询所有报修类型
  39. },
  40. /**
  41. * 生命周期函数--监听页面初次渲染完成
  42. */
  43. onReady() {
  44. },
  45. /**
  46. * 生命周期函数--监听页面显示
  47. */
  48. onShow() {
  49. },
  50. /**
  51. * 生命周期函数--监听页面隐藏
  52. */
  53. onHide() {
  54. },
  55. /**
  56. * 生命周期函数--监听页面卸载
  57. */
  58. onUnload() {
  59. },
  60. /**
  61. * 页面相关事件处理函数--监听用户下拉动作
  62. */
  63. onPullDownRefresh() {
  64. },
  65. /**
  66. * 页面上拉触底事件的处理函数
  67. */
  68. onReachBottom() {
  69. },
  70. /**
  71. * 点击切换标题
  72. * @param {*} e
  73. */
  74. titleClick(e) {
  75. this.setData({
  76. currentIndex: e.currentTarget.dataset.idx
  77. });
  78. },
  79. /**
  80. * 切换swiper-item触发bindchange事件
  81. * @param {*} e
  82. */
  83. pagechange: function (e) {
  84. console.info(e)
  85. // 通过touch判断,改变tab的下标值
  86. if ("touch" === e.detail.source) {
  87. // let currentPageIndex = this.data.currentIndex;
  88. // currentPageIndex = (currentPageIndex + 1) % 2;
  89. // 拿到当前索引并动态改变
  90. this.setData({
  91. currentIndex: e.detail.current
  92. });
  93. }
  94. },
  95. /**
  96. * 报修类型选择
  97. * @param {*} e
  98. */
  99. typePickerChange(e) {
  100. console.log('picker发送选择改变,携带值为', e.detail.value)
  101. this.setData({
  102. index: e.detail.value
  103. });
  104. },
  105. /**
  106. * 提交工单
  107. * @param {*} e
  108. */
  109. submitWorkOrder(e) {
  110. console.info(e);
  111. if (!e.detail.value.type) {
  112. wx.showToast({
  113. title: '请选择报修类型',
  114. icon: 'error'
  115. });
  116. return;
  117. }
  118. if (!e.detail.value.address) {
  119. wx.showToast({
  120. title: '请输入地址',
  121. icon: 'error'
  122. });
  123. return;
  124. }
  125. if (!e.detail.value.description) {
  126. wx.showToast({
  127. title: '请输入问题描述',
  128. icon: 'error'
  129. });
  130. return;
  131. }
  132. if (!e.detail.value.phone) {
  133. wx.showToast({
  134. title: '请输入联系电话',
  135. icon: 'error'
  136. });
  137. return;
  138. }
  139. if (!e.detail.value.arriveTime) {
  140. wx.showToast({
  141. title: '请选择上门时间',
  142. icon: 'error'
  143. });
  144. return;
  145. }
  146. let tempList = this.data.tempFileList;
  147. if (!tempList || tempList.length == 0) {
  148. wx.showToast({
  149. title: '请上传报修图片',
  150. icon: 'error'
  151. });
  152. return;
  153. }
  154. let formData = new FormData();
  155. formData.append('repairType', e.detail.value.type);
  156. formData.append('userDescription', e.detail.value.description);
  157. formData.append('phoneNum', e.detail.value.phone);
  158. formData.append('appointmentTime', e.detail.value.arriveTime);
  159. formData.append('maintenanceAddress', e.detail.value.address);
  160. for (let i in tempList) {
  161. formData.appendFile('files', tempList[i]);
  162. }
  163. let data = formData.getData();
  164. request({
  165. url: '/mini/worker/addOrder',
  166. method: 'POST',
  167. data: data.buffer,
  168. contentType: data.contentType
  169. }).then(res => {
  170. if (res.data.result) {
  171. wx.showToast({
  172. title: '提交成功',
  173. icon: 'success'
  174. });
  175. wx.navigateBack();
  176. } else {
  177. wx.showToast({
  178. title: '提交失败',
  179. icon: 'error'
  180. });
  181. }
  182. });
  183. },
  184. /**
  185. * 上传报修图片
  186. */
  187. uploadImage() {
  188. let that = this;
  189. wx.chooseMedia({
  190. success(res) {
  191. console.info(res);
  192. if (res.errMsg == 'chooseMedia:ok') {
  193. let tempList = that.data.tempFileList;
  194. for (let i in res.tempFiles) {
  195. tempList.push(res.tempFiles[i].tempFilePath);
  196. }
  197. that.setData({
  198. tempFileList: tempList
  199. });
  200. }
  201. }
  202. });
  203. },
  204. changeDateTime(e) {
  205. this.setData({ dateTime: e.detail.value });
  206. },
  207. changeDateTimeColumn(e) {
  208. var arr = this.data.dateTime, dateArr = this.data.dateTimeArray;
  209. arr[e.detail.column] = e.detail.value;
  210. dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
  211. this.setData({
  212. dateTimeArray: dateArr,
  213. dateTime: arr
  214. });
  215. },
  216. /**
  217. * 查看工单详情
  218. * @param {*} e
  219. */
  220. toDetail(e) {
  221. wx.navigateTo({
  222. url: '../work-order-detail/work-order-detail',
  223. });
  224. },
  225. toRepairDetail() {
  226. wx.navigateTo({
  227. url: '../work-order-detail/work-order-detail',
  228. });
  229. }
  230. })