index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. const api = require("../../api/api");
  2. import Dialog from 'tdesign-miniprogram/dialog/index';
  3. // pages/workOrderDetail/index.js
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. workLeaderDialog: false,
  10. showTeams: false,
  11. teams: []
  12. },
  13. toServiceBillDetail() {
  14. console.log("查看来源申请单", this.data.billData)
  15. wx.navigateTo({
  16. url: '/Eservice/saler/serviceBillDetail/index?id=' + this.data.billData.sa_serviceorderid,
  17. })
  18. },
  19. async mainData() {
  20. const res = await api._post({
  21. "id": "20230208140103",
  22. "content": {
  23. nocache: true,
  24. "sa_workorderid": this.data.id
  25. }
  26. })
  27. console.log("详情", res)
  28. this.setData({
  29. billData: res.data,
  30. isleader: res.data.team.find(v => v.isleader).userid == wx.getStorageSync('userMsg').userid
  31. })
  32. this.workerData()
  33. },
  34. changeBillStatus(e) {
  35. const {
  36. id,
  37. name
  38. } = e.target.dataset;
  39. if (!name) return;
  40. const dialogConfig = {
  41. context: this,
  42. title: getApp().globalData.Language.getMapText('提示'),
  43. content: getApp().globalData.Language.joint([{
  44. t: 1,
  45. v: '是否确定',
  46. }, {
  47. t: 1,
  48. v: name,
  49. f: "“",
  50. r: "”"
  51. }, {
  52. t: 1,
  53. v: '当前工单',
  54. r: "?"
  55. }]),
  56. confirmBtn: getApp().globalData.Language.getMapText(name),
  57. cancelBtn: getApp().globalData.Language.getMapText('取消'),
  58. }
  59. Dialog.confirm(dialogConfig)
  60. .then(async () => {
  61. const res = await api._post({
  62. "id": id,
  63. "content": {
  64. "sa_workorderid": this.data.id
  65. }
  66. })
  67. wx.showToast({
  68. title: res.code == '1' ? getApp().globalData.Language.joint([{
  69. t: 1,
  70. v: '工单',
  71. }, {
  72. t: 1,
  73. v: name,
  74. f: "“",
  75. r: "”"
  76. }, {
  77. t: 1,
  78. v: '成功',
  79. r: "!"
  80. }]) : res.msg,
  81. icon: "none",
  82. mask: true
  83. });
  84. if (name == '作废') {
  85. setTimeout(() => {
  86. wx.navigateBack()
  87. }, 500);
  88. } else {
  89. this.mainData()
  90. }
  91. })
  92. .catch(() => console.log('点击了取消'))
  93. .finally(() => Dialog.close())
  94. },
  95. async addConfirmBill() {
  96. const res = await api._post({
  97. "id": "20230211105703",
  98. "version": 1,
  99. "content": {
  100. "sa_workorder_confirmationid": 0,
  101. "sa_workorderid": this.data.id,
  102. "attitudescore": 0,
  103. "responsescore": 0,
  104. }
  105. })
  106. if (this.data.billData.actiontype === "非工序模板") {
  107. wx.navigateTo({
  108. url: '/Eservice/materielConfirmBill/index?id=' + res.data.sa_workorder_confirmationid,
  109. })
  110. } else if (this.data.billData.type === '安装培训') {
  111. wx.navigateTo({
  112. url: '/Eservice/trainConfirmBill/index?id=' + res.data.sa_workorder_confirmationid,
  113. })
  114. } else if (this.data.billData.type === '安装调试') {
  115. wx.navigateTo({
  116. url: '/Eservice/installConfirmBill/index?id=' + res.data.sa_workorder_confirmationid,
  117. })
  118. } else {
  119. wx.navigateTo({
  120. url: '/Eservice/serviceConfirmBill/index?id=' + res.data.sa_workorder_confirmationid,
  121. })
  122. }
  123. },
  124. toConfirmBill(data) {
  125. if (this.data.billData.actiontype === "非工序模板") {
  126. wx.navigateTo({
  127. url: '/Eservice/materielConfirmBill/index?id=' + data.currentTarget.dataset.item.sa_workorder_confirmationid + '&class=' + this.data.stopClick,
  128. })
  129. } else if (this.data.billData.type === '安装培训') {
  130. wx.navigateTo({
  131. url: '/Eservice/trainConfirmBill/index?id=' + data.currentTarget.dataset.item.sa_workorder_confirmationid + '&class=' + this.data.stopClick,
  132. })
  133. } else if (this.data.billData.type === '安装调试') {
  134. wx.navigateTo({
  135. url: '/Eservice/installConfirmBill/index?id=' + data.currentTarget.dataset.item.sa_workorder_confirmationid + '&class=' + this.data.stopClick,
  136. })
  137. } else {
  138. wx.navigateTo({
  139. url: '/Eservice/serviceConfirmBill/index?id=' + data.currentTarget.dataset.item.sa_workorder_confirmationid + '&class=' + this.data.stopClick,
  140. })
  141. }
  142. },
  143. async confirmBillList() {
  144. const res = await api._post({
  145. "id": "20230211105903",
  146. "content": {
  147. "where": {
  148. nocahce: true,
  149. "condition": "",
  150. "sa_workorderid": this.data.id
  151. }
  152. }
  153. })
  154. this.setData({
  155. confirmBills: res.data
  156. })
  157. },
  158. toWorkConfirmInfo() {
  159. getApp().globalData.handelSelect = this
  160. wx.navigateTo({
  161. url: '/Eservice/workBillConfirmInfo/index?class=stopClick'
  162. })
  163. },
  164. async workerData() {
  165. const res = await api._post({
  166. "id": "20230213143003",
  167. "version": 1,
  168. "content": {
  169. "where": {
  170. "condition": ""
  171. }
  172. }
  173. })
  174. this.setData({
  175. workers: res.data
  176. })
  177. },
  178. /**
  179. * 开始添加成员或者取消添加
  180. */
  181. showTeamDialog() {
  182. this.setData({
  183. showTeams: !this.data.showTeams,
  184. teams: this.data.billData.team.map(v => {
  185. return v.isleader == 1 ? 0 : v.userid
  186. })
  187. })
  188. },
  189. /**
  190. * 选择添加成员
  191. */
  192. selectTeams(e) {
  193. const {
  194. userid
  195. } = e.currentTarget.dataset.item;
  196. let teams = this.data.teams;
  197. let i = teams.findIndex(v => v == userid);
  198. if (i != -1) {
  199. teams = teams.filter(v => v != userid)
  200. } else {
  201. teams.push(userid)
  202. }
  203. this.setData({
  204. teams
  205. })
  206. },
  207. addUser() {
  208. api._post({
  209. "id": 20220930103603,
  210. "content": {
  211. ownertable: 'sa_workorder',
  212. ownerid: this.data.billData.sa_workorderid,
  213. "userids": this.data.teams,
  214. "justuserids": 1
  215. }
  216. }).then(res => {
  217. console.log("添加成员", res)
  218. wx.showToast({
  219. title: res.code == '1' ? getApp().globalData.Language.getMapText('修改成功') : res.msg,
  220. icon: "none",
  221. mask: true
  222. });
  223. if (res.code == '1') {
  224. this.showTeamDialog()
  225. api._post({
  226. "id": 2025062416033402,
  227. "content": {
  228. "userid": wx.getStorageSync('userMsg').userid,
  229. "sa_workorderid": this.data.billData.sa_workorderid,
  230. },
  231. }).then(res => {
  232. console.log("查询权限", res)
  233. if (res.code == 1) {
  234. if (res.data.isteamleader || res.data.isworkleader) {
  235. this.mainData()
  236. } else {
  237. wx.redirectTo({
  238. url: '/Eservice/workOrderDetail/index?id=' + this.data.billData.sa_workorderid
  239. })
  240. }
  241. } else {
  242. this.mainData()
  243. }
  244. })
  245. }
  246. })
  247. },
  248. showWorkerDialog() {
  249. this.setData({
  250. workLeaderDialog: !this.data.workLeaderDialog
  251. })
  252. },
  253. selectLeader(data) {
  254. this.setData({
  255. actLeader: data.currentTarget.dataset.item
  256. })
  257. },
  258. async toWorker() {
  259. if (!this.data.actLeader) {
  260. getApp().globalData.Language.showToast('未选择负责人')
  261. } else {
  262. let teams = this.data.billData.team;
  263. const res = await api._post({
  264. "id": "20220930103703",
  265. "content": {
  266. ownertable: 'sa_workorder',
  267. ownerid: this.data.billData.sa_workorderid,
  268. "userid": this.data.actLeader.userid
  269. }
  270. })
  271. await api._post({
  272. "id": 20220930103603,
  273. "content": {
  274. ownertable: 'sa_workorder',
  275. ownerid: this.data.billData.sa_workorderid,
  276. "userids": [this.data.actLeader.userid].concat(this.data.billData.team.map(v => v.userid)),
  277. "justuserids": 1
  278. }
  279. }).then(res => {
  280. console.log("添加成员", res)
  281. })
  282. this.setData({
  283. workLeaderDialog: false
  284. })
  285. if (res.code != '1') return wx.showToast({
  286. title: res.msg,
  287. icon: "none"
  288. });
  289. api._post({
  290. "id": 2025062416033402,
  291. "content": {
  292. "userid": wx.getStorageSync('userMsg').userid,
  293. "sa_workorderid": this.data.billData.sa_workorderid,
  294. },
  295. }).then(res => {
  296. console.log("查询权限", res)
  297. if (res.code == 1) {
  298. if (res.data.isteamleader || res.data.isworkleader) {
  299. this.mainData()
  300. } else {
  301. wx.redirectTo({
  302. url: '/Eservice/workOrderDetail/index?id=' + this.data.billData.sa_workorderid
  303. })
  304. }
  305. } else {
  306. this.mainData()
  307. }
  308. })
  309. }
  310. },
  311. onLoad(options) {
  312. this.setData({
  313. id: options.id
  314. })
  315. getApp().globalData.Language.getLanguagePackage(this, 'E-订单');
  316. },
  317. onShow() {
  318. this.mainData()
  319. this.confirmBillList()
  320. },
  321. })