index.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. paidServiceAmount: 0,
  13. SignName: true,
  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. 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. this.setData({
  44. mainData: res.data,
  45. sa_serviceorderid: res.data.workorder.sa_serviceorderid || "0",
  46. sa_orderid: res.data.workorder.sa_orderid || "0",
  47. stopClick: res.data.status !== '新建' ? 'stopClick' : this.data.stopClick,
  48. isSign: res.data.attinfos.some(v => v.usetype == 'signature')
  49. })
  50. this.setInputData()
  51. this.selectComponent("#signName").fileData()
  52. },
  53. setInputData() {
  54. let that = this
  55. that.data.mainData.confirmationcontent.forEach(e => {
  56. Object.keys(e).map((key, index) => {
  57. that.setData({
  58. paidServiceAmount: that.data.paidServiceAmount + e[key].amount
  59. })
  60. if (key.includes('是否需要拆卸配件或整拆')) {
  61. that.setData({
  62. node1: e[key].confirm_value
  63. })
  64. }
  65. if (key.includes('与现场协商确认维修方案')) {
  66. that.setData({
  67. node2: e[key].confirm_value ? e[key].confirm_value : e[key].textcontent
  68. })
  69. }
  70. if (key.includes('实施内容')) {
  71. that.setData({
  72. node3: e[key].confirm_value ? e[key].confirm_value : e[key].textcontent
  73. })
  74. }
  75. if (key.includes('与现场协商试运行')) {
  76. that.setData({
  77. node4: e[key].confirm_value ? e[key].confirm_value : e[key].textcontent
  78. })
  79. }
  80. if (key.includes('现场交代事项')) {
  81. that.setData({
  82. node5: e[key].confirm_value ? e[key].confirm_value : e[key].textcontent
  83. })
  84. }
  85. })
  86. })
  87. },
  88. async updateBill() {
  89. if (this.data.mainData.status !== '新建') return getApp().globalData.Language.modeBoxPrompts('非新建状态,修改的数据将不会保存')
  90. const res = await api._post({
  91. "id": "20230211105703",
  92. "content": this.data.mainData
  93. })
  94. },
  95. // 跳转到物料添加
  96. addProduct() {
  97. wx.navigateTo({
  98. url: '/Eservice/agent/billCanUseProduct/index?id=' + this.data.mainData.sa_workorderid,
  99. })
  100. },
  101. // 添加物料
  102. async getAdd(selection) {
  103. let arr = selection.map(e => {
  104. return {
  105. "sa_workorder_node_itemsid": 0,
  106. "itemid": e,
  107. "qty": 1
  108. }
  109. })
  110. this.data.mainData.trainertitems = this.data.mainData.trainertitems.concat(arr)
  111. this.updateMaterial(this.data.mainData.trainertitems)
  112. },
  113. async updateMaterial(trainertitems) {
  114. const res = await api._post({
  115. "id": "20230215201903",
  116. "content": {
  117. "sa_workorder_confirmationid": this.data.mainData.sa_workorder_confirmationid,
  118. "sa_workorderid": this.data.mainData.workorder.sa_workorderid,
  119. "iteminfos": trainertitems
  120. }
  121. })
  122. this.billData()
  123. },
  124. // 删除物料
  125. async deleteMaterial(data) {
  126. let itemid = data.detail.sa_workorder_node_itemsid
  127. const res = await api._post({
  128. "id": "20230215202003",
  129. "version": 1,
  130. "content": {
  131. "sa_workorder_node_itemsids": [itemid]
  132. }
  133. })
  134. this.billData()
  135. },
  136. // 改变评分
  137. onChange(e) {
  138. this.data.mainData[e.currentTarget.dataset.name] = e.detail.value
  139. this.setData({
  140. mainData: this.data.mainData
  141. });
  142. this.updateBill()
  143. },
  144. async submit() {
  145. this.createImage(true);
  146. const res = await api._post({
  147. "id": "20230211110003",
  148. "content": {
  149. "sa_workorder_confirmationid": this.data.mainData.sa_workorder_confirmationid
  150. }
  151. })
  152. if (res.code == 1) {
  153. wx.showToast({
  154. title: getApp().globalData.Language.getMapText('提交成功'),
  155. icon: "success"
  156. })
  157. this.billData()
  158. }
  159. },
  160. async delete() {
  161. const res = await api._post({
  162. "id": "20230211110103",
  163. "content": {
  164. "sa_workorder_confirmationids": [this.data.mainData.sa_workorder_confirmationid]
  165. }
  166. })
  167. if (res.code == 1) {
  168. wx.navigateBack()
  169. }
  170. },
  171. inputChange(data) {
  172. let keyValue = data.currentTarget.dataset.name
  173. this.data.mainData.confirmationcontent.forEach(e => {
  174. Object.keys(e).map((key, index) => {
  175. if (key.includes(keyValue)) {
  176. e[key].confirm_value = data.detail.value
  177. }
  178. })
  179. })
  180. this.updateBill()
  181. },
  182. createImage(active = false) {
  183. let token = wx.getStorageSync('userMsg').token
  184. let parentid = wx.getStorageSync('siteP').appfolderid
  185. let url = `${getApp().globalData.http.baseUrl}/yosweb/#/printTable?token=${token}&parentid=${parentid}&ownerid=${this.data.mainData.sa_workorder_confirmationid}${active==true?'&action=1':''}`
  186. this.setData({
  187. url: url
  188. })
  189. wx.navigateTo({
  190. url: '/Eservice/webView/index',
  191. })
  192. },
  193. /* 查看单据 */
  194. checkImage() {
  195. let attinfos = this.data.mainData.attinfos.map(v => v.usetype);
  196. let index = attinfos.lastIndexOf("comfirmbill");
  197. //没有查询到有效单据 跳转生成
  198. if (index == -1) return this.createImage(true);
  199. wx.previewImage({
  200. urls: [this.data.mainData.attinfos[index].url],
  201. })
  202. },
  203. onShareAppMessage() {
  204. return {
  205. title: '工单评价',
  206. path: `Eservice/installConfirmBill/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'))}`
  207. }
  208. },
  209. onShow() {
  210. this.setData({
  211. SignName: true
  212. })
  213. if (this.data.mainData) this.billData()
  214. },
  215. onHide() {
  216. this.setData({
  217. SignName: false
  218. })
  219. },
  220. onUnload() {
  221. clearInterval(circulation)
  222. _Http.updateList && _Http.updateList("", true)
  223. },
  224. async updateDetail() {
  225. if (this.data.mainData.status != '新建') return;
  226. const res = await api._post({
  227. "id": "20230211105803",
  228. "content": {
  229. "sa_workorder_confirmationid": this.data.id,
  230. nocache: true
  231. }
  232. })
  233. try {
  234. if (res.data.attinfos.length != this.data.mainData.attinfos.length || res.data.attinfos[0].url != this.data.mainData.attinfos[0].url) {
  235. this.setData({
  236. SignName: false
  237. })
  238. this.setData({
  239. SignName: true
  240. })
  241. }
  242. } catch (error) {
  243. this.setData({
  244. SignName: false
  245. })
  246. this.setData({
  247. SignName: true
  248. })
  249. }
  250. this.setData({
  251. "mainData.responsescore": res.data.responsescore,
  252. "mainData.attitudescore": res.data.attitudescore,
  253. "mainData.attinfos": res.data.attinfos,
  254. isSign: res.data.attinfos.some(v => v.usetype == 'signature')
  255. })
  256. this.setInputData()
  257. this.selectComponent("#signName").fileData()
  258. },
  259. })