TestYTViews.vue 13 KB

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