index.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { sendMsgToMQ } from "../../../../services/api/common/index"
  2. import { FunCode } from "../../../../constants/enum/funcode"
  3. import { accountid, getErrorMsg, isEncrypted, protoHeader, userid } from "../../../../services/utils";
  4. import services from "../../../../services/index"
  5. import { hideLoading, showLoading, showToast } from "../../../../utils/message/index";
  6. import { encryptBody } from "../../../../utils/websocket/crypto";
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. /// 履约单据信息
  13. order: <GuangZuan.MyPerformanc>({}),
  14. /// 备注信息
  15. remark: '',
  16. /// 文件上传列表
  17. fileList: [],
  18. /// 上传的文件路径
  19. filePath: ''
  20. },
  21. /// 照片上传
  22. afterRead(e: any) {
  23. const { file } = e.detail;
  24. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  25. wx.uploadFile({
  26. url: services.config.uploadUrl,
  27. filePath: file.url,
  28. name: 'file',
  29. formData: { user: 'test' },
  30. success: (res) => {
  31. if (res.statusCode != 200) {
  32. showToast('图片上传失败,原因:'+res.errMsg)
  33. return
  34. }
  35. // 上传完成需要更新 fileList
  36. const { fileList = [] } = this.data;
  37. fileList.push({ ...file, url: res.data});
  38. this.setData({ fileList });
  39. /// 设置文件路径
  40. this.setData({ filePath: JSON.parse(res.data)[0].filePath })
  41. },
  42. });
  43. },
  44. /// 删除图片
  45. deleteImage(e: any) {
  46. const {index} = e.detail.index
  47. // 上传完成需要更新 fileList
  48. const { fileList = [] } = this.data;
  49. fileList.splice(index, 1)
  50. this.setData({ fileList });
  51. },
  52. /**
  53. * 违约申请
  54. */
  55. doBreach() {
  56. /// 校验失败
  57. if (!this.check()) { return }
  58. /// loding.....
  59. showLoading(()=>{
  60. /// 参数信息
  61. const info = JSON.stringify({
  62. PerformancePlanID: this.data.order.performanceplanid,
  63. BreachType: this.data.order.buyaccountid === accountid() ? 2 : 1,
  64. ApplyRemark: this.data.remark,
  65. Attachment: this.data.filePath,
  66. Applicant: userid(),
  67. Header: protoHeader(FunCode.PerformanceContractedApplyReq)
  68. })
  69. /// 发送请求
  70. sendMsgToMQ({
  71. data: {
  72. data: encryptBody(info),
  73. funCodeReq: FunCode.PerformanceContractedApplyReq,
  74. funCodeRsp: FunCode.PerformanceContractedApplyRsp,
  75. isEncrypted: isEncrypted()
  76. },
  77. success: (res) => {
  78. /// 解析对象
  79. const data = JSON.parse(res.data.data)
  80. if (data.RetCode != 0) {
  81. hideLoading(() => {}, getErrorMsg(data.RetCode))
  82. return
  83. }
  84. /// 操作成功
  85. hideLoading(()=>{
  86. /// 返回上层视图
  87. wx.navigateBack()
  88. }, '操作成功', 'success')
  89. },
  90. fail: (emsg) => {
  91. /// 操作失败
  92. hideLoading(()=>{}, emsg)
  93. }
  94. })
  95. }, '违约申请请求中.....')
  96. },
  97. check(): boolean {
  98. if (this.data.remark === '') {
  99. showToast('请输入备注!')
  100. return false
  101. }
  102. if (this.data.filePath === '') {
  103. showToast('请上传附件!')
  104. return false
  105. }
  106. return true
  107. },
  108. /**
  109. * 返回上层视图
  110. */
  111. backToParent() {
  112. /// 返回上层视图
  113. wx.navigateBack()
  114. },
  115. /**
  116. * 生命周期函数--监听页面加载
  117. */
  118. onLoad(options: any) {
  119. const myPerformanc: GuangZuan.MyPerformanc = JSON.parse(options.id ?? '')
  120. if (myPerformanc) {
  121. this.setData({
  122. order: myPerformanc
  123. })
  124. }
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady() {
  130. },
  131. /**
  132. * 生命周期函数--监听页面显示
  133. */
  134. onShow() {
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide() {
  140. },
  141. /**
  142. * 生命周期函数--监听页面卸载
  143. */
  144. onUnload() {
  145. },
  146. /**
  147. * 页面相关事件处理函数--监听用户下拉动作
  148. */
  149. onPullDownRefresh() {
  150. },
  151. /**
  152. * 页面上拉触底事件的处理函数
  153. */
  154. onReachBottom() {
  155. },
  156. /**
  157. * 用户点击右上角分享
  158. */
  159. onShareAppMessage() {
  160. }
  161. })