123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- $(".sendbox").hide();
- $(document).on("click", ".collectcontent", function (event) {
- $(".sendbox").show(500);
- $(this).addClass("select");
- $(".select").siblings().removeClass('select');
- });
- $(document).on("click", ".close", function (event) {
-
- $(".sendbox").hide(500);
- $(".collectcontent").removeClass("select");
- });
- function collection(collectuserid='') {
- console.log('Call collection(' + collectuserid + ')');
- var collectcontent = '';
- $.ajax({
- method: "GET",
- url: "https://api.ptt.cx:8750/api/v1/line/collection/" + collectuserid + "",
- dataType: "json",
- })
- .done(function (msg) {
- if (msg == "error: user don't have any nft") {
- collectcontent += '<p>您可以到我們的「NFT商店」頁面,去購買您喜愛的NFT收藏品哦!</p>';
- } else {
- console.log(msg)
- let len = Object.keys(msg).length;
- let arr = []
- for(let i = 0; i < len; i++) {
- arr.push(msg[i]);
- }
- console.log(arr);
- for(let i = 0; i < arr.length; i++) {
- collectcontent += '\
- <div class="collectcontent col">\
- <input style="display: none;" type="radio" value="'+ arr[i].id + '" name="nftid" id="' + arr[i].id + '">\
- <label for="'+ arr[i].id + '">\
- <div class="collectcard card h-100">\
- <a target="_blank">\
- <img src="'+ arr[i].imgurl + '"class="card-img-top" alt="...">\
- </a>\
- <div class="card-body p-2">\
- <a target="_blank">\
- <h5 class="card-title pt-3">'+ arr[i].title + '</h5>\
- <p class="card-text">數量:'+ arr[i].amount + '</p>\
- </a>\
- </div>\
- </div>\
- </label>\
- </div>';
- }
-
- }
- $('.sec05-moblie-container').html(collectcontent);
- });
- }
- function shop(collectuserid='') {
- console.log('Call shop(' + collectuserid + ')');
- $.ajax({
- method: "GET",
- url: "https://api.ptt.cx:8750/api/v1/line/shop/" + collectuserid + "",
- dataType: "json",
- })
- .done(function (msg) {
- console.log(msg);
-
- let msgLen = Object.keys(msg).length;
- console.log(msgLen);
- var nftmall = '';
- var buybox = "";
- for (var i = 0; i < msgLen; i++) {
- nftmall += '\
- <div class="nftmall col">\
- <input style="display:none" type="radio" value="'+ msg[i].id + '" name="nftid" class="nftname" id="' + msg[i].id + '">\
- <label for="'+ msg[i].id + '">\
- <div class="collectcard card h-100">\
- <a target="_blank">\
- <img src="'+ msg[i].imgurl + '"class="card-img-top" alt="...">\
- </a>\
- <div class="card-body p-2">\
- <a target="_blank">\
- <h5 class="card-title pt-3">'+ msg[i].title + '</h5>\
- </a>\
- </div>\
- </div>\
- </label>\
- </div>';
- }
- buybox += '\
- <div class="p-2">\
- <input id="userid" style="border-radius: 10px; border:none; display: none;" class="p-2 w-100 mb-3" type="text" name="userid" value="' + collectuserid + '" placeholder="請輸入您的userid" required>\
- <div class="text-end px-2">\
- <p class="text-start text-white mb-2">※一次只能購買一則NFT收藏品</p>\
- <button type="button" style="border:1px solid #fff; border-radius: 30px;" class="close btn text-white px-3">取消</button>\
- <input style="border-radius: 30px; background:#fff; border: none;" class="send-btn px-3 ms-1 py-2" type="submit" value="購買">\
- </div>\
- </div>\
- </div>';
- $('.sec06-nft-mall').html(nftmall);
- $('.buybox').html(buybox);
- });
- }
- function get_data(collectuserid='') {
- console.log('Call get_data(' + collectuserid + ')');
- $.ajax({
- method: "GET",
- url: "https://api.ptt.cx:8750/api/v1/line/receive/" + collectuserid + "",
- dataType: "json",
- })
- .done(function (msg) {
- console.log(msg);
- var Qrcodeimg = '';
- var useraddress = '';
- Qrcodeimg += '\
- <img class="img-fluid" src="./qrcode/'+ collectuserid + '.png" alt="">\
- ';
- useraddress += '\
- '+ msg.useraddress + '\
- ';
- $('#Qrcode').html(Qrcodeimg);
- $('#copy').html(useraddress);
- });
- }
- $(".buybox").hide();
- $(document).on("click", ".nftmall", function (event) {
- $(".buybox").show(500);
- $(this).addClass("select");
- $(".select").siblings().removeClass('select');
- });
- $(document).on("click", ".close", function (event) {
-
- $(".buybox").hide(500);
- $(".nftmall").removeClass("select");
- $(".nftname").prop("checked", false);
- });
- $.fn.serializeObject = function () {
- var o = {};
- var a = this.serializeArray();
- $.each(a, function () {
- if (o[this.name]) {
- console.log(o[this.name], o[this.value]);
- if (!o[this.name].push) {
- o[this.name] = [o[this.name]];
- }
- o[this.name].push(this.value || '');
- } else {
- o[this.name] = this.value || '';
- }
- });
- return o;
- };
- $(".collect-send").submit(function (e) {
- var nftid = $("input[name='nftid']:checked").val();
- var address = $('#address').val();
- var data = `{"nftid":"` + nftid +`","address":"` + address +`"}`;
-
- console.log(data);
-
- var url = "https://api.ptt.cx:8750/api/v1/line/send";
- var xhr = new XMLHttpRequest();
- xhr.open("POST", url, false);
-
- xhr.setRequestHeader("accept", "application/json");
- xhr.setRequestHeader("Content-Type", "application/json");
-
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4) {
- console.log(xhr.status);
- console.log(xhr.responseText);
- alert("發送成功");
- location.replace("collect.html");
- }
- };
-
- xhr.send(data);
- });
- $(".nft-buy").submit(function (e) {
- var nftid = $("input[name='nftid']:checked").val();
- var userid = $('#userid').val();
- var data = `{"nftid":"` + nftid +`","userid":"` + userid +`"}`;
-
- console.log(data);
-
- var url = "https://api.ptt.cx:8750/api/v1/line/buy";
- var xhr = new XMLHttpRequest();
- xhr.open("POST", url, false);
-
- xhr.setRequestHeader("accept", "application/json");
- xhr.setRequestHeader("Content-Type", "application/json");
-
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4) {
- console.log(xhr.status);
- console.log(xhr.responseText);
- alert("購買成功");
- location.replace("shop.html");
- }
- };
-
- xhr.send(data);
- });
- function copyEvent(id) {
- var str = document.getElementById(id);
- window.getSelection().selectAllChildren(str);
- document.execCommand("Copy")
- toastr.options = {
-
- "closeButton": false,
- "debug": false,
- "newestOnTop": false,
- "progressBar": false,
- "positionClass": "toast-top-center",
- "preventDuplicates": false,
- "onclick": null,
- "showDuration": "300",
- "hideDuration": "1000",
- "timeOut": "1000",
- "extendedTimeOut": "1000",
- "showEasing": "swing",
- "hideEasing": "linear",
- "showMethod": "fadeIn",
- "hideMethod": "fadeOut"
- }
- toastr.success("複製成功");
- }
|