detail.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. tabColorS: {
  5. 售前: {
  6. bgColor: "#E1EAFE",
  7. color: "#3874F6"
  8. },
  9. 售中: {
  10. bgColor: "#FEF0E1",
  11. color: "#F69E38"
  12. },
  13. 售后: {
  14. bgColor: "#FCE4E4",
  15. color: "#ED4949"
  16. },
  17. 紧急: {
  18. bgColor: "#FCE4E4",
  19. color: "#ED4949"
  20. },
  21. 历史售后: {
  22. bgColor: "#eeeeee",
  23. color: "#888888"
  24. }
  25. },
  26. tabsList: [{
  27. label: "工单服务商品",
  28. model: "#WorkOrderProduct",
  29. idname: "sa_workorderid",
  30. color: "#2AA520"
  31. }, {
  32. label: "工序详情",
  33. model: "#WorkOrderNodes",
  34. idname: "sa_workorderid",
  35. color: "#2AA520"
  36. }, {
  37. label: "工单物料",
  38. model: "#WorkOrderMaterial",
  39. idname: "sa_workorderid",
  40. color: "#2AA520"
  41. }, {
  42. label: "服务确认单",
  43. model: "#WorkOrderNotarizeBill",
  44. idname: "sa_workorderid",
  45. color: "#2AA520"
  46. }, {
  47. label: "服务团队",
  48. idname: "sa_workorderid",
  49. color: "#2AA520"
  50. }, {
  51. label: "工单信息",
  52. idname: "sa_workorderid",
  53. color: "#2AA520"
  54. }],
  55. tabsActive: 0,
  56. reason: {
  57. abortreason: ""
  58. },
  59. abortreasonShow: false,
  60. takeOrderShow: false,
  61. isqQuery: false,
  62. takeOrderForm: {
  63. isout: "否"
  64. }
  65. },
  66. onLoad(options) {
  67. console.log("options",options)
  68. getApp().globalData.Language.getLanguagePackage(this, '工单详情');
  69. this.setData({
  70. sa_workorderid: options.id
  71. })
  72. this.getDetail()
  73. },
  74. getDetail() {
  75. _Http.basic({
  76. "id": 20230208140103,
  77. "content": {
  78. "sa_workorderid": this.data.sa_workorderid,
  79. nocache: true
  80. },
  81. }).then(async res => {
  82. console.log("工单详情", res)
  83. if (res.code != '1') return wx.showToast({
  84. title: res.msg,
  85. icon: "none"
  86. })
  87. this.setData({
  88. detail: res.data
  89. })
  90. if (res.data.actiontype == '非工序模板') {
  91. this.setData({
  92. tabsList: this.data.tabsList.filter(v => ['工单服务商品', '服务确认单', '服务团队', '工单信息', '关联改善单'].includes(v.label))
  93. })
  94. } else {
  95. this.setData({
  96. tabsList: this.data.tabsList.filter(v => ['工序详情', '工单物料', '服务确认单', '服务团队', '工单信息', '关联改善单'].includes(v.label))
  97. })
  98. }
  99. this.selectComponent("#WorkOrderPview").setPreview(res);
  100. this.setTabbar()
  101. this.partialRenewal()
  102. const appAuth = wx.getStorageSync('auth').workBill;
  103. if (appAuth.options.some(v => v == 'applicationForm')) await this.getServiceDetail(res.data.sa_serviceorderid)
  104. if (!this.data.tabsList.some(v => v.label == '附件')) {
  105. let list = [{
  106. label: "附件",
  107. color: "#ED4949",
  108. model: "#Files"
  109. }, {
  110. label: "操作记录",
  111. color: "#ED4949",
  112. model: "#Record"
  113. }]
  114. if (appAuth.options.some(v => v == 'improve')) list.unshift({
  115. label: "关联改善单",
  116. idname: "sa_workorderid",
  117. color: "#F48403",
  118. model: "#Improvement"
  119. })
  120. this.setData({
  121. tabsList: this.data.tabsList.concat(list)
  122. })
  123. }
  124. })
  125. },
  126. getServiceDetail(id) {
  127. if (!id) return;
  128. return new Promise((resolve) => {
  129. _Http.basic({
  130. "id": 20230206091603,
  131. "content": {
  132. "sa_serviceorderid": id
  133. },
  134. }).then(res => {
  135. console.log("申请单详情", res)
  136. resolve()
  137. if (res.code != '1') return wx.showToast({
  138. title: res.msg,
  139. icon: "none"
  140. })
  141. let tabsList = [{
  142. label: "申请信息",
  143. idname: "sa_serviceorderid",
  144. color: "#3874F6"
  145. }, {
  146. label: "受理信息",
  147. idname: "sa_serviceorderid",
  148. color: "#3874F6"
  149. }];
  150. if (['售中', "售后"].includes(res.data.servicetype)) {
  151. tabsList.unshift({
  152. label: "服务商品",
  153. model: "#ServiceProduct",
  154. idname: "sa_serviceorderid",
  155. color: "#3874F6"
  156. })
  157. }
  158. this.setData({
  159. tabsList: this.data.tabsList.some(v => v.label == '申请信息') ? this.data.tabsList : this.data.tabsList.concat(tabsList),
  160. serviceDetail: res.data
  161. })
  162. this.selectComponent("#ServicePview1").setPreview(res);
  163. this.selectComponent("#ServicePview2").setPreview(res);
  164. })
  165. })
  166. },
  167. areaInput(e) {
  168. this.data.reason[e.currentTarget.dataset.name] = e.detail.value;
  169. },
  170. addConfirmBill() {
  171. let page = this.selectComponent("#WorkOrderNotarizeBill");
  172. page.setData({
  173. sa_workorderid: this.data.detail.sa_workorderid
  174. })
  175. page.addConfirmBill()
  176. },
  177. onCancel() {
  178. this.setData({
  179. abortreasonShow: false,
  180. backreasonShow: false,
  181. takeOrderShow: false,
  182. takeOrderForm: {
  183. isout: "否"
  184. }
  185. })
  186. },
  187. onIsOutChange(e) {
  188. this.setData({
  189. 'takeOrderForm.isout': e.detail
  190. })
  191. },
  192. onTake() {
  193. let that = this;
  194. setTimeout(() => {
  195. let isout = that.data.takeOrderForm.isout === '是' ? 1 : 0;
  196. _Http.basic({
  197. "content": {
  198. "sa_workorderid": that.data.detail.sa_workorderid,
  199. "isout": isout,
  200. userid: that.data.detail.team.find(v => v.isleader).userid
  201. },
  202. "id": 20230210101103,
  203. }).then(res => {
  204. getApp().globalData.Language.showToast(res.code == '1' ? "接单成功" : res.msg)
  205. if (res.code == 1) {
  206. that.getDetail();
  207. that.onCancel();
  208. }
  209. })
  210. });
  211. },
  212. // 中止
  213. onSuspend() {
  214. let that = this;
  215. setTimeout(() => {
  216. let abortreason = that.data.reason.abortreason;
  217. if (abortreason == '') return wx.showToast({
  218. title: getApp().globalData.Language.getMapText("请说明中止原因"),
  219. icon: "none"
  220. })
  221. _Http.basic({
  222. "content": {
  223. "sa_workorderid": that.data.detail.sa_workorderid,
  224. abortreason
  225. },
  226. "id": 2026012714282702,
  227. }).then(res => {
  228. getApp().globalData.Language.showToast(res.code == '1' ? "中止成功" : res.msg)
  229. if (res.code == 1) that.getDetail();
  230. })
  231. });
  232. },
  233. tabbarOnClick(e) {
  234. let that = this,
  235. detail = this.data.detail;
  236. switch (e.detail.label) {
  237. case '转单':
  238. let leader = '';
  239. try {
  240. leader = detail.team.find(v => v.isleader).userid || 0
  241. } catch (error) {
  242. }
  243. _Http.basic({
  244. id: 20230213143003,
  245. content: {
  246. pageSize: 9999
  247. }
  248. }).then(res => {
  249. console.log("转单", res)
  250. if (res.code != '1') return wx.showToast({
  251. title: res.msg,
  252. icon: "none"
  253. })
  254. this.setData({
  255. users: res.data.map(v => {
  256. v.disabled = v.userid == leader
  257. return v
  258. })
  259. })
  260. })
  261. break;
  262. case '编辑':
  263. wx.navigateTo({
  264. url: `/E-service/workOrder/insert`
  265. })
  266. break;
  267. case '确认信息':
  268. wx.navigateTo({
  269. url: '/E-service/workOrder/confirm?id=' + detail.sa_workorderid
  270. })
  271. break;
  272. case '接单':
  273. this.setData({
  274. takeOrderShow: true
  275. })
  276. // wx.navigateTo({
  277. // url: `/E-service/workOrder/takeOrder`
  278. // })
  279. break;
  280. case '中止':
  281. this.setData({
  282. abortreasonShow: true
  283. })
  284. break;
  285. case '暂停':
  286. wx.showModal({
  287. title: getApp().globalData.Language.getMapText('提示'),
  288. content: getApp().globalData.Language.getMapText(`确认暂停当前工单吗`) + '?',
  289. confirmBtn: getApp().globalData.Language.getMapText('确定'),
  290. cancelBtn: getApp().globalData.Language.getMapText('取消'),
  291. complete: ({
  292. confirm
  293. }) => {
  294. if (confirm) _Http.basic({
  295. "content": {
  296. "sa_workorderid": detail.sa_workorderid
  297. },
  298. "id": "20230209144603",
  299. }).then(res => {
  300. getApp().globalData.Language.showToast(res.code == '1' ? "暂停成功" : res.msg)
  301. that.getDetail()
  302. })
  303. }
  304. })
  305. break;
  306. case '完结工单':
  307. wx.showModal({
  308. title: getApp().globalData.Language.getMapText('提示'),
  309. content: getApp().globalData.Language.getMapText(`确认完结工单吗`) + '?',
  310. confirmBtn: getApp().globalData.Language.getMapText('确定'),
  311. cancelBtn: getApp().globalData.Language.getMapText('取消'),
  312. complete: ({
  313. confirm
  314. }) => {
  315. if (confirm) _Http.basic({
  316. "content": {
  317. "sa_workorderid": detail.sa_workorderid
  318. },
  319. "id": "20230209144903",
  320. }).then(res => {
  321. getApp().globalData.Language.showToast(res.code == '1' ? "完结成功" : res.msg)
  322. that.getDetail()
  323. })
  324. }
  325. })
  326. break;
  327. case '开始工单':
  328. wx.showModal({
  329. title: getApp().globalData.Language.getMapText('提示'),
  330. content: getApp().globalData.Language.getMapText(`确认开始工单吗`) + '?',
  331. confirmBtn: getApp().globalData.Language.getMapText('确定'),
  332. cancelBtn: getApp().globalData.Language.getMapText('取消'),
  333. complete: ({
  334. confirm
  335. }) => {
  336. if (confirm) _Http.basic({
  337. "content": {
  338. "sa_workorderid": detail.sa_workorderid
  339. },
  340. "id": "20230209144503",
  341. }).then(res => {
  342. getApp().globalData.Language.showToast(res.code == '1' ? "开始成功" : res.msg)
  343. that.getDetail()
  344. })
  345. }
  346. })
  347. break;
  348. case '启用':
  349. wx.showModal({
  350. title: getApp().globalData.Language.getMapText('提示'),
  351. content: getApp().globalData.Language.getMapText(`确认启用当前工单吗`) + '?',
  352. confirmBtn: getApp().globalData.Language.getMapText('确定'),
  353. cancelBtn: getApp().globalData.Language.getMapText('取消'),
  354. complete: ({
  355. confirm
  356. }) => {
  357. if (confirm) _Http.basic({
  358. "content": {
  359. "sa_workorderid": detail.sa_workorderid
  360. },
  361. "id": "20230209144703",
  362. }).then(res => {
  363. getApp().globalData.Language.showToast(res.code == '1' ? "启用成功" : res.msg)
  364. that.getDetail()
  365. })
  366. }
  367. })
  368. break;
  369. }
  370. },
  371. onSelectLeader({
  372. detail
  373. }) {
  374. const that = this;
  375. wx.showModal({
  376. title: getApp().globalData.Language.getMapText('提示'),
  377. content: getApp().globalData.Language.getMapText(`是否确认选择`) + getApp().globalData.Language.getMapText(detail.name) + getApp().globalData.Language.getMapText(`执行工单`) + '?',
  378. confirmBtn: getApp().globalData.Language.getMapText('确定'),
  379. cancelBtn: getApp().globalData.Language.getMapText('取消'),
  380. complete: ({
  381. confirm
  382. }) => {
  383. if (confirm) _Http.basic({
  384. "content": {
  385. "sa_workorderid": that.data.detail.sa_workorderid,
  386. "userid": detail.userid
  387. },
  388. "id": 2026012714183302,
  389. }).then(res => {
  390. getApp().globalData.Language.showToast(res.code == '1' ? "操作成功" : res.msg)
  391. if (res.code == 1) {
  392. that.getDetail()
  393. that.clearUsers()
  394. }
  395. })
  396. }
  397. })
  398. },
  399. clearUsers() {
  400. this.setData({
  401. "users": []
  402. })
  403. },
  404. /* 底部功能 */
  405. async setTabbar() {
  406. let status = this.data.detail.status,
  407. tabbarList = [],
  408. isLeader = false,
  409. isqQuery = this.data.isqQuery,
  410. isworkleader = this.data.isworkleader || false;
  411. try {
  412. isLeader = this.data.detail.team.find(v => v.isleader).userid == wx.getStorageSync("userMsg").userid
  413. } catch (error) {}
  414. let options = {
  415. 编辑: {
  416. icon: "icon-bianji2",
  417. label: "编辑"
  418. },
  419. 转单: {
  420. icon: "icon-dibu-biangengchengjiaozhuangtai",
  421. label: "转单"
  422. },
  423. 确认信息: {
  424. icon: "icon-jiaoqiqueren",
  425. label: "确认信息"
  426. },
  427. 接单: {
  428. icon: "icon-a-tonggaoshujuxiazailiang",
  429. label: "接单"
  430. },
  431. 开始工单: {
  432. icon: "icon-huifu1",
  433. label: "开始工单"
  434. },
  435. 暂停: {
  436. icon: "icon-zanhuan",
  437. label: "暂停"
  438. },
  439. 完结工单: {
  440. icon: "icon-dibu-chengjiao",
  441. label: "完结工单"
  442. },
  443. 启用: {
  444. icon: "icon-quxiaozanhuan",
  445. label: "启用"
  446. },
  447. 中止: {
  448. icon: "icon-dibu-zuofei",
  449. label: "中止"
  450. }
  451. };
  452. if (!isqQuery) await _Http.basic({
  453. "id": 2025062416033402,
  454. "content": {
  455. "userid": wx.getStorageSync('userMsg').userid,
  456. "sa_workorderid": this.data.detail.sa_workorderid,
  457. },
  458. }).then(res => {
  459. console.log("重新是否服务主管", res)
  460. if (res.code == 1) {
  461. isworkleader = res.data.isworkleader
  462. isLeader = res.data.isteamleader
  463. this.setData({
  464. isworkleader: res.data.isworkleader,
  465. isqQuery: true,
  466. isLeader
  467. })
  468. }
  469. })
  470. let statusOptions = {
  471. 待接单: ['接单', '中止'],
  472. 待开始: ['开始工单', '中止'],
  473. 进行中: ['完结工单', '暂停', '中止'],
  474. 暂停: ['启用', '中止'],
  475. };
  476. if (statusOptions[status]) {
  477. if (!isLeader) statusOptions[status] = [];
  478. if ((isworkleader || isLeader) && status == '待接单') {
  479. statusOptions[status] = statusOptions[status] = ['确认信息', '转单'].concat(statusOptions[status])
  480. }
  481. if (isLeader || isworkleader) {
  482. if (status == '待开始') statusOptions[status].unshift("确认信息");
  483. statusOptions[status].unshift("编辑");
  484. }
  485. tabbarList = statusOptions[status].map(v => options[v]);
  486. }
  487. this.setData({
  488. tabbarList
  489. })
  490. },
  491. //tabs 切换
  492. tabsChange({
  493. detail
  494. }) {
  495. this.setData({
  496. tabsActive: detail
  497. });
  498. this.partialRenewal();
  499. },
  500. //局部数据更新 tabs
  501. partialRenewal(init = false) {
  502. try {
  503. let ac = this.data.tabsList[this.data.tabsActive];
  504. let model = ac.model;
  505. if (model) {
  506. let Component = this.selectComponent(model),
  507. {
  508. total,
  509. pageNumber,
  510. pageTotal
  511. } = Component.data.content,
  512. id = this.data.detail[ac.idname || 'sa_workorderid'];
  513. if (total == null || init) {
  514. Component.getList(id, init);
  515. } else if (pageNumber <= pageTotal) {
  516. Component.getList(id, false);
  517. }
  518. }
  519. } catch (error) {
  520. }
  521. },
  522. onReachBottom() {
  523. this.partialRenewal();
  524. },
  525. callPhone(e) {
  526. wx.makePhoneCall({
  527. phoneNumber: e.currentTarget.dataset.number
  528. })
  529. },
  530. onUnload() {
  531. getCurrentPages().forEach(page => {
  532. if (page.__route__ == 'E-service/workOrder/index') {
  533. let content = JSON.parse(JSON.stringify(page.data.content));
  534. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  535. content.pageNumber = 1;
  536. _Http.basic({
  537. id: page.data.id,
  538. content
  539. }).then(res => {
  540. console.log("更新列表", res);
  541. if (res.code == '1') {
  542. page.setData({
  543. list: res.data,
  544. "content.total": res.total
  545. })
  546. }
  547. })
  548. } else {}
  549. })
  550. }
  551. })