index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <!-- 商品分类 -->
  3. <view :style="colorStyle">
  4. <storeCate1 v-if="popupVisible == 0" :info="info" :pageVisible="pageVisible" ref="refresh2"></storeCate1>
  5. <tuiModal :show="popupVisible == 1" custom>
  6. <view class="popup">
  7. <view class="body">
  8. <view class="title">请选择用餐人数</view>
  9. <view class="spinner-box acea-row">
  10. <view v-for="(item, index) in 6" :class="{ on: index + 1 === number }" class="btn" @click="onNumber(index + 1)">
  11. <view class="inner">{{ index + 1 }}</view>
  12. </view>
  13. <input v-model="inputNumber" :class="{ on: inputFocus }" type="number" placeholder="自定义" class="input" @focus="onFocus" @blur="onBlur" />
  14. </view>
  15. </view>
  16. <view class="foot acea-row">
  17. <button :class="{ disabled: !number }" class="btn" hover-class="none" @tap="addTableCode(number)">
  18. <view class="inner">开始点餐</view>
  19. </button>
  20. </view>
  21. </view>
  22. </tuiModal>
  23. </view>
  24. </template>
  25. <script>
  26. import {
  27. mapGetters
  28. } from 'vuex';
  29. import colors from "@/mixins/color";
  30. import storeCate1 from './cart.vue'
  31. import tuiModal from '@/components/tui-modal/index.vue'
  32. import {
  33. getTableData,
  34. addTableCode,
  35. isTableCode,
  36. changeTable,
  37. getStoreData,
  38. } from '@/api/store.js';
  39. import {
  40. toLogin
  41. } from '@/libs/login.js';
  42. import util from '../../../utils/util.js';
  43. export default {
  44. computed: mapGetters(['isLogin']),
  45. components: {
  46. storeCate1,
  47. tuiModal,
  48. },
  49. mixins: [colors],
  50. data() {
  51. return {
  52. info: {},
  53. number: 0,
  54. inputNumber: '',
  55. popupVisible: -1,
  56. pageVisible: true,
  57. inputFocus: false,
  58. }
  59. },
  60. watch: {
  61. inputNumber(val) {
  62. this.$nextTick(() => {
  63. this.number = Number(val);
  64. this.inputNumber = this.number || '';
  65. });
  66. }
  67. },
  68. onLoad(options) {
  69. if (options.scene) {
  70. options = util.getUrlParams(decodeURIComponent(options.scene));
  71. }
  72. const {
  73. store_id,
  74. qrcode_id
  75. } = options;
  76. this.info = {
  77. ...this.info,
  78. store_id,
  79. qrcode_id
  80. };
  81. },
  82. onShow() {
  83. this.info.tableId = 0;
  84. if (this.isLogin) {
  85. this.getTableData();
  86. } else {
  87. toLogin()
  88. }
  89. },
  90. onHide() {
  91. this.pageVisible = false;
  92. },
  93. methods: {
  94. // 获取桌码配置
  95. getTableData() {
  96. getTableData({
  97. store_id: this.info.store_id
  98. }).then(res => {
  99. let data = res.data;
  100. if (Array.isArray(data)) {
  101. data = {};
  102. }
  103. const {
  104. store_code_switch,
  105. store_number_diners_window
  106. } = data;
  107. this.info = {
  108. ...this.info,
  109. store_number_diners_window
  110. };
  111. // 门店是否开启桌码
  112. if (store_code_switch == 1) {
  113. this.isTableCode(store_number_diners_window);
  114. } else {
  115. this.$util.Tips({
  116. title: '当前门店未开启桌码'
  117. });
  118. }
  119. });
  120. },
  121. // 选择用餐人数
  122. changeNumber(value) {
  123. this.number += value;
  124. },
  125. // 记录桌码
  126. addTableCode(number) {
  127. const {
  128. store_id,
  129. qrcode_id,
  130. tableId: y_tableId
  131. } = this.info;
  132. let data = {
  133. store_id,
  134. qrcode_id
  135. };
  136. if (!number) {
  137. return;
  138. }
  139. data.number = number;
  140. return new Promise((resolve, reject) => {
  141. addTableCode(data).then(res => {
  142. this.info = {
  143. ...this.info,
  144. tableId: res.data.tableId
  145. };
  146. this.getStore();
  147. resolve(y_tableId);
  148. if (number) {
  149. this.popupVisible = 0;
  150. }
  151. }).catch(err => {
  152. reject(y_tableId);
  153. this.$util.Tips({
  154. title: err
  155. });
  156. });
  157. });
  158. },
  159. // 检查桌码记录
  160. isTableCode(store_number_diners_window) {
  161. const {
  162. store_id,
  163. qrcode_id
  164. } = this.info;
  165. isTableCode({
  166. store_id,
  167. qrcode_id
  168. }).then(res => {
  169. const {
  170. code,
  171. tableId
  172. } = res.data;
  173. this.info = {
  174. ...this.info,
  175. tableId
  176. };
  177. // 判断是不是换桌
  178. if (!code) {
  179. return uni.showModal({
  180. title: '确定要换桌吗?',
  181. content: '换桌后,您已点的商品会自动转移到新桌',
  182. success: (res) => {
  183. if (res.confirm) {
  184. this.changeTable();
  185. } else {
  186. this.getStore();
  187. }
  188. }
  189. });
  190. }
  191. // 判断这桌是否记录桌码
  192. if (tableId) {
  193. this.popupVisible = 0;
  194. this.getStore();
  195. } else {
  196. // 是否弹出选择人数弹窗
  197. this.popupVisible = store_number_diners_window == 1 ? 1 : 0;
  198. if (!this.popupVisible) {
  199. this.addTableCode();
  200. }
  201. }
  202. });
  203. },
  204. // 处理换桌商品
  205. async changeTable() {
  206. const y_tableId = await this.addTableCode();
  207. if (!y_tableId) {
  208. return;
  209. }
  210. changeTable({
  211. tableId: this.info.tableId,
  212. y_tableId
  213. }).then(() => {
  214. this.$util.Tips({
  215. title: '换桌完成',
  216. success: this.getStore
  217. });
  218. }).catch(err => {
  219. this.$util.Tips({
  220. title: err
  221. });
  222. });
  223. },
  224. // 获取接口附近门店
  225. getStore() {
  226. getStoreData({
  227. store_id: this.info.store_id
  228. }).then(res => {
  229. this.info = {
  230. ...this.info,
  231. ...res.data
  232. };
  233. this.$refs.refresh2.getAllCategory();
  234. });
  235. },
  236. onNumber(number) {
  237. this.number = number;
  238. },
  239. onFocus() {
  240. this.inputFocus = true;
  241. let inputNumber = this.inputNumber;
  242. this.$nextTick(() => {
  243. this.inputNumber = inputNumber;
  244. })
  245. },
  246. onBlur() {
  247. this.inputFocus = false;
  248. }
  249. },
  250. }
  251. </script>
  252. <style scoped lang="scss">
  253. /deep/.goodCate .uni-badge-left-margin .uni-badge--error {
  254. background-color: #fff !important;
  255. color: var(--view-theme);
  256. border-color: var(--view-theme);
  257. z-index: 8;
  258. }
  259. /deep/.goodCate .footer .cartIcon .uni-badge-left-margin .uni-badge--error {
  260. right: 0 !important;
  261. top: 10px !important;
  262. }
  263. /deep/.mask {
  264. z-index: 102;
  265. }
  266. /deep/.good-cate {
  267. padding: 80rpx;
  268. }
  269. .white {
  270. position: fixed;
  271. top: 0;
  272. right: 0;
  273. bottom: 0;
  274. left: 0;
  275. z-index: 101;
  276. background: #FFFFFF;
  277. }
  278. .popup {
  279. position: fixed;
  280. top: 50%;
  281. left: 50%;
  282. z-index: 103;
  283. width: 644rpx;
  284. padding: 56rpx 52rpx;
  285. border-radius: 32rpx;
  286. background: #FFFFFF;
  287. transform: translate(-50%, -50%);
  288. .title {
  289. text-align: center;
  290. font-weight: 500;
  291. font-size: 32rpx;
  292. line-height: 52rpx;
  293. color: #333333;
  294. }
  295. .passive {
  296. width: 112rpx;
  297. height: 56rpx;
  298. background: #F5F5F5;
  299. text-align: center;
  300. font-family: SemiBold;
  301. font-size: 31rpx;
  302. line-height: 56rpx;
  303. color: #333333;
  304. }
  305. .foot {
  306. margin-top: 64rpx;
  307. .btn {
  308. flex: 1;
  309. height: 80rpx;
  310. border: 0;
  311. border-radius: 40rpx;
  312. background: var(--view-theme);
  313. font-weight: 500;
  314. font-size: 28rpx;
  315. line-height: 80rpx;
  316. color: #FFFFFF;
  317. .inner {
  318. height: 80rpx;
  319. border-radius: 40rpx;
  320. background: transparent;
  321. }
  322. &.disabled {
  323. .inner {
  324. background: rgba(255, 255, 255, 0.5);
  325. }
  326. }
  327. }
  328. }
  329. }
  330. /deep/.cartList {
  331. z-index: 150 !important;
  332. }
  333. .spinner-box {
  334. margin: 48rpx -32rpx -40rpx 0;
  335. .btn {
  336. width: 111rpx;
  337. height: 80rpx;
  338. border-radius: 16rpx;
  339. margin: 0 32rpx 40rpx 0;
  340. background: #F5F5F5;
  341. text-align: center;
  342. font-family: SemiBold;
  343. font-size: 32rpx;
  344. line-height: 80rpx;
  345. color: #999999;
  346. .inner {
  347. width: 111rpx;
  348. height: 80rpx;
  349. border: 2rpx solid transparent;
  350. border-radius: 16rpx;
  351. background-color: transparent;
  352. background-clip: content-box;
  353. }
  354. &.on {
  355. background: var(--view-theme);
  356. color: var(--view-theme);
  357. .inner {
  358. background-color: rgba(255, 255, 255, 0.9);
  359. }
  360. }
  361. }
  362. .input {
  363. width: 254rpx;
  364. height: 80rpx;
  365. border: 2rpx solid #CCCCCC;
  366. border-radius: 16rpx;
  367. text-align: center;
  368. font-family: SemiBold;
  369. font-size: 32rpx;
  370. line-height: 80rpx;
  371. color: #999999;
  372. &.on {
  373. border-color: var(--view-theme);
  374. color: var(--view-theme);
  375. }
  376. }
  377. /deep/.input-placeholder {
  378. font-weight: 500;
  379. font-size: 28rpx;
  380. color: #CCCCCC;
  381. }
  382. }
  383. </style>