index.js 6.7 KB

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