index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. const _Http = getApp().globalData.http;
  2. const __env = wx.getAccountInfoSync().miniProgram.envVersion;
  3. const ESIGN_APPID = __env === 'release' ? 'wxa023b292fd19d41d' : 'wx371151823f6f3edf';
  4. Page({
  5. data: {
  6. "id": "2026041315425102",
  7. list: [],
  8. content: {
  9. nocache: true,
  10. pageNumber: 1,
  11. pageSize: 20,
  12. pageTotal: 1,
  13. where: {
  14. condition: ""
  15. }
  16. }
  17. },
  18. onLoad() {
  19. this.getList();
  20. },
  21. onShow() {
  22. if (this.data._loaded) {
  23. this.getList(true);
  24. }
  25. this.setData({
  26. _loaded: true
  27. });
  28. },
  29. /* 获取合同列表 */
  30. getList(init = false) {
  31. if (init.detail != undefined) init = init.detail;
  32. if (init) {
  33. this.setData({
  34. 'content.pageNumber': 1
  35. });
  36. }
  37. if (this.data.content.pageNumber > (this.data.content.pageTotal || 1)) return;
  38. this.setListHeight();
  39. _Http.basic({
  40. id: this.data.id,
  41. content: this.data.content
  42. }).then(res => {
  43. console.log("我的合同列表", res);
  44. this.selectComponent('#ListBox').RefreshToComplete();
  45. const statusMap = { '合同创建': '待签署' };
  46. const list = (res.data || []).map(item => ({
  47. ...item,
  48. _status: statusMap[(item.status || '').trim()] || (item.status || '').trim() || this.inferStatus(item)
  49. }));
  50. this.setData({
  51. 'content.pageNumber': res.pageNumber + 1,
  52. 'content.pageTotal': res.pageTotal,
  53. list: res.pageNumber == 1 ? list : this.data.list.concat(list),
  54. total: res.total
  55. });
  56. }).catch(err => {
  57. console.error("获取合同列表失败", err);
  58. this.selectComponent('#ListBox').RefreshToComplete();
  59. wx.showToast({
  60. title: '加载失败',
  61. icon: 'none'
  62. });
  63. });
  64. },
  65. /* 设置页面高度 */
  66. setListHeight() {
  67. this.selectComponent("#ListBox").setHeight(".header", this);
  68. },
  69. /* 推断状态(后端 status 为空时的兜底) */
  70. inferStatus(item) {
  71. if (!item.flowid) return '待开始';
  72. if (item.flowid && !item.downloadurl) return '待签署';
  73. if (item.downloadurl) return '已签署';
  74. return '';
  75. },
  76. /* 搜索 */
  77. onSearch({
  78. detail
  79. }) {
  80. this.setData({
  81. 'content.where.condition': detail
  82. });
  83. this.getList(true);
  84. },
  85. /* 重新变更确认信息 */
  86. onReconfirm(e) {
  87. const item = e.currentTarget.dataset.item;
  88. wx.showModal({
  89. title: '温馨提示',
  90. content: '变更签署信息将作废当前合同并重新创建,之前的签署进度将会丢失,确定继续吗?',
  91. confirmText: '前去变更',
  92. cancelText: '取消',
  93. confirmColor: '#3874F6',
  94. success: (res) => {
  95. if (res.confirm) {
  96. wx.navigateTo({
  97. url: `/CRM/wmycontract/confirm?id=${item.sa_esign_contract_taskmxid}`
  98. });
  99. }
  100. }
  101. });
  102. },
  103. /* 点击列表项 - 根据状态跳转不同页面 */
  104. onItemClick(e) {
  105. const item = e.currentTarget.dataset.item;
  106. const status = item._status;
  107. if (status === '待开始') {
  108. wx.navigateTo({
  109. url: `/CRM/wmycontract/confirm?id=${item.sa_esign_contract_taskmxid}`
  110. });
  111. } else {
  112. if (item.flowid) {
  113. wx.navigateToMiniProgram({
  114. appId: ESIGN_APPID,
  115. path: `pages/guide?from=app&to=CONTRACT_DETAIL&id=${item.flowid}`,
  116. envVersion: 'release',
  117. success(res) {
  118. console.log('跳转电子签成功', res);
  119. },
  120. fail(err) {
  121. console.error('跳转电子签失败', err);
  122. }
  123. });
  124. } else {
  125. wx.showToast({
  126. title: '签署链接暂未生成',
  127. icon: 'none'
  128. });
  129. }
  130. }
  131. }
  132. });