index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. addpersonBadge: {},
  38. additemBadge: {},
  39. addpersonLabel: '',
  40. additemLabel: '',
  41. activeTab: 0
  42. },
  43. onTabChange(e) {
  44. const value = parseInt(e.currentTarget.dataset.value)
  45. this.setData({
  46. activeTab: value
  47. })
  48. },
  49. async nodeDetail() {
  50. const res = await api._post({
  51. "id": "20230209091103",
  52. "version": 1,
  53. "content": {
  54. nocache: true,
  55. "sa_workorderid": this.data.sa_workorderid,
  56. "sa_workorder_nodeid": this.data.sa_workorder_nodeid
  57. }
  58. })
  59. console.log("详情", res.data)
  60. const language = getApp().globalData.Language.getMapText('E-订单') || {}
  61. const isAddpersonRequired = res.data[0].workpresetjson.addperson == 11
  62. const isAdditemRequired = res.data[0].workpresetjson.additem == 11
  63. this.setData({
  64. mainData: res.data[0],
  65. teams: res.data[0].team.map(v => v.userid),
  66. titems: res.data[0].titems,
  67. addpersonBadge: isAddpersonRequired ? {
  68. count: '*',
  69. color: '#e34d59',
  70. offset: ['20rpx', '-10rpx'],
  71. size: 'small'
  72. } : {},
  73. additemBadge: isAdditemRequired ? {
  74. count: '*',
  75. color: '#e34d59',
  76. offset: ['20rpx', '-10rpx'],
  77. size: 'small'
  78. } : {},
  79. addpersonLabel: language['培训人员'] || '培训人员',
  80. additemLabel: language['工单物料'] || '工单物料',
  81. activeTab: res.data[0].workpresetjson.addperson !== 0 ? 0 : 1
  82. })
  83. this.setDefaultData()
  84. try {
  85. this.selectComponent("#signName").fileData()
  86. } catch (error) {
  87. }
  88. },
  89. // 是否确认
  90. confirmValue(data) {
  91. this.data.form.confirm_value = data.currentTarget.dataset.item
  92. this.setData({
  93. form: this.data.form
  94. })
  95. this.updateNode()
  96. },
  97. // 文本信息
  98. textContent(data) {
  99. this.data.form.textcontent = data.detail.value
  100. this.setData({
  101. form: this.data.form
  102. })
  103. this.updateNode()
  104. },
  105. // 是否有偿
  106. amountPay(data) {
  107. this.data.form.amount = data.detail.value
  108. this.setData({
  109. form: this.data.form
  110. })
  111. this.updateNode()
  112. },
  113. // 备 注
  114. remarkEdit(data) {
  115. this.data.form.remarks = data.detail.value
  116. this.setData({
  117. form: this.data.form
  118. })
  119. this.updateNode()
  120. },
  121. // 校验必填项
  122. validateRequiredFields() {
  123. const workpreset = this.data.mainData.workpresetjson
  124. const errors = []
  125. if (workpreset.confirm == 11 && !this.data.form.confirm_value) {
  126. errors.push('是否确认')
  127. }
  128. if (workpreset.fileupload == 11) {
  129. const uploadComponent = this.selectComponent('#fileUpload')
  130. if (uploadComponent && (!uploadComponent.data.originFiles || uploadComponent.data.originFiles.length === 0)) {
  131. errors.push('上传附件')
  132. }
  133. }
  134. if (workpreset.textedit == 11 && !this.data.form.textcontent) {
  135. errors.push('文本信息')
  136. }
  137. if (workpreset.contractupload == 11) {
  138. const contractUploadComponent = this.selectComponent('#contractUpload')
  139. if (contractUploadComponent && (!contractUploadComponent.data.originFiles || contractUploadComponent.data.originFiles.length === 0)) {
  140. errors.push('上传合同')
  141. }
  142. }
  143. if (workpreset.amountpay == 11 && (!this.data.form.amount || this.data.form.amount == 0)) {
  144. errors.push('是否有偿')
  145. }
  146. if (workpreset.signature == 11) {
  147. const signNameComponent = this.selectComponent('#signName')
  148. if (signNameComponent && (!signNameComponent.data.originFiles || signNameComponent.data.originFiles.length === 0)) {
  149. errors.push('客户签字')
  150. }
  151. }
  152. if (workpreset.addperson == 11 && (!this.data.mainData.trainers || this.data.mainData.trainers.length === 0)) {
  153. errors.push('培训人员')
  154. }
  155. if (workpreset.additem == 11 && (!this.data.titems || this.data.titems.length === 0)) {
  156. errors.push('工单物料')
  157. }
  158. return errors
  159. },
  160. confirmBill() {
  161. const errors = this.validateRequiredFields()
  162. if (errors.length > 0) {
  163. wx.showToast({
  164. title: '必填信息未完善',
  165. icon: 'none',
  166. duration: 2000
  167. })
  168. return
  169. }
  170. this.data.form.isconfirm = 1
  171. this.setData({
  172. form: this.data.form
  173. })
  174. this.updateNode()
  175. },
  176. // 保存节点(不校验)
  177. saveNode(e) {
  178. this.updateNode(false, e)
  179. },
  180. // 更新节点
  181. async updateNode(needValidate = false, e) {
  182. if (needValidate) {
  183. const errors = this.validateRequiredFields()
  184. if (errors.length > 0) {
  185. wx.showToast({
  186. title: '必填信息未完善',
  187. icon: 'none',
  188. duration: 2000
  189. })
  190. return
  191. }
  192. }
  193. this.data.form.traintitem = this.data.titems
  194. this.data.form.sa_workorderid = this.data.sa_workorderid
  195. this.data.form.sa_workorder_nodeid = this.data.sa_workorder_nodeid
  196. this.data.form.team = []
  197. const res = await api._post({
  198. "id": "20230209094203",
  199. "content": this.data.form
  200. });
  201. if (!this.data.form.team.some(v => v.userid == wx.getStorageSync('userMsg').userid)) {
  202. this.setData({
  203. teams: [wx.getStorageSync('userMsg').userid]
  204. })
  205. this.addUser(false);
  206. }
  207. if (e && e.currentTarget && e.currentTarget.dataset.info === 'needBack') {
  208. wx.navigateBack()
  209. } else {
  210. this.nodeDetail()
  211. }
  212. try {
  213. this.selectComponent("#signName").fileData()
  214. } catch (error) {
  215. }
  216. },
  217. // 获取输入的数据
  218. setDefaultData() {
  219. let that = this
  220. Object.keys(this.data.mainData).map((key, index) => {
  221. Object.keys(this.data.form).map((key2, index) => {
  222. if (key === key2) {
  223. that.data.form[key2] = that.data.mainData[key2]
  224. }
  225. })
  226. })
  227. this.setData({
  228. form: this.data.form
  229. })
  230. },
  231. // 跳转到添加人员
  232. addTrainers() {
  233. wx.navigateTo({
  234. url: '/Eservice/addTrainers/index',
  235. })
  236. },
  237. // 添加人员
  238. getAddTrainers(data) {
  239. this.data.form.trainers.push(data)
  240. this.data.mainData.trainers = this.data.form.trainers
  241. this.setData({
  242. // form:this.data.form,
  243. mainData: this.data.mainData
  244. })
  245. this.updateNode()
  246. },
  247. // 删除人员
  248. deleteMenber(data) {
  249. this.data.mainData.trainers = this.data.mainData.trainers.filter(e => {
  250. return e.sa_workorder_node_teamid !== data.detail.sa_workorder_node_teamid
  251. })
  252. this.data.form.trainers = this.data.mainData.trainers
  253. this.setData({
  254. form: this.data.form,
  255. mainData: this.data.mainData
  256. })
  257. this.updateNode()
  258. },
  259. // 跳转到物料添加
  260. addProduct() {
  261. let itemtype = this.data.mainData.workpresetjson.itemtype;
  262. // ①若itemtype是"服务商品",则type=2:查询申请单商品
  263. // ②若itemtype是"培训物料",则type=1:查询档案商品
  264. let type = itemtype === '服务商品' ? 2 : 1;
  265. wx.navigateTo({
  266. url: `/E-service/serviceBillList/product/select?params=${JSON.stringify({
  267. "content": {
  268. "sa_workorderid": this.data.sa_workorderid,
  269. "type": type, // 1档案, 2:申请单
  270. "pageNumber": 1,
  271. "pageSize": 20,
  272. "where": {
  273. "condition": ""
  274. }
  275. },
  276. "id": "2026022710102502",
  277. })}`
  278. });
  279. getApp().globalData.handleSelect = this.handleSelect.bind(this)
  280. },
  281. /* 处理新增产品 */
  282. handleSelect(detail) {
  283. let newItems = detail.list.map(v => {
  284. return {
  285. "itemname": v.itemname,
  286. "itemid": v.itemid,
  287. "model": v.model,
  288. "spec": v.spec,
  289. qty: v.qty || 1
  290. }
  291. })
  292. let existingItems = this.data.titems || []
  293. let allItems = [...existingItems, ...newItems]
  294. this.setData({
  295. titems: allItems
  296. })
  297. this.updateNode()
  298. wx.navigateBack();
  299. },
  300. // 修改物料数量
  301. qtyChange(data) {
  302. clearTimeout(this.data.timerid)
  303. this.data.timerid = setTimeout(() => {
  304. this.data.titems.forEach(e => {
  305. if (e.itemid == data.detail.itemid) {
  306. e.qty = data.detail.qty
  307. }
  308. })
  309. this.setData({
  310. titems: this.data.titems
  311. })
  312. this.updateNode()
  313. }, 1000)
  314. this.setData({
  315. timerid: this.data.timerid
  316. })
  317. },
  318. // 删除物料
  319. deleteMaterial(data) {
  320. this.setData({
  321. titems: this.data.titems.filter(e => {
  322. return e.itemid !== data.detail.itemid
  323. })
  324. })
  325. this.updateNode()
  326. },
  327. /**
  328. * 生命周期函数--监听页面加载
  329. */
  330. onLoad(options) {
  331. this.data.bindContractData.ownerid = options.id
  332. this.data.bindNormalData.ownerid = options.id
  333. this.data.bindSignNameData.ownerid = options.id
  334. this.setData({
  335. bindContractData: this.data.bindContractData,
  336. bindNormalData: this.data.bindNormalData,
  337. bindSignNameData: this.data.bindSignNameData,
  338. sa_workorder_nodeid: options.id,
  339. sa_workorderid: options.wid,
  340. stopClick: options.class
  341. })
  342. this.nodeDetail();
  343. let page = getCurrentPages()[getCurrentPages().length - 2];
  344. if (page.__route__ == 'E-service/workOrder/detail') this.setData({
  345. workers: page.data.detail.team
  346. })
  347. getApp().globalData.Language.getLanguagePackage(this, 'E-订单');
  348. },
  349. onShow() {
  350. this.setData({
  351. SignName: true
  352. })
  353. },
  354. onHide() {
  355. this.setData({
  356. SignName: false
  357. })
  358. },
  359. /**
  360. * 开始添加成员或者取消添加
  361. */
  362. showTeamDialog() {
  363. this.setData({
  364. showTeams: !this.data.showTeams
  365. })
  366. },
  367. /**
  368. * 选择添加成员
  369. */
  370. selectTeams(e) {
  371. const {
  372. userid
  373. } = e.currentTarget.dataset.item;
  374. let teams = this.data.teams;
  375. if (teams.some(v => v == userid)) {
  376. teams = teams.filter(v => v != userid)
  377. deleteUsers.push(userid);
  378. } else {
  379. teams.push(userid)
  380. }
  381. this.setData({
  382. teams
  383. })
  384. },
  385. addUser(init = true) {
  386. api._post({
  387. "id": 20220930103803,
  388. "content": {
  389. ownertable: 'sa_workorder_node',
  390. ownerid: this.data.mainData.sa_workorder_nodeid,
  391. "userids": deleteUsers
  392. }
  393. }).then(s => {
  394. console.log("先删除", s)
  395. deleteUsers = [];
  396. api._post({
  397. "id": 20220930103603,
  398. "content": {
  399. ownertable: 'sa_workorder_node',
  400. ownerid: this.data.mainData.sa_workorder_nodeid,
  401. "userids": this.data.teams
  402. }
  403. }).then(res => {
  404. console.log("添加成员", res)
  405. wx.showToast({
  406. title: res.code == '1' ? getApp().globalData.Language.getMapText('修改成功') : res.msg,
  407. icon: "none",
  408. mask: true
  409. });
  410. if (res.code == '1') {
  411. this.nodeDetail();
  412. if (init) this.showTeamDialog();
  413. }
  414. })
  415. })
  416. },
  417. onUnload() {
  418. getCurrentPages().find(v => v.__route__ == 'E-service/workOrder/detail').getDetail()
  419. }
  420. })