menu.vue 25 KB

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