selected.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <script>
  2. import {gameStart} from "@/requests/game";
  3. import Toast from "../../../../static/vant/toast/toast";
  4. import game_store from "../../../store/game";
  5. let $this;
  6. export default {
  7. name: "ToySelected",
  8. props: [
  9. "connect_toy",
  10. "toy",
  11. "device_bg",
  12. "device_power",
  13. "toy_power",
  14. "toy_sn",
  15. ],
  16. data() {
  17. return {
  18. pay_window: false,
  19. // 使用类型 1 次数 2时间 0未选择
  20. pay_type: 0,
  21. // 限制点击一次
  22. is_started: false,
  23. start_show: false,
  24. };
  25. },
  26. created() {
  27. $this = this;
  28. },
  29. methods: {
  30. // 断开脑机
  31. cancelConnect() {
  32. $this.$emit("deviceStatus", 3);
  33. },
  34. // 打开玩具下拉列表
  35. openToyList() {
  36. $this.$emit("openToys", true);
  37. },
  38. // 打开选择消费的选项框
  39. openPayWindow() {
  40. if (!$this.device_bg) {
  41. Toast.fail("请佩戴好脑机开始训练");
  42. return false;
  43. }
  44. if (wx.getStorageSync("userinfo").level*1 === 11) {
  45. $this.choosePayType(2);
  46. } else {
  47. $this.pay_window = true;
  48. }
  49. },
  50. //点击隐藏
  51. hidePayWindow() {
  52. $this.pay_window = false;
  53. },
  54. //选择消费的时间或者次数
  55. choosePayType($type) {
  56. if (!$this.device_bg) {
  57. Toast.fail("请佩戴好脑机开始训练");
  58. return false;
  59. }
  60. let $toyId = $this.toy.id;
  61. if($toyId === 8){
  62. $toyId = 0;
  63. }
  64. $this.pay_type = $type;
  65. let $params = {
  66. type: $type,
  67. device_id: $toyId,
  68. access_token: wx.getStorageSync("token"),
  69. };
  70. gameStart($params).then(
  71. (res) => {
  72. let $data = res.data;
  73. let $res = $data.data;
  74. if ($data.code === 0) {
  75. $this.is_started = true;
  76. // 设置游戏模式: 1次数 2时间
  77. game_store.setters.setMode($type);
  78. // 设置游戏记录id
  79. game_store.setters.setGameRecordId($res["game_record_id"]);
  80. //打开脑控
  81. $this.$bluetooth.sendControl();
  82. Toast.success($data.errmsg);
  83. game_store.setters.setPlayTime($res["play_time"]);
  84. game_store.setters.setOverPlayTime($res["play_time"]);
  85. setTimeout(() => {
  86. $this.pageToPlay();
  87. }, 800);
  88. } else {
  89. $this.is_started = false;
  90. Toast.fail($data.errmsg);
  91. }
  92. },
  93. (err) => {
  94. $this.is_started = false;
  95. console.log(err);
  96. }
  97. );
  98. },
  99. // 前往正在玩的波动时间界面
  100. pageToPlay() {
  101. $this.$emit("gameStart", true);
  102. mpvue.navigateTo({
  103. url: "/pages/start/main",
  104. success() {
  105. // 设置游戏状态为游戏中
  106. game_store.setters.setGameStatus(1);
  107. },
  108. });
  109. },
  110. },
  111. onShow() {
  112. $this.is_started = false;
  113. },
  114. };
  115. </script>
  116. <template>
  117. <div>
  118. <van-row class="padding">
  119. <van-col span="5">
  120. <div class="device_bg flex flex-direction align-center justify-center">
  121. <img src="https://img.shuimuai.com/web/phone.png" alt="" class="device_phone" />
  122. <text class="text-gray device_text"> 我的手机</text>
  123. </div>
  124. </van-col>
  125. <van-col span="3" offset="1">
  126. <div class="dot_container flex align-center">
  127. <div class="dot_wait"> <img src="https://img.shuimuai.com/m_sign_gou%402x.png" alt="" class="moving_dot" />
  128. </div>
  129. </div>
  130. </van-col>
  131. <van-col span="5" offset="0">
  132. <div class="device_bg flex flex-direction align-center justify-center">
  133. <img v-if="device_bg" src="https://img.shuimuai.com/web/sign_green.png" alt="" class="sign_green"/>
  134. <img v-else src="https://img.shuimuai.com/web/sign_red.png" class="sign_green" alt=""/>
  135. <img src="https://img.shuimuai.com/web/brain.png" alt="" class="device_brain"/>
  136. <text class="text-gray device_text second_device_text"> 已连接({{ device_power }}%)</text>
  137. </div>
  138. </van-col>
  139. <van-col span="3" offset="1">
  140. <div class="dot_container flex align-center">
  141. <div class="dot_wait"> <img v-if="connect_toy === 1" src="https://img.shuimuai.com/web/dot.png" alt="" class="moving_dot" :class="{ moving: connect_toy === 1 }"/>
  142. <img v-if="connect_toy === 2" src="https://img.shuimuai.com/m_sign_gou%402x.png" alt="" class="moving_dot"/>
  143. <img v-if="connect_toy === 3" src="https://img.shuimuai.com/fail.png" alt="" class="moving_dot"/>
  144. </div>
  145. </div>
  146. </van-col>
  147. <van-col span="5" offset="0">
  148. <div v-if="toy" class="device_bg flex flex-direction align-center justify-center">
  149. <img :src="toy['img']" alt="" class="uav_toy" />
  150. <text class="text-gray device_text">
  151. <template v-if="connect_toy === 1 || connect_toy === 3">
  152. {{ toy["name"] }}
  153. </template>
  154. <template v-if="connect_toy === 2 || connect_toy === 4">
  155. {{ toy_sn }}
  156. </template>
  157. </text>
  158. </div>
  159. </van-col>
  160. </van-row>
  161. <!-- 按钮组合 -->
  162. <van-row gutter="6">
  163. <van-col span="8">
  164. <button class="cu-btn bg-red lg text-white" @click="cancelConnect">
  165. <img src="https://img.shuimuai.com/m_duankainaohuan.png" class="cut_brain_icon" alt=""/>
  166. <text class="cut_text">断开脑机</text>
  167. </button>
  168. </van-col>
  169. <van-col span="12" offset="1" v-if="connect_toy === 1">
  170. <van-row class="text-center">
  171. <text class="text-gray text-lg"> 连接中... </text>
  172. </van-row>
  173. </van-col>
  174. <!-- 已经连接教具 -->
  175. <div v-if="connect_toy === 2">
  176. <van-col span="8">
  177. <button class="cu-btn bg-red lg cu-btn-primary" @click="openToyList">
  178. <img src="https://img.shuimuai.com/m_xuanzewanju.png" alt="" class="cut_brain_icon"/>
  179. <text class="cut_text">选择教具</text>
  180. </button>
  181. </van-col>
  182. <van-col span="8">
  183. <button class="cu-btn bg-red lg cu-btn-primary" @click="openPayWindow" :disabled="is_started">
  184. <img src="https://img.shuimuai.com/web/start_game_icon.png" alt="" class="cut_start_game_icon"/>
  185. <text class="cut_text" style="padding:0px">开始训练</text>
  186. </button>
  187. </van-col>
  188. </div>
  189. <!-- 教具连接失败 -->
  190. <div v-if="connect_toy === 3">
  191. <van-col span="8">
  192. <button class="cu-btn bg-red lg cu-btn-primary" @click="openToyList">
  193. <img src="https://img.shuimuai.com/m_xuanzewanju.png" alt="" class="cut_brain_icon"/>
  194. <text class="cut_text">选择教具</text>
  195. </button>
  196. </van-col>
  197. <van-col span="8">
  198. <van-row class="text-center">
  199. <text class="text-gray text-lg"> 连接失败 </text>
  200. </van-row>
  201. </van-col>
  202. </div>
  203. <!-- 游戏中 -->
  204. <div v-if="connect_toy === 4">
  205. <van-col span="16">
  206. <button class="cu-btn bg-green lg" @click="pageToPlay" style="width: 100%">
  207. <img src="https://img.shuimuai.com/web/start_game_icon.png" alt="" class="cut_start_game_icon"/>
  208. <text class="cut_text" style="padding: 0px">游戏中</text>
  209. </button>
  210. </van-col>
  211. </div>
  212. </van-row>
  213. <!-- 选择消费方式的窗口 -->
  214. <van-overlay :show="pay_window" @click="hidePayWindow" z-index="5">
  215. <div class="pay_type_window">
  216. <div class="pay_type_title padding">
  217. <text class="text-bold pay_type_title_text">选择消费方式</text>
  218. </div>
  219. <van-row gutter="11">
  220. <van-col span="11" offset="1">
  221. <div class=" pay_type_item flex flex-direction justify-center align-center" @click.prevent="choosePayType(2)">
  222. <view class="text-xl padding"><text class="text-white text-bold">消费时间</text></view>
  223. </div>
  224. </van-col>
  225. <van-col span="11">
  226. <div class=" pay_type_item flex flex-direction justify-center align-center"@click.prevent="choosePayType(1)">
  227. <view class="text-xl padding"><text class="text-white text-bold">消费次卡</text></view>
  228. <view class="text-sm"><text class="text-white">次卡时间为10分钟</text></view>
  229. </div>
  230. </van-col>
  231. </van-row>
  232. </div>
  233. <img src="https://img.shuimuai.com/web/boy2.png" alt="" class="connected_boy2"/>
  234. </van-overlay>
  235. <van-toast id="van-toast" />
  236. <van-popup
  237. :show="start_show"
  238. closeable
  239. position="bottom"
  240. custom-style="height: 100%"
  241. >
  242. <view>
  243. <text>游戏中界面</text>
  244. </view>
  245. </van-popup>
  246. </div>
  247. </template>
  248. <style scoped>
  249. .uav_toy {
  250. width: 47px;
  251. height: 47px;
  252. }
  253. .cut_text {
  254. padding: 0px 5px;
  255. font-size: 11px;
  256. }
  257. .cut_start_game_icon {
  258. width: 21px;
  259. height: 23px;
  260. }
  261. /*消费类型窗口*/
  262. .pay_type_window {
  263. width: 95%;
  264. height: 180px;
  265. background-image: url("https://img.shuimuai.com/web/dialog.png");
  266. background-position: center;
  267. background-size: 100% 100%;
  268. position: absolute;
  269. bottom: 225px;
  270. right: 10px;
  271. }
  272. .pay_type_title_text {
  273. color: #6b6b6b;
  274. font-size: 12px;
  275. }
  276. .pay_type_item {
  277. width: 100%;
  278. height: 100px;
  279. background-image: url("https://img.shuimuai.com/web/pay_type_bg.png");
  280. background-position: center;
  281. background-size: 100% 100%;
  282. }
  283. .connected_boy2 {
  284. width: 60px;
  285. height: 82px;
  286. position: absolute;
  287. right: 0px;
  288. bottom: 160px;
  289. }
  290. .started_bg {
  291. position: fixed;
  292. left: 0;
  293. right: 0;
  294. top: 0;
  295. bottom: 0;
  296. background: rgba(255, 255, 255, 0);
  297. z-index: 999;
  298. }
  299. </style>