acceptFill.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. var util = require('../../../utils/util.js')
  2. const app = getApp()
  3. Page({
  4. data: {
  5. orderId: null,
  6. customerId: null,
  7. statusName: '',
  8. orderDetail: {},
  9. images: [], // 存储已选图片的临时路径
  10. records: [],
  11. serviceList: [], // 服务
  12. custormList: [], // 客户
  13. formObj: {
  14. checkUserName: app.globalData.g_lgName,
  15. checkUserId: app.globalData.g_userId,
  16. checkDate: util.getRealToday(),
  17. contactId: '',
  18. orderId: null,
  19. telephone: '',
  20. },
  21. receiverShow: false,
  22. r_txt_Show: false,
  23. allDisabled: true, //有客户下拉时临时用来控制其他下拉不显示
  24. receiverChoose: 'true',
  25. },
  26. onLoad(options) {
  27. const id = options.id
  28. this.setData({
  29. orderId: id,
  30. ['formObj.checkUserName']: app.globalData.g_lgName,
  31. ['formObj.checkUserId']: app.globalData.g_userId,
  32. })
  33. console.log(app.globalData.g_lgName, 'app.globalData.g_lgName')
  34. this.getDetail()
  35. this.getinstallerList()
  36. console.log(util.getToday(), 'util.getToday()')
  37. },
  38. // 获取服务工单基本信息 和 工单记录进度
  39. getDetail() {
  40. var send_data = [
  41. {
  42. name: 'getInstallationOrderById',
  43. returntype: 'Map',
  44. parammaps: { id: this.data.orderId },
  45. },
  46. {
  47. name: 'getInstallationDailyDetailByOrderId',
  48. returntype: 'Map',
  49. parammaps: { orderId: this.data.orderId },
  50. },
  51. ]
  52. util.getDataByNames(send_data, this.handleDetail)
  53. },
  54. handleDetail(res) {
  55. console.log(res, '详情页')
  56. var data = res.data
  57. if (data.getInstallationDailyDetailByOrderId.list != null) {
  58. this.setData({
  59. records: data.getInstallationDailyDetailByOrderId.list,
  60. orderDetail: data.getInstallationOrderById.list[0],
  61. customerId: data.getInstallationOrderById.list[0].customerId,
  62. statusName: data.getInstallationOrderById.list[0].statusName,
  63. })
  64. } else {
  65. this.setData({
  66. records: [],
  67. orderDetail: data.getInstallationOrderById.list[0],
  68. customerId: data.getInstallationOrderById.list[0].customerId,
  69. statusName: '',
  70. })
  71. }
  72. this.getCustormList()
  73. },
  74. // 服务人员
  75. getinstallerList() {
  76. var send_data = [
  77. {
  78. name: 'getUsersSelect',
  79. offset: 0,
  80. pagecount: 0,
  81. parammaps: {
  82. enable: '1',
  83. },
  84. },
  85. ]
  86. util.getDataByNames(send_data, this.handleInstallerList)
  87. },
  88. handleInstallerList(res) {
  89. if (res.data.getUsersSelect) {
  90. this.setData({
  91. serviceList: res.data.getUsersSelect.list,
  92. })
  93. }
  94. },
  95. // 客户对接
  96. getCustormList() {
  97. var send_data = {
  98. name: 'getContacts',
  99. returntype: 'Map',
  100. parammaps: { customerId: this.data.customerId },
  101. }
  102. util.getDataByName(send_data, this.handleCustormList)
  103. },
  104. handleCustormList(res) {
  105. console.log(res, 'res')
  106. if (res.data.list) {
  107. this.setData({
  108. custormList: res.data.list,
  109. })
  110. }
  111. },
  112. onSelectCustorm(event) {
  113. this.setData({
  114. ['formObj.contactName']: this.data.custormList[event.detail.value].contactName,
  115. ['formObj.contactId']: this.data.custormList[event.detail.value].id,
  116. })
  117. },
  118. onDateChange(e) {
  119. this.setData({
  120. 'formObj.checkDate': e.detail.value,
  121. })
  122. },
  123. onSelectPerson(e) {
  124. this.setData({
  125. ['formObj.checkUserName']: this.data.serviceList[e.detail.value].name,
  126. ['formObj.checkUserId']: this.data.serviceList[e.detail.value].id,
  127. })
  128. },
  129. viewHistory() {
  130. var id = this.data.orderId
  131. wx.navigateTo({
  132. url: `/pages/workbench/historyFill/historyFill?id=${id}`,
  133. })
  134. },
  135. validateForm() {
  136. const { checkUserName, checkDate, contactName, telephone } = this.data.formObj
  137. const { images } = this.data
  138. if (!checkUserName) {
  139. wx.showToast({ title: '请填写服务人员', icon: 'none' })
  140. return false
  141. }
  142. if (!checkDate) {
  143. wx.showToast({ title: '请选择验收日期', icon: 'none' })
  144. return false
  145. }
  146. if (images.length === 0) {
  147. wx.showToast({ title: '请先选择图片', icon: 'none' })
  148. return
  149. }
  150. if (!contactName) {
  151. wx.showToast({ title: '请输入客户对接人', icon: 'none' })
  152. return false
  153. }
  154. if (!telephone) {
  155. wx.showToast({ title: '请输入电话号码', icon: 'none' })
  156. return
  157. }
  158. // 手机号格式校验
  159. const phoneRegex = /^1[3-9]\d{9}$/ // 正则表达式
  160. if (!phoneRegex.test(telephone)) {
  161. wx.showToast({ title: '请输入正确的手机号', icon: 'none' })
  162. return
  163. }
  164. return true
  165. },
  166. goBack() {
  167. wx.navigateBack()
  168. },
  169. // 删除图片
  170. deleteImage(e) {
  171. const index = e.currentTarget.dataset.index
  172. const images = this.data.images.filter((_, i) => i !== index)
  173. this.setData({ images })
  174. },
  175. // 预览图片
  176. previewImage(e) {
  177. const index = e.currentTarget.dataset.index
  178. wx.previewImage({
  179. current: this.data.images[index].tempFilePath,
  180. urls: [this.data.images[index].tempFilePath],
  181. })
  182. },
  183. // 选择图片
  184. chooseImage() {
  185. const remaining = 3 - this.data.images.length
  186. wx.chooseMedia({
  187. count: remaining,
  188. sizeType: ['compressed'],
  189. sourceType: ['album', 'camera'],
  190. success: (res) => {
  191. const newImages = res.tempFiles.map((item) => ({
  192. tempFilePath: item.tempFilePath,
  193. progress: 0,
  194. index: this.data.images.length,
  195. imageType: 'check_image',
  196. }))
  197. this.setData({
  198. images: this.data.images.concat(newImages),
  199. })
  200. this.uploadImages(newImages[0])
  201. },
  202. })
  203. },
  204. // 上传图片到服务器
  205. uploadImages(image) {
  206. // 逐个上传
  207. const index = image.index
  208. const uploadTasks = wx.uploadFile({
  209. url: app.globalData.g_url + 'authdata/uploaderimage',
  210. filePath: image.tempFilePath,
  211. name: 'file',
  212. header: {
  213. optname: 'insertcustompic',
  214. id: 1,
  215. token: app.globalData.g_token,
  216. },
  217. formData: {
  218. optname: 'insertcustompic',
  219. id: 1,
  220. token: app.globalData.g_token,
  221. },
  222. success: (res) => {
  223. if (res.statusCode === 200) {
  224. var data = JSON.parse(res.data)
  225. console.log(this.data.images, '图片上传成功', '111')
  226. this.data.images[index].imageId = data.execresult.LastInsertId
  227. } else {
  228. wx.showToast({ title: '图片上传失败', icon: 'none' })
  229. }
  230. console.log(this.data.images, '图片上传成功', '111')
  231. },
  232. fail: () => {
  233. wx.showToast({ title: '图片上传失败', icon: 'none' })
  234. },
  235. })
  236. // 监听上传进度
  237. uploadTasks.onProgressUpdate((res) => {
  238. this.setData({
  239. [`images[${index}].progress`]: res.progress,
  240. })
  241. })
  242. },
  243. formSubmit(e) {
  244. console.log(this.data.formObj, 'this.data.formObj')
  245. if (!this.validateForm()) return
  246. this.data.formObj.orderId = this.data.orderId
  247. this.uploadForm()
  248. },
  249. // 验收表单上传
  250. uploadForm() {
  251. var send_data = {
  252. common: {
  253. returnmap: '0',
  254. },
  255. data: [
  256. {
  257. name: 'insertInstallationOrderImages',
  258. resultmaps: { list: this.data.images },
  259. children: [
  260. {
  261. name: 'insertInstallationOrderImages',
  262. type: 'e',
  263. parammaps: {
  264. orderId: this.data.orderId,
  265. imageId: '@insertInstallationOrderImages.imageId',
  266. imageType: '@insertInstallationOrderImages.imageType',
  267. },
  268. },
  269. ],
  270. },
  271. {
  272. name: 'insertInstallationOrderProcessLog',
  273. type: 'e',
  274. parammaps: {
  275. orderId: this.data.orderId,
  276. operationType: 'check',
  277. operationUserId: app.globalData.g_userId,
  278. operationUserName: app.globalData.g_lgName,
  279. beforeStatus: this.data.statusName,
  280. afterStatus: '已完成',
  281. operationContent: '验收服务工单',
  282. },
  283. },
  284. {
  285. name: 'checkInstallationOrder',
  286. type: 'e',
  287. parammaps: {
  288. orderId: this.data.formObj.orderId,
  289. checkUserId: this.data.formObj.checkUserId,
  290. checkUserName: this.data.formObj.checkUserName,
  291. contactId:
  292. this.data.receiverChoose == 'false'
  293. ? '@insertContacts.LastInsertId'
  294. : this.data.formObj.contactId,
  295. checkDate: this.data.formObj.checkDate,
  296. },
  297. },
  298. ],
  299. }
  300. // 如果对接人从下拉框中选择,则直接走之前的功能,
  301. // 如果对接人是新增的 则需要创建一下
  302. if (this.data.receiverChoose == 'false') {
  303. send_data.data.unshift({
  304. name: 'insertContacts',
  305. type: 'e',
  306. parammaps: {
  307. customerId: this.data.customerId, // 客户id
  308. contactName: this.data.formObj.contactName, // 联系人
  309. telephone: this.data.formObj.telephone, // 客户电话
  310. },
  311. })
  312. }
  313. console.log('send_data:', send_data)
  314. util.execDataByConfig(send_data, this.handleuploadForm)
  315. },
  316. handleuploadForm(res) {
  317. if (res.msg !== 'fail') {
  318. wx.showToast({
  319. title: '验收提交成功',
  320. icon: 'success',
  321. duration: 3000,
  322. success: function () {
  323. setTimeout(function () {
  324. // wx.navigateBack()
  325. wx.redirectTo({ url: '../serviceTicket/serviceTicket' })
  326. }, 1000)
  327. },
  328. })
  329. // wx.navigateBack();
  330. } else {
  331. wx.showToast({
  332. title: '验收提交失败' + res.data,
  333. icon: 'error',
  334. duration: 4000,
  335. })
  336. }
  337. },
  338. //接待人文本框输入
  339. change_receiver_input: function (e) {
  340. var value = e.detail.value
  341. var customerId = this.data.customerId
  342. console.log(value)
  343. //接待人列表框
  344. util.getDataByName(
  345. { name: 'getContacts', parammaps: { customerId: customerId } },
  346. this.getPickerList2,
  347. )
  348. },
  349. getPickerList2: function (res) {
  350. var custormList = res.data.list
  351. console.log('接待人下拉数据======>', custormList)
  352. this.setData({
  353. receiverShow: true,
  354. allDisabled: false,
  355. custormList: custormList,
  356. })
  357. if (custormList !== null) {
  358. this.setData({ r_txt_Show: false })
  359. } else {
  360. this.setData({ r_txt_Show: true })
  361. }
  362. },
  363. // 电话填写
  364. onPhoneChange: function (e) {
  365. console.log('onPhoneChange', e)
  366. this.setData({
  367. ['formObj.telephone']: e.detail.value,
  368. })
  369. },
  370. //接待人完成
  371. confirm_receiver_input: function (e) {
  372. console.log('接收人直接输入', e)
  373. this.setData({
  374. receiverShow: false,
  375. allDisabled: true,
  376. receiverChoose: 'false',
  377. ['formObj.contactName']: e.detail.value,
  378. })
  379. },
  380. //下拉框:接待人
  381. change_receiver: function (e) {
  382. console.log('receiver的选项', e.detail.value)
  383. var newId = this.data.custormList[e.detail.value]['id']
  384. this.setData({
  385. receiverIndex: e.detail.value,
  386. ['formObj.contactId']: newId,
  387. ['formObj.contactName']: this.data.custormList[e.detail.value].contactName,
  388. receiverShow: false,
  389. })
  390. },
  391. //接待人列表点击
  392. on_rece_tap: function (e) {
  393. console.log('接待人列表点击')
  394. var newId = e.currentTarget.dataset.id
  395. var name = e.currentTarget.dataset.name
  396. var that = this
  397. that.setData({
  398. receiverShow: false,
  399. allDisabled: true,
  400. ['formObj.contactName']: name,
  401. ['formObj.contactId']: newId,
  402. receiverChoose: 'true',
  403. })
  404. //获取电话
  405. util.getDataByName(
  406. { name: 'getTelById', returntype: 'Map', parammaps: { id: newId } },
  407. function (e) {
  408. console.log(e)
  409. var telephone = e.data.list[0].telephone
  410. that.setData({
  411. ['formObj.telephone']: telephone,
  412. })
  413. },
  414. )
  415. },
  416. })