index.js 8.0 KB

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