index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. import api from '../api/api';
  2. const _Http = getApp().globalData.http;
  3. let deleteUsers = [];
  4. Page({
  5. data: {
  6. stopClick: '',
  7. SignName: true,
  8. timerid: null,
  9. act_confirm_value: '是',
  10. form: {
  11. "sa_workorderid": 0,
  12. "sa_workorder_nodeid": 0,
  13. "remarks": "",
  14. "textcontent": "",
  15. "confirm_value": "",
  16. "amount": 0,
  17. "isconfirm": 0,
  18. "team": [],
  19. "trainers": [],
  20. "traintitem": [],
  21. },
  22. bindNormalData: {
  23. ownertable: 'sa_workorder_node',
  24. ownerid: 0,
  25. usetype: 'default'
  26. },
  27. bindContractData: {
  28. "ownertable": "sa_workorder_node",
  29. "ownerid": 0,
  30. "usetype": "contract",
  31. },
  32. bindSignNameData: {
  33. "ownertable": "sa_workorder_node",
  34. "ownerid": 0,
  35. "usetype": "signature",
  36. }
  37. },
  38. async nodeDetail() {
  39. const res = await api._post({
  40. "id": "20230209091103",
  41. "version": 1,
  42. "content": {
  43. nocache: true,
  44. "sa_workorderid": this.data.sa_workorderid,
  45. "sa_workorder_nodeid": this.data.sa_workorder_nodeid
  46. }
  47. })
  48. console.log("详情", res.data)
  49. this.setData({
  50. mainData: res.data[0],
  51. teams: res.data[0].team.map(v => v.userid),
  52. titems: res.data[0].titems
  53. })
  54. this.setDefaultData()
  55. },
  56. // 是否确认
  57. confirmValue(data) {
  58. this.data.form.confirm_value = data.currentTarget.dataset.item
  59. this.setData({
  60. form: this.data.form
  61. })
  62. this.updateNode()
  63. },
  64. // 文本信息
  65. textContent(data) {
  66. this.data.form.textcontent = data.detail.value
  67. this.setData({
  68. form: this.data.form
  69. })
  70. this.updateNode()
  71. },
  72. // 是否有偿
  73. amountPay(data) {
  74. this.data.form.amount = data.detail.value
  75. this.setData({
  76. form: this.data.form
  77. })
  78. this.updateNode()
  79. },
  80. // 备 注
  81. remarkEdit(data) {
  82. this.data.form.remarks = data.detail.value
  83. this.setData({
  84. form: this.data.form
  85. })
  86. this.updateNode()
  87. },
  88. confirmBill() {
  89. this.data.form.isconfirm = 1
  90. this.setData({
  91. form: this.data.form
  92. })
  93. this.updateNode()
  94. },
  95. // 更新节点
  96. async updateNode(e) {
  97. this.data.form.traintitem = this.data.titems
  98. this.data.form.sa_workorderid = this.data.sa_workorderid
  99. this.data.form.sa_workorder_nodeid = this.data.sa_workorder_nodeid
  100. this.data.form.team = []
  101. const res = await api._post({
  102. "id": "20230209094203",
  103. "content": this.data.form
  104. });
  105. if (!this.data.form.team.some(v => v.userid == wx.getStorageSync('userMsg').userid)) {
  106. this.setData({
  107. teams: [wx.getStorageSync('userMsg').userid]
  108. })
  109. this.addUser(false);
  110. }
  111. if (e && e.currentTarget.dataset.info === 'needBack') {
  112. wx.navigateBack()
  113. } else {
  114. this.nodeDetail()
  115. }
  116. },
  117. // 获取输入的数据
  118. setDefaultData() {
  119. let that = this
  120. Object.keys(this.data.mainData).map((key, index) => {
  121. Object.keys(this.data.form).map((key2, index) => {
  122. if (key === key2) {
  123. that.data.form[key2] = that.data.mainData[key2]
  124. }
  125. })
  126. })
  127. this.setData({
  128. form: this.data.form
  129. })
  130. },
  131. // 跳转到添加人员
  132. addTrainers() {
  133. wx.navigateTo({
  134. url: '/Eservice/addTrainers/index',
  135. })
  136. },
  137. // 添加人员
  138. getAddTrainers(data) {
  139. this.data.form.trainers.push(data)
  140. this.data.mainData.trainers = this.data.form.trainers
  141. this.setData({
  142. // form:this.data.form,
  143. mainData: this.data.mainData
  144. })
  145. this.updateNode()
  146. },
  147. // 删除人员
  148. deleteMenber(data) {
  149. this.data.mainData.trainers = this.data.mainData.trainers.filter(e => {
  150. return e.sa_workorder_node_teamid !== data.detail.sa_workorder_node_teamid
  151. })
  152. this.data.form.trainers = this.data.mainData.trainers
  153. this.setData({
  154. form: this.data.form,
  155. mainData: this.data.mainData
  156. })
  157. this.updateNode()
  158. },
  159. // 跳转到物料添加
  160. addProduct() {
  161. wx.navigateTo({
  162. url: '/Eservice/serviceMaterial/index',
  163. })
  164. },
  165. // 添加物料
  166. getAdd(selection) {
  167. this.data.form.traintitem = selection.map(e => {
  168. return {
  169. "itemname": e.itemname,
  170. "itemid": e.itemid,
  171. "model": e.model,
  172. "spec": e.spec,
  173. "qty": 1
  174. }
  175. })
  176. this.setData({
  177. titems: this.data.form.traintitem
  178. })
  179. this.updateNode()
  180. },
  181. // 修改物料数量
  182. qtyChange(data) {
  183. clearTimeout(this.data.timerid)
  184. this.data.timerid = setTimeout(() => {
  185. this.data.titems.forEach(e => {
  186. if (e.itemid == data.detail.itemid) {
  187. e.qty = data.detail.qty
  188. }
  189. })
  190. this.setData({
  191. titems: this.data.titems
  192. })
  193. this.updateNode()
  194. }, 1000)
  195. this.setData({
  196. timerid: this.data.timerid
  197. })
  198. },
  199. // 删除物料
  200. deleteMaterial(data) {
  201. this.setData({
  202. titems: this.data.titems.filter(e => {
  203. return e.itemid !== data.detail.itemid
  204. })
  205. })
  206. this.updateNode()
  207. },
  208. /**
  209. * 生命周期函数--监听页面加载
  210. */
  211. onLoad(options) {
  212. this.data.bindContractData.ownerid = options.id
  213. this.data.bindNormalData.ownerid = options.id
  214. this.data.bindSignNameData.ownerid = options.id
  215. this.setData({
  216. bindContractData: this.data.bindContractData,
  217. bindNormalData: this.data.bindNormalData,
  218. bindSignNameData: this.data.bindSignNameData,
  219. sa_workorder_nodeid: options.id,
  220. sa_workorderid: options.wid,
  221. stopClick: options.class
  222. })
  223. this.nodeDetail();
  224. let page = getCurrentPages()[getCurrentPages().length - 2];
  225. if (page.__route__ == 'Eservice/workOrderDetail/index') this.setData({
  226. workers: page.data.billData.team
  227. })
  228. },
  229. onShow() {
  230. this.setData({
  231. SignName: true
  232. })
  233. },
  234. onHide() {
  235. this.setData({
  236. SignName: false
  237. })
  238. },
  239. /**
  240. * 开始添加成员或者取消添加
  241. */
  242. showTeamDialog() {
  243. this.setData({
  244. showTeams: !this.data.showTeams
  245. })
  246. },
  247. /**
  248. * 选择添加成员
  249. */
  250. selectTeams(e) {
  251. const {
  252. userid
  253. } = e.currentTarget.dataset.item;
  254. let teams = this.data.teams;
  255. if (teams.some(v => v == userid)) {
  256. teams = teams.filter(v => v != userid)
  257. deleteUsers.push(userid);
  258. } else {
  259. teams.push(userid)
  260. }
  261. this.setData({
  262. teams
  263. })
  264. },
  265. addUser(init = true) {
  266. api._post({
  267. "id": 20220930103803,
  268. "content": {
  269. ownertable: 'sa_workorder_node',
  270. ownerid: this.data.mainData.sa_workorder_nodeid,
  271. "userids": deleteUsers
  272. }
  273. }).then(s => {
  274. console.log("先删除", s)
  275. deleteUsers = [];
  276. api._post({
  277. "id": 20220930103603,
  278. "content": {
  279. ownertable: 'sa_workorder_node',
  280. ownerid: this.data.mainData.sa_workorder_nodeid,
  281. "userids": this.data.teams
  282. }
  283. }).then(res => {
  284. console.log("添加成员", res)
  285. wx.showToast({
  286. title: res.msg == '成功' ? '修改成功' : res.msg,
  287. icon: "none",
  288. mask: true
  289. });
  290. if (res.msg == '成功') {
  291. this.nodeDetail();
  292. if (init) this.showTeamDialog();
  293. }
  294. })
  295. })
  296. },
  297. })