index.js 9.4 KB

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