index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. // pages/agent/serviceBillDetail/index.js
  2. import api from '../../api/api'
  3. import Dialog from 'tdesign-miniprogram/dialog/index';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. showWithInput: false,
  10. showProgress: false,
  11. showToWoker: false,
  12. orderMainData: {},
  13. list: [],
  14. templist: [],
  15. actTemp: null,
  16. actLeader: null
  17. },
  18. async mainData() {
  19. const res = await api._post({
  20. "id": "20230206091603",
  21. "version": 1,
  22. "content": {
  23. nocache: true,
  24. "sa_serviceorderid": this.data.id
  25. }
  26. })
  27. let tabbarsList = [];
  28. if (res.data.status == '新建') {
  29. tabbarsList = [{
  30. label: "编辑",
  31. icon: "icon-dibu-bianji"
  32. }, {
  33. label: "提交",
  34. icon: "icon-tijiao",
  35. }, {
  36. label: "删除",
  37. icon: "icon-guanlian-shanchu"
  38. }];
  39. } else if (res.data.status == '待指派') {
  40. tabbarsList = [{
  41. label: "转工单",
  42. icon: "icon-shenhe"
  43. }, {
  44. label: "退回",
  45. icon: "icon-a-fanshenhetuihui",
  46. }];
  47. }
  48. this.setData({
  49. orderMainData: res.data,
  50. tabbarsList
  51. })
  52. this.productmx()
  53. this.fileData()
  54. this.workOrderTemp()
  55. this.workerData()
  56. },
  57. async fileData() {
  58. const res = await api._post({
  59. "method": "queryFileLink",
  60. "classname": "system.attachment.Attachment",
  61. "content": {
  62. "ownertable": "sa_serviceorder",
  63. "ownerid": this.data.id,
  64. "usetype": "附件" //传空返回有所
  65. }
  66. })
  67. this.setData({
  68. filelist: res.data,
  69. refresh: true
  70. })
  71. },
  72. addProduct() {
  73. wx.navigateTo({
  74. url: '/Eservice/workerLeader/billCanUseProduct/index',
  75. })
  76. },
  77. async getAdd(selection) {
  78. const res = await api._post({
  79. "id": "20230206161803",
  80. "version": 1,
  81. "content": {
  82. "sa_serviceorderid": this.data.id,
  83. "iteminfos": selection.map(e => {
  84. return {
  85. "sa_serviceorderitemsid": 0,
  86. "itemid": e,
  87. "reason": ""
  88. }
  89. })
  90. }
  91. })
  92. this.productmx()
  93. },
  94. async productmx() {
  95. const res = await api._post({
  96. "id": "20230206161903",
  97. "version": 1,
  98. "content": {
  99. "sa_serviceorderid": this.data.id
  100. }
  101. })
  102. this.setData({
  103. list: res.data
  104. })
  105. },
  106. async onMXDelete(data) {
  107. let itemid = data.detail.sa_serviceorderitemsid
  108. const res = await api._post({
  109. "id": "20230206162003",
  110. "content": {
  111. "sa_serviceorderitemsids": [itemid]
  112. }
  113. })
  114. this.productmx()
  115. },
  116. /* 底部按钮回调 */
  117. tabbarOnClick(e) {
  118. let that = this,
  119. dialogConfig = null,
  120. res = null;
  121. switch (e.detail.label) {
  122. case "编辑":
  123. getApp().globalData.handelSelect = this
  124. wx.navigateTo({
  125. url: '/Eservice/workerLeader/editServiceBill/index',
  126. })
  127. break;
  128. case "提交":
  129. dialogConfig = {
  130. context: this,
  131. title: '提示',
  132. content: '确认提交当前申请单吗',
  133. confirmBtn: '确定',
  134. cancelBtn: '取消',
  135. };
  136. Dialog.confirm(dialogConfig)
  137. .then(async () => {
  138. res = await api._post({
  139. "id": "20230206101403",
  140. "version": 1,
  141. "content": {
  142. "sa_serviceorderid": that.data.id,
  143. "issumbit": 1,
  144. }
  145. });
  146. wx.showToast({
  147. title: res.msg == '成功' ? '工单提交成功' : res.msg,
  148. icon: "none",
  149. mask: true
  150. })
  151. if (res.msg == '成功') that.mainData();
  152. })
  153. .catch((err) => console.log(err))
  154. .finally(() => Dialog.close());
  155. break;
  156. case "删除":
  157. dialogConfig = {
  158. context: this,
  159. title: '提示',
  160. content: '确认删除当前申请单吗',
  161. confirmBtn: '确定',
  162. cancelBtn: '取消',
  163. };
  164. Dialog.confirm(dialogConfig)
  165. .then(async () => {
  166. res = await api._post({
  167. "id": "20230206091803",
  168. "version": 1,
  169. "content": {
  170. "sa_serviceorderids": [that.data.id],
  171. }
  172. })
  173. wx.showToast({
  174. title: res.msg == '成功' ? '工单删除成功' : res.msg,
  175. icon: "none",
  176. mask: true
  177. })
  178. if (res.msg == '成功') setTimeout(() => {
  179. wx.navigateBack()
  180. }, 500);
  181. })
  182. .catch((err) => console.log(err))
  183. .finally(() => Dialog.close());
  184. break;
  185. case "转工单":
  186. this.setData({
  187. showToWoker: true
  188. })
  189. break;
  190. case "退回":
  191. this.setData({
  192. showWithInput: true
  193. })
  194. break;
  195. }
  196. },
  197. /* 专工单/退回 取消 */
  198. showBackReason() {
  199. this.setData({
  200. showWithInput: false,
  201. showToWoker: false,
  202. backreason: ""
  203. })
  204. },
  205. inputReason(data) {
  206. this.data.backreason = data.detail.value;
  207. },
  208. async onBack() {
  209. let that = this
  210. if (!that.data.backreason) return wx.showToast({
  211. title: '请说明退回原因!',
  212. icon: "none"
  213. })
  214. const res = await api._post({
  215. "id": "20230206101403",
  216. "version": 1,
  217. "content": {
  218. "sa_serviceorderid": that.data.id,
  219. "issumbit": 0,
  220. "backreason": that.data.backreason
  221. }
  222. })
  223. wx.showToast({
  224. title: res.msg == '成功' ? '已退回工单' : res.msg,
  225. icon: "none",
  226. mask: true
  227. })
  228. if (res.msg == '成功') {
  229. that.mainData()
  230. that.showBackReason()
  231. }
  232. },
  233. async workOrderTemp() {
  234. const res = await api._post({
  235. "id": "20230206155803",
  236. "version": 1,
  237. "content": {}
  238. })
  239. this.setData({
  240. templist: res.data
  241. })
  242. },
  243. selectTemp(data) {
  244. this.setData({
  245. actTemp: data.currentTarget.dataset.item
  246. })
  247. },
  248. async workerData() {
  249. const res = await api._post({
  250. "id": "20230213143003",
  251. "version": 1,
  252. "content": {
  253. "where": {
  254. "condition": ""
  255. }
  256. }
  257. })
  258. this.setData({
  259. workers: res.data
  260. })
  261. },
  262. selectLeader(data) {
  263. this.setData({
  264. actLeader: data.currentTarget.dataset.item
  265. })
  266. },
  267. async toWorker() {
  268. if (!this.data.actTemp && !this.data.actLeader) {
  269. wx.showToast({
  270. title: '未选择工单模板或负责人',
  271. icon: 'none'
  272. })
  273. } else {
  274. const res = await api._post({
  275. "id": "20230207091003",
  276. "content": {
  277. "type": this.data.actTemp.type,
  278. "sa_serviceorderid": this.data.id,
  279. "sa_workorder_templateid": this.data.actTemp.sa_workorder_templateid,
  280. "projectlearders": [this.data.actLeader.userid]
  281. }
  282. })
  283. wx.showToast({
  284. title: res.msg == '成功' ? '操作成功' : res.msg,
  285. icon: "none",
  286. mask: true
  287. });
  288. if (res.msg == '成功') {
  289. this.mainData();
  290. this.linkWorkOrder();
  291. this.showBackReason()
  292. }
  293. }
  294. },
  295. async linkWorkOrder() {
  296. const res = await api._post({
  297. "id": "20230207154203",
  298. "version": 1,
  299. "content": {
  300. nocache: true,
  301. "sa_serviceorderid": this.data.id
  302. }
  303. })
  304. this.setData({
  305. linkWorkOrders: res.data
  306. })
  307. },
  308. tolinkWorkOrder(e) {
  309. let id = e.currentTarget.dataset.item.sa_workorderid
  310. let app = getApp()
  311. app.globalData.action = ['editLeader']
  312. wx.navigateTo({
  313. url: '/Eservice/workerLeader/editworkOrderDetail/index?id=' + id
  314. })
  315. },
  316. async showProgressDialog() {
  317. const res = await api._post({
  318. id: "20230208140203",
  319. content: {}
  320. })
  321. this.setData({
  322. showProgress: !this.data.showProgress,
  323. progress: res.data
  324. })
  325. },
  326. onLoad(options) {
  327. this.setData({
  328. id: options.id
  329. })
  330. },
  331. onShow() {
  332. this.mainData();
  333. this.linkWorkOrder();
  334. },
  335. })