menu.vue 25 KB

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