| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>活动</title>
- <!--引入 element-ui 的样式,-->
- <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
- <!-- 必须先引入vue, 后使用element-ui -->
- <script src="./js/vue.js"></script>
- <!-- 引入element 的组件库-->
- <script src="https://unpkg.com/element-ui/lib/index.js"></script>
- <script src="https://unpkg.com/vconsole/dist/vconsole.min.js"></script>
- <!-- <script>
- var vConsole = new window.VConsole();
- </script> -->
- </head>
- <style>
- body {
- margin: 0;
- padding: 0;
- }
- .box {
- width: 100vw;
- height: 100vh;
- box-sizing: border-box;
- background: #FAFAFA;
- }
- .page6 {
- width: 100vw;
- height: 100vh;
- background: url('./img/signup_bg.png') no-repeat top;
- background-size: 100vw 210px;
- background-repeat: no-repeat;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .page_title {
- font-weight: 800;
- font-size: 40px;
- color: #FFFFFF;
- position: fixed;
- top: 40px;
- left: 20px;
- }
- .form_content {
- width: 100%;
- height: calc(100vh - 180px);
- margin-top: 180px;
- background: #FFFFFF;
- border-radius: 20px 20px 0px 0px;
- padding: 20px 20px 66px;
- overflow-y: auto;
- box-sizing: border-box;
- }
- .foot_btn {
- position: fixed;
- bottom: 14px;
- padding: 0 35px;
- width: 100%;
- box-sizing: border-box;
- }
- .signUp_btn {
- height: 52px;
- line-height: 52px;
- background: #1677FF;
- border-radius: 20px;
- font-weight: 500;
- font-size: 16px;
- color: #FFFFFF;
- text-align: center;
- }
- .el-form-item__label {
- padding-right: 0;
- font-weight: 500;
- font-size: 14px;
- color: #666666;
- }
- .el-input__inner{
- border: none;
- font-weight: 500;
- font-size: 14px;
- color: #222222;
- text-align: right;
- }
- .el-form-item {
- margin-bottom: 0;
- border-bottom: 1px solid #F9F9F9;
- padding: 10px 0;
- }
- .el-form-item__content .el-select {
- margin-left: 18px;
- }
- .el-form-item__content .el-cascader {
- margin-left: 18px;
- }
- .page6s {
- width: 100vw;
- height: 100vh;
- background: url('./img/signup_success.png') no-repeat center;
- background-size: 100vw 100vh;
- background-repeat: no-repeat;
- }
- .succ_tip {
- padding-top: 240px;
- font-weight: bold;
- font-size: 24px;
- color: #222222;
- line-height: 40px;
- text-align: center;
- width: 100%;
- white-space: pre-wrap;
- }
- .signup_page {
- width: 100vw;
- height: 100vh;
- background: url('./img/sign_up.png') no-repeat center;
- background-size: 100vw 100vh;
- background-repeat: no-repeat;
- }
- .signup_title {
- font-weight: bold;
- font-size: 24px;
- color: #FFFFFF;
- padding-top: 80px;
- text-align: center;
- line-height: 41px;
- }
- .fail_box {
- margin: 80px 20px 0;
- height: 287px;
- background: linear-gradient(#D5E6FF 50%, #FFFFFF 100%);
- border-radius: 20px;
- box-sizing: border-box;
- text-align: center;
- }
- .fail_img {
- width: 246px;
- height: 144px;
- margin-top: -20px;
- }
- .fail_title {
- font-weight: 500;
- font-size: 20px;
- color: #222222;
- line-height: 30px;
- padding: 20px 0;
- }
- .fail_tip {
- font-weight: 400;
- font-size: 16px;
- color: #666666;
- line-height: 30px;
- }
- </style>
- <body>
- <div id="box" class="box">
- <div class="page6" v-if="step === 1">
- <div class="page_title">核销领取礼品</div>
- <div class="form_content">
- <el-form ref="form" label-position="left" label-width="100px">
- <el-form-item label="核销码" required>
- <el-input v-model="verificationCode" placeholder="请输入"></el-input>
- </el-form-item>
- <el-form-item v-for="(item, index) in toshopData.formProList" :key="index" :label="item.name "
- :required="Boolean(item.isNeed)">
- <el-cascader v-if="item.type === 10" v-model="item.value" :options="transformedData" @change="handleInfoCity">
- </el-cascader>
- <el-select v-if="item.type === 11" v-model="item.value" placeholder="请选择" @change="handlechange">
- <el-option v-for="(sto, sindex) in storeList" :key="sindex" :label="sto.name" :value="sto.name">
- </el-option>
- </el-select>
- <el-input v-if="item.type === 0" v-model="item.value" placeholder="请输入"></el-input>
- <el-input v-if="item.type === 1" type="textarea" autosize v-model="item.value" placeholder="请输入"></el-input>
- <el-input v-if="item.type === 2" type="number" v-model="item.value" placeholder="请输入"></el-input>
- <el-select v-if="item.type === 3" v-model="item.value" placeholder="请选择">
- <el-option v-for="sto in item.formProTagReqs" :key="sto.proValue" :label="sto.proValue" :value="sto.proValue">
- </el-option>
- </el-select>
- <el-date-picker v-if="item.type === 5" v-model="item.value" type="date" placeholder="选择日期">
- <el-time-picker v-if="item.type === 6" v-model="item.value" placeholder="请选择"></el-time-picker>
- <el-date-picker v-if="item.type === 7" v-model="item.value" type="datetime" placeholder="选择日期时间"></el-date-picker>
- </el-form-item>
- </el-form>
- </div>
- <div class="foot_btn">
- <div class="signUp_btn" @click="toSignUp">核销</div>
- </div>
- </div>
- <div class="page6s" v-else-if="step === 2">
- <div class="succ_tip">
- {{toshopData.verificationGuide}}
- </div>
- </div>
- <div class="signup_page" v-else-if="step === 3">
- <div class="signup_title">{{toshopData.name}}</div>
- <div class="fail_box">
- <img class="fail_img" src="./img/fail_img.png" />
- <div class="fail_title">{{toshopData.verificationFailGuide}}</div>
- <div class="fail_tip">{{toshopData.verificationFailGuide2}}</div>
- </div>
- </div>
- </div>
- </body>
- <script>
- new Vue({
- el: '#box',
- data() {
- return {
- httpUrl: '',
- bId: null,
- env: '',
- toshopData: {
- name: '',
- verificationGuide: '',
- verificationFailGuide: '',
- verificationFailGuide2: '',
- formProList: [],
- },
- step: 1,
- verificationCode: '',
- transformedData: [],
- storeList: [],
- province: '',
- city: '',
- }
- },
- created() {
- this.bId = this.getQueryParam('bId')
- this.env = this.getQueryParam('env')
- if (!this.env || this.env === 'prod') {
- this.httpUrl = 'https://wlapi.wefanbot.com'
- } else {
- this.httpUrl = 'http://test.wefanbot.com:18993'
- }
- this.ifH5Type()
- },
- methods: {
- ifH5Type() {
- if (this.getQueryParam('openId') || localStorage.getItem('openId')) {
- if (!this.getQueryParam('externalUserid')) {
- this.gerQwAuth(this.bId);
- } else {
- this.getCityLevel()
- this.lightenShare()
- }
- } else {
- // 走授权操作
- this.getAuth();
- }
- },
- getAuth() {
- // 获取url上的code
- let code = this.getQueryParam('code')
- if (code) {
- // 判断业务id是否生产环境业务id
- fetch(this.httpUrl + `/p/insuite/p/isProdId?id=${this.bId}`)
- .then(res => {
- return res.json()
- }).then(result => {
- let { data, msg } = result
- if (typeof data === 'boolean' && data) {
- this.httpUrl = 'https://wlapi.wefanbot.com'
- } else {
- this.httpUrl = 'http://test.wefanbot.com:18993'
- }
- this.getInfoByh5Code(this.getQueryParam('code'))
- })
- } else {
- let redirect_uri = window.location.href
- // code 不存在,走微信网页授权逻辑
- let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appId=wx99ec0d0828a4d2d3&redirect_uri=${redirect_uri}&scope=snsapi_userinfo&state=STATE#wechat_redirect`
- window.location.replace(url)
- }
- },
- getInfoByh5Code(code) {
- fetch(this.httpUrl + `/scrm/v1/mp-client/p/getInfoByh5Code?code=${code}&bId=${this.bId}`)
- .then(res => {
- return res.json()
- }).then(result => {
- let { data, code, msg } = result
- if (code === 1) {
- localStorage.setItem('openId', data.openId)
- this.ifH5Type()
- }
- })
- },
- // 企微授权
- gerQwAuth(bId) {
- let openId = this.getQueryParam('openId') || localStorage.getItem('openId')
- fetch(this.httpUrl + `/p/insuite/p/getOAUrl?openId=${openId}&bId=${bId}`)
- .then(res => {
- return res.json()
- }).then(result => {
- let { data, code, msg } = result
- if (code === 1) {
- window.location.replace(data)
- } else {
- this.$message({
- message: msg,
- type: 'warning'
- })
- }
- })
- },
- // 获取城市数据
- getCityLevel() {
- fetch('https://wl-1306604067.cos.ap-guangzhou.myqcloud.com/production/ct/1000/1720161853377/pc-code.json')
- .then(res => {
- return res.json()
- }).then(result => {
- this.transformedData = this.transformData(result)
- })
- },
- // 省市数据做转换
- transformData(data) {
- return data.map(item => {
- // 创建一个新对象,避免直接修改原始对象
- const newItem = { ...item };
- // 重命名 text 为 label
- if (newItem.text) {
- newItem.label = newItem.text;
- newItem.value = newItem.text;
- delete newItem.text;
- }
- // 如果存在 children 数组,则递归处理每个子项
- if (newItem.children && Array.isArray(newItem.children)) {
- newItem.children = this.transformData(newItem.children);
- }
- return newItem;
- })
- },
- handleInfoCity(value) {
- this.province = value[0]
- this.city = value[1]
- // 清空经销商类型的数据
- this.toshopData.formProList.forEach(item => {
- if (item.type === 11) {
- item.value = ''
- }
- })
- this.storeList = []
- this.getStoreList()
- },
- handlechange(value) {
- this.toshopData.formProList.forEach(item => {
- if (item.type === 11) {
- item.value = value
- }
- })
- this.$forceUpdate()
- },
- getStoreList() {
- fetch(this.httpUrl + `/scrm/v1/wxcp-toshop-store/p/findListByPage?city=${this.city}&province=${this.province}`, {
- method: 'post',
- body: JSON.stringify({
- page: 1,
- pageCount: 10000,
- }),
- headers: {
- 'Content-Type': 'application/json'
- }
- }).then(res => {
- return res.json()
- }).then(result => {
- let { data, code, msg } = result
- if (code === 1) {
- this.storeList = data.records
- } else {
- this.$message({
- message: msg,
- type: 'warning'
- })
- }
- })
- },
- lightenShare() {
- let externalUserid = this.getQueryParam('externalUserid')
- let openId = this.getQueryParam('openId') || localStorage.getItem('openId')
- const headers = new Headers();
- headers.append('police', 110);
- fetch(this.httpUrl + `/scrm/v1/wxcp-toshop-verification/p/lottery?externalUserid=${externalUserid}&openId=${openId}&bId=${this.bId}`, {
- method: 'GET',
- headers: headers
- })
- .then(res => {
- return res.json()
- }).then(result => {
- let { data, code, msg } = result
- if (code === 1) {
- this.toshopData = data
- } else {
- this.$message({
- message: msg,
- })
- }
- })
- },
- toSignUp() {
- if (!this.verificationCode) {
- this.$message({
- message: '核销码不能为空',
- type: 'warning'
- })
- return
- }
- const isValid = this.toshopData.formProList.some(item => {
- if (item.isNeed && !item.value) {
- this.$message({
- message: '必填项不能为空',
- type: 'warning'
- })
- return true
- }
- return false
- })
- if (isValid) return
- let cols = []
- cols = this.toshopData.formProList.map(item => {
- return {
- name: item.name,
- type: item.type,
- value: item.type === 10 ? [item.value.join('')] : [item.value],
- }
- })
- let openId = this.getQueryParam('openId') || localStorage.getItem('openId')
- fetch(this.httpUrl + `/scrm/v1/wxcp-toshop-verification/p/formData?openId=${openId}`, {
- method: 'post',
- body: JSON.stringify({
- bid: this.bId,
- cols: cols,
- verificationCode: this.verificationCode
- }),
- headers: {
- 'Content-Type': 'application/json'
- }
- }).then(res => {
- return res.json()
- }).then(result => {
- let { data, code, msg } = result
- if (code === 1) {
- if (data.client.state === 3) {
- // 已核销(已提交核销表单)
- this.step = 2
- } else if (data.client.state === -1) {
- // 不符合资格
- this.step = 3
- }
- } else if (code === 2) {
- this.$message({
- message: '核销码无效',
- type: 'warning'
- })
- } else if (code === 3) {
- this.$message({
- message: msg,
- type: 'warning'
- })
- } else {
- this.$message({
- message: msg,
- type: 'warning'
- })
- }
- })
- },
- // 截取url中的数据
- getQueryParam(paramName) {
- // 获取当前URL的查询字符串部分
- const queryString = window.location.search;
- // 创建一个URLSearchParams对象
- const urlParams = new URLSearchParams(queryString);
- // 返回指定参数的值,如果不存在则返回null
- return urlParams.get(paramName);
- },
- }
- })
- </script>
- </html>
|