index.js 7.9 KB

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