work-order-detail.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. // pagesPublic/pages/work-order-detail/work-order-detail.js
  2. const FormData = require('../../pages/menu/formData.js');
  3. import {
  4. imgUrl
  5. } from "../api/request"
  6. import {
  7. baseUrl,
  8. request
  9. } from "../../../pages/api/canteen-request.js"
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. imgUrl: imgUrl,
  16. isUser: true,
  17. colorComplete: '#508FF4',
  18. colorIncomplete: '#999999',
  19. complete: true,
  20. statusText2: '待审核',
  21. statusText3: '未分配',
  22. statusText4: '待确认',
  23. tempFileList: [],
  24. typeList: [],
  25. infoId: ''
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad(options) {
  31. console.info(options);
  32. this.setData({
  33. isUser: (options.isuser == 'true' ? true : false),
  34. infoId: options.id
  35. });
  36. // 设置所有报修类型
  37. this.setRepairType(options.id);
  38. },
  39. /**
  40. * 生命周期函数--监听页面初次渲染完成
  41. */
  42. onReady() {
  43. },
  44. /**
  45. * 生命周期函数--监听页面显示
  46. */
  47. onShow() {
  48. },
  49. /**
  50. * 生命周期函数--监听页面隐藏
  51. */
  52. onHide() {
  53. },
  54. /**
  55. * 生命周期函数--监听页面卸载
  56. */
  57. onUnload() {
  58. },
  59. /**
  60. * 点击返回上一层页面
  61. */
  62. backTap() {
  63. wx.navigateBack();
  64. },
  65. radioChange(e) {
  66. console.info(e)
  67. // e.detail.value
  68. if (e.detail.value == '已完成') {
  69. this.setData({
  70. colorComplete: '#508FF4',
  71. colorIncomplete: '#999999',
  72. complete: true
  73. });
  74. } else {
  75. this.setData({
  76. colorComplete: '#999999',
  77. colorIncomplete: '#508FF4',
  78. complete: false
  79. });
  80. }
  81. },
  82. /**
  83. * 上传报修结果图片
  84. */
  85. uploadImage() {
  86. let that = this;
  87. wx.chooseMedia({
  88. success(res) {
  89. console.info(res);
  90. if (res.errMsg == 'chooseMedia:ok') {
  91. let tempList = that.data.tempFileList;
  92. for (let i in res.tempFiles) {
  93. tempList.push(res.tempFiles[i].tempFilePath);
  94. }
  95. that.setData({
  96. tempFileList: tempList
  97. });
  98. }
  99. }
  100. });
  101. },
  102. /**
  103. * 提交维修结果
  104. * @param {*} e
  105. */
  106. submitReport(e) {
  107. console.info(e)
  108. let complete = this.data.complete;
  109. let tempList = this.data.tempFileList;
  110. if (complete && tempList.length == 0) {
  111. wx.showToast({
  112. title: '请上传维修结果照片',
  113. icon: 'error'
  114. });
  115. return;
  116. }
  117. if (!complete && !e.detail.value.reason) {
  118. wx.showToast({
  119. title: '请填写失败原因',
  120. icon: 'error'
  121. });
  122. return;
  123. }
  124. let formData = new FormData();
  125. if (complete) {
  126. formData.append('status', 3);
  127. } else {
  128. formData.append('status', -1);
  129. }
  130. formData.append('id', this.data.infoId);
  131. formData.append('workerDescription', e.detail.value.reason ? e.detail.value.reason : '');
  132. // formData.append('userId', wx.getStorageSync('userid'));
  133. for (let i in tempList) {
  134. formData.appendFile('files', tempList[i]);
  135. }
  136. let data = formData.getData();
  137. request({
  138. url: '/mini/worker/closeOrder',
  139. method: 'POST',
  140. data: data.buffer,
  141. contentType: data.contentType
  142. }).then(res => {
  143. console.info(res)
  144. if (res.result) {
  145. wx.showToast({
  146. title: '提交成功',
  147. icon: 'success',
  148. mask: true,
  149. });
  150. setTimeout(() => {
  151. wx.navigateBack();
  152. }, 1500);
  153. } else {
  154. wx.showToast({
  155. title: '提交失败',
  156. icon: 'error',
  157. mask: true
  158. });
  159. }
  160. });
  161. },
  162. /**
  163. * 设置报修类型
  164. */
  165. setRepairType(id) {
  166. request({
  167. url: '/mini/worker/getDictByType',
  168. method: 'GET',
  169. data: {
  170. types: 'repair_type',
  171. codes: ''
  172. }
  173. }).then(res => {
  174. // console.info(res)
  175. if (res.result) {
  176. let data = res.data;
  177. this.setData({
  178. typeList: data
  179. });
  180. // 加载工单详情
  181. this.loadWorkOrderInfo(id);
  182. }
  183. });
  184. },
  185. /**
  186. * 加载工单详情
  187. * @param {*} id
  188. */
  189. loadWorkOrderInfo(id) {
  190. wx.showLoading({
  191. title: '加载中...'
  192. });
  193. request({
  194. url: '/mini/worker/orderInfo',
  195. method: 'GET',
  196. data: {
  197. 'id': id
  198. }
  199. }).then(res => {
  200. console.info(res)
  201. let data = res.data;
  202. this.setData({
  203. type: data.repairType,
  204. address: data.maintenanceAddress,
  205. phone: data.phoneNum,
  206. arriveTime: data.appointmentTime,
  207. description: data.userDescription,
  208. status: data.status,
  209. workerDescription: data.workerDescription
  210. });
  211. let typeList = this.data.typeList;
  212. for (let i in typeList) {
  213. if (typeList[i].code == data.repairType) {
  214. this.setData({
  215. type: typeList[i].codeValue,
  216. });
  217. break;
  218. }
  219. }
  220. request({
  221. url: '/food/getFoodPicByPicId',
  222. method: 'GET',
  223. data: {
  224. 'picId': data.repairPic
  225. }
  226. }).then(re => {
  227. console.info(re)
  228. if (re.data && re.data.length > 0) {
  229. let arr = [];
  230. for (let i in re.data) {
  231. arr.push(baseUrl + '/' + re.data[i].path);
  232. }
  233. this.setData({
  234. image: arr
  235. });
  236. }
  237. });
  238. if (data.resultPic) {
  239. request({
  240. url: '/food/getFoodPicByPicId',
  241. method: 'GET',
  242. data: {
  243. 'picId': data.resultPic
  244. }
  245. }).then(re => {
  246. console.info(re)
  247. if (re.data && re.data.length > 0) {
  248. let arr = [];
  249. for (let i in re.data) {
  250. arr.push(baseUrl + '/' + re.data[i].path);
  251. }
  252. this.setData({
  253. images: arr
  254. });
  255. }
  256. });
  257. }
  258. if (data.status == 0) {
  259. this.setData({
  260. checked2: '',
  261. checked3: '',
  262. checked4: '',
  263. });
  264. } else if (data.status == 1) {
  265. this.setData({
  266. checked2: 'checked',
  267. checked3: '',
  268. checked4: '',
  269. statusText2: '已审核'
  270. });
  271. } else if (data.status == 2) {
  272. this.setData({
  273. checked2: 'checked',
  274. checked3: 'checked',
  275. checked4: '',
  276. statusText2: '已审核',
  277. statusText3: '待上门'
  278. });
  279. } else if (data.status == 3) {
  280. this.setData({
  281. checked2: 'checked',
  282. checked3: 'checked',
  283. checked4: 'checked',
  284. statusText2: '已审核',
  285. statusText3: '已上门',
  286. statusText4: '已确认'
  287. });
  288. } else {
  289. this.setData({
  290. checked2: 'checked',
  291. checked3: 'checked',
  292. checked4: 'checked',
  293. statusText2: '已审核',
  294. statusText3: '已上门',
  295. statusText4: '已确认'
  296. });
  297. }
  298. wx.hideLoading();
  299. });
  300. },
  301. /**
  302. * 预览图片
  303. */
  304. previewImg(e) {
  305. wx.previewImage({
  306. urls: this.data.image,
  307. current: e.currentTarget.dataset.src
  308. });
  309. },
  310. previewResultImg(e) {
  311. wx.previewImage({
  312. urls: this.data.images,
  313. current: e.currentTarget.dataset.src
  314. });
  315. },
  316. })