index.js 7.8 KB

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