index.vue 7.2 KB

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