QrCode.js 7.7 KB

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