onePersonOneCode.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport"
  7. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no, viewport-fit=cover" />
  8. <title>专属活码</title>
  9. <!--引入 element-ui 的样式,-->
  10. <link rel="stylesheet"
  11. href="https://wl-1306604067.cos.ap-guangzhou.myqcloud.com/production/ct/103548289110001/1742018383195/element-ui.css">
  12. <!-- 必须先引入vue, 后使用element-ui -->
  13. <script
  14. src="https://wl-1306604067.cos.ap-guangzhou.myqcloud.com/production/ct/103548289110001/1742017957144/vue.js"></script>
  15. <!-- 引入element 的组件库-->
  16. <script
  17. src="https://wl-1306604067.cos.ap-guangzhou.myqcloud.com/production/ct/103548289110001/1742017747738/element-ui.js"></script>
  18. <!-- <script src="js/vconsole.min.js"></script>
  19. <script>
  20. var vConsole = new window.VConsole();
  21. </script> -->
  22. </head>
  23. <style>
  24. body {
  25. margin: 0;
  26. padding: 0;
  27. }
  28. .box {
  29. width: 100vw;
  30. height: 100vh;
  31. box-sizing: border-box;
  32. }
  33. .page1 {
  34. background: #FAFAFA;
  35. }
  36. .page2 {
  37. background: #FFFFFF;
  38. }
  39. .ready_code_box {
  40. position: relative;
  41. padding-top: 70px;
  42. }
  43. .ready_code {
  44. width: 100%;
  45. }
  46. .code_tip {
  47. position: absolute;
  48. bottom: 7px;
  49. font-weight: bold;
  50. font-size: 24px;
  51. color: #222222;
  52. text-align: center;
  53. width: 100%;
  54. }
  55. .form_title {
  56. font-weight: bold;
  57. font-size: 24px;
  58. color: #222222;
  59. text-align: center;
  60. width: 100%;
  61. padding: 60px 0 7px;
  62. background: #FAFAFA;
  63. }
  64. .main_tip {
  65. color: #2885FF;
  66. }
  67. .page_tip {
  68. font-weight: 500;
  69. font-size: 14px;
  70. color: #222222;
  71. text-align: center;
  72. width: 100%;
  73. padding-top: 8px;
  74. }
  75. .page_tip_page2 {
  76. padding-bottom: 40px;
  77. }
  78. .form_list {
  79. background: #FFFFFF;
  80. }
  81. .el-form-item__label {
  82. padding-right: 0;
  83. font-weight: 500;
  84. font-size: 14px;
  85. color: #666666;
  86. }
  87. .el-input__inner {
  88. border: none;
  89. font-weight: 500;
  90. font-size: 14px;
  91. color: #222222;
  92. text-align: right;
  93. }
  94. .el-form-item {
  95. margin-bottom: 0;
  96. border-bottom: 1px solid #F9F9F9;
  97. padding: 10px 0;
  98. padding-left: 35px;
  99. }
  100. .post_box {
  101. padding: 20px 35px;
  102. height: calc(100vh - 92px);
  103. box-sizing: border-box;
  104. display: flex;
  105. justify-content: center;
  106. align-items: center;
  107. }
  108. .post_img {
  109. width: auto;
  110. height: auto;
  111. max-width: 100%;
  112. max-height: 100%;
  113. }
  114. .foot_btn {
  115. position: absolute;
  116. bottom: 40px;
  117. padding: 0 35px;
  118. width: 100%;
  119. box-sizing: border-box;
  120. }
  121. .create_btn {
  122. width: 100%;
  123. height: 52px;
  124. background: #222222;
  125. border-radius: 20px;
  126. font-weight: 500;
  127. font-size: 16px;
  128. color: #FFFFFF;
  129. text-align: center;
  130. }
  131. .save_btn {
  132. width: 100%;
  133. height: 52px;
  134. line-height: 52px;
  135. text-align: center;
  136. border-radius: 20px;
  137. border: 1px solid #222222;
  138. box-sizing: border-box;
  139. font-weight: 500;
  140. font-size: 16px;
  141. color: #222222;
  142. }
  143. </style>
  144. <body>
  145. <div id="box" class="box" :class="step === 2 ? 'page2' : 'page1'">
  146. <!-- 引导页面 -->
  147. <div v-if="step === 1">
  148. <div class="ready_code_box">
  149. <image class="ready_code" src="./img/ready_code.png"></image>
  150. <div class="code_tip">
  151. <span>生成我的</span>
  152. <span class="main_tip">专属活码</span>
  153. </div>
  154. </div>
  155. <div class="page_tip">引导门店客户添加,领取引流激励!</div>
  156. <div class="foot_btn">
  157. <div class="create_btn" style="line-height: 52px;" @click="createQrcode">创建活码</div>
  158. </div>
  159. </div>
  160. <!-- 创建活码 -->
  161. <div v-if="step === 2">
  162. <div class="form_title">
  163. <span>生成我的</span>
  164. <span class="main_tip">专属活码</span>
  165. </div>
  166. <div class="page_tip page1 page_tip_page2">引导好友添加,领取引流激励!</div>
  167. <div class="form_list">
  168. <el-form ref="form" :model="form" label-position="left" label-width="100px">
  169. <el-form-item label="顾问姓名:">
  170. <el-input v-model="form.salesMan" placeholder="请输入"></el-input>
  171. </el-form-item>
  172. <el-form-item label="合伙人姓名:">
  173. <el-input v-model="form.partner" placeholder="请输入"></el-input>
  174. </el-form-item>
  175. </el-form>
  176. </div>
  177. <div class="foot_btn">
  178. <el-button class="create_btn" :loading="loading" @click="handleQrcode">创建活码</el-button>
  179. </div>
  180. </div>
  181. <!-- 我的活码 -->
  182. <div v-if="step === 3">
  183. <div class="post_box">
  184. <image class="post_img" :src="postCode"></image>
  185. </div>
  186. <div class="foot_btn">
  187. <div class="save_btn" @click="saveImage">长按二维码保存</div>
  188. </div>
  189. </div>
  190. </div>
  191. </body>
  192. <script>
  193. new Vue({
  194. el: '#box',
  195. data() {
  196. return {
  197. httpUrl: '',
  198. bId: null,
  199. env: '',
  200. step: null,
  201. postCode: '',
  202. form: {
  203. salesMan: '',
  204. partner: '',
  205. ownerDealerCode: '',
  206. phone: ''
  207. },
  208. loading: false,
  209. }
  210. },
  211. created() {
  212. this.bId = this.getQueryParam('bId')
  213. this.env = this.getQueryParam('env')
  214. if (!this.env || this.env === 'prod') {
  215. this.httpUrl = 'https://wlapi.wefanbot.com'
  216. } else {
  217. this.httpUrl = 'http://test.wefanbot.com:18993'
  218. }
  219. localStorage.removeItem('openId')
  220. this.ifH5Type()
  221. },
  222. methods: {
  223. ifH5Type() {
  224. if (this.getQueryParam('openId') || localStorage.getItem('openId')) {
  225. this.findQrCode()
  226. } else {
  227. // 走授权操作
  228. this.getAuth();
  229. }
  230. },
  231. getAuth() {
  232. // 获取url上的code
  233. let code = this.getQueryParam('code')
  234. if (code) {
  235. // 判断业务id是否生产环境业务id
  236. fetch(this.httpUrl + `/p/insuite/p/isProdId?id=${this.bId}`)
  237. .then(res => {
  238. return res.json()
  239. }).then(result => {
  240. let { data, msg } = result
  241. if (typeof data === 'boolean' && data) {
  242. this.httpUrl = 'https://wlapi.wefanbot.com'
  243. } else {
  244. this.httpUrl = 'http://test.wefanbot.com:18993'
  245. }
  246. this.getInfoByh5Code(this.getQueryParam('code'))
  247. })
  248. } else {
  249. let redirect_uri = window.location.href
  250. // code 不存在,走微信网页授权逻辑
  251. let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appId=wx99ec0d0828a4d2d3&redirect_uri=${redirect_uri}&scope=snsapi_userinfo&state=STATE#wechat_redirect`
  252. window.location.replace(url)
  253. }
  254. },
  255. getInfoByh5Code(code) {
  256. fetch(this.httpUrl + `/scrm/v1/mp-client/p/getInfoByh5Code?code=${code}&bId=${this.bId}`)
  257. .then(res => {
  258. return res.json()
  259. }).then(result => {
  260. let { data, code, msg } = result
  261. if (code === 1) {
  262. localStorage.setItem('openId', data.openId)
  263. this.ifH5Type()
  264. }
  265. })
  266. },
  267. findQrCode() {
  268. fetch(this.httpUrl + '/scrm/v1/wxcp-live-code-opoc/p/findQrCodeByH5', {
  269. method: 'post',
  270. body: JSON.stringify({
  271. bid: this.bId,
  272. openId: this.getQueryParam('openId') || localStorage.getItem('openId'),
  273. }),
  274. headers: {
  275. 'Content-Type': 'application/json'
  276. }
  277. }).then(res => {
  278. return res.json()
  279. }).then(result => {
  280. let { data, code, msg } = result
  281. if (code === 1) {
  282. if (data && data.postCode) {
  283. this.step = 3
  284. this.postCode = data.postCode
  285. } else {
  286. this.step = 1
  287. }
  288. } else {
  289. this.$message.error(msg)
  290. this.step = 1
  291. }
  292. })
  293. },
  294. createQrcode() {
  295. this.step = 2
  296. },
  297. // 创建活码
  298. handleQrcode() {
  299. if (!this.form.salesMan) {
  300. this.$message.error('请输入顾问姓名')
  301. return
  302. }
  303. if (!this.form.partner) {
  304. this.$message.error('请输入合伙人姓名')
  305. return
  306. }
  307. this.loading = true
  308. fetch(this.httpUrl + '/scrm/v1/wxcp-live-code-opoc/p/addByH5', {
  309. method: 'post',
  310. body: JSON.stringify({
  311. bid: this.bId,
  312. openId: this.getQueryParam('openId') || localStorage.getItem('openId'),
  313. ...this.form
  314. }),
  315. headers: {
  316. 'Content-Type': 'application/json'
  317. }
  318. }).then(res => {
  319. return res.json()
  320. }).then(result => {
  321. let { data, code, msg } = result
  322. if (code === 1) {
  323. if (data && data.postCode) {
  324. this.step = 3
  325. this.postCode = data.postCode
  326. } else {
  327. this.step = 1
  328. }
  329. } else {
  330. this.$message.error(msg)
  331. this.step = 1
  332. }
  333. }).finally(() => {
  334. this.loading = false
  335. })
  336. },
  337. // 保存二维码
  338. saveImage() {
  339. this.$message({
  340. message: '长按二维码保存',
  341. type: 'success',
  342. })
  343. },
  344. // 截取url中的数据
  345. getQueryParam(paramName) {
  346. // 获取当前URL的查询字符串部分
  347. const queryString = window.location.search;
  348. // 创建一个URLSearchParams对象
  349. const urlParams = new URLSearchParams(queryString);
  350. // 返回指定参数的值,如果不存在则返回null
  351. return urlParams.get(paramName);
  352. },
  353. }
  354. })
  355. </script>
  356. </html>