signUp.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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" content="width=device-width, initial-scale=1.0">
  7. <title>活动</title>
  8. <!--引入 element-ui 的样式,-->
  9. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  10. <!-- 必须先引入vue, 后使用element-ui -->
  11. <script src="./js/vue.js"></script>
  12. <!-- 引入element 的组件库-->
  13. <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  14. <script src="https://unpkg.com/vconsole/dist/vconsole.min.js"></script>
  15. <!-- <script>
  16. var vConsole = new window.VConsole();
  17. </script> -->
  18. </head>
  19. <style>
  20. body {
  21. margin: 0;
  22. padding: 0;
  23. }
  24. .box {
  25. width: 100vw;
  26. height: 100vh;
  27. box-sizing: border-box;
  28. background: #FAFAFA;
  29. }
  30. .page6 {
  31. width: 100vw;
  32. height: 100vh;
  33. background: url('./img/signup_bg.png') no-repeat top;
  34. background-size: 100vw 210px;
  35. background-repeat: no-repeat;
  36. display: flex;
  37. justify-content: center;
  38. align-items: center;
  39. }
  40. .page_title {
  41. font-weight: 800;
  42. font-size: 40px;
  43. color: #FFFFFF;
  44. position: fixed;
  45. top: 40px;
  46. left: 20px;
  47. }
  48. .form_content {
  49. width: 100%;
  50. height: calc(100vh - 180px);
  51. margin-top: 180px;
  52. background: #FFFFFF;
  53. border-radius: 20px 20px 0px 0px;
  54. padding: 20px 20px 66px;
  55. overflow-y: auto;
  56. box-sizing: border-box;
  57. }
  58. .foot_btn {
  59. position: fixed;
  60. bottom: 14px;
  61. padding: 0 35px;
  62. width: 100%;
  63. box-sizing: border-box;
  64. }
  65. .signUp_btn {
  66. height: 52px;
  67. line-height: 52px;
  68. background: #1677FF;
  69. border-radius: 20px;
  70. font-weight: 500;
  71. font-size: 16px;
  72. color: #FFFFFF;
  73. text-align: center;
  74. }
  75. .el-form-item__label {
  76. padding-right: 0;
  77. font-weight: 500;
  78. font-size: 14px;
  79. color: #666666;
  80. }
  81. .el-input__inner{
  82. border: none;
  83. font-weight: 500;
  84. font-size: 14px;
  85. color: #222222;
  86. text-align: right;
  87. }
  88. .el-form-item {
  89. margin-bottom: 0;
  90. border-bottom: 1px solid #F9F9F9;
  91. padding: 10px 0;
  92. }
  93. .el-form-item__content .el-select {
  94. margin-left: 18px;
  95. }
  96. .el-form-item__content .el-cascader {
  97. margin-left: 18px;
  98. }
  99. .page6s {
  100. width: 100vw;
  101. height: 100vh;
  102. background: url('./img/signup_success.png') no-repeat center;
  103. background-size: 100vw 100vh;
  104. background-repeat: no-repeat;
  105. }
  106. .succ_tip {
  107. padding-top: 240px;
  108. font-weight: bold;
  109. font-size: 24px;
  110. color: #222222;
  111. line-height: 40px;
  112. text-align: center;
  113. width: 100%;
  114. white-space: pre-wrap;
  115. }
  116. .signup_page {
  117. width: 100vw;
  118. height: 100vh;
  119. background: url('./img/sign_up.png') no-repeat center;
  120. background-size: 100vw 100vh;
  121. background-repeat: no-repeat;
  122. }
  123. .signup_title {
  124. font-weight: bold;
  125. font-size: 24px;
  126. color: #FFFFFF;
  127. padding-top: 80px;
  128. text-align: center;
  129. line-height: 41px;
  130. }
  131. .fail_box {
  132. margin: 80px 20px 0;
  133. height: 287px;
  134. background: linear-gradient(#D5E6FF 50%, #FFFFFF 100%);
  135. border-radius: 20px;
  136. box-sizing: border-box;
  137. text-align: center;
  138. }
  139. .fail_img {
  140. width: 246px;
  141. height: 144px;
  142. margin-top: -20px;
  143. }
  144. .fail_title {
  145. font-weight: 500;
  146. font-size: 20px;
  147. color: #222222;
  148. line-height: 30px;
  149. padding: 20px 0;
  150. }
  151. .fail_tip {
  152. font-weight: 400;
  153. font-size: 16px;
  154. color: #666666;
  155. line-height: 30px;
  156. }
  157. </style>
  158. <body>
  159. <div id="box" class="box">
  160. <div class="page6" v-if="step === 1">
  161. <div class="page_title">核销领取礼品</div>
  162. <div class="form_content">
  163. <el-form ref="form" label-position="left" label-width="100px">
  164. <el-form-item label="核销码" required>
  165. <el-input v-model="verificationCode" placeholder="请输入"></el-input>
  166. </el-form-item>
  167. <el-form-item v-for="(item, index) in toshopData.formProList" :key="index" :label="item.name "
  168. :required="Boolean(item.isNeed)">
  169. <el-cascader v-if="item.type === 10" v-model="item.value" :options="transformedData" @change="handleInfoCity">
  170. </el-cascader>
  171. <el-select v-if="item.type === 11" v-model="item.value" placeholder="请选择" @change="handlechange">
  172. <el-option v-for="(sto, sindex) in storeList" :key="sindex" :label="sto.name" :value="sto.name">
  173. </el-option>
  174. </el-select>
  175. <el-input v-if="item.type === 0" v-model="item.value" placeholder="请输入"></el-input>
  176. <el-input v-if="item.type === 1" type="textarea" autosize v-model="item.value" placeholder="请输入"></el-input>
  177. <el-input v-if="item.type === 2" type="number" v-model="item.value" placeholder="请输入"></el-input>
  178. <el-select v-if="item.type === 3" v-model="item.value" placeholder="请选择">
  179. <el-option v-for="sto in item.formProTagReqs" :key="sto.proValue" :label="sto.proValue" :value="sto.proValue">
  180. </el-option>
  181. </el-select>
  182. <el-date-picker v-if="item.type === 5" v-model="item.value" type="date" placeholder="选择日期">
  183. <el-time-picker v-if="item.type === 6" v-model="item.value" placeholder="请选择"></el-time-picker>
  184. <el-date-picker v-if="item.type === 7" v-model="item.value" type="datetime" placeholder="选择日期时间"></el-date-picker>
  185. </el-form-item>
  186. </el-form>
  187. </div>
  188. <div class="foot_btn">
  189. <div class="signUp_btn" @click="toSignUp">核销</div>
  190. </div>
  191. </div>
  192. <div class="page6s" v-else-if="step === 2">
  193. <div class="succ_tip">
  194. {{toshopData.verificationGuide}}
  195. </div>
  196. </div>
  197. <div class="signup_page" v-else-if="step === 3">
  198. <div class="signup_title">{{toshopData.name}}</div>
  199. <div class="fail_box">
  200. <img class="fail_img" src="./img/fail_img.png" />
  201. <div class="fail_title">{{toshopData.verificationFailGuide}}</div>
  202. <div class="fail_tip">{{toshopData.verificationFailGuide2}}</div>
  203. </div>
  204. </div>
  205. </div>
  206. </body>
  207. <script>
  208. new Vue({
  209. el: '#box',
  210. data() {
  211. return {
  212. httpUrl: '',
  213. bId: null,
  214. env: '',
  215. toshopData: {
  216. name: '',
  217. verificationGuide: '',
  218. verificationFailGuide: '',
  219. verificationFailGuide2: '',
  220. formProList: [],
  221. },
  222. step: 1,
  223. verificationCode: '',
  224. transformedData: [],
  225. storeList: [],
  226. province: '',
  227. city: '',
  228. }
  229. },
  230. created() {
  231. this.bId = this.getQueryParam('bId')
  232. this.env = this.getQueryParam('env')
  233. if (!this.env || this.env === 'prod') {
  234. this.httpUrl = 'https://wlapi.wefanbot.com'
  235. } else {
  236. this.httpUrl = 'http://test.wefanbot.com:18993'
  237. }
  238. this.ifH5Type()
  239. },
  240. methods: {
  241. ifH5Type() {
  242. if (this.getQueryParam('openId') || localStorage.getItem('openId')) {
  243. if (!this.getQueryParam('externalUserid')) {
  244. this.gerQwAuth(this.bId);
  245. } else {
  246. this.getCityLevel()
  247. this.lightenShare()
  248. }
  249. } else {
  250. // 走授权操作
  251. this.getAuth();
  252. }
  253. },
  254. getAuth() {
  255. // 获取url上的code
  256. let code = this.getQueryParam('code')
  257. if (code) {
  258. // 判断业务id是否生产环境业务id
  259. fetch(this.httpUrl + `/p/insuite/p/isProdId?id=${this.bId}`)
  260. .then(res => {
  261. return res.json()
  262. }).then(result => {
  263. let { data, msg } = result
  264. if (typeof data === 'boolean' && data) {
  265. this.httpUrl = 'https://wlapi.wefanbot.com'
  266. } else {
  267. this.httpUrl = 'http://test.wefanbot.com:18993'
  268. }
  269. this.getInfoByh5Code(this.getQueryParam('code'))
  270. })
  271. } else {
  272. let redirect_uri = window.location.href
  273. // code 不存在,走微信网页授权逻辑
  274. let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appId=wx99ec0d0828a4d2d3&redirect_uri=${redirect_uri}&scope=snsapi_userinfo&state=STATE#wechat_redirect`
  275. window.location.replace(url)
  276. }
  277. },
  278. getInfoByh5Code(code) {
  279. fetch(this.httpUrl + `/scrm/v1/mp-client/p/getInfoByh5Code?code=${code}&bId=${this.bId}`)
  280. .then(res => {
  281. return res.json()
  282. }).then(result => {
  283. let { data, code, msg } = result
  284. if (code === 1) {
  285. localStorage.setItem('openId', data.openId)
  286. this.ifH5Type()
  287. }
  288. })
  289. },
  290. // 企微授权
  291. gerQwAuth(bId) {
  292. let openId = this.getQueryParam('openId') || localStorage.getItem('openId')
  293. fetch(this.httpUrl + `/p/insuite/p/getOAUrl?openId=${openId}&bId=${bId}`)
  294. .then(res => {
  295. return res.json()
  296. }).then(result => {
  297. let { data, code, msg } = result
  298. if (code === 1) {
  299. window.location.replace(data)
  300. } else {
  301. this.$message({
  302. message: msg,
  303. type: 'warning'
  304. })
  305. }
  306. })
  307. },
  308. // 获取城市数据
  309. getCityLevel() {
  310. fetch('https://wl-1306604067.cos.ap-guangzhou.myqcloud.com/production/ct/1000/1720161853377/pc-code.json')
  311. .then(res => {
  312. return res.json()
  313. }).then(result => {
  314. this.transformedData = this.transformData(result)
  315. })
  316. },
  317. // 省市数据做转换
  318. transformData(data) {
  319. return data.map(item => {
  320. // 创建一个新对象,避免直接修改原始对象
  321. const newItem = { ...item };
  322. // 重命名 text 为 label
  323. if (newItem.text) {
  324. newItem.label = newItem.text;
  325. newItem.value = newItem.text;
  326. delete newItem.text;
  327. }
  328. // 如果存在 children 数组,则递归处理每个子项
  329. if (newItem.children && Array.isArray(newItem.children)) {
  330. newItem.children = this.transformData(newItem.children);
  331. }
  332. return newItem;
  333. })
  334. },
  335. handleInfoCity(value) {
  336. this.province = value[0]
  337. this.city = value[1]
  338. // 清空经销商类型的数据
  339. this.toshopData.formProList.forEach(item => {
  340. if (item.type === 11) {
  341. item.value = ''
  342. }
  343. })
  344. this.storeList = []
  345. this.getStoreList()
  346. },
  347. handlechange(value) {
  348. this.toshopData.formProList.forEach(item => {
  349. if (item.type === 11) {
  350. item.value = value
  351. }
  352. })
  353. this.$forceUpdate()
  354. },
  355. getStoreList() {
  356. fetch(this.httpUrl + `/scrm/v1/wxcp-toshop-store/p/findListByPage?city=${this.city}&province=${this.province}`, {
  357. method: 'post',
  358. body: JSON.stringify({
  359. page: 1,
  360. pageCount: 10000,
  361. }),
  362. headers: {
  363. 'Content-Type': 'application/json'
  364. }
  365. }).then(res => {
  366. return res.json()
  367. }).then(result => {
  368. let { data, code, msg } = result
  369. if (code === 1) {
  370. this.storeList = data.records
  371. } else {
  372. this.$message({
  373. message: msg,
  374. type: 'warning'
  375. })
  376. }
  377. })
  378. },
  379. lightenShare() {
  380. let externalUserid = this.getQueryParam('externalUserid')
  381. let openId = this.getQueryParam('openId') || localStorage.getItem('openId')
  382. const headers = new Headers();
  383. headers.append('police', 110);
  384. fetch(this.httpUrl + `/scrm/v1/wxcp-toshop-verification/p/lottery?externalUserid=${externalUserid}&openId=${openId}&bId=${this.bId}`, {
  385. method: 'GET',
  386. headers: headers
  387. })
  388. .then(res => {
  389. return res.json()
  390. }).then(result => {
  391. let { data, code, msg } = result
  392. if (code === 1) {
  393. this.toshopData = data
  394. } else {
  395. this.$message({
  396. message: msg,
  397. })
  398. }
  399. })
  400. },
  401. toSignUp() {
  402. if (!this.verificationCode) {
  403. this.$message({
  404. message: '核销码不能为空',
  405. type: 'warning'
  406. })
  407. return
  408. }
  409. const isValid = this.toshopData.formProList.some(item => {
  410. if (item.isNeed && !item.value) {
  411. this.$message({
  412. message: '必填项不能为空',
  413. type: 'warning'
  414. })
  415. return true
  416. }
  417. return false
  418. })
  419. if (isValid) return
  420. let cols = []
  421. cols = this.toshopData.formProList.map(item => {
  422. return {
  423. name: item.name,
  424. type: item.type,
  425. value: item.type === 10 ? [item.value.join('')] : [item.value],
  426. }
  427. })
  428. let openId = this.getQueryParam('openId') || localStorage.getItem('openId')
  429. fetch(this.httpUrl + `/scrm/v1/wxcp-toshop-verification/p/formData?openId=${openId}`, {
  430. method: 'post',
  431. body: JSON.stringify({
  432. bid: this.bId,
  433. cols: cols,
  434. verificationCode: this.verificationCode
  435. }),
  436. headers: {
  437. 'Content-Type': 'application/json'
  438. }
  439. }).then(res => {
  440. return res.json()
  441. }).then(result => {
  442. let { data, code, msg } = result
  443. if (code === 1) {
  444. if (data.client.state === 3) {
  445. // 已核销(已提交核销表单)
  446. this.step = 2
  447. } else if (data.client.state === -1) {
  448. // 不符合资格
  449. this.step = 3
  450. }
  451. } else if (code === 2) {
  452. this.$message({
  453. message: '核销码无效',
  454. type: 'warning'
  455. })
  456. } else if (code === 3) {
  457. this.$message({
  458. message: msg,
  459. type: 'warning'
  460. })
  461. } else {
  462. this.$message({
  463. message: msg,
  464. type: 'warning'
  465. })
  466. }
  467. })
  468. },
  469. // 截取url中的数据
  470. getQueryParam(paramName) {
  471. // 获取当前URL的查询字符串部分
  472. const queryString = window.location.search;
  473. // 创建一个URLSearchParams对象
  474. const urlParams = new URLSearchParams(queryString);
  475. // 返回指定参数的值,如果不存在则返回null
  476. return urlParams.get(paramName);
  477. },
  478. }
  479. })
  480. </script>
  481. </html>