strong.js 7.0 KB

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