index.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. const api = require("../api/api")
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. timerid: null,
  8. bindSignNameData: {
  9. "ownertable": "sa_workorder_confirmation",
  10. "ownerid": 0,
  11. "usetype": "signature",
  12. }
  13. },
  14. async billData() {
  15. const res = await api._post({
  16. "id": "20230211105803",
  17. "content": {
  18. "sa_workorder_confirmationid": this.data.id
  19. }
  20. })
  21. console.log('详情', res)
  22. this.setData({
  23. mainData: res.data,
  24. sa_serviceorderid: res.data.workorder.sa_serviceorderid || '0',
  25. sa_orderid: res.data.workorder.sa_orderid || '0',
  26. stopClick: res.data.status !== '新建' ? 'stopClick' : this.data.stopClick
  27. })
  28. this.setInputData()
  29. },
  30. setInputData() {
  31. this.data.mainData.confirmationcontent.forEach(e => {
  32. Object.keys(e).map((key, index) => {
  33. if (key.includes('现场培训内容')) {
  34. this.setData({
  35. trainerContent: e[key].confirm_value
  36. })
  37. } else if (key.includes('现场互动及测试培训效果')) {
  38. this.setData({
  39. trainerResult: e[key].confirm_value
  40. })
  41. } else {
  42. }
  43. })
  44. })
  45. },
  46. async updateBill() {
  47. if (this.data.mainData.status !== '新建') return getApp().globalData.Language.showToast('非新建状态,修改的数据将不会保存')
  48. const res = await api._post({
  49. "id": "20230211105703",
  50. "content": this.data.mainData
  51. })
  52. },
  53. // 跳转到物料添加
  54. addProduct() {
  55. /* wx.navigateTo({
  56. url: '/Eservice/serviceMaterial/index',
  57. }) */
  58. wx.navigateTo({
  59. url: '/Eservice/agent/billCanUseProduct/index?id=' + this.data.mainData.sa_workorderid
  60. })
  61. },
  62. // 跳转到添加人员
  63. addTrainers() {
  64. wx.navigateTo({
  65. url: '/Eservice/addTrainers/index',
  66. })
  67. },
  68. // 添加人员
  69. async getAddTrainers(data) {
  70. data.sa_workorder_node_teamid = 0
  71. this.data.mainData.trainers.push(data)
  72. const res = await api._post({
  73. "id": "20230215202103",
  74. "content": {
  75. "sa_workorder_confirmationid": this.data.mainData.sa_workorder_confirmationid,
  76. "sa_workorderid": this.data.mainData.workorder.sa_workorderid,
  77. "trainers": this.data.mainData.trainers
  78. }
  79. })
  80. this.billData()
  81. },
  82. // 删除人员
  83. async deleteMenber(data) {
  84. let id = data.detail.sa_workorder_node_teamid
  85. const res = await api._post({
  86. "id": "20230215202203",
  87. "version": 1,
  88. "content": {
  89. "sa_workorder_node_teamids": [id]
  90. }
  91. })
  92. this.billData()
  93. },
  94. // 添加物料
  95. async getAdd(selection) {
  96. console.log(selection)
  97. let arr = selection.map(e => {
  98. return {
  99. "sa_workorder_node_itemsid": 0,
  100. "itemid": e,
  101. "qty": 1
  102. }
  103. })
  104. this.data.mainData.trainertitems = this.data.mainData.trainertitems.concat(arr)
  105. this.updateMaterial(this.data.mainData.trainertitems)
  106. },
  107. async updateMaterial(trainertitems) {
  108. const res = await api._post({
  109. "id": "20230215201903",
  110. "content": {
  111. "sa_workorder_confirmationid": this.data.mainData.sa_workorder_confirmationid,
  112. "sa_workorderid": this.data.mainData.workorder.sa_workorderid,
  113. "iteminfos": trainertitems
  114. }
  115. })
  116. this.billData()
  117. },
  118. // 修改物料数量
  119. qtyChange(data) {
  120. clearTimeout(this.data.timerid)
  121. this.data.timerid = setTimeout(() => {
  122. this.data.mainData.trainertitems.forEach(e => {
  123. if (e.itemid == data.detail.itemid) {
  124. e.qty = data.detail.qty
  125. }
  126. })
  127. this.updateMaterial(this.data.mainData.trainertitems)
  128. }, 1000)
  129. this.setData({
  130. timerid: this.data.timerid
  131. })
  132. },
  133. // 删除物料
  134. async deleteMaterial(data) {
  135. let itemid = data.detail.sa_workorder_node_itemsid
  136. const res = await api._post({
  137. "id": "20230215202003",
  138. "content": {
  139. "sa_workorder_node_itemsids": [itemid]
  140. }
  141. })
  142. this.billData()
  143. },
  144. // 改变评分
  145. onChange(e) {
  146. this.data.mainData[e.currentTarget.dataset.name] = e.detail.value
  147. this.setData({
  148. mainData: this.data.mainData
  149. });
  150. this.updateBill()
  151. },
  152. async submit() {
  153. this.createImage(true);
  154. const res = await api._post({
  155. "id": "20230211110003",
  156. "content": {
  157. "sa_workorder_confirmationid": this.data.mainData.sa_workorder_confirmationid
  158. }
  159. })
  160. if (res.code == 1) {
  161. wx.showToast({
  162. title: getApp().globalData.Language.getMapText('提交成功'),
  163. icon: "success"
  164. })
  165. this.billData()
  166. }
  167. },
  168. async delete() {
  169. const res = await api._post({
  170. "id": "20230211110103",
  171. "content": {
  172. "sa_workorder_confirmationids": [this.data.mainData.sa_workorder_confirmationid]
  173. }
  174. })
  175. if (res.code == 1) {
  176. wx.navigateBack()
  177. }
  178. },
  179. inputChange(data) {
  180. let keyValue = data.currentTarget.dataset.name
  181. this.data.mainData.confirmationcontent.forEach(e => {
  182. Object.keys(e).map((key, index) => {
  183. if (key.includes(keyValue)) {
  184. console.log(e)
  185. e[key].confirm_value = data.detail.value
  186. }
  187. })
  188. })
  189. this.updateBill()
  190. },
  191. /* 查看单据 */
  192. checkImage() {
  193. let attinfos = this.data.mainData.attinfos.map(v => v.usetype);
  194. let index = attinfos.lastIndexOf("comfirmbill");
  195. //没有查询到有效单据 跳转生成
  196. if (index == -1) return this.createImage(true);
  197. wx.previewImage({
  198. urls: [this.data.mainData.attinfos[index].url],
  199. })
  200. },
  201. createImage(active = false) {
  202. let token = wx.getStorageSync('userMsg').token
  203. let parentid = wx.getStorageSync('siteP').appfolderid
  204. let url = `${getApp().globalData.http.baseUrl}/yosweb/#/printTable?token=${token}&parentid=${parentid}&ownerid=${this.data.mainData.sa_workorder_confirmationid}${active==true?'&action=1':''}`
  205. this.setData({
  206. url: url
  207. })
  208. wx.navigateTo({
  209. url: '/Eservice/webView/index',
  210. })
  211. },
  212. onLoad(options) {
  213. this.data.bindSignNameData.ownerid = options.id
  214. this.setData({
  215. stopClick: options.class,
  216. id: options.id,
  217. bindSignNameData: this.data.bindSignNameData
  218. })
  219. getApp().globalData.Language.getLanguagePackage(this, 'E-订单');
  220. },
  221. onShow() {
  222. this.setData({
  223. SignName: true
  224. })
  225. this.billData()
  226. },
  227. onHide() {
  228. this.setData({
  229. SignName: false
  230. })
  231. },
  232. })