index.ts 4.0 KB

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