index.js 9.6 KB

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