index.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. Applicant: userid(),
  66. Header: protoHeader(FunCode.PerformanceContractedApplyReq)
  67. })
  68. /// 发送请求
  69. sendMsgToMQ({
  70. data: {
  71. data: encryptBody(info),
  72. funCodeReq: FunCode.PerformanceContractedApplyReq,
  73. funCodeRsp: FunCode.PerformanceContractedApplyRsp,
  74. isEncrypted: isEncrypted()
  75. },
  76. success: (res) => {
  77. /// 解析对象
  78. const data = JSON.parse(res.data.data)
  79. if (data.RetCode != 0) {
  80. hideLoading(() => {}, getErrorMsg(data.RetCode), 'error')
  81. return
  82. }
  83. /// 操作成功
  84. hideLoading(()=>{
  85. /// 返回上层视图
  86. wx.navigateBack()
  87. }, '操作成功', 'success')
  88. },
  89. fail: (emsg) => {
  90. /// 操作失败
  91. hideLoading(()=>{}, emsg, 'error')
  92. }
  93. })
  94. }, '违约申请请求中.....')
  95. },
  96. check(): boolean {
  97. if (this.data.remark === '') {
  98. showToast('请输入备注!')
  99. return false
  100. }
  101. if (this.data.filePath === '') {
  102. showToast('请上传附件!')
  103. return false
  104. }
  105. return true
  106. },
  107. /**
  108. * 返回上层视图
  109. */
  110. backToParent() {
  111. /// 返回上层视图
  112. wx.navigateBack()
  113. },
  114. /**
  115. * 生命周期函数--监听页面加载
  116. */
  117. onLoad(options: any) {
  118. const myPerformanc: GuangZuan.MyPerformanc = JSON.parse(options.id ?? '')
  119. if (myPerformanc) {
  120. this.setData({
  121. order: myPerformanc
  122. })
  123. }
  124. },
  125. /**
  126. * 生命周期函数--监听页面初次渲染完成
  127. */
  128. onReady() {
  129. },
  130. /**
  131. * 生命周期函数--监听页面显示
  132. */
  133. onShow() {
  134. },
  135. /**
  136. * 生命周期函数--监听页面隐藏
  137. */
  138. onHide() {
  139. },
  140. /**
  141. * 生命周期函数--监听页面卸载
  142. */
  143. onUnload() {
  144. },
  145. /**
  146. * 页面相关事件处理函数--监听用户下拉动作
  147. */
  148. onPullDownRefresh() {
  149. },
  150. /**
  151. * 页面上拉触底事件的处理函数
  152. */
  153. onReachBottom() {
  154. },
  155. /**
  156. * 用户点击右上角分享
  157. */
  158. onShareAppMessage() {
  159. }
  160. })