index.js 6.8 KB

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