menu.vue 27 KB

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