index.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { sendMsgToMQ } from "../../../../services/api/common/index"
  2. import Toast from "../../../../miniprogram_npm/@vant/weapp/toast/toast";
  3. import { FunCode } from "../../../../constants/enum/funcode"
  4. import { accountid, isEncrypted, protoHeader, userid } from "../../../../services/utils";
  5. import services from "../../../../services/index"
  6. import { hideLoading, showLoading, showToast } from "../../../../utils/message/index";
  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 params = {
  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: JSON.stringify(params),
  72. funCodeReq: FunCode.PerformanceContractedApplyReq,
  73. funCodeRsp: FunCode.PerformanceContractedApplyRsp,
  74. isEncrypted: isEncrypted()
  75. },
  76. success: (res) => {
  77. if (res.code != 0) {
  78. hideLoading(()=>{}, '操作申请请求失败,原因:'+res.msg, 'error')
  79. return
  80. }
  81. /// 操作成功
  82. hideLoading(()=>{
  83. /// 返回上层视图
  84. wx.navigateBack()
  85. }, '操作成功', 'success')
  86. },
  87. fail: (emsg) => {
  88. /// 操作失败
  89. hideLoading(()=>{}, '操作申请请求失败,原因:'+emsg, 'error')
  90. }
  91. })
  92. }, '违约申请请求中.....')
  93. },
  94. check(): boolean {
  95. if (this.data.remark === '') {
  96. showToast('请输入备注!')
  97. return false
  98. }
  99. if (this.data.filePath === '') {
  100. showToast('请上传附件!')
  101. return false
  102. }
  103. return true
  104. },
  105. /**
  106. * 返回上层视图
  107. */
  108. backToParent() {
  109. /// 返回上层视图
  110. wx.navigateBack()
  111. },
  112. /**
  113. * 生命周期函数--监听页面加载
  114. */
  115. onLoad(options: any) {
  116. const myPerformanc: GuangZuan.MyPerformanc = JSON.parse(options.id ?? '')
  117. if (myPerformanc) {
  118. this.setData({
  119. order: myPerformanc
  120. })
  121. }
  122. },
  123. /**
  124. * 生命周期函数--监听页面初次渲染完成
  125. */
  126. onReady() {
  127. },
  128. /**
  129. * 生命周期函数--监听页面显示
  130. */
  131. onShow() {
  132. },
  133. /**
  134. * 生命周期函数--监听页面隐藏
  135. */
  136. onHide() {
  137. },
  138. /**
  139. * 生命周期函数--监听页面卸载
  140. */
  141. onUnload() {
  142. },
  143. /**
  144. * 页面相关事件处理函数--监听用户下拉动作
  145. */
  146. onPullDownRefresh() {
  147. },
  148. /**
  149. * 页面上拉触底事件的处理函数
  150. */
  151. onReachBottom() {
  152. },
  153. /**
  154. * 用户点击右上角分享
  155. */
  156. onShareAppMessage() {
  157. }
  158. })