menu.vue 25 KB

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