index.js 9.4 KB

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