index.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. <template>
  2. <block>
  3. <!-- z-paging插件:具体使用文档请看https://z-paging.zxlee.cn/ -->
  4. <z-paging
  5. v-if="!isNeedScan"
  6. auto-show-back-to-top
  7. back-to-top-bottom="300rpx"
  8. :auto="false"
  9. :paging-style="{ paddingBottom: 'constant(safe-area-inset-bottom)', paddingBottom: 'env(safe-area-inset-bottom)' }"
  10. ref="paging"
  11. v-model="dataList"
  12. @query="queryList"
  13. >
  14. <view class="homeIdx o-plr-24">
  15. <view class="l-flex-between o-mt-20">
  16. <view class="l-flex-RC">
  17. <u-icon name="map" class="c-color-8"></u-icon>
  18. <text class="c-color-8 u-line-1">{{ GETT_clientStatus.storeName }}</text>
  19. </view>
  20. <u-icon @click="toScan" name="scan" class="c-color-8" size="28"></u-icon>
  21. </view>
  22. <view class="o-mb-20" style="color: #ce2929;">图片仅供参考,具体以实物为准。</view>
  23. <view class="">
  24. <view class="l-flex-between l-flex-w">
  25. <view v-for="item in dataList" style="width:48%;" class="l-re l-boxShadow o-mb-20 c-bg-f o-plr-10 o-pb-10 o-pt-66 c-radius-10">
  26. <view class="l-flex-center">
  27. <view :style="{'width': GETT_miniProduct.includes(item.imgId) ? '200rpx' : '250rpx', 'height': GETT_miniProduct.includes(item.imgId) ? '200rpx' : '250rpx'}">
  28. <u--image
  29. :width="GETT_miniProduct.includes(item.imgId) ? '200rpx' : '250rpx'"
  30. :height="GETT_miniProduct.includes(item.imgId) ? '200rpx' : '250rpx'"
  31. @click="goodsClick(item)"
  32. mode="aspectFit"
  33. :lazy-load="true"
  34. :fade="true"
  35. duration="450"
  36. :src="item.imgUrl"
  37. >
  38. <view slot="error" style="font-size: 24rpx;">加载失败</view>
  39. </u--image>
  40. </view>
  41. </view>
  42. <view class="">
  43. <view class="o-mtb-10 c-color-8">{{ item.imgName }}</view>
  44. <view class="l-flex-between o-mb-10">
  45. <text class="c-text-12 c-color-MR">¥{{ item.goodsPrice }}</text>
  46. <!-- 如果优惠券总金额大于0,则显示预估到手价 -->
  47. <view v-if="GETT_home_totalCoupon > 0" class="estiPriceCon c-text-12 c-color-f l-flex-RC">
  48. <view class="estiPriceTxt c-text-12 o-ptb-10 o-plr-14">预估到手</view>
  49. <view class="estiPrice c-text-12 o-ptb-10 o-plr-14">¥{{ item.estiPrice }}</view>
  50. </view>
  51. </view>
  52. </view>
  53. <template v-if="item.showType !== 1">
  54. <u-button v-if="getCartGoodsNum(item) === 0" @click="addCart(item)" throttleTime="300" type="primary" shape="circle" size="normal" text="加入购物车"></u-button>
  55. <view v-else style="float: right; height: 40px;">
  56. <u-number-box
  57. @overlimit="
  58. e => {
  59. numsOverlimit(e, item);
  60. }
  61. "
  62. v-model="item.nums"
  63. @change="
  64. e => {
  65. numsChg(e, item);
  66. }
  67. "
  68. disabledInput
  69. @minus="
  70. e => {
  71. goodMinus(e, item);
  72. }
  73. "
  74. @plus="
  75. e => {
  76. goodPlus(e, item);
  77. }
  78. "
  79. ></u-number-box>
  80. </view>
  81. </template>
  82. <view
  83. :style="[headerStyle(item)]"
  84. class="l-ab l-flex-between o-w o-ptb-10 o-plr-10"
  85. style="left: 0;top: 0;
  86. border-top-right-radius: 10rpx;
  87. border-top-left-radius: 10rpx;"
  88. >
  89. <text class="c-text-12">{{ item.flavorName }}</text>
  90. <view class="l-flex-RC">
  91. <image
  92. class="o-mr-6"
  93. v-if="item.flavor.includes(1)"
  94. style="width: 30rpx;height: 30rpx;"
  95. src="/static/images/home/flavor/icon_milk.png"
  96. mode=""
  97. ></image>
  98. <image
  99. class="o-mr-6"
  100. v-if="item.flavor.includes(2)"
  101. style="width: 30rpx;height: 30rpx;"
  102. src="/static/images/home/flavor/icon_strawberry.png"
  103. mode=""
  104. ></image>
  105. <image
  106. class="o-mr-6"
  107. v-if="item.flavor.includes(3)"
  108. style="width: 30rpx;height: 30rpx;"
  109. src="/static/images/home/flavor/icon_orange.png"
  110. mode=""
  111. ></image>
  112. <image
  113. class="o-mr-6"
  114. v-if="item.flavor.includes(4)"
  115. style="width: 30rpx;height: 30rpx;"
  116. src="/static/images/home/flavor/icon_melon.png"
  117. mode=""
  118. ></image>
  119. </view>
  120. </view>
  121. </view>
  122. </view>
  123. </view>
  124. </view>
  125. <template #bottom>
  126. <view v-show="totalNums !== 0" class="l-boxShadow c-bg-f l-flex-between o-plr-24 o-ptb-20" style="width: 100%;height: 100rpx;">
  127. <view @click="toTabCar" class="l-re">
  128. <u-badge absolute :offset="[0, 0]" :value="totalNums"></u-badge>
  129. <u-icon size="40" name="shopping-cart"></u-icon>
  130. </view>
  131. <view class="c-color-1 c-text-16">
  132. 合计:
  133. <text class="c-text-16 c-color-MR">¥{{ totalPrice }}</text>
  134. </view>
  135. <view>
  136. <u-button
  137. v-if="GETT_loginInfos.phone"
  138. @click="toPayPop"
  139. throttleTime="2000"
  140. type="primary"
  141. shape="circle"
  142. size="normal"
  143. :text="`去支付(${totalNums})`"
  144. ></u-button>
  145. <u-button
  146. v-else
  147. open-type="getPhoneNumber"
  148. @getphonenumber="getPhone"
  149. type="primary"
  150. shape="circle"
  151. size="normal"
  152. :text="`去支付(${totalNums})`"
  153. ></u-button>
  154. </view>
  155. </view>
  156. <!-- 底部导航栏-占位符解决上拉刷新没显示加载更多的问题 -->
  157. <k-tabbar :fixed="false" :placeholder="false" :safeAreaInsetBottom="false" />
  158. </template>
  159. </z-paging>
  160. <view class="content-fixed" v-else>
  161. <view style="padding: 0 24rpx;">
  162. <view class="l-flex-between o-mt-20">
  163. <view class="l-flex-RC">
  164. <u-icon name="map" class="c-color-8"></u-icon>
  165. <text class="c-color-8 u-line-1">{{ GETT_clientStatus.storeName }}</text>
  166. </view>
  167. <u-icon @click="toScan" name="scan" class="c-color-8" size="28"></u-icon>
  168. </view>
  169. <view class="o-mb-20" style="color: #ce2929;">图片仅供参考,具体以实物为准。</view>
  170. </view>
  171. <view style="flex-direction: column; flex: 1; justify-content: center;" class="l-flex-between l-flex-w">
  172. <view style="display: flex; flex-direction: column; justify-content: center; align-items: center; flex: 1;">
  173. <img style="width: 200rpx; height: 200rpx;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADIBAMAAABfdrOtAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAbUExURdvc3EdwTMLBwcjIyLSzs/Hx8ff39////19dXXz7IJEAAAAFdFJOU/4A6J9QDyyutAAAB5VJREFUeNrtnM1z4jYYxhUHkR4hdu9eU7Z75Ct7jgPbs9ZZmSuTrUWPmXTA186e+LMrf0u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VyU2/yqFmF2VZGYop3peitdUiQd1pnrL7qTE01tPzE6eaEKm23dQwh2jNlbiay+/245zl94abw45CzNPyqYQ2++kxHGV1crWzg4A2yvR+BY7wziwnRLN7+O36aA54+ZKGjxZYK3txJpxQyUNn5GwtquII4+ACiWtnvawduu1A3SVtH5uhTvAVSpBG7fDYz6RQ+M6JWjmKm6g+RvTla9UMtspu+s+37VbVCupNqPx43CsNawSb1PbtcmDfQWmUILW7rRXSPHtSq5k5ur0a/hb7DQCUiW3G71ejX/wvV1kSoyNbp8Wvyqn1lCIKvl6gNDkNBYzt0GHdr+Pt9xGl1//ncAVcoVcIVfIFXKFXCFXyP8I8i8SyTW4yTz2lwAAAABJRU5ErkJggg=="></img>
  174. <view v-if="!GETT_clientStatus.contactName" style="margin-top: 10rpx;" class="l-flex-between">
  175. <text>请扫机器二维码进行下单噢~</text>
  176. <u-icon @click="toScan" name="scan" class="c-color-8" size="28"></u-icon>
  177. </view>
  178. <view v-else style="margin-top: 10rpx;" class="l-flex-between">
  179. <text>机器已关机,如有需要请联系开机~</text>
  180. <u-icon @click="toPhone" name="phone" class="c-color-8" size="28"></u-icon>
  181. </view>
  182. </view>
  183. <!-- 底部导航栏-占位符解决上拉刷新没显示加载更多的问题 -->
  184. <k-tabbar :fixed="false" :placeholder="false" :safeAreaInsetBottom="false" />
  185. </view>
  186. </view>
  187. <u-modal @confirm="uModalConfirm" @cancel="uModalShow = false" showCancelButton :show="uModalShow" title="提示">
  188. <view class="slot-content"><view class="c-text-c">确定需要删除该商品吗?</view></view>
  189. </u-modal>
  190. <!-- 支付弹窗 -->
  191. <k-payPop ref="kPayPopRef"></k-payPop>
  192. <!-- 支付提示弹窗 -->
  193. <u-modal @confirm="payShow = false" :show="payShow" title="提示" :content="payContent"></u-modal>
  194. <!-- 优惠券弹窗 -->
  195. <k-coupon ref="kCouponRef"></k-coupon>
  196. <!-- 领取优惠券弹窗 -->
  197. <u-overlay :show="coupPopShow">
  198. <view class="coupPopCon l-fixed o-w o-plr-100">
  199. <view class="coupPop l-boxShadow c-radius-10 o-w o-pb-50">
  200. <view class="headerCon o-w c-text-c c-text-b c-text-18 o-ptb-40" style="color: #926135;">送你一张优惠券</view>
  201. <!-- <view v-else class="headerCon o-w c-text-c c-text-b c-text-18 o-ptb-40" style="color: #926135;">你已领取优惠券</view> -->
  202. <view class="o-w c-text-c c-text-12 o-ptb-20" style="color: #926135;">每个用户只可领取一次</view>
  203. <view class="content o-w l-flex-center o-pt-30">
  204. <view class="contentCon c-text-c o-pb-20">
  205. <text class="c-text-40 c-text-b" style="color: #926135;">{{ GETT_home_coupon.split('J')[1] }}</text>
  206. <text class="rmbCls c-text-14 c-color-f o-ptb-10 o-plr-10" style="color: #926135;">元</text>
  207. </view>
  208. </view>
  209. <view class="o-w l-flex-center c-text-12 o-ptb-30" style="color: #926135;">全场商品满0.01元使用</view>
  210. <view class="o-w l-flex-center"><view @click="getCoupon" class="immedCls c-text-c c-color-f o-ptb-20">立即领取</view></view>
  211. </view>
  212. <view class="o-w l-flex-center o-mt-20"><u-icon @click="hideCoupPop" size="26" color="#fff" name="close-circle"></u-icon></view>
  213. </view>
  214. </u-overlay>
  215. <view v-if="showToast" class="l-flex-center l-fixed" style="width: 100vw;height: 100vh;z-index: 9999;">
  216. <view class="c-text-c c-text-16 c-color-f o-ptb-20 o-plr-50" style="background-color: #585858;border-radius: 10rpx;">
  217. <view style="line-height: 26px;">
  218. 此券每人限领一张
  219. </view>
  220. <view style="line-height: 26px;">
  221. 您已领取过,不能再领!
  222. </view>
  223. </view>
  224. </view>
  225. </block>
  226. </template>
  227. <script>
  228. // 导入登录方法
  229. import appLogin from '@/common/login.js';
  230. // 导入优惠券弹窗
  231. import kCoupon from '@/components/common/k-coupon/index.vue';
  232. // 导入支付弹窗
  233. import kPayPop from '@/components/common/k-payPop/index.vue';
  234. // 导入接口
  235. import { API_selectProductList, API_getPhone, API_getOpenid, API_getConpon,API_setDingYue } from '@/common/api.js';
  236. // 引入辅助函数
  237. import { mapGetters } from 'vuex';
  238. // 引入底部导航栏
  239. import kTabbar from '@/components/common/k-tabbar/k-tabbar.vue';
  240. // 引入商品数据
  241. import goodsList from '@/static/images/home/goods.js';
  242. import cartMixins from '@/mixins/cart.js';
  243. export default {
  244. components: {
  245. kTabbar,
  246. kPayPop,
  247. kCoupon
  248. },
  249. data() {
  250. return {
  251. showToast:false,
  252. // 领取优惠券弹窗显示
  253. coupPopShow: false,
  254. // 用来解决单个商品购买联动问题
  255. copyData: [],
  256. // 支付提示弹窗
  257. payShow: false,
  258. payContent: false,
  259. // z-paging插件的主数据,用作列表渲染
  260. dataList: [],
  261. isNeedScan: false,
  262. cssSafeAreaInsetBottom: -1,
  263. // 用来存储要删除的商品
  264. deleteShops: {},
  265. uModalShow: false
  266. };
  267. },
  268. mixins: [cartMixins],
  269. computed: {
  270. // 获取vuex中购物车的数据
  271. // $S_tabbar_shopCarts() {
  272. // return this.$M_GS('common', '$S_tabbar_shopCarts');
  273. // },
  274. // 使用辅助函数
  275. ...mapGetters([
  276. 'GETT_clientStatus',
  277. 'totalNums',
  278. 'totalPrice',
  279. 'isGetUserInfo',
  280. 'GETT_loginInfos',
  281. 'GETT_clientId',
  282. 'GETT_miniProduct',
  283. 'GETT_home_coupon',
  284. 'GETT_home_couponList',
  285. 'GETT_home_totalCoupon',
  286. 'GETT_home_hasReceCoup',
  287. 'GETShopCartsNo'
  288. ]),
  289. headerStyle() {
  290. return function(row) {
  291. let headerSye = {};
  292. switch (row.flavorName) {
  293. case '牛奶味':
  294. headerSye = {
  295. color: '#fff',
  296. backgroundColor: '#c8e5ec'
  297. };
  298. break;
  299. case '草莓味':
  300. headerSye = {
  301. color: '#fe796d',
  302. backgroundColor: '#fff5f4'
  303. };
  304. break;
  305. case '香橙味':
  306. headerSye = {
  307. color: '#fdd08f',
  308. backgroundColor: '#fff5e6'
  309. };
  310. break;
  311. case '蜜瓜味':
  312. headerSye = {
  313. color: '#a3d5f1',
  314. backgroundColor: '#ebf8ff'
  315. };
  316. break;
  317. case '混合口味':
  318. headerSye = {
  319. color: '#ccd77e',
  320. backgroundColor: '#f5f7e5'
  321. };
  322. break;
  323. }
  324. return headerSye;
  325. };
  326. }
  327. },
  328. methods: {
  329. // 点击隐藏优惠券弹窗
  330. hideCoupPop() {
  331. // 储存优惠券(控制弹窗的显示)
  332. this.$M_Cm('MUTA_SETCOUPON', '');
  333. this.coupPopShow = false;
  334. },
  335. // 初始化页面
  336. init(val) {
  337. if (val) {
  338. // 重新刷新页面数据
  339. this.$refs.paging.refresh();
  340. } else {
  341. // 空列表
  342. this.$refs.paging.complete([]);
  343. }
  344. },
  345. // 生成优惠券
  346. async getCoupon() {
  347. // 关闭弹窗
  348. this.coupPopShow = false;
  349. const param = {
  350. wxId: this.GETT_loginInfos.id,
  351. flag: this.GETT_home_coupon
  352. };
  353. const res = await API_getConpon(param, {
  354. catch: true
  355. });
  356. if(res.data === 1){
  357. this.showToast = true;
  358. setTimeout(()=>{
  359. this.showToast = false;
  360. },3000);
  361. }
  362. // 获取优惠券列表
  363. const hasCoupList = await this.$M_Dp('ACTI_SETCOUPONLIST');
  364. if (hasCoupList) {
  365. setTimeout(() => {
  366. // 先清空列表
  367. this.$refs.paging.complete([]);
  368. this.hideCoupPop();
  369. // 重新刷新页面数据
  370. this.$refs.paging.refresh();
  371. }, 200);
  372. }
  373. },
  374. // 点击商品
  375. goodsClick(row) {
  376. let curGoods = {};
  377. if (this.copyData.length > 0) {
  378. this.copyData.forEach(item => {
  379. if (item.imgId === row.imgId) {
  380. curGoods = uni.$u.deepClone(item);
  381. }
  382. });
  383. }
  384. this.$M_Cm('MUTA_SINGSHOPCARTS', curGoods);
  385. this.$M_Go(`/otherPages/home/singleBye/index`);
  386. },
  387. // 获取手机号
  388. async getPhone(e) {
  389. const { code } = e.detail;
  390. // 如果用户点击允许获取手机号
  391. if (!!code) {
  392. let param = {
  393. code,
  394. id: this.GETT_loginInfos.id
  395. };
  396. // 调用获取手机号的接口
  397. let res = await API_getPhone(param);
  398. // 把手机号信息存到vuex里面
  399. await this.$M_Cm('MUTA_GETOPENID', res);
  400. }
  401. this.toPayPop();
  402. },
  403. // 点击支付按钮
  404. toPayPop() {
  405. // 规定支付的商品数量不能超过5
  406. if (this.totalNums > 5) {
  407. this.payContent = '支付商品的数量不能超过5件,请到购物车页面减少数量后,重新支付!!!';
  408. this.payShow = true;
  409. return;
  410. }
  411. //询问是否订阅取餐通知
  412. this.dingyue();
  413. const payParam = {
  414. shopCarts: this.$S_tabbar_shopCarts,
  415. clientId: this.GETT_clientId,
  416. id: this.GETT_loginInfos.id
  417. };
  418. // 如果有优惠券要提醒用户去选择优惠券
  419. if (this.GETT_home_couponList.length > 0) {
  420. uni.showModal({
  421. title: '提示',
  422. confirmText: '去使用',
  423. cancelText: '不使用',
  424. confirmColor: '#3c9cff',
  425. content: `当前可使用优惠券${this.GETT_home_couponList.length}张。`,
  426. success: modelRes => {
  427. if (modelRes.confirm) {
  428. // 打开优惠券弹窗
  429. this.$refs.kCouponRef.popOpen(this.GETT_home_couponList, payParam, 1, this.totalPrice);
  430. } else {
  431. // 显示支付弹窗
  432. this.$refs.kPayPopRef.popOpen(payParam, 1);
  433. }
  434. }
  435. });
  436. } else {
  437. // 显示支付弹窗
  438. this.$refs.kPayPopRef.popOpen(payParam, 1);
  439. }
  440. },
  441. //询问是否订阅取餐通知
  442. dingyue(){
  443. var that = this;
  444. wx.requestSubscribeMessage({
  445. tmplIds: ['NVmdaK4MwygT63ME830pwM6wZt4eufxhBr6jlQ2XXJ4'],
  446. success(res) {
  447. var status = res.NVmdaK4MwygT63ME830pwM6wZt4eufxhBr6jlQ2XXJ4;
  448. if(status=='accept'){
  449. //通知后台该用户订阅了消息
  450. var id = that.GETT_loginInfos.id;
  451. console.log('id=', id);
  452. API_setDingYue( {id:id} ).then(res => {
  453. console.log('res', res);
  454. });
  455. }
  456. console.log('授权成功');
  457. }
  458. })
  459. },
  460. // 方式二、直接下小程序首页扫码的
  461. // 点击扫码图标
  462. toScan() {
  463. // 只允许通过相机扫码
  464. uni.scanCode({
  465. onlyFromCamera: true,
  466. success: async codeRes => {
  467. // 初始化vuxe中优惠券数据
  468. this.$M_Cm('MUTA_SETCOUPON', '');
  469. this.$M_Cm('MUTA_SETCOUPONLIST', []);
  470. // 如果扫的是小程序码
  471. if (codeRes.scanType === 'WX_CODE') {
  472. // 获取到机器码和优惠券
  473. const clientIdAndCoup = codeRes.path.split('=')[1];
  474. // 获取机器码
  475. const clientId = clientIdAndCoup.split('-')[0];
  476. // 获取优惠券
  477. const coupon = clientIdAndCoup.split('-')[1];
  478. // 如果扫描的小程序有机器编码
  479. if (clientId) {
  480. // 登录
  481. const appLoginData = await appLogin({ clientId, flag: coupon }, true);
  482. if (appLoginData) {
  483. // // 重新刷新页面数据
  484. this.isNeedScan = false;
  485. this.$refs.paging.refresh();
  486. } else {
  487. this.tipsDialog();
  488. }
  489. } else {
  490. this.tipsDialog();
  491. }
  492. }
  493. // 如果扫的是二维码
  494. else if (codeRes.scanType === 'QR_CODE') {
  495. let clientId = codeRes.result;
  496. // 如果扫描的小程序有机器编码
  497. if (clientId) {
  498. // 登录
  499. const appLoginData = await appLogin({ clientId, flag: '' }, true);
  500. if (appLoginData) {
  501. // // 重新刷新页面数据
  502. this.isNeedScan = false;
  503. this.$refs.paging.refresh();
  504. } else {
  505. this.tipsDialog();
  506. }
  507. } else {
  508. this.tipsDialog();
  509. }
  510. } else {
  511. // 如果扫描的是其他码,提示用户重新扫码
  512. this.scanCodeDialog();
  513. }
  514. }
  515. });
  516. },
  517. // 扫描小程序码弹窗提示
  518. scanCodeDialog() {
  519. uni.showModal({
  520. title: '提示',
  521. confirmText: '确定',
  522. confirmColor: '#3c9cff',
  523. content: '请扫描机器上的小程序码或二维码!!!',
  524. success: modelRes => {
  525. if (modelRes.confirm) {
  526. // 直接跳转扫码界面
  527. this.toScan();
  528. }
  529. }
  530. });
  531. },
  532. // 联系人弹窗
  533. contactDailog() {
  534. // 如果没有机器编码就提示联系管理员
  535. uni.showModal({
  536. title: '当前设备处于关机状态,请联系机主后重新扫码。',
  537. confirmText: '拨打电话',
  538. confirmColor: '#3c9cff',
  539. content: `联系人:${this.GETT_clientStatus.contactName},联系电话:${this.GETT_clientStatus.contactPhone}`,
  540. success: modelRes => {
  541. if (modelRes.confirm) {
  542. uni.makePhoneCall({
  543. phoneNumber: this.GETT_clientStatus.contactPhone
  544. });
  545. }
  546. }
  547. });
  548. },
  549. // 点击支付按钮
  550. toTabCar() {
  551. this.$M_Dp('ACTI_TABIDX', 1);
  552. },
  553. // 获取小程序个人信息
  554. getUserInfo() {
  555. return new Promise((resolve, reject) => {
  556. uni.getUserProfile({
  557. desc: '用户我的页面展示效果',
  558. success: res => {
  559. if (res.errMsg === 'getUserProfile:ok') {
  560. const { nickName, avatarUrl } = res.userInfo;
  561. let param = {
  562. nickName,
  563. avatarUrl
  564. };
  565. this.$M_Cm('MUTA_AVATARNICK', param);
  566. resolve(true);
  567. } else {
  568. resolve(false);
  569. }
  570. },
  571. fail: err => {
  572. resolve(false);
  573. }
  574. });
  575. });
  576. },
  577. // 点击加入购物车
  578. async addCart(row) {
  579. // 增加用户体验
  580. uni.showLoading({
  581. title: '请稍等',
  582. mask: true,
  583. });
  584. setTimeout(() => {
  585. uni.hideLoading();
  586. }, 200);
  587. // 看有vuex没有小程序个人信息,没有调用微信接口获取
  588. let isGetUserInfo = true;
  589. if (!this.isGetUserInfo) {
  590. isGetUserInfo = await this.getUserInfo();
  591. }
  592. if (!isGetUserInfo) {
  593. return;
  594. }
  595. // 加入购物车初始状态都是选中状态
  596. row['isCheck'] = true;
  597. // 获取vuxe购物车数据
  598. let shopCarts = this.$S_tabbar_shopCarts;
  599. // 如果不存在imgId这个属性,则创建
  600. if (!shopCarts[row['imgId']]) {
  601. // 给优惠码和优惠价的列表添加一个0值
  602. row.codeList.push(0);
  603. row.discountList.push(0);
  604. // 用$M_Extend继承row创建新对象并赋值给shopCarts的属性
  605. shopCarts[row['imgId']] = this.$M_Extend(row, {
  606. nums: 1
  607. });
  608. } else {
  609. // 如果存在imgId这个属性,则数量+1,总数totalPrice=价格goodsPrice*数量nums
  610. let nums = shopCarts[row['imgId']]['nums'] + 1;
  611. // $M_Big用来计算总数量的方法(具体用法请看common)
  612. row['totalPrice'] = this.$M_Big(row['goodsPrice'])
  613. .mul(nums)
  614. .toNumber();
  615. // 给优惠码和优惠价的列表添加一个0值
  616. row.codeList.push(0);
  617. row.discountList.push(0);
  618. shopCarts[row['imgId']] = this.$M_Extend(row, {
  619. nums
  620. });
  621. }
  622. // 修改vuex购物车数据
  623. this.$M_Dp('ACTI_SHOPCARTS', shopCarts);
  624. },
  625. // z-paging插件分页的方法
  626. async queryList(pageNo, pageSize) {
  627. // 如果是关机状态
  628. if (!this.GETT_clientStatus.startStatus) {
  629. this.$refs.paging.complete([]);
  630. this.tipsDialog();
  631. return;
  632. }
  633. // 如果存在优惠券要弹出优惠券窗口
  634. if (!!this.GETT_home_coupon) {
  635. this.coupPopShow = true;
  636. }
  637. let param = {
  638. clientId: this.GETT_clientId,
  639. size: pageSize,
  640. current: pageNo
  641. };
  642. // 发起获取商品类表请求
  643. API_selectProductList(param).then(res => {
  644. const { records } = res;
  645. if (records.length > 0) {
  646. goodsList.forEach(item => {
  647. records.forEach(item1 => {
  648. // 给前台数据赋值接口数组
  649. if (item1.no === item.imgId) {
  650. // 商品id
  651. item1.imgId = item.imgId;
  652. // 商品名字
  653. item1.imgName = item.imgName;
  654. // 商品图片
  655. item1.imgUrl = item.imgUrl;
  656. // 单价
  657. item1.goodsPrice = item1.rmbPrice;
  658. // 总价格
  659. item1.totalPrice = item1.rmbPrice;
  660. // 购物车对应商品是否选中
  661. item1.isCheck = true;
  662. // 优惠码
  663. item1.codeList = [];
  664. // 优惠价格
  665. item1.discountList = [];
  666. // 商品口味
  667. item1.flavorName = item.flavorName;
  668. item1.flavor = item.flavor;
  669. // 商品数量
  670. item1.nums = 1;
  671. }
  672. // 根据优惠券总数,计算出每件商品的预估到手价
  673. if (this.GETT_home_totalCoupon > 0) {
  674. // 预估到手价
  675. const estiPrice = this.$M_Big(item1.rmbPrice)
  676. .sub(this.GETT_home_totalCoupon)
  677. .toNumber();
  678. // 预估到手价最低也只能是0
  679. if (estiPrice <= 0) {
  680. item1.estiPrice = 0.01;
  681. } else {
  682. item1.estiPrice = estiPrice;
  683. }
  684. }
  685. });
  686. });
  687. // 改为ES6合并
  688. // var data = this.copyData;
  689. // for(var i=0;i<records.length;i++){
  690. // data.push(records[i]);
  691. // }
  692. // this.copyData = data;
  693. this.copyData = this.copyData.concat(records)
  694. this.$refs.paging.completeByTotal(records, res.total);
  695. }
  696. // this.$refs.paging.complete(records);
  697. // this.copyData = uni.$u.deepClone(records);
  698. });
  699. },
  700. tipsDialog() {
  701. // 如果是扫码进来的肯定会有机器的联系方式
  702. if (this.GETT_clientStatus.contactName) {
  703. // 并且弹窗
  704. this.contactDailog();
  705. this.isNeedScan = true;
  706. } else {
  707. // 如果没有用户信息,提示用户重新扫码
  708. // this.scanCodeDialog();
  709. // 用户如果误操作或者内存被清除导致小程序退出,则重新进入还会弹窗
  710. this.isNeedScan = true;
  711. }
  712. },
  713. getCartGoodsNum(item) {
  714. return this.GETShopCartsNo[item['no']] || 0;
  715. },
  716. toPhone() {
  717. uni.makePhoneCall({
  718. phoneNumber: this.GETT_clientStatus.contactPhone
  719. });
  720. }
  721. }
  722. };
  723. </script>
  724. <style lang="scss" scoped>
  725. .homeIdx {
  726. .estiPriceCon {
  727. .estiPriceTxt {
  728. position: relative;
  729. color: #ff9900;
  730. background-color: #fff5f4;
  731. border-right: 1px solid #fff;
  732. }
  733. .estiPrice {
  734. background-color: #f15c34;
  735. border-top-right-radius: 10rpx;
  736. border-bottom-right-radius: 10rpx;
  737. }
  738. }
  739. }
  740. .coupPopCon {
  741. left: 0;
  742. top: 10vh;
  743. height: 100vh;
  744. z-index: 10071;
  745. .coupPop {
  746. background-color: #ffedd8;
  747. .headerCon {
  748. border-bottom: 2rpx dashed #d59035;
  749. }
  750. .content {
  751. .contentCon {
  752. width: 60%;
  753. border-bottom: 2rpx solid #d59035;
  754. .rmbCls {
  755. // background-color: #926135;
  756. border-radius: 50%;
  757. }
  758. }
  759. }
  760. .immedCls {
  761. width: 60%;
  762. background-color: #ff4b4a;
  763. border-radius: 40rpx;
  764. }
  765. }
  766. }
  767. .inset-bottom {
  768. position: absolute;
  769. /* #ifndef APP-PLUS */
  770. height: env(safe-area-inset-bottom);
  771. /* #endif */
  772. }
  773. .content-fixed {
  774. display: flex;
  775. flex-direction: column;
  776. position: fixed;
  777. height: auto;
  778. width: auto;
  779. top: 0;
  780. left: 0;
  781. bottom: 0;
  782. right: 0;
  783. /* #ifndef APP-PLUS */
  784. padding-bottom: env(safe-area-inset-bottom);
  785. /* #endif */
  786. font-size: 26rpx;
  787. color: #aaaaaa;
  788. }
  789. </style>