index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <!-- 商品分类 -->
  3. <view :style="colorStyle">
  4. <!-- 门店的两种样式布局 -->
  5. <storeCate1 :info="info" :isFooter="isFooter" :pageVisible="pageVisible" ref="refresh2">
  6. </storeCate1>
  7. <pageFooter @newDataStatus="newDataStatus"></pageFooter>
  8. <template v-if="popupVisible">
  9. <view class="white"></view>
  10. <view class="mask"></view>
  11. <view class="popup">
  12. <view class="body">
  13. <view class="title">请选择用餐人数</view>
  14. <view class="spinner">
  15. <button :class="{ disabled: number == 1 }" :disabled="number == 1" class="btn" hover-class="none" @tap="changeNumber(-1)">
  16. <text class="iconfont icon-shangpinshuliang-jian"></text>
  17. </button>
  18. <view class="passive">{{ number }}</view>
  19. <button class="btn" hover-class="none" @tap="changeNumber(1)">
  20. <text class="iconfont icon-shangpinshuliang-jia"></text>
  21. </button>
  22. </view>
  23. </view>
  24. <view class="foot">
  25. <button class="btn" hover-class="none" @tap="addTableCode(number)">提交</button>
  26. </view>
  27. </view>
  28. </template>
  29. <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. mapGetters
  35. } from 'vuex';
  36. import colors from "@/mixins/color";
  37. import storeCate1 from './cart.vue'
  38. import pageFooter from '@/components/pageFooter/index.vue'
  39. import {
  40. colorChange
  41. } from '@/api/api.js';
  42. import {
  43. getTableData,
  44. addTableCode,
  45. isTableCode,
  46. changeTable,
  47. getStoreData,
  48. } from '@/api/store.js';
  49. import util from '../../../utils/util.js';
  50. export default {
  51. computed: mapGetters(['isLogin', 'uid']),
  52. components: {
  53. storeCate1,
  54. pageFooter
  55. },
  56. mixins: [colors],
  57. data() {
  58. return {
  59. info: {},
  60. id: 0,
  61. isFooter: false,
  62. category: '',
  63. customerType: 1,
  64. cart_num: 0,
  65. number: 1,
  66. popupVisible: false,
  67. pageVisible: true,
  68. isShowAuth: false,
  69. }
  70. },
  71. onLoad(options) {
  72. if (options.scene) {
  73. options = util.getUrlParams(decodeURIComponent(options.scene));
  74. }
  75. const { store_id, qrcode_id } = options;
  76. this.info = { ...this.info, store_id, qrcode_id };
  77. },
  78. onShow() {
  79. this.info.tableId = 0;
  80. if (this.isLogin) {
  81. this.getTableData();
  82. } else {
  83. this.isShowAuth = true;
  84. }
  85. },
  86. onHide() {
  87. this.pageVisible = false;
  88. },
  89. methods: {
  90. // 授权关闭
  91. authColse: function(e) {
  92. this.isShowAuth = e
  93. },
  94. // 授权回调
  95. onLoadFun() {
  96. this.isShowAuth = false;
  97. this.getTableData();
  98. },
  99. // 获取桌码配置
  100. getTableData() {
  101. getTableData({
  102. store_id: this.info.store_id
  103. }).then(res => {
  104. let data = res.data;
  105. if (Array.isArray(data)) {
  106. data = {};
  107. }
  108. const { store_code_switch, store_number_diners_window } = data;
  109. // 门店是否开启桌码
  110. if (store_code_switch == 1) {
  111. this.isTableCode(store_number_diners_window);
  112. } else{
  113. this.$util.Tips({
  114. title: '当前门店未开启桌码'
  115. });
  116. }
  117. });
  118. },
  119. // 选择用餐人数
  120. changeNumber(value) {
  121. this.number += value;
  122. },
  123. // 记录桌码
  124. addTableCode(number) {
  125. const { store_id, qrcode_id, tableId: y_tableId } = this.info;
  126. let data = { store_id, qrcode_id };
  127. if (number) {
  128. data.number = number;
  129. }
  130. return new Promise((resolve, reject) => {
  131. addTableCode(data).then(res => {
  132. this.info = { ...this.info, tableId: res.data.tableId };
  133. this.getStore();
  134. resolve(y_tableId);
  135. if (number) {
  136. this.popupVisible = false;
  137. }
  138. }).catch(err => {
  139. reject(y_tableId);
  140. this.$util.Tips({
  141. title: err
  142. });
  143. });
  144. });
  145. },
  146. // 检查桌码记录
  147. isTableCode(store_number_diners_window) {
  148. const { store_id, qrcode_id } = this.info;
  149. isTableCode({ store_id, qrcode_id }).then(res => {
  150. const { code, tableId } = res.data;
  151. this.info = { ...this.info, tableId };
  152. // 判断是不是换桌
  153. if (!code) {
  154. return uni.showModal({
  155. title: '确定要换桌吗?',
  156. content: '换桌后,您已点的商品会自动转移到新桌',
  157. success: (res) => {
  158. if (res.confirm) {
  159. this.changeTable();
  160. } else{
  161. this.getStore();
  162. }
  163. }
  164. });
  165. }
  166. // 判断这桌是否记录桌码
  167. if (tableId) {
  168. this.getStore();
  169. } else{
  170. // 是否弹出选择人数弹窗
  171. this.popupVisible = store_number_diners_window == 1;
  172. if (!this.popupVisible) {
  173. this.addTableCode();
  174. }
  175. }
  176. });
  177. },
  178. // 处理换桌商品
  179. async changeTable() {
  180. const y_tableId = await this.addTableCode();
  181. if (!y_tableId) {
  182. return;
  183. }
  184. changeTable({
  185. tableId: this.info.tableId,
  186. y_tableId
  187. }).then(() => {
  188. this.$util.Tips({
  189. title: '换桌完成',
  190. success: this.getStore
  191. });
  192. }).catch(err => {
  193. this.$util.Tips({
  194. title: err
  195. });
  196. });
  197. },
  198. // 获取接口附近门店
  199. getStore() {
  200. getStoreData({
  201. store_id: this.info.store_id
  202. }).then(res => {
  203. this.info = {
  204. ...this.info,
  205. ...res.data
  206. };
  207. this.$refs.refresh2.getMarTop();
  208. this.$refs.refresh2.getAllCategory();
  209. });
  210. },
  211. newDataStatus(val) {
  212. this.isFooter = val;
  213. },
  214. },
  215. onReachBottom: function() {
  216. setTimeout(() => {
  217. this.$refs.refresh2.getProducts()
  218. }, 10)
  219. }
  220. }
  221. </script>
  222. <style scoped lang="scss">
  223. /deep/.goodCate .uni-badge-left-margin .uni-badge--error{
  224. background-color: #fff !important;
  225. color: var(--view-theme);
  226. border-color: var(--view-theme);
  227. z-index: 8;
  228. }
  229. /deep/.goodCate .footer .cartIcon .uni-badge-left-margin .uni-badge--error{
  230. right: 0 !important;
  231. top: 10px !important;
  232. }
  233. /deep/.mask {
  234. z-index: 99;
  235. }
  236. /deep/.good-cate {
  237. padding: 80rpx;
  238. }
  239. .white {
  240. position: fixed;
  241. top: 0;
  242. right: 0;
  243. bottom: 0;
  244. left: 0;
  245. z-index: 100;
  246. background-color: #FFFFFF;
  247. }
  248. .mask {
  249. z-index: 100;
  250. }
  251. .popup {
  252. position: fixed;
  253. top: 50%;
  254. left: 50%;
  255. z-index: 100;
  256. width: 600rpx;
  257. border-radius: 16rpx;
  258. background-color: #FFFFFF;
  259. transform: translate(-50%, -50%);
  260. .body {
  261. padding: 52rpx 0;
  262. }
  263. .title {
  264. display: flex;
  265. justify-content: center;
  266. align-items: center;
  267. font-weight: 500;
  268. font-size: 34rpx;
  269. color: #282828;
  270. }
  271. .spinner {
  272. display: flex;
  273. justify-content: center;
  274. align-items: center;
  275. margin-top: 46rpx;
  276. .btn {
  277. background-color: transparent;
  278. .iconfont {
  279. display: inline-block;
  280. vertical-align: middle;
  281. text-align: center;
  282. line-height: 56rpx;
  283. width: 56rpx;
  284. height: 56rpx;
  285. border-radius: 28rpx;
  286. background-color: var(--view-theme);
  287. font-size: 22rpx;
  288. color: #FFFFFF;
  289. }
  290. &.disabled {
  291. .iconfont {
  292. background-color: #F5F5F5;
  293. color: #000000;
  294. }
  295. }
  296. }
  297. }
  298. .passive {
  299. display: flex;
  300. justify-content: center;
  301. align-items: center;
  302. width: 98rpx;
  303. font-weight: 600;
  304. font-size: 36rpx;
  305. color: #000000;
  306. }
  307. .foot {
  308. display: flex;
  309. height: 98rpx;
  310. border-top: 1rpx solid #EEEEEE;
  311. .btn {
  312. flex: 1;
  313. display: flex;
  314. justify-content: center;
  315. align-items: center;
  316. font-size: 30rpx;
  317. color: var(--view-theme);
  318. }
  319. }
  320. }
  321. </style>