index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. async mainData() {
  14. const res = await api._post({
  15. "id": "20230208140103",
  16. "content": {
  17. nocache: true,
  18. "sa_workorderid": this.data.id
  19. }
  20. })
  21. this.setData({
  22. billData: res.data
  23. })
  24. this.workerData()
  25. },
  26. changeBillStatus(e) {
  27. const {
  28. id,
  29. name
  30. } = e.target.dataset;
  31. if (!name) return;
  32. const dialogConfig = {
  33. context: this,
  34. title: '提示',
  35. content: `是否确定${name}当前工单?`,
  36. confirmBtn: name,
  37. cancelBtn: '取消',
  38. }
  39. Dialog.confirm(dialogConfig)
  40. .then(async () => {
  41. const res = await api._post({
  42. "id": id,
  43. "content": {
  44. "sa_workorderid": this.data.id
  45. }
  46. })
  47. wx.showToast({
  48. title: res.msg == '成功' ? `工单${name}成功` : res.msg,
  49. icon: "none",
  50. mask: true
  51. });
  52. if (name == '作废') {
  53. setTimeout(() => {
  54. wx.navigateBack()
  55. }, 500);
  56. } else {
  57. this.mainData()
  58. }
  59. })
  60. .catch(() => console.log('点击了取消'))
  61. .finally(() => Dialog.close())
  62. },
  63. async addConfirmBill() {
  64. const res = await api._post({
  65. "id": "20230211105703",
  66. "version": 1,
  67. "content": {
  68. "sa_workorder_confirmationid": 0,
  69. "sa_workorderid": this.data.id,
  70. "attitudescore": 0,
  71. "responsescore": 0,
  72. }
  73. })
  74. if (this.data.billData.type === '安装培训') {
  75. wx.navigateTo({
  76. url: '/Eservice/trainConfirmBill/index?id=' + res.data.sa_workorder_confirmationid,
  77. })
  78. } else if (this.data.billData.type === '安装调试') {
  79. wx.navigateTo({
  80. url: '/Eservice/installConfirmBill/index?id=' + res.data.sa_workorder_confirmationid,
  81. })
  82. } else {}
  83. },
  84. toConfirmBill(data) {
  85. if (this.data.billData.type === '安装培训') {
  86. wx.navigateTo({
  87. url: '/Eservice/trainConfirmBill/index?class=stopClick&id=' + data.currentTarget.dataset.item.sa_workorder_confirmationid,
  88. })
  89. }
  90. },
  91. async confirmBillList() {
  92. const res = await api._post({
  93. "id": "20230211105903",
  94. "content": {
  95. "where": {
  96. nocahce: true,
  97. "condition": "",
  98. "sa_workorderid": this.data.id
  99. }
  100. }
  101. })
  102. this.setData({
  103. confirmBills: res.data
  104. })
  105. },
  106. toWorkConfirmInfo() {
  107. getApp().globalData.handelSelect = this
  108. wx.navigateTo({
  109. url: '/Eservice/workBillConfirmInfo/index?class=stopClick'
  110. })
  111. },
  112. async workerData() {
  113. const res = await api._post({
  114. "id": "20230213143003",
  115. "version": 1,
  116. "content": {
  117. "where": {
  118. "condition": ""
  119. }
  120. }
  121. })
  122. this.setData({
  123. workers: res.data
  124. })
  125. },
  126. /**
  127. * 开始添加成员或者取消添加
  128. */
  129. showTeamDialog() {
  130. this.setData({
  131. showTeams: !this.data.showTeams,
  132. teams: this.data.billData.team.map(v => {
  133. return v.isleader == 1 ? 0 : v.userid
  134. })
  135. })
  136. },
  137. /**
  138. * 选择添加成员
  139. */
  140. selectTeams(e) {
  141. const {
  142. userid
  143. } = e.currentTarget.dataset.item;
  144. let teams = this.data.teams;
  145. let i = teams.findIndex(v => v == userid);
  146. if (i != -1) {
  147. teams = teams.filter(v => v != userid)
  148. } else {
  149. teams.push(userid)
  150. }
  151. this.setData({
  152. teams
  153. })
  154. },
  155. addUser() {
  156. api._post({
  157. "id": 20220930103603,
  158. "content": {
  159. ownertable: 'sa_workorder',
  160. ownerid: this.data.billData.sa_workorderid,
  161. "userids": this.data.teams,
  162. "justuserids": 1
  163. }
  164. }).then(res => {
  165. console.log("添加成员", res)
  166. wx.showToast({
  167. title: res.msg == '成功' ? '修改成功' : res.msg,
  168. icon: "none",
  169. mask: true
  170. });
  171. if (res.msg == '成功') {
  172. this.mainData()
  173. this.showTeamDialog()
  174. }
  175. })
  176. },
  177. showWorkerDialog() {
  178. this.setData({
  179. workLeaderDialog: !this.data.workLeaderDialog
  180. })
  181. },
  182. selectLeader(data) {
  183. this.setData({
  184. actLeader: data.currentTarget.dataset.item
  185. })
  186. },
  187. async toWorker() {
  188. if (!this.data.actLeader) {
  189. wx.showToast({
  190. title: '未选择负责人',
  191. icon: 'none'
  192. })
  193. } else {
  194. /* this.data.billData.projectlearders = [this.data.actLeader.userid]
  195. const res = await api._post({
  196. "id": "20230208140003",
  197. "content": this.data.billData
  198. }) */
  199. const res = await api._post({
  200. "id": "20220930103703",
  201. "content": {
  202. ownertable: 'sa_workorder',
  203. ownerid: this.data.billData.sa_workorderid,
  204. "userid": this.data.actLeader.userid
  205. }
  206. })
  207. this.setData({
  208. workLeaderDialog: false
  209. })
  210. if (res.msg != '成功') return wx.showToast({
  211. title: res.msg,
  212. icon: "none"
  213. });
  214. this.mainData()
  215. // this.confirmBillList()
  216. }
  217. },
  218. onLoad(options) {
  219. this.setData({
  220. id: options.id
  221. })
  222. },
  223. onShow() {
  224. this.mainData()
  225. this.confirmBillList()
  226. },
  227. })