index.vue 12.1 KB
Newer Older
1
<template>
2 3 4 5 6 7 8
  <div class="main">
    <div class="contents">
      <div class="zListActive">
        <div class="inputs">
          <div class="button" @click="zReadySetVoucherList">ReLoad</div>
        </div>
      </div>
xulili's avatar
xulili committed
9
      <div v-for="item of zlist.voucher" :key="item.coupon_id" >
Z's avatar
Z committed
10 11
        <div class="content">
          <div class="content-imgs">
Z's avatar
Z committed
12
            <img class="imgs-img" :src="zcache.defaultImgUrl" alt />
Z's avatar
Z committed
13 14 15 16
          </div>
          <div class="content-infos">
            <div class="infos-mains">
              <div class="mains">
Z's avatar
Z committed
17 18
                <div class="main-usedPercent">活动ID:{{item.action_id}}</div>
                <div class="main-money">{{item.coupon_title}}</div>
Z's avatar
Z committed
19 20
              </div>
              <div class="buttons">
21
                <button class="button-send" @click="zVoucherPick(item.action_id, item.coupon_id)">推送</button>
Z's avatar
Z committed
22 23 24
              </div>
            </div>
            <div class="infos-tips">
Z's avatar
Z committed
25 26
              <div class="tip-shareMan">优惠券ID:{{item.coupon_id}}</div>
              <!-- <div class="tip-commision">佣金:¥ {{item.commision}}</div> -->
Z's avatar
Z committed
27 28 29 30
            </div>
          </div>
        </div>
      </div>
31
    </div>
32
  </div>
33 34 35
</template>

<script>
36 37 38
// import { ApiTestCfPost, ApiTestEaPost } from "@/api/test/main";
import { ApiEaPost, ApiEaActiveList } from "@/api/test/test";
import { configWx, getUserInfo } from "@/utils/aCommon";
39 40
// import * as APISidebarEA from "@/api/sidebar/ea";
import { getVoucherList, getVoucherWxUrl } from "@/api/sidebar/ea";
Z's avatar
Z committed
41
import { getUserInfoByUserId } from "@/api/sidebar/voucher";
42 43 44 45 46 47 48 49 50 51 52 53
import Vue from "vue";
import { Field } from "vant";
const zlog = console.log.bind(console);

Vue.use(Field);

export default {
  name: "discountIndex",
  data() {
    return {
      zcache: {
        storeId: 1,
Z's avatar
Z committed
54
        userId: "",
55
        unionId: "",
Z's avatar
Z committed
56
        userInfo: "",
57
        defaultImgUrl: "/mainSale/2.png",
58 59 60 61
        now: {
          activeId: "",
          voucherId: "",
        }
62 63 64 65 66 67 68 69 70 71 72 73 74 75
      },
      zlist: {
        voucher: [],
        voucherUrl: ""
      },
      test: {
        list: {
          main: [
            {
              imgUrl: "/mainSale/test-city.png",
              usedPercent: "10",
              money: "100",
              shareMan: "Alice",
              commision: "11"
76
            },
77 78 79 80 81 82
            {
              imgUrl: "/mainSale/test-city.png",
              usedPercent: "20",
              money: "200",
              shareMan: "Bob",
              commision: "22"
83
            }
84
          ]
85
        }
86 87
      },
      dis: {}
88
    };
89 90
  },
  created() {
91 92 93 94 95
    if(this.$route.params.userId) {
      this.zcache.userId = this.$route.params.userId;
    }else {
      this.zcache.userId = sessionStorage.getItem("userId")
    }    
Z's avatar
Z committed
96
    this.zReadyGetUserFromId();
97
    this.getAgentAuth();
98
    // this.zReadySetVoucherList()
99 100 101 102 103 104 105 106
  },
  mounted() {
  },
  methods: {
    // 测试-获取预授权码
    zTestPreAuthCode() {
      const basicInfo = {
        head: "https://open.weixin.qq.com/connect/oauth2/authorize?",
107 108
        // appId: "wwd1cdbca7b8b2b6c4",
        appId: "ww4df265003b43fa0d",
xd's avatar
xd committed
109
        redirectUrI: encodeURIComponent("oysales.oywanhao.com"),
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
        responseType: "code",
        scope: "snsapi_base",
        state: "ztest",
        tail: "#wechat_redirect"
      };

      let url =
        basicInfo.head +
        "appid=" +
        basicInfo.appId +
        "&redirect_uri=" +
        basicInfo.redirectUrI +
        "&response_type=" +
        basicInfo.responseType +
        "&scope=" +
        basicInfo.scope +
        "&state=" +
        basicInfo.state +
        basicInfo.tail;
      zlog("%c--->zTestPreAuthCode: Url =", "background: orange", url);
      // window.location.href = url
    },
    zReadyGetUserFromId() {
Z's avatar
Z committed
133
      let postData = {
xd's avatar
xd committed
134
        userName: this.zcache.userId
135
      }
Z's avatar
Z committed
136 137
      getUserInfoByUserId(postData)
        .then(res => {
138 139
          // alert(`--->userInfoFromId: res = ${JSON.stringify(res.data)}`);
          // this.zcache.userInfo = String(res.data[0].departmentId);
xd's avatar
xd committed
140 141 142 143 144 145 146
          if(res.data[0].oyStallCode == '') {
            alert('您当前没有绑定店铺')
          }else {
            this.zcache.storeId = res.data[0].oyStallCode
            // this.zcache.storeId = Number(res.data[0].stall);
            this.zReadySetVoucherList()
          }         
Z's avatar
Z committed
147
        })
148
        .catch(err => {})
149
    },
xd's avatar
xd committed
150
    // 获取优惠券列表
151 152 153
    zReadySetVoucherList() {
      this.zReadyDelVoucherList();
      const postData = {
xd's avatar
xd committed
154
        appCode: "0696",    // j接口编码
155
        mdid: this.zcache.storeId 
156 157
      }
      getVoucherList(postData).then(res => {
xd's avatar
xd committed
158 159 160 161 162
        if(res.result.coupons.length == 0) {
          alert('当前店铺暂无优惠券可发放')
        }else {
          this.zVoucherSet(res.result.coupons)
        }
163 164
        })
        .catch(err => {
xd's avatar
xd committed
165
        })
166 167
    },
    zReadyDelVoucherList() {
xd's avatar
xd committed
168 169
      this.zVoucherDel()
      this.zVoucherUrlDel()
170
    },
171

172
    zVoucherPick(inActiveId, inVoucherId) {
173 174 175
      this.zcache.now.activeId = String(inActiveId)
      this.zcache.now.voucherId = String(inVoucherId)

176
      this.zVoucherUrlDel()
177

178 179 180 181
      const postData = {
        appCode: "0697",
        action_id: Number(inActiveId),
        coupon_id: Number(inVoucherId)
xd's avatar
xd committed
182
      }
183
      getVoucherWxUrl(postData).then(res => {
184
        this.zVoucherUrlSet(res.result.link)
185 186
      });
    },
187 188 189

    zpick(inMsgType, inUrl) {
      switch (inMsgType) {
190

191 192 193 194 195 196 197 198 199 200 201
        case "text":
          wx.invoke(
            "sendChatMessage",
            {
              msgtype: "text", //消息类型,必填
              text: {
                content: inUrl
              }
            },
            function(res) {
              if (res.err_msg == "sendChatMessage:ok") {
xd's avatar
xd committed
202
                // alert("--->discount.vue: zpick: text 分享成功!")
203
              } else if (res.err_msg != "sendChatMessage:ok") {
xd's avatar
xd committed
204
                // alert('分享失败')
205 206 207 208 209
              }
            }
          );
          break;
        case "h5":
xulili's avatar
xulili committed
210
          // alert(`--->discount.vue: zpick: H5: IN.`);
xd's avatar
xd committed
211
          // alert('zpick')
212 213 214
          wx.invoke(
            "sendChatMessage",
            {
215 216
              msgtype: "news", //消息类型,必填
               news: {
xd's avatar
xd committed
217
                link: `http://oysales.oywanhao.com/qrCode?Url=${inUrl}&activeId=${this.zcache.now.activeId}&voucherId=${this.zcache.now.voucherId}&unionId=1234`, //H5消息页面url 必填
218
                title: "领取优惠券", //H5消息标题
219 220 221 222 223
                desc: inUrl, //H5消息摘要
                imgUrl: inUrl //H5消息封面图片URL
              }
            },
            function(res) {
xd's avatar
xd committed
224
              // alert('sendChatMessage')
225
              if (res.err_msg == "sendChatMessage:ok") {
xd's avatar
xd committed
226
                // alert("--->discount.vue: zpick: h5 分享成功!")
227
              } else if (res.err_msg != "sendChatMessage:ok") {
xd's avatar
xd committed
228
                // alert(`--->discount.vue: zpick: h5 分享失败.`)
xulili's avatar
xulili committed
229 230 231
                // alert(
                //   `--->discount.vue: zpick: h5 分享失败: res =${res.err_msg}`
                // );
232 233 234 235 236 237 238
              }
            }
          );
          break;
        default:
          break;
      }
239 240
    },
    zVoucherSet(inArray) {
xd's avatar
xd committed
241
      // alert('zVoucherSet')
242
      this.zlist.voucher = inArray;
243

244 245 246 247 248 249
    },
    zVoucherDel() {
      this.zlist.voucher = [];
    },
    zVoucherUrlSet(inData) {
      this.zlist.voucherUrl = String(inData);
250
      this.zpick('h5', String(inData))
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
    },
    zVoucherUrlDel() {
      this.zlist.voucherUrl = "";
    },

    testEaPost() {
      let postData = {
        appCode: "0696",
        mdid: 1
      };
      ApiEaActiveList(postData).then(res => {
        // console.log(res);
      });
    },

    buttonSingleMarketingClick() {
      // this.$router.push("");
    },
    buttonMainMarketingClick() {
      this.$router.push("MainSale");
271
    }
272 273 274
  }
};
</script>
275

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
<style scoped>
.main {
  background-color: white;
  width: 100%;
  height: 100%;

  display: flex;
  flex-direction: column;
  justify-content: start;
}

.tops {
  border: 2px solid lightblue;
  width: 100%;
  height: 100px;
}

.contents {
  /* border: 2px solid lightpink; */
  width: 100%;
  height: 100%;
  padding: 16px;
  padding-bottom: 40px;
}

.content {
  border: 0px solid orange;
  height: 100px;
  width: 100%;
  padding: 4px 0px;
  margin-bottom: 16px;

  border-radius: 4px;
  box-shadow: 0px 2px 4px 0px rgb(187, 187, 187);

  display: flex;
  flex-direction: row;
  justify-content: start;
}

.content-imgs {
  /* border: 1px solid pink; */
  width: 20%;
  height: 100%;

  display: flex;
  flex-direction: column;
  justify-content: start;
  align-items: center;
}

.imgs-img {
  width: 50px;
  height: 50px;
  margin-top: 10px;
  border-radius: 50%;
  object-fit: cover;
}

.content-infos {
  /* border: 1px solid orange; */
  width: 80%;
  height: 100%;
}

.infos-mains {
  height: 70%;
  width: 100%;
  /* border: 1px solid green; */

  display: flex;
  flex-direction: row;
  justify-content: start;
}

.mains {
  /* border: 1px solid red; */
  width: 70%;
  height: 100%;

  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.main-usedPercent {
  font-size: 14px;
  color: grey;
}

.main-money {
  /* border: 1px solid lightgreen; */
Z's avatar
Z committed
368 369
  /* font-size: 24px; */
  font-size: 20px;
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
}

.buttons {
  /* border: 1px solid darkorange; */
  /* background-color: bisque; */
  width: 30%;
  height: 100%;

  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.button-send {
  border: 0px solid blue;
  height: 40px;
  width: 60px;
  border-radius: 4px;
  background-color: rgba(68, 93, 251, 1);
  color: white;

  font-size: 16px;
}

.infos-tips {
  height: 30%;
  width: 100%;
  /* border: 1px solid red; */
  border-top: 1px dashed gray;
  padding-top: 6px;

  display: flex;
  flex-direction: row;
  justify-content: start;
  align-items: center;
}

.tip-shareMan {
  /* border: 1px solid orange; */
  width: 70%;
  height: 100%;

  font-size: 14px;
  line-height: 16px;
  color: rgb(150, 150, 150);
}

.tip-commision {
  /* border: 1px solid green; */
  width: 30%;
  height: 100%;

  font-size: 14px;
  line-height: 16px;
  color: rgb(150, 150, 150);
}

.menus {
  border-top: 1px solid rgb(194, 194, 194);

  position: fixed;
  bottom: 0px;
  left: 0px;
  width: 100%;
  height: 50px;
  background-color: white;

  display: flex;
  flex-direction: row;
  justify-content: start;
  align-items: center;
}

.menu {
  /* border: 1px solid red; */
  height: 50px;
  /* width: 120px; */
  width: 50%;
  line-height: 50px;
  text-align: center;
  font-size: 14px;
  color: black;
}

.activeMenu {
  color: lightcoral;
}

.zListActive {
  /*border: 1px solid limegreen;*/
  width: 100%;
  height: auto;
Z's avatar
Z committed
463
  margin-bottom: 16px;
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539

  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
}

.zListActive > .inputs {
  /*border: 1px solid dodgerblue;*/
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.zListActive > .inputs > .input {
  /*border-bottom: 2px solid red;*/
  border-color: dodgerblue;
  border-radius: 4px;
  width: 70%;
  height: 40px;
  font-size: 16px;
}

.zListActive > .inputs > .button {
  border: 1px solid dodgerblue;
  border-radius: 4px;
  width: 40%;
  height: 40px;
  font-size: 14px;
  line-height: 36px;
  text-align: center;
}

.zListActive > .lists {
  /*border: 1px solid red;*/
  width: 100%;
  height: auto;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
}

.zListActive > .lists > .item {
  border: 1px solid red;
  width: 100%;
  height: 100px;
  margin-bottom: 16px;
  padding: 4px 4px;

  border-radius: 4px;
  box-shadow: 0px 2px 4px 0px rgb(187, 187, 187);

  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: flex-start;
  font-size: 14px;
}

.zListActive > .lists > .voucherUrl {
  border: 1px solid orange;
  width: 100%;
  height: 100px;
  margin-bottom: 16px;
  padding: 4px 4px;

  border-radius: 4px;
  box-shadow: 0px 2px 4px 0px rgb(187, 187, 187);

  display: flex;
  flex-direction: column;
Z's avatar
Z committed
540
  justify-content: center;
541 542
  align-items: flex-start;
  font-size: 14px;
Z's avatar
Z committed
543
  /* text-wrap: none; */
544
}
545
</style>