You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

exbSignProtocol.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. const {
  2. updateContractState,
  3. } = require("../../../config");
  4. const network = require('../../../network/index');
  5. // plugin/etc/pages/exbSignProtocol/exbSignProtocol.js
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. loading: false,
  12. orderNo: "",
  13. loadMsg: "请稍后...",
  14. isJunpSign: false,
  15. signType: 0, // 0 协议初始界面 1 查询协议状态界面 2 验证成功 3 签约失败,
  16. failMsg: "签署失败,请稍后重试",
  17. agreements: null,
  18. isAgree: false,
  19. path: "",
  20. isReadFile: false // 是否已经阅读过文件
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad(options) {
  26. updateContractState();
  27. this.configData(options);
  28. this.configContractQuery();
  29. },
  30. onShow() {
  31. if (this.data.isJunpSign) {
  32. this.setData({
  33. isJunpSign: false,
  34. })
  35. this.configContractQuery(1);
  36. }
  37. },
  38. // 配置默认参数
  39. configData(options) {
  40. const orderNo = options?.orderNo
  41. if (orderNo) {
  42. this.setData({
  43. orderNo: orderNo
  44. })
  45. }
  46. },
  47. /// 1.5.2.合同查询接口
  48. async configContractQuery(type = 0) {
  49. if (type == 0) {
  50. this.setData({
  51. loading: true,
  52. })
  53. } else {
  54. this.setData({
  55. signType: 1,
  56. })
  57. }
  58. this.configNavTitle();
  59. var res = await network.etc.checkProtocol({
  60. orderNo: this.data.orderNo,
  61. })
  62. if (type == 0) {
  63. this.setData({
  64. loading: false,
  65. })
  66. }
  67. const that = this;
  68. const {
  69. data,
  70. code,
  71. message,
  72. } = res;
  73. if (code == 0) {
  74. const {
  75. agreements,
  76. flag
  77. } = data;
  78. if (!flag) {
  79. wx.showModal({
  80. title: "您已签署合同",
  81. content: '系统查询您已签署合同,无需再次签署,请选择以下操作',
  82. showCancel: false,
  83. confirmColor: "rgba(62, 125, 245, 1)",
  84. confirmText: "返回",
  85. complete: () => {
  86. that.configContractState(0);
  87. }
  88. })
  89. } else {
  90. // 转换为组件可用的格式:[{key: '昱路用户协议', value: 'https://...'}]
  91. const agreementsData = agreements.map(obj => {
  92. const [key, path] = Object.entries(obj)[0];
  93. return {
  94. key,
  95. path
  96. };
  97. })
  98. this.setData({
  99. agreements: agreementsData,
  100. })
  101. }
  102. } else {
  103. wx.showModal({
  104. title: message || "签署状态查询失败,请稍后重试",
  105. confirmColor: "rgba(62, 125, 245, 1)",
  106. confirmText: "返回",
  107. showCancel: false,
  108. complete: () => {
  109. that.configContractState(1);
  110. }
  111. })
  112. }
  113. },
  114. /// 1.5.1.用户签约接口
  115. async configAccountSign() {
  116. let that = this
  117. var res = await network.etc.agreeProtocol({
  118. orderNo: this.data.orderNo,
  119. protocol: 1,
  120. loginSource: '431bfdc8b9c645e0b293b85d6ce1925b'
  121. })
  122. this.setData({
  123. loading: false,
  124. });
  125. const {
  126. code,
  127. message,
  128. } = res;
  129. if (code == 0) {
  130. that.configContractState(0);
  131. // wx.showModal({
  132. // content: message,
  133. // showCancel: false,
  134. // complete: () => {
  135. // that.configContractState(0);
  136. // }
  137. // })
  138. } else {
  139. wx.showToast({
  140. icon: "none",
  141. title: message || "签署参数获取失败,请稍后重试",
  142. });
  143. }
  144. },
  145. async tapSign() {
  146. if (this.data.isAgree) {
  147. this.setData({
  148. loading: true,
  149. });
  150. this.configAccountSign();
  151. } else {
  152. wx.showToast({
  153. title: '请先同意用户协议',
  154. icon: "none",
  155. })
  156. }
  157. },
  158. configContractState(state = 1) {
  159. console.log("合同界面:签约状态", state)
  160. updateContractState(state);
  161. wx.navigateBack();
  162. },
  163. tapReload() {
  164. this.configContractState();
  165. },
  166. configNavTitle() {
  167. wx.setNavigationBarTitle({
  168. title: this.data.signType == 0 ? "" : "签署合同",
  169. })
  170. },
  171. tapAgree() {
  172. if (this.data.isReadFile) {
  173. this.setData({
  174. isAgree: !this.data.isAgree
  175. })
  176. } else {
  177. let text = this.data.agreements.map(item => `《${item.key}》`).join(" ")
  178. wx.showModal({
  179. title: "签署合同",
  180. content: `请先点击阅读${text}`,
  181. showCancel: false,
  182. confirmColor: "rgb(72, 207, 60)",
  183. })
  184. }
  185. },
  186. tapProtocol(e) {
  187. const path = e.target.dataset.info;
  188. const name = e.target.dataset.name;
  189. this.openDocFile(path, name)
  190. },
  191. openDocFile(
  192. url,
  193. fileName,
  194. fileType = "pdf"
  195. ) {
  196. let _that = this
  197. let newpath = `${wx.env.USER_DATA_PATH}/${fileName}`;
  198. wx.showLoading({
  199. title: "加载中…",
  200. });
  201. console.log(url)
  202. console.log(newpath);
  203. wx.downloadFile({
  204. url: url,
  205. // filePath: newpath,
  206. success(res) {
  207. console.log(res);
  208. wx.hideLoading();
  209. if (res.statusCode === 200) {
  210. wx.openDocument({
  211. filePath: res.tempFilePath, // newpath,
  212. fileType,
  213. success: () => {
  214. _that.setData({
  215. isReadFile: true
  216. })
  217. },
  218. fail() {
  219. wx.showToast({
  220. title: "打开失败,请稍后重试",
  221. icon: "none",
  222. });
  223. },
  224. });
  225. } else {
  226. wx.showToast({
  227. title: "打开失败,请稍后重试",
  228. icon: "none",
  229. });
  230. }
  231. },
  232. fail(res) {
  233. wx.hideLoading()
  234. console.log("下载失败")
  235. console.log(res);
  236. }
  237. });
  238. }
  239. })