menu.vue 25 KB

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