index.vue 11.9 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() {
Z's avatar
Z committed
91 92
    this.zcache.userId = this.$route.params.userId;
    this.zReadyGetUserFromId();
93
    this.getAgentAuth();
94
    // this.zReadySetVoucherList()
95 96 97 98 99 100 101 102
  },
  mounted() {
  },
  methods: {
    // 测试-获取预授权码
    zTestPreAuthCode() {
      const basicInfo = {
        head: "https://open.weixin.qq.com/connect/oauth2/authorize?",
103 104
        // appId: "wwd1cdbca7b8b2b6c4",
        appId: "ww4df265003b43fa0d",
xd's avatar
xd committed
105
        redirectUrI: encodeURIComponent("oysales.oywanhao.com"),
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
        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
129
      let postData = {
xd's avatar
xd committed
130
        userName: this.zcache.userId
131
      }
Z's avatar
Z committed
132 133
      getUserInfoByUserId(postData)
        .then(res => {
134 135
          // alert(`--->userInfoFromId: res = ${JSON.stringify(res.data)}`);
          // this.zcache.userInfo = String(res.data[0].departmentId);
xd's avatar
xd committed
136 137 138 139 140 141 142
          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
143
        })
144
        .catch(err => {})
145
    },
xd's avatar
xd committed
146
    // 获取优惠券列表
147 148 149
    zReadySetVoucherList() {
      this.zReadyDelVoucherList();
      const postData = {
xd's avatar
xd committed
150
        appCode: "0696",    // j接口编码
151
        mdid: this.zcache.storeId 
152 153
      }
      getVoucherList(postData).then(res => {
xd's avatar
xd committed
154 155 156 157 158
        if(res.result.coupons.length == 0) {
          alert('当前店铺暂无优惠券可发放')
        }else {
          this.zVoucherSet(res.result.coupons)
        }
159 160
        })
        .catch(err => {
xd's avatar
xd committed
161
        })
162 163
    },
    zReadyDelVoucherList() {
xd's avatar
xd committed
164 165
      this.zVoucherDel()
      this.zVoucherUrlDel()
166
    },
167

168
    zVoucherPick(inActiveId, inVoucherId) {
169 170 171
      this.zcache.now.activeId = String(inActiveId)
      this.zcache.now.voucherId = String(inVoucherId)

172
      this.zVoucherUrlDel()
173

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

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

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

240 241 242 243 244 245
    },
    zVoucherDel() {
      this.zlist.voucher = [];
    },
    zVoucherUrlSet(inData) {
      this.zlist.voucherUrl = String(inData);
246
      this.zpick('h5', String(inData))
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
    },
    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");
267
    }
268 269 270
  }
};
</script>
271

272 273 274 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
<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
364 365
  /* font-size: 24px; */
  font-size: 20px;
366 367 368 369 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
}

.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
459
  margin-bottom: 16px;
460 461 462 463 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

  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
536
  justify-content: center;
537 538
  align-items: flex-start;
  font-size: 14px;
Z's avatar
Z committed
539
  /* text-wrap: none; */
540
}
541
</style>