strong.js 6.6 KB

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