YTViews.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <script setup lang="ts">
  2. import { ref, reactive, computed } from "vue";
  3. import { required, emailRules } from "@/utils";
  4. import { useMainStore } from "@/stores/main";
  5. import type { YTViewsUserData } from "@/interfaces";
  6. import Navbar from "@/components/Navbar.vue";
  7. const mainStore = useMainStore();
  8. const urlRules = [
  9. (v:any) => /^(http|https):\/\//.test(v) || '請輸入以 http 或 https 開頭的有效網址',
  10. ];
  11. const items = reactive([
  12. { title: "100% 真人觀看" },
  13. { title: "包含影片設定費" },
  14. { title: "開發票" },
  15. { title: "包含成效報表" },
  16. ]);
  17. const cardItems = reactive([
  18. { view: "5,000", price: "2,700", originalPrice: "3,500", param: 2700 },
  19. { view: "10,000", price: "4,400", originalPrice: "5,000", param: 4400 },
  20. { view: "30,000", price: "12,400", originalPrice: "13,000", param: 12400 },
  21. { view: "50,000", price: "20,400", originalPrice: "21,000", param: 20400 },
  22. ]);
  23. const ageOptions = [
  24. { label: "18 - 24 歲" },
  25. { label: "25 - 34 歲" },
  26. { label: "35 - 44 歲" },
  27. { label: "45 - 54 歲" },
  28. { label: "55 - 64 歲" },
  29. { label: "65 歲以上" },
  30. ];
  31. const objectOptions = [
  32. { label: "交通工具與運輸" },
  33. { label: "媒體和娛樂" },
  34. { label: "家居與園藝" },
  35. { label: "新聞與政治" },
  36. { label: "旅遊" },
  37. { label: "生活型態與興趣" },
  38. { label: "科技" },
  39. { label: "美容與健康" },
  40. { label: "美食與餐飲" },
  41. { label: "購物愛好者" },
  42. { label: "運動與健身" },
  43. { label: "銀行與金融" },
  44. ];
  45. const themeOptions = [
  46. { label: "人文與社會" },
  47. { label: "保健" },
  48. { label: "全球地點(各地區)" },
  49. { label: "參考資料(圖書館、博物館與目錄、清單等)" },
  50. { label: "圖書與文學" },
  51. { label: "家居與園藝" },
  52. { label: "寵物與動物" },
  53. { label: "工作與教育" },
  54. { label: "工商業" },
  55. { label: "房地產" },
  56. { label: "新聞" },
  57. { label: "旅遊與交通" },
  58. { label: "汽車與交通工具" },
  59. { label: "法律與政府" },
  60. { label: "科學" },
  61. { label: "網路社群" },
  62. { label: "網際網路與電信" },
  63. { label: "美容與健身" },
  64. { label: "美食佳飲" },
  65. { label: "興趣與休閒" },
  66. { label: "藝術與娛樂" },
  67. { label: "購物" },
  68. { label: "遊戲" },
  69. { label: "運動" },
  70. { label: "金融" },
  71. { label: "電腦和電子產品" },
  72. ];
  73. let chooseError = ref(false);
  74. let assignView = ref();
  75. let assignPrice = ref();
  76. function activeBtn(view: string, param: number) {
  77. assignView.value = view;
  78. assignPrice.value = param;
  79. chooseError.value = false;
  80. }
  81. let userData = reactive({
  82. email: "",
  83. name: "",
  84. company: "",
  85. url: "",
  86. area: "",
  87. language: "",
  88. ages: [],
  89. target: "",
  90. theme: "",
  91. taxID: "",
  92. });
  93. // 其他選項
  94. let target = ref("");
  95. let theme = ref("");
  96. let otherTarget = ref("");
  97. let otherTheme = ref("");
  98. // 檢查必填欄位
  99. const isSubmitDisabled = computed(() => {
  100. return (
  101. !userData.email ||
  102. !userData.name ||
  103. !userData.url ||
  104. !userData.area ||
  105. !userData.language ||
  106. !target.value ||
  107. !theme.value
  108. );
  109. });
  110. async function ECPaySubmit() {
  111. if (!assignPrice.value) {
  112. chooseError.value = true;
  113. window.scrollTo({ top: 0, behavior: "smooth" });
  114. } else {
  115. chooseError.value = false;
  116. }
  117. if (target.value === "其他" && otherTarget.value !== "") {
  118. userData.target = otherTarget.value;
  119. } else {
  120. userData.target = target.value;
  121. }
  122. if (theme.value === "其他" && otherTheme.value !== "") {
  123. userData.theme = otherTheme.value;
  124. } else {
  125. userData.theme = theme.value;
  126. }
  127. let data: YTViewsUserData = {
  128. item: `YT0.4-(${assignView.value})`,
  129. amount: assignPrice.value,
  130. email: userData.email,
  131. name: userData.name,
  132. company: userData.company,
  133. url: userData.url,
  134. area: userData.area,
  135. language: userData.language,
  136. ages: userData.ages.join(","),
  137. target: userData.target,
  138. theme: userData.theme,
  139. taxID: userData.taxID,
  140. };
  141. const originalHTML = await mainStore.YTViewsTestPayment(data);
  142. let formHTML = originalHTML?.replace(
  143. '<script type="text/javascript">document.getElementById("data_set").submit();</scr',
  144. ""
  145. );
  146. formHTML = formHTML?.replace("ipt>", "");
  147. const payFormElement = document.getElementById("pay-form");
  148. payFormElement!.innerHTML = formHTML!;
  149. const ecpayForm: HTMLFormElement = <HTMLFormElement>(
  150. document.getElementById("data_set")
  151. );
  152. console.log(ecpayForm);
  153. ecpayForm.submit();
  154. }
  155. // 資料存進 Google Sheets
  156. // async function saveData() {
  157. // const scriptURL =
  158. // "https://script.google.com/macros/s/AKfycbxCcfiOQ695DaxIa3peClqRRTWNj2aUNLbx7ty8U2wKlyU7wreQLioHG-sls5MPKBdlRQ/exec";
  159. // let formdata = new FormData();
  160. // formdata.append("email", userData.email);
  161. // formdata.append("name", userData.name);
  162. // formdata.append("company", userData.company);
  163. // formdata.append("url", userData.url);
  164. // formdata.append("area", userData.area);
  165. // formdata.append("language", userData.language);
  166. // formdata.append("age", userData.age.join("、"));
  167. // formdata.append("object", userData.object);
  168. // formdata.append("theme", userData.theme);
  169. // formdata.append("tax", userData.tax);
  170. // axios
  171. // .post(scriptURL, formdata)
  172. // .then(function (response) {
  173. // console.log(response.data);
  174. // })
  175. // .catch(function (error) {
  176. // console.log(error);
  177. // });
  178. // }
  179. </script>
  180. <template>
  181. <Navbar />
  182. <v-container fluid class="mt-16">
  183. <v-card class="ma-3 pa-3">
  184. <v-card-title primary-title class="mb-3">
  185. <h3 class="headline primary--text">YouTube 觀看數</h3>
  186. </v-card-title>
  187. <v-card-text>
  188. <p class="ms-3">請選擇方案:</p>
  189. <v-row no-gutters class="pay-card">
  190. <v-col
  191. xs="12"
  192. sm="6"
  193. lg="3"
  194. v-for="(item, index) in cardItems"
  195. :key="index"
  196. >
  197. <button @click="activeBtn(item.view, item.param)" class="w-100">
  198. <v-card
  199. class="ma-3 py-3"
  200. :class="{ active: assignPrice === item.param }"
  201. >
  202. <v-card-title primary-title class="pa-0">
  203. <div class="d-flex flex-column">
  204. <section class="d-flex mx-auto">
  205. <img
  206. width="30"
  207. height="30"
  208. src="@/assets/img/icon/play-button.png"
  209. alt=""
  210. class="me-2"
  211. />
  212. <h5 class="m-0">{{ item.view }}</h5>
  213. </section>
  214. <span class="text-center" style="color: #7c8ba7"
  215. >Views</span
  216. >
  217. </div>
  218. <p class="price">
  219. NT${{ item.price }} <br />
  220. <small>NT${{ item.originalPrice }}</small>
  221. </p>
  222. </v-card-title>
  223. <v-card-text class="d-flex align-center justify-center mt-3">
  224. <ul>
  225. <li
  226. v-for="(item, index) in items"
  227. :key="index"
  228. class="d-flex align-center"
  229. >
  230. <img
  231. width="30"
  232. src="@/assets/img/icon/check.png"
  233. alt=""
  234. />
  235. {{ item.title }}
  236. </li>
  237. </ul>
  238. </v-card-text>
  239. <!-- <v-card-actions class="d-flex justify-center">
  240. <v-btn @click="ECPaySubmit(item.param)"> Buy Now </v-btn>
  241. </v-card-actions> -->
  242. </v-card>
  243. </button>
  244. </v-col>
  245. <p class="ms-3 error" v-show="chooseError">尚未選擇方案</p>
  246. </v-row>
  247. <v-sheet max-width="500" class="mx-auto mt-10">
  248. <v-form @submit.prevent class="ECPay-form">
  249. <v-text-field
  250. v-model="userData.email"
  251. :rules="emailRules()"
  252. label="電子郵件"
  253. required
  254. ></v-text-field>
  255. <v-text-field
  256. v-model="userData.name"
  257. :rules="required()"
  258. label="姓名"
  259. required
  260. ></v-text-field>
  261. <v-text-field
  262. v-model="userData.company"
  263. label="公司 / 所屬產業"
  264. ></v-text-field>
  265. <v-text-field
  266. v-model="userData.url"
  267. :rules="urlRules"
  268. label="YouTube 影片網址"
  269. required
  270. ></v-text-field>
  271. <v-text-field
  272. v-model="userData.area"
  273. :rules="required()"
  274. label="影片放送地區(國家 / 縣市)"
  275. required
  276. ></v-text-field>
  277. <v-text-field
  278. v-model="userData.language"
  279. :rules="required()"
  280. label="受眾語言"
  281. required
  282. ></v-text-field>
  283. <p class="mt-5">客層(未選擇的話視為全部)</p>
  284. <div class="checkbox ms-5">
  285. <v-checkbox
  286. v-for="option in ageOptions"
  287. v-model="userData.ages"
  288. :key="option.label"
  289. :label="option.label"
  290. :value="option.label"
  291. color="primary"
  292. ></v-checkbox>
  293. </div>
  294. <p class="mt-10 mb-3">
  295. 目標對象區隔(興趣、習慣)<span class="text-red-darken-1">*</span>
  296. </p>
  297. <div class="ms-5">
  298. <v-radio-group v-model="target">
  299. <v-radio
  300. v-for="option in objectOptions"
  301. :key="option.label"
  302. :label="option.label"
  303. :value="option.label"
  304. color="primary"
  305. ></v-radio>
  306. <v-radio label="其他" value="其他" color="primary"></v-radio>
  307. <input v-model="otherTarget" type="text" class="other" />
  308. </v-radio-group>
  309. </div>
  310. <p class="mt-5 mb-3">
  311. 影片主題 <span class="text-red-darken-1">*</span>
  312. </p>
  313. <div class="ms-5">
  314. <v-radio-group v-model="theme">
  315. <v-radio
  316. v-for="option in themeOptions"
  317. :key="option.label"
  318. :label="option.label"
  319. :value="option.label"
  320. color="primary"
  321. ></v-radio>
  322. <v-radio label="其他" value="其他" color="primary"></v-radio>
  323. <input v-model="otherTheme" type="text" class="other" />
  324. </v-radio-group>
  325. </div>
  326. <v-text-field
  327. type="number"
  328. label="是否需要統編(可填寫統編號碼)"
  329. v-model="userData.taxID"
  330. ></v-text-field>
  331. <v-btn
  332. @click="ECPaySubmit()"
  333. type="submit"
  334. block
  335. class="mt-2 submit-btn"
  336. :disabled="isSubmitDisabled"
  337. >送出</v-btn
  338. >
  339. </v-form>
  340. </v-sheet>
  341. </v-card-text>
  342. </v-card>
  343. </v-container>
  344. <div id="pay-form"></div>
  345. </template>
  346. <style lang="scss">
  347. .pay-card {
  348. .v-card-title {
  349. h5 {
  350. font-size: 20px;
  351. }
  352. span {
  353. font-size: 16px;
  354. letter-spacing: 1px;
  355. }
  356. .price {
  357. padding: 10px 0;
  358. font-size: 26px;
  359. font-weight: 600;
  360. text-align: center;
  361. color: #fff;
  362. background-color: var(--main-color);
  363. letter-spacing: 2px;
  364. small {
  365. display: block;
  366. margin-top: -3px;
  367. font-size: 18px;
  368. font-weight: 100;
  369. text-decoration: line-through;
  370. }
  371. }
  372. }
  373. .v-card-text {
  374. ul {
  375. padding: 0;
  376. list-style: none;
  377. }
  378. }
  379. .v-card-actions {
  380. button {
  381. padding: 5px 15px;
  382. color: #fff;
  383. border-radius: 100px;
  384. background-color: var(--main-color);
  385. border: 1px solid transparent;
  386. &:hover {
  387. color: var(--main-color);
  388. background-color: #fff;
  389. border: 1px solid var(--main-color);
  390. }
  391. }
  392. }
  393. .active {
  394. border: 3px solid var(--main-color);
  395. }
  396. .error {
  397. color: #b00020;
  398. }
  399. }
  400. .ECPay-form {
  401. font-size: 16px;
  402. .checkbox {
  403. margin-left: 5px;
  404. list-style: none;
  405. .v-input {
  406. height: 40px;
  407. }
  408. }
  409. .v-input__details {
  410. padding-top: 0;
  411. padding-bottom: 3px;
  412. }
  413. .other {
  414. margin-left: 40px;
  415. border-bottom: 1px solid #333;
  416. &:focus-visible {
  417. outline: none !important;
  418. }
  419. }
  420. .submit-btn {
  421. color: #fff;
  422. background-color: var(--main-color);
  423. }
  424. }
  425. </style>