QrCode.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. codeMsg: '', // type: partner-申请合作 shop-加入团队
  11. manner: "双向合作",
  12. selectType: 3,
  13. show: false
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. query */
  18. onLoad: function (query) {
  19. console.log(query)
  20. if (query.url) {
  21. const q = decodeURIComponent(query.url);
  22. return this.setDataUrl(q)
  23. } else if (query.q) { // 获取到二维码原始链接内容、
  24. const q = decodeURIComponent(query.q);
  25. return this.setDataUrl(q)
  26. } else {
  27. this.setData({
  28. codeMsg: wx.getStorageSync('qrCodeMsg')
  29. })
  30. wx.setStorageSync('qrCodeMsg', "")
  31. console.log(wx.getStorageSync('qrCodeMsg'))
  32. }
  33. },
  34. setDataUrl(url) {
  35. let q = url;
  36. console.log("q", q)
  37. const data = {
  38. type: q.slice(q.indexOf("type=") + 5, q.indexOf('&')),
  39. id: q.slice(q.lastIndexOf('=') + 1),
  40. name: q.slice(q.lastIndexOf('fbrand=') + 7, q.lastIndexOf('&'))
  41. }
  42. if (!wx.getStorageSync('userData').token) {
  43. wx.setStorageSync('qrCodeMsg', data);
  44. wx.showModal({
  45. title: '提示',
  46. content: '当前未登录,请登录后进入',
  47. showCancel: false,
  48. success: (res => {
  49. if (res.confirm) wx.navigateTo({
  50. url: '/pages/login/index',
  51. })
  52. })
  53. });
  54. } else {
  55. this.setData({
  56. codeMsg: data
  57. })
  58. }
  59. },
  60. /* 确定 */
  61. confirm() {
  62. const that = this;
  63. if (this.data.codeMsg.type == 'partner') {
  64. wx.showModal({
  65. title: "提示",
  66. content: "是否确定将“" + this.data.codeMsg.name + "”作为您的" + this.data.manner + "合作伙伴",
  67. success: (s => {
  68. if (s.confirm) {
  69. _Http.basic({
  70. "accesstoken": wx.getStorageSync('userData').token,
  71. "classname": "customer.tagents.tagents",
  72. "method": "apply_cooperation",
  73. "content": {
  74. "tcooperationagentsid": that.data.codeMsg.id,
  75. "ftype": that.data.selectType
  76. }
  77. }).then(res => {
  78. if (res.msg != '成功') return wx.showToast({
  79. title: res.data,
  80. icon: "none"
  81. });
  82. wx.showToast({
  83. title: "合作申请成功",
  84. });
  85. setTimeout(() => {
  86. wx.switchTab({
  87. url: '/pages/tabbar-pages/home/index',
  88. })
  89. }, 500)
  90. wx.removeStorageSync('qrCodeMsg');
  91. })
  92. }
  93. })
  94. })
  95. } else if (this.data.codeMsg.type == 'shop') {
  96. wx.showModal({
  97. title: "提示",
  98. content: "是否确定加入“" + this.data.codeMsg.name + "”成为团队的一份子",
  99. success: (s => {
  100. if (s.confirm) {
  101. _Http.basic({
  102. "classname": "publicmethod.users.Users",
  103. "method": "entryTeamApply",
  104. "content": {
  105. "userid": wx.getStorageSync('userData').userid,
  106. "tagentsid": that.data.codeMsg.id
  107. }
  108. }).then(res => {
  109. if (res.data != '成功') return wx.showToast({
  110. title: res.data,
  111. icon: "none"
  112. });
  113. wx.showToast({
  114. title: "申请成功",
  115. });
  116. setTimeout(() => {
  117. wx.switchTab({
  118. url: '/pages/tabbar-pages/home/index',
  119. })
  120. }, 500)
  121. wx.removeStorageSync('qrCodeMsg');
  122. })
  123. }
  124. })
  125. })
  126. }
  127. },
  128. /* 取消 */
  129. refuse() {
  130. if (this.data.codeMsg.type == 'partner') {
  131. wx.showModal({
  132. title: "提示",
  133. content: "是否确定取消与“" + this.data.codeMsg.name + "”建立合作关系",
  134. success: (res => {
  135. console.log(res)
  136. if (res.confirm) {
  137. wx.showToast({
  138. title: "取消成功",
  139. });
  140. setTimeout(() => {
  141. wx.switchTab({
  142. url: '/pages/tabbar-pages/home/index',
  143. })
  144. }, 500)
  145. wx.removeStorageSync('qrCodeMsg');
  146. }
  147. })
  148. })
  149. } else if (this.data.codeMsg.type == 'shop') {
  150. wx.showModal({
  151. title: "提示",
  152. content: "是否确定取消加入“" + this.data.codeMsg.name + "”",
  153. success: (res => {
  154. if (res.confirm) {
  155. wx.showToast({
  156. title: "取消成功",
  157. });
  158. setTimeout(() => {
  159. wx.switchTab({
  160. url: '/pages/tabbar-pages/home/index',
  161. })
  162. }, 500)
  163. wx.removeStorageSync('qrCodeMsg');
  164. }
  165. })
  166. })
  167. }
  168. },
  169. /* 选择合作方式 */
  170. selectManner() {
  171. this.setData({
  172. show: !this.data.show
  173. })
  174. },
  175. optionChange({
  176. detail
  177. }) {
  178. let selectType = 3;
  179. switch (detail) {
  180. case "上游":
  181. selectType = 1;
  182. break;
  183. case "下游":
  184. selectType = 2;
  185. break;
  186. case "双向合作":
  187. selectType = 3;
  188. break;
  189. default:
  190. break;
  191. }
  192. this.setData({
  193. manner: detail,
  194. selectType,
  195. show: false
  196. })
  197. },
  198. /**
  199. * 生命周期函数--监听页面初次渲染完成
  200. */
  201. onReady: function () {
  202. },
  203. /**
  204. * 生命周期函数--监听页面显示
  205. */
  206. onShow: function () {},
  207. /**
  208. * 生命周期函数--监听页面隐藏
  209. */
  210. onHide: function () {
  211. },
  212. /**
  213. * 生命周期函数--监听页面卸载
  214. */
  215. onUnload: function () {
  216. },
  217. /**
  218. * 页面相关事件处理函数--监听用户下拉动作
  219. */
  220. onPullDownRefresh: function () {
  221. },
  222. /**
  223. * 页面上拉触底事件的处理函数
  224. */
  225. onReachBottom: function () {
  226. },
  227. /**
  228. * 用户点击右上角分享
  229. */
  230. onShareAppMessage: function () {
  231. }
  232. })