strong.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const utils_auth = require("../../utils/auth.js");
  4. require("../../utils/api.js");
  5. const _sfc_main = {
  6. __name: "strong",
  7. setup(__props) {
  8. const isLoggedIn = common_vendor.ref(false);
  9. const stockList = common_vendor.ref([
  10. {
  11. name: "美的集团",
  12. code: "000333",
  13. price: "68.00",
  14. score: "88.5"
  15. },
  16. {
  17. name: "贵州茅台",
  18. code: "600519",
  19. price: "1700.00",
  20. score: "85.1"
  21. }
  22. ]);
  23. const selectedDate = common_vendor.ref("2025年11月20日");
  24. const showBuyModalFlag = common_vendor.ref(false);
  25. const showSellModalFlag = common_vendor.ref(false);
  26. const currentStock = common_vendor.ref({});
  27. const buyQuantity = common_vendor.ref("100");
  28. const sellQuantity = common_vendor.ref("100");
  29. const checkLogin = () => {
  30. isLoggedIn.value = utils_auth.isLoggedIn();
  31. console.log("[强势池] 登录状态:", isLoggedIn.value);
  32. };
  33. const goToLogin = () => {
  34. common_vendor.index.navigateTo({
  35. url: "/pages/login/login"
  36. });
  37. };
  38. const buyTotalAmount = common_vendor.computed(() => {
  39. const qty = parseInt(buyQuantity.value) || 0;
  40. const price = parseFloat(currentStock.value.price) || 0;
  41. return qty * price;
  42. });
  43. const sellTotalAmount = common_vendor.computed(() => {
  44. const qty = parseInt(sellQuantity.value) || 0;
  45. const price = parseFloat(currentStock.value.price) || 0;
  46. return qty * price;
  47. });
  48. const showBuyModal = (stock) => {
  49. console.log("点击买入按钮");
  50. currentStock.value = { ...stock };
  51. buyQuantity.value = "100";
  52. showBuyModalFlag.value = true;
  53. };
  54. const closeBuyModal = () => {
  55. showBuyModalFlag.value = false;
  56. };
  57. const showSellModal = (stock) => {
  58. console.log("点击卖出按钮");
  59. currentStock.value = { ...stock };
  60. sellQuantity.value = "100";
  61. showSellModalFlag.value = true;
  62. };
  63. const closeSellModal = () => {
  64. showSellModalFlag.value = false;
  65. };
  66. const onBuyQuantityChange = (e) => {
  67. const value = e.detail.value;
  68. if (value && parseInt(value) % 100 !== 0) {
  69. common_vendor.index.showToast({
  70. title: "股数必须是100的倍数",
  71. icon: "none"
  72. });
  73. }
  74. };
  75. const onSellQuantityChange = (e) => {
  76. const value = e.detail.value;
  77. if (value && parseInt(value) % 100 !== 0) {
  78. common_vendor.index.showToast({
  79. title: "股数必须是100的倍数",
  80. icon: "none"
  81. });
  82. }
  83. };
  84. const handleBuy = () => {
  85. const qty = parseInt(buyQuantity.value);
  86. if (!qty || qty <= 0) {
  87. common_vendor.index.showToast({
  88. title: "请输入有效的股数",
  89. icon: "none"
  90. });
  91. return;
  92. }
  93. if (qty % 100 !== 0) {
  94. common_vendor.index.showToast({
  95. title: "股数必须是100的倍数",
  96. icon: "none"
  97. });
  98. return;
  99. }
  100. const transaction = {
  101. type: "buy",
  102. stockName: currentStock.value.name,
  103. stockCode: currentStock.value.code,
  104. price: parseFloat(currentStock.value.price),
  105. quantity: qty,
  106. totalAmount: buyTotalAmount.value,
  107. timestamp: Date.now()
  108. };
  109. const transactions = common_vendor.index.getStorageSync("simulated_transactions") || [];
  110. transactions.push(transaction);
  111. common_vendor.index.setStorageSync("simulated_transactions", transactions);
  112. closeBuyModal();
  113. common_vendor.index.showToast({
  114. title: "买入成功",
  115. icon: "success"
  116. });
  117. };
  118. const handleSell = () => {
  119. const qty = parseInt(sellQuantity.value);
  120. if (!qty || qty <= 0) {
  121. common_vendor.index.showToast({
  122. title: "请输入有效的股数",
  123. icon: "none"
  124. });
  125. return;
  126. }
  127. if (qty % 100 !== 0) {
  128. common_vendor.index.showToast({
  129. title: "股数必须是100的倍数",
  130. icon: "none"
  131. });
  132. return;
  133. }
  134. const transaction = {
  135. type: "sell",
  136. stockName: currentStock.value.name,
  137. stockCode: currentStock.value.code,
  138. price: parseFloat(currentStock.value.price),
  139. quantity: qty,
  140. totalAmount: sellTotalAmount.value,
  141. timestamp: Date.now()
  142. };
  143. const transactions = common_vendor.index.getStorageSync("simulated_transactions") || [];
  144. transactions.push(transaction);
  145. common_vendor.index.setStorageSync("simulated_transactions", transactions);
  146. closeSellModal();
  147. common_vendor.index.showToast({
  148. title: "卖出成功",
  149. icon: "success"
  150. });
  151. };
  152. const onHistorySearch = () => {
  153. common_vendor.index.showToast({
  154. title: "历史查询功能开发中",
  155. icon: "none"
  156. });
  157. };
  158. common_vendor.onLoad(() => {
  159. checkLogin();
  160. });
  161. common_vendor.onShow(() => {
  162. checkLogin();
  163. });
  164. return (_ctx, _cache) => {
  165. return common_vendor.e({
  166. a: common_vendor.t(stockList.value.length),
  167. b: common_vendor.f(stockList.value, (stock, index, i0) => {
  168. return {
  169. a: common_vendor.t(stock.name),
  170. b: common_vendor.t(stock.code),
  171. c: common_vendor.t(stock.price),
  172. d: common_vendor.t(stock.score),
  173. e: common_vendor.o(($event) => showBuyModal(stock), index),
  174. f: common_vendor.o(($event) => showSellModal(stock), index),
  175. g: index
  176. };
  177. }),
  178. c: selectedDate.value,
  179. d: common_vendor.o(($event) => selectedDate.value = $event.detail.value),
  180. e: common_vendor.o(onHistorySearch),
  181. f: !isLoggedIn.value ? 1 : "",
  182. g: !isLoggedIn.value
  183. }, !isLoggedIn.value ? {
  184. h: common_vendor.o(goToLogin)
  185. } : {}, {
  186. i: showBuyModalFlag.value
  187. }, showBuyModalFlag.value ? {
  188. j: common_vendor.o(closeBuyModal),
  189. k: common_vendor.t(currentStock.value.name),
  190. l: common_vendor.t(currentStock.value.code),
  191. m: common_vendor.t(currentStock.value.price),
  192. n: common_vendor.o([($event) => buyQuantity.value = $event.detail.value, onBuyQuantityChange]),
  193. o: buyQuantity.value,
  194. p: common_vendor.t(common_vendor.unref(buyTotalAmount).toFixed(2)),
  195. q: common_vendor.o(handleBuy),
  196. r: common_vendor.o(() => {
  197. }),
  198. s: common_vendor.o(closeBuyModal)
  199. } : {}, {
  200. t: showSellModalFlag.value
  201. }, showSellModalFlag.value ? {
  202. v: common_vendor.o(closeSellModal),
  203. w: common_vendor.t(currentStock.value.name),
  204. x: common_vendor.t(currentStock.value.code),
  205. y: common_vendor.t(currentStock.value.price),
  206. z: common_vendor.o([($event) => sellQuantity.value = $event.detail.value, onSellQuantityChange]),
  207. A: sellQuantity.value,
  208. B: common_vendor.t(common_vendor.unref(sellTotalAmount).toFixed(2)),
  209. C: common_vendor.o(handleSell),
  210. D: common_vendor.o(() => {
  211. }),
  212. E: common_vendor.o(closeSellModal)
  213. } : {});
  214. };
  215. }
  216. };
  217. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/strong/strong.vue"]]);
  218. wx.createPage(MiniProgramPage);