index.js 8.1 KB

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