new-menu.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  1. <template>
  2. <view class="menu-box box-border-box align-items-flex-start">
  3. <view class="menu-box-left" :style="{top: newNavHeight + 'rpx'}">
  4. <view class="menu-box-left-box" :style="{height: menuLeftType?`calc(100vh - ${newNavHeight}rpx - ${68}rpx)`:''}">
  5. <view class="menu-type-list fs-26 box-border-box align-items-center flex-justify-center"
  6. v-for="(item,i) in categoryData" :key="i" @click="selectType(item)"
  7. :class="type === item.type?'bgc-f fc-3 fw-600':'fc-6 fw-400'" :id="'scroll'+ item.type">
  8. {{item.name}}
  9. <view class="menu-type-num fc-f" v-show="item.num > 0">{{item.num > 99?'99+':item.num}}</view>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="menu-box-only">
  14. <view class="" v-for="(item,i) in categoryData" :key="i" :id="'scroll'+ item.type">
  15. <view class="fs-28 fw-600 fc-3 sticky-nav bgc-f p-20 box-border-box" :style="{top: newNavHeight + 'rpx'}">
  16. {{item.name}}
  17. </view>
  18. <view class="menu-list flex-justify-space box-border-box" v-for="(info,k) in item.list" :key="k"
  19. :id="'goods_id'+ info.goods_id">
  20. <image class="flex-shrink0 goods_img" :src="info.goods_image" mode="scaleToFill"></image>
  21. <view class="menu-list-right flex-direction flex-justify-space">
  22. <view class="mb-8">
  23. <view class="mb-4 goods-name text-overflow-ellipsis fs-32 fw-600">{{info.goods_name}}
  24. </view>
  25. <view class="text-overflow-ellipsis-one fw-400 fc-9 fs-24 mb-2 goods-name" v-if="info.spec_type == 1">
  26. {{info.goods_desc?info.goods_desc:''}}
  27. </view>
  28. <view class="fw-400 fc-9 fs-24">月销{{info.sales}}</view>
  29. </view>
  30. <view class="flex-justify-space align-items-flex-end">
  31. <view class="">
  32. <span class="fs-24 fw-400 fc-FB3D03">¥</span>
  33. <span class="fs-40 fw-b fc-FB3D03">{{info.seckill_money>0?info.seckill_money:info.price}}</span>
  34. </view>
  35. <view class="display-flex align-items-center" v-if="info.spec_type == 1">
  36. <image v-show="info.num > 0" class="wh-44" @click="addred(1,i,k,info)" src="@/static/img/takeout/j.png"
  37. mode=""></image>
  38. <view v-show="info.num > 0" class="right-only-right-2 text-align-center fs-28 fw-400">{{info.num}}
  39. </view>
  40. <image class="wh-44" src="@/static/img/takeout/add.png" @click="addred(2,i,k,info)" mode=""></image>
  41. </view>
  42. <view v-else class="right-only-right text-align-center" @click="addred(3,i,k,info)">
  43. <view class="fw-600 fs-28 fc-f">
  44. 选规格
  45. </view>
  46. <view class="selectedNum" v-if="info.num>0">
  47. {{info.num}}
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import tools from "@/service/tools";
  59. import {
  60. shopCategory,
  61. shopGoods,
  62. shopGoodsSpec
  63. } from "@/api/shop";
  64. import {
  65. shoppingSave,
  66. getShopIngList,
  67. setShopIngAdd,
  68. setShopIngDel,
  69. setShopIngNumber
  70. } from "@/api/shopping";
  71. export default {
  72. name: 'menu-box',
  73. props: {
  74. 'shop_id': {
  75. default: 0
  76. },
  77. 'newNavHeight': {
  78. default: 0
  79. },
  80. 'menuLeftType': {
  81. default: false
  82. }
  83. },
  84. data() {
  85. return {
  86. idMark: '', //滚动自适应参数
  87. idMarkTwo: '', //滚动自适应参数
  88. type: 0, //分类标识
  89. typeList: [],
  90. categoryData: [{
  91. type: 0,
  92. name: '测试1',
  93. list: [{
  94. goods_id: 1,
  95. goods_name: '测试商品1-1',
  96. price: '10',
  97. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  98. }, {
  99. goods_id: 2,
  100. goods_name: '测试商品1-2',
  101. price: '10',
  102. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  103. }, {
  104. goods_id: 3,
  105. goods_name: '测试商品1-3',
  106. price: '10',
  107. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  108. }]
  109. }, {
  110. type: 1,
  111. name: '测试2',
  112. list: [{
  113. goods_id: 4,
  114. goods_name: '测试商品2-1',
  115. price: '10',
  116. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  117. }, {
  118. goods_id: 5,
  119. goods_name: '测试商品2-2',
  120. price: '10',
  121. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  122. }, {
  123. goods_id: 6,
  124. goods_name: '测试商品2-3',
  125. price: '10',
  126. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  127. }]
  128. }, {
  129. type: 2,
  130. name: '测试3',
  131. list: [{
  132. goods_id: 7,
  133. goods_name: '测试商品3',
  134. price: '10',
  135. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  136. }]
  137. }, {
  138. type: 3,
  139. name: '测试4',
  140. list: [{
  141. goods_id: 8,
  142. goods_name: '测试商品4',
  143. price: '10',
  144. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  145. }]
  146. }, {
  147. type: 4,
  148. name: '测试5',
  149. list: [{
  150. goods_id: 9,
  151. goods_name: '测试商品5',
  152. price: '10',
  153. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  154. }]
  155. },
  156. {
  157. type: 5,
  158. name: '测试6',
  159. list: [{
  160. goods_id: 10,
  161. goods_name: '测试商品6',
  162. price: '10',
  163. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  164. }]
  165. },
  166. {
  167. type: 6,
  168. name: '测试7',
  169. list: [{
  170. goods_id: 11,
  171. goods_name: '测试商品7',
  172. price: '10',
  173. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  174. }]
  175. },
  176. {
  177. type: 7,
  178. name: '测试8',
  179. list: [{
  180. goods_id: 12,
  181. goods_name: '测试商品8',
  182. price: '10',
  183. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  184. }]
  185. },
  186. {
  187. type: 8,
  188. name: '测试9',
  189. list: [{
  190. goods_id: 13,
  191. goods_name: '测试商品9',
  192. price: '10',
  193. goods_image: 'https://qcloud.dpfile.com/pc/JvY4fMzO0Km80S9Sn-tNxYin28jkvrNMJV-pUo8YwCctS4AHLKPXFhGyuI2dCwk8.jpg'
  194. }]
  195. },
  196. ],
  197. menuList: [],
  198. cartData: {
  199. total_price: 0,
  200. total_num: 0,
  201. total_goods_money: 0,
  202. pack_price: 0,
  203. must_category: 0,
  204. is_place_order: 0,
  205. err_msg: 0,
  206. goods_list: [],
  207. },
  208. isAjax: false,
  209. operate_id: '',
  210. popData: {
  211. goodsItem: {},
  212. price: '0.00',
  213. line_price: '',
  214. num: 0,
  215. goods_id: '',
  216. is_quota: 0,
  217. is_infinite: 0,
  218. quota_num: 0,
  219. payNum: 0,
  220. stock: 0,
  221. spec_key: '',
  222. goods_spec_id: '',
  223. spec_name: [],
  224. spec_ids: [],
  225. spec_list: [],
  226. spec_attr: [],
  227. },
  228. selectedNum: 1,
  229. selectedSpecification: [],
  230. scrollType: true
  231. }
  232. },
  233. watch: {},
  234. mounted() {},
  235. methods: {
  236. setSpecNum(type) {
  237. // this.popData.spec_ids
  238. if (!this.popData.spec_key) {
  239. console.log('被阻挡');
  240. tools.error('请选择规格')
  241. return;
  242. }
  243. if (type === 1) {
  244. // 减
  245. console.log('减');
  246. if (this.popData.num > 1) {
  247. --this.popData.num;
  248. this.$forceUpdate()
  249. } else {
  250. this.isAjax = false
  251. }
  252. } else {
  253. console.log('加');
  254. if (this.popData.is_infinite === 0 && this.popData.payNum > this.popData.stock) {
  255. console.log('加1');
  256. tools.error('商品库存' + this.popData.stock + '件')
  257. } else if (this.popData.is_quota > 0 && this.popData.payNum > this.popData.quota_num) {
  258. console.log('加2');
  259. tools.error('限购' + this.popData.quota_num + '件')
  260. } else {
  261. // 加
  262. console.log('加3');
  263. ++this.popData.num;
  264. this.$forceUpdate()
  265. }
  266. }
  267. },
  268. getShopGoodsSpec(item) {
  269. console.log(item, this.cartData, 'item');
  270. shopGoodsSpec({
  271. 'goods_id': item.goods_id
  272. }).then(res => {
  273. console.log(item, 'item');
  274. this.popData.goodsItem = item
  275. if (this.popData.goods_id !== item.goods_id) {
  276. this.popData.goods_id = item.goods_id
  277. this.popData.spec_name = []
  278. // this.popData.price = '0.00'
  279. this.popData.price = item.price
  280. this.popData.line_price = ''
  281. this.popData.spec_key = ''
  282. this.popData.num = 1
  283. this.popData.spec_ids = []
  284. console.log(this.popData, '走if');
  285. this.$forceUpdate()
  286. } else {
  287. console.log(this.popData, '无');
  288. this.popData.num = 1;
  289. // this.popData.price = item.price
  290. if (this.cartData.goods_list.length > 0) {
  291. this.cartData.goods_list.forEach(item => {
  292. if (item.goods_spec_id === this.popData.spec_key) {
  293. // this.popData.num = this.selectedSpecification.goods_number
  294. this.popData.num = this.popData.payNum
  295. console.log(this.popData, '走else');
  296. this.$forceUpdate()
  297. }
  298. })
  299. }
  300. }
  301. this.popData.spec_list = res.data
  302. this.popData.spec_attr = res.data
  303. console.log(this.selectedSpecification, 'this.selectedSpecification');
  304. this.selectedSpecification.forEach((v, k) => {
  305. if (v.goods_id === item.goods_id) {
  306. v.goodsItem = item
  307. v.spec_list = res.data
  308. v.spec_attr = res.data
  309. v.num = v.goods_number
  310. let data = JSON.parse(JSON.stringify(v))
  311. this.popData = data
  312. }
  313. })
  314. console.log(this.popData, 'this.popData');
  315. this.$refs.popupGG.open();
  316. this.setGoodsSpecPrice()
  317. this.isAjax = false
  318. }).catch(() => {
  319. tools.error('规格信息异常')
  320. this.isAjax = false
  321. })
  322. },
  323. setGoodsSpecPrice() {
  324. console.log(this.popData.spec_ids)
  325. if (this.popData.spec_ids.length > 0) {
  326. let spec_ids = JSON.parse(JSON.stringify(this.popData.spec_ids))
  327. spec_ids.sort((a, b) => a - b);
  328. let spec_key = spec_ids.join('_')
  329. this.popData.spec_key = spec_key
  330. } else {
  331. this.popData.num = 1
  332. this.popData.goods_spec_id = ''
  333. }
  334. },
  335. setShopIngList(cartData) {
  336. this.cartData = cartData
  337. this.selectedSpecification = []
  338. this.setGoodsNum()
  339. },
  340. getShopIngList(isStart) {
  341. getShopIngList({
  342. 'shop_id': this.shop_id,
  343. }).then(res => {
  344. if (res.code === 1) {
  345. this.cartData = res.data
  346. let data = res.data
  347. data.goods_list.forEach((v, k) => {
  348. let ge = JSON.parse(JSON.stringify(v))
  349. ge.spec_ids = ge.goods_spec_id.split('_').map(item => Number(item.trim()))
  350. ge.spec_name = ge.goods_attr.split(',').map(item => item.trim())
  351. this.selectedSpecification.push(ge)
  352. })
  353. console.log(this.selectedSpecification, '初始回显已选数据');
  354. this.$emit('setCartData', this.cartData)
  355. this.setGoodsNum()
  356. }
  357. })
  358. },
  359. setGoodsNum() {
  360. if (this.cartData.goods_list.length > 0) {
  361. let goodsIds = []
  362. this.categoryData.forEach(categoryItem => {
  363. categoryItem.list.forEach(goodsItem => {
  364. goodsItem.num = 0
  365. this.cartData.goods_list.forEach(item => {
  366. if (item.goods_id === goodsItem.goods_id) {
  367. if (goodsIds.indexOf(item.goods_id) < 0) {
  368. goodsIds.push(item.goods_id)
  369. goodsItem.num = item.goods_number * 1
  370. } else {
  371. goodsItem.num += item.goods_number * 1
  372. }
  373. }
  374. })
  375. })
  376. })
  377. } else {
  378. //购物车数据清除
  379. this.categoryData.forEach(categoryItem => {
  380. categoryItem.list.forEach(goodsItem => {
  381. goodsItem.num = 0
  382. })
  383. })
  384. }
  385. },
  386. getShopGoods() {
  387. if (this.shop_id < 0 || !this.operate_id) {
  388. return;
  389. }
  390. shopGoods({
  391. 'shop_id': this.shop_id,
  392. operate_id: this.operate_id,
  393. }).then(res => {
  394. if (res.code === 1) {
  395. this.categoryData = res.data
  396. const category_id = uni.getStorageSync('category_id')
  397. const goods_id = uni.getStorageSync('goods_id')
  398. if (category_id.type && category_id.type != 'undefined') {
  399. this.selectType(category_id, goods_id)
  400. } else {
  401. this.selectType(this.categoryData[0])
  402. }
  403. this.categoryData.forEach(categoryItem => {
  404. categoryItem.list.forEach(goodsItem => {
  405. goodsItem.payNum = 0
  406. goodsItem.spec = []
  407. })
  408. })
  409. setTimeout(() => {
  410. this.setGoodsNum()
  411. }, 1000)
  412. }
  413. })
  414. },
  415. selectType(item, itemTwo) {
  416. if (this.type != item.type) {
  417. this.type = item.type;
  418. this.idMark = 'scroll' + item.type
  419. // 触发事件通知父组件需要滚动
  420. this.$emit('scrollToCategory', {
  421. type: item.type,
  422. selector: `#scroll${item.type}`
  423. });
  424. this.$forceUpdate()
  425. }
  426. },
  427. menuScroll(e) {
  428. let _this = this;
  429. let query = uni.createSelectorQuery().in(this);
  430. const goods_id = uni.getStorageSync('goods_id')
  431. if (goods_id.goodsId && goods_id.goodsId != 'undefined') {
  432. query.selectAll(".menu-list").boundingClientRect(data => {
  433. data.forEach((v) => {
  434. if (data[this.categoryData.length - 1].top <= 392) {
  435. return
  436. }
  437. if (v.top < 332 && v.top > 0) {
  438. // _this.idMark = v.id;
  439. let arr = v.id.split('scroll');
  440. }
  441. })
  442. uni.setStorageSync('category_id', '')
  443. uni.setStorageSync('goods_id', '')
  444. }).exec();
  445. } else {
  446. query.selectAll(".menu-box-only").boundingClientRect(data => {
  447. data.forEach((v) => {
  448. if (data[this.categoryData.length - 1].top <= 392) {
  449. return
  450. }
  451. if (v.top < 332 && v.top > 0) {
  452. // _this.idMark = v.id;
  453. let arr = v.id.split('scroll');
  454. _this.type = Number(arr[1]);
  455. }
  456. this.$forceUpdate()
  457. })
  458. }).exec();
  459. }
  460. },
  461. addred(type, i, k, item) {
  462. if (this.isAjax) {
  463. return
  464. }
  465. this.isAjax = true
  466. if (type === 1) {
  467. // 减
  468. --item.num;
  469. if (item.num >= 0) {
  470. this.addShoppingSave(item, item.num, type)
  471. } else {
  472. this.isAjax = false
  473. }
  474. } else if (type === 2) {
  475. // 加
  476. ++item.num;
  477. if (item.is_infinite === 0 && item.num > item.stock) {
  478. tools.error('商品库存' + item.stock + '件')
  479. --item.num
  480. this.isAjax = false
  481. } else if (item.is_quota > 0 && item.num > item.quota_num) {
  482. tools.error('限购' + item.quota_num + '件')
  483. --item.num
  484. this.isAjax = false
  485. } else {
  486. this.addShoppingSave(item, item.num, type)
  487. }
  488. } else if (type === 3) {
  489. // 选规格
  490. console.log(item, '000000000')
  491. console.log(this.selectedSpecification, '1111111111111');
  492. this.selectedSpecification.forEach((v, k) => {
  493. if (v.goods_id === item.goods_id) {
  494. v.quota_num = item.quota_num
  495. v.payNum = item.num
  496. v.stock = item.stock
  497. }
  498. })
  499. this.popData.is_quota = item.is_quota
  500. this.popData.quota_num = item.quota_num
  501. this.popData.is_infinite = item.is_infinite
  502. this.popData.payNum = item.num
  503. this.popData.stock = item.stock
  504. this.getShopGoodsSpec(item)
  505. } else {
  506. let data = JSON.parse(JSON.stringify(this.popData))
  507. this.selectedSpecification.push(data)
  508. console.log(this.popData, "666666666666666666")
  509. console.log('1', this.popData.goods_id, this.shop_id, this.popData.goodsItem.category_id, this.popData
  510. .spec_key, this.popData.num);
  511. this.setShoppingSave()
  512. this.isAjax = false
  513. }
  514. },
  515. addShoppingSave(item, num, type) {
  516. shoppingSave({
  517. type: 1,
  518. goods_id: item.goods_id,
  519. shop_id: this.shop_id,
  520. category_id: item.category_id,
  521. goods_spec_id: '',
  522. number: num
  523. }).then((res) => {
  524. if (res.code === 1) {
  525. if (type === 1) {
  526. tools.success('操作成功')
  527. } else {
  528. tools.success(res.msg)
  529. }
  530. this.isAjax = false
  531. this.getShopIngList()
  532. } else {
  533. this.isAjax = false
  534. tools.error(res.msg)
  535. }
  536. })
  537. },
  538. gbPop() {
  539. this.$refs.popupGG.close();
  540. },
  541. setSub(item, type) {
  542. let cartKey = this.cartData.goods_list.findIndex(row => row.goods_id === item.goods_id)
  543. if (type === 2 && cartKey < 0) {
  544. this.setShopIngAdd(item.goods_id, item.category_id, '', 1, item)
  545. } else {
  546. this.setShopIngNumber(item.goods_id, item.category_id, type, '', 1, item)
  547. }
  548. },
  549. setShoppingSave() {
  550. shoppingSave({
  551. type: 1,
  552. goods_id: this.popData.goods_id,
  553. shop_id: this.shop_id,
  554. category_id: this.popData.goodsItem.category_id,
  555. goods_spec_id: this.popData.spec_key,
  556. number: this.popData.num
  557. }).then((res) => {
  558. if (res.code === 1) {
  559. tools.success(res.msg)
  560. this.$refs.popupGG.close();
  561. this.getShopIngList()
  562. } else {
  563. tools.error(res.msg)
  564. }
  565. })
  566. },
  567. setShopIngAdd(goodsId, categoryId, goodsSpecId, number, item) {
  568. setShopIngAdd({
  569. 'type': 1,
  570. 'goods_id': goodsId,
  571. 'shop_id': this.shop_id,
  572. 'category_id': categoryId,
  573. 'goods_spec_id': goodsSpecId,
  574. 'number': number,
  575. }).then(res => {
  576. this.isAjax = false
  577. if (res.code === 1) {
  578. if (item) {
  579. ++item.num;
  580. }
  581. this.getShopIngList()
  582. } else if (res.code === 2) {
  583. tools.error(res.msg)
  584. if (item) {
  585. ++item.num;
  586. }
  587. this.getShopIngList()
  588. } else {
  589. tools.error(res.msg)
  590. }
  591. }).catch(() => {
  592. this.isAjax = false
  593. })
  594. },
  595. setShopIngNumber(goodsId, categoryId, operation, goodsSpecId, number, item) {
  596. setShopIngNumber({
  597. 'type': 1,
  598. 'goods_id': goodsId,
  599. 'shop_id': this.shop_id,
  600. 'category_id': categoryId,
  601. 'goods_spec_id': goodsSpecId,
  602. 'number': number,
  603. 'operation': operation === 2 ? 1 : 2,
  604. }).then(res => {
  605. this.isAjax = false
  606. if (res.code === 1) {
  607. if (item) {
  608. if (operation === 2) {
  609. ++item.num;
  610. } else {
  611. --item.num;
  612. }
  613. }
  614. this.getShopIngList()
  615. } else if (res.code === 2) {
  616. tools.error(res.msg)
  617. if (item) {
  618. if (operation === 2) {
  619. ++item.num;
  620. } else {
  621. --item.num;
  622. }
  623. }
  624. this.getShopIngList()
  625. } else {
  626. tools.error(res.msg)
  627. }
  628. }).catch(() => {
  629. this.isAjax = false
  630. })
  631. },
  632. setShopIngDel() {},
  633. // -------弹窗选择规格-----------
  634. selectSpec(info, groupKey) {
  635. let specKey = this.popData.spec_ids.indexOf(info.spec_id)
  636. if (specKey >= 0) {
  637. this.popData.spec_ids.splice(specKey, 1)
  638. this.popData.spec_name.splice(specKey, 1)
  639. if (Number(info.spec_price) > 0) {
  640. this.popData.price = Number(this.popData.price) - Number(info.spec_price)
  641. }
  642. } else {
  643. this.popData.spec_ids.push(info.spec_id)
  644. this.popData.spec_name.push(info.spec_name)
  645. if (Number(info.spec_price) > 0) {
  646. this.popData.price = Number(this.popData.price) + Number(info.spec_price)
  647. }
  648. for (const attrKey in this.popData.spec_attr[groupKey].spec_list) {
  649. if (this.popData.spec_attr[groupKey].spec_list[attrKey].spec_id !== info.spec_id) {
  650. let oldKey = this.popData.spec_ids.indexOf(this.popData.spec_attr[groupKey].spec_list[attrKey]
  651. .spec_id)
  652. if (oldKey >= 0) {
  653. this.popData.spec_ids.splice(oldKey, 1)
  654. this.popData.spec_name.splice(oldKey, 1)
  655. this.popData.price = Number(this.popData.price) - Number(this.popData.spec_attr[groupKey]
  656. .spec_list[attrKey].spec_price)
  657. }
  658. }
  659. }
  660. }
  661. // this.spec_ids = this.popData.spec_list.join('_')
  662. this.setGoodsSpecPrice()
  663. },
  664. },
  665. }
  666. </script>
  667. <style scoped lang="scss">
  668. .sticky-nav {
  669. width: 100%;
  670. position: sticky;
  671. z-index: 3;
  672. }
  673. .wh-44 {
  674. width: 44rpx;
  675. height: 44rpx;
  676. }
  677. .menu-box-left-f {
  678. position: sticky;
  679. // transition: all .3s ease;
  680. // overflow: auto;
  681. }
  682. .menu-box-left {
  683. width: 160rpx;
  684. height: auto;
  685. position: sticky;
  686. overflow: auto;
  687. // transition: all .3s ease;
  688. // height: 100%;
  689. // background-color: #F7F8FA;
  690. // position: absolute;
  691. // left: 0;
  692. // top: 0;
  693. // border-radius: 0rpx 20rpx 0 0rpx;
  694. }
  695. .menu-box-left-box {
  696. overflow-y: auto;
  697. }
  698. .menu-type-list {
  699. width: 160rpx;
  700. min-height: 108rpx;
  701. padding: 18rpx 28rpx;
  702. position: relative;
  703. z-index: 10;
  704. .menu-type-num {
  705. position: absolute;
  706. top: 2rpx;
  707. right: 8rpx;
  708. padding: 0 6rpx;
  709. min-width: 20rpx;
  710. height: 32rpx;
  711. text-align: center;
  712. line-height: 32rpx;
  713. background: #FB3D03;
  714. border-radius: 50%;
  715. }
  716. }
  717. .menu-type-list-f {
  718. // width: 160rpx;
  719. background-color: #007AFF;
  720. width: 100%;
  721. height: 100%;
  722. overflow-y: auto;
  723. /* 如果分类项很多,允许内部滚动 */
  724. -webkit-overflow-scrolling: touch;
  725. /* 改善移动端滚动体验 */
  726. // height: 100%;
  727. }
  728. .menu-box-only {
  729. // flex: 1;
  730. width: calc(100% - 160rpx);
  731. }
  732. .menu-box-right {
  733. // flex: 1;
  734. width: 100%;
  735. height: 100%;
  736. // padding: 16rpx 0;
  737. // box-sizing: border-box;
  738. // position: relative;
  739. }
  740. .menu-list {
  741. width: 100%;
  742. padding: 0 20rpx 40rpx;
  743. // height: 200rpx;
  744. // margin-bottom: 40rpx;
  745. .goods_img {
  746. width: 200rpx;
  747. height: 200rpx;
  748. border-radius: 12rpx;
  749. margin-right: 16rpx;
  750. }
  751. .menu-list-right {
  752. flex: 1;
  753. .right-only-right {
  754. width: 100rpx;
  755. height: 44rpx;
  756. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  757. border-radius: 12rpx;
  758. line-height: 44rpx;
  759. position: relative;
  760. .selectedNum {
  761. position: absolute;
  762. right: 2rpx;
  763. top: -22rpx;
  764. font-size: 24rpx;
  765. color: #fff;
  766. width: 32rpx;
  767. height: 32rpx;
  768. line-height: 32rpx;
  769. background: #FB3D03;
  770. border-radius: 50%;
  771. }
  772. }
  773. .right-only-right-red {
  774. width: 44rpx;
  775. height: 44rpx;
  776. line-height: 40rpx;
  777. border-radius: 12rpx;
  778. border: 1rpx solid #41ABF5;
  779. color: #41ABF5;
  780. }
  781. .right-only-right-add {
  782. width: 44rpx;
  783. height: 44rpx;
  784. line-height: 40rpx;
  785. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  786. border-radius: 12rpx;
  787. }
  788. .right-only-right-2 {
  789. min-width: 50rpx;
  790. }
  791. }
  792. }
  793. .menu-box {
  794. width: 100%;
  795. height: 100%;
  796. // padding-bottom: 140rpx;
  797. .gg-box {
  798. width: 750rpx;
  799. height: 1208rpx;
  800. background: #FFFFFF;
  801. border-radius: 24rpx 24rpx 0rpx 0rpx;
  802. .goods-info {
  803. border-bottom: 1rpx solid #EEEEEE;
  804. image {
  805. width: 170rpx;
  806. height: 160rpx;
  807. border-radius: 8rpx;
  808. margin-right: 22rpx;
  809. margin-bottom: 32rpx;
  810. }
  811. }
  812. .pop-buttom {
  813. width: 100%;
  814. // height: 250rpx;
  815. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(51, 51, 51, 0.1);
  816. .pop-buttom-left {
  817. padding-top: 12rpx;
  818. }
  819. .pop-buttom-2 {
  820. width: 100%;
  821. height: 96rpx;
  822. line-height: 96rpx;
  823. background: #41ABF5;
  824. border-radius: 200rpx
  825. }
  826. .right-only-right-red {
  827. width: 44rpx;
  828. height: 44rpx;
  829. line-height: 40rpx;
  830. border-radius: 12rpx;
  831. border: 1rpx solid #41ABF5;
  832. color: #41ABF5;
  833. }
  834. .right-only-right-add {
  835. width: 44rpx;
  836. height: 44rpx;
  837. line-height: 40rpx;
  838. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  839. border-radius: 12rpx;
  840. }
  841. .right-only-right-2 {
  842. min-width: 50rpx;
  843. }
  844. }
  845. .w-m {
  846. width: calc(100% + 30rpx);
  847. }
  848. .spec-item {
  849. min-width: 210rpx;
  850. height: 66rpx;
  851. line-height: 66rpx;
  852. box-sizing: border-box;
  853. border-radius: 12rpx;
  854. margin: 0 26rpx 26rpx 0;
  855. padding: 0 10rpx;
  856. }
  857. // .spec-item:nth-child(3) {
  858. // margin-right: 0rpx !important;
  859. // }
  860. .s-item {
  861. background-color: #ECF7FE;
  862. border: 2rpx solid #41ABF5;
  863. color: #41ABF5;
  864. }
  865. .n-item {
  866. border: 2rpx solid #EEEEEE;
  867. color: #000;
  868. }
  869. }
  870. }
  871. .goods-name {
  872. max-width: 310rpx;
  873. }
  874. </style>