index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <template>
  2. <view class="content">
  3. <scroll-view scroll-y="true" class="scroll-view">
  4. <view class="list-scroll-view">
  5. <view class="one">
  6. <view class="one_1">
  7. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#ffffff"
  8. indicator-active-color="#007AFF" :interval="3000" :duration="1000">
  9. <swiper-item class="list" v-for="(item,index) in fileList" :key="index">
  10. <image class="image" :src="item.url" mode="aspectFit">
  11. </image>
  12. </swiper-item>
  13. </swiper>
  14. </view>
  15. <view class="one_2">
  16. <text class="money"><text>¥</text>{{info.money||0}}</text>
  17. </view>
  18. <view class="one_3">
  19. <text class="num">已售{{info&&info.sell_num||0}}件</text>
  20. </view>
  21. <view class="one_4">
  22. <view class="name">
  23. {{info&&info.name}}
  24. </view>
  25. <view class="brief">
  26. {{info&&info.brief||''}}
  27. </view>
  28. </view>
  29. <view class="one_5">
  30. <view class="list" v-for="(item,index) in fileList" :key="index">
  31. <image class="image" :src="item.url" mode="aspectFit">
  32. </image>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </scroll-view>
  38. <view class="bottom">
  39. <uni-goods-nav :fill="true" :options="options" :button-group="buttonGroup" @click="onClick"
  40. @buttonClick="buttonClick" style="margin-top: 20px;" />
  41. </view>
  42. <!-- 规格弹窗 -->
  43. <uni-popup ref="popup" background-color="#fff" type="bottom" :is-mask-click="false">
  44. <view class="popup">
  45. <view class="close">
  46. <text @click="toClose" class="iconfont icon-icon-cross-empty"></text>
  47. </view>
  48. <!-- 规格 -->
  49. <view class="specs_1" v-if="popupShow=='1'">
  50. <view class="info_1">
  51. <scroll-view scroll-y="true" class="scroll-view">
  52. <view class="list-scroll-view">
  53. <view class="one">
  54. <view class="one_1">
  55. <view class="l">
  56. <image class="image"
  57. :src="specsInfo&&specsInfo.file.length>0?specsInfo.file[0].url:''"
  58. mode="aspectFill"></image>
  59. </view>
  60. <view class="r">
  61. <view class="money">
  62. <text class="money_1"><text>¥</text>{{specsInfo.money}}</text>
  63. </view>
  64. <view class="other_1">
  65. <text>已选:</text>
  66. <text>{{specsInfo.name||'暂无'}}</text>
  67. </view>
  68. <view class="other_1">
  69. <text>库存:</text>
  70. <text>{{specsInfo.num||'0'}}</text>
  71. </view>
  72. </view>
  73. </view>
  74. <view class="one_2">
  75. <view class="one_2_1">
  76. 规格
  77. </view>
  78. <view class="one_2_2">
  79. <view
  80. :class="['list',is_specs!=index&&item.num>0?'list':is_specs!=index&&item.num<=0?'huilist':is_specs==index&&item.num>0?'redlist':is_specs==index&&item.num<=0?'huiilist':'list']"
  81. v-for="(item,index) in specList" :key="index" @tap="toSpecs(item)">
  82. <text>{{item.name}}</text>
  83. </view>
  84. </view>
  85. </view>
  86. <view class="one_3">
  87. <view class="one_3_1">
  88. <text>数量</text>
  89. </view>
  90. <view class="one_3_1">
  91. <uni-number-box v-model="buy_num" @change="toCount" :min="1"
  92. :max="specsInfo.num" />
  93. </view>
  94. <view class="one_3_1">
  95. <text>库存{{specsInfo.num||0}}</text>
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. </scroll-view>
  101. </view>
  102. <view class="info_2">
  103. <button :disabled="is_zero" class="button" @tap="toMarket">加入购物车</button>
  104. </view>
  105. </view>
  106. </view>
  107. </uni-popup>
  108. </view>
  109. </template>
  110. <script>
  111. export default {
  112. data() {
  113. return {
  114. // 商品id
  115. id: '',
  116. // 当前用户信息
  117. user: {},
  118. // 商品详情
  119. info: {},
  120. // 轮播图
  121. fileList: [],
  122. // 规格弹框
  123. popupShow: '1',
  124. // 规格数组
  125. specList: [],
  126. specsInfo: {},
  127. // 规格信息
  128. is_specs: 0,
  129. // 购买数量
  130. buy_num: 1,
  131. is_zero: false,
  132. // 底部商品导航
  133. options: [{
  134. icon: 'shop',
  135. text: '店铺'
  136. },
  137. {
  138. icon: 'cart',
  139. text: '购物车',
  140. infoBackgroundColor: '#007aff',
  141. infoColor: "#f5f5f5"
  142. }
  143. ],
  144. buttonGroup: [{
  145. text: '加入购物车',
  146. backgroundColor: 'linear-gradient(90deg, #1E83FF, #0053B8)',
  147. color: '#fff'
  148. }]
  149. }
  150. },
  151. onLoad: async function(e) {
  152. const that = this;
  153. that.$set(that, `id`, e.id || '');
  154. that.searchToken();
  155. await that.search();
  156. },
  157. onShow() {
  158. const that = this;
  159. that.searchOther()
  160. },
  161. methods: {
  162. searchToken() {
  163. const that = this;
  164. try {
  165. const res = uni.getStorageSync('token');
  166. if (res) that.$set(that, `user`, res);
  167. } catch (e) {
  168. uni.showToast({
  169. title: err.errmsg,
  170. icon: 'error',
  171. duration: 2000
  172. });
  173. }
  174. },
  175. // 查询商品详情
  176. async search() {
  177. const that = this;
  178. let res;
  179. res = await that.$api(`/Good/${that.id}`, 'GET', {})
  180. if (res.errcode == '0') {
  181. const arr = await that.$api(`/Specs`, 'GET', {
  182. goods: res.data._id,
  183. is_use: '0'
  184. })
  185. if (arr.errcode == '0') {
  186. let data = arr.data.sort((a, b) => {
  187. return a.money - b.money
  188. })
  189. if (data) {
  190. res.data.money = data[0].money
  191. that.$set(that, `specsInfo`, data[0]);
  192. that.$set(that, `specList`, data);
  193. }
  194. that.$set(that, `info`, res.data);
  195. that.$set(that, `fileList`, res.data.file);
  196. }
  197. }
  198. res = await that.$api(`/Cart/num`, 'GET', {
  199. user: that.user._id
  200. })
  201. if (res.errcode == '0') that.$set(that.options[1], `info`, res.data);
  202. },
  203. // 点击店铺或者购物车
  204. onClick(e) {
  205. uni.showToast({
  206. title: `点击${e.content.text}`,
  207. icon: 'none'
  208. })
  209. },
  210. // 加入购物车
  211. buttonClick(e) {
  212. const that = this;
  213. that.$set(that, `popupShow`, '1')
  214. that.$refs.popup.open();
  215. },
  216. // 加入购物车
  217. async toMarket(e) {
  218. const that = this;
  219. let user = that.user;
  220. let info = that.info;
  221. let specsInfo = that.specsInfo;
  222. if (user && user._id) {
  223. let res;
  224. let obj = {
  225. user: user._id,
  226. supplier_id: info.supplier_id,
  227. spec: specsInfo._id,
  228. goods: info._id,
  229. num: that.buy_num,
  230. money: parseFloat(specsInfo.money) * that.buy_num
  231. }
  232. res = await that.$api(`/Cart`, 'POST', obj)
  233. if (res.errcode == '0') {
  234. uni.showToast({
  235. title: `加入购物车成功`,
  236. icon: 'none'
  237. })
  238. that.toClose();
  239. } else {
  240. uni.showToast({
  241. title: res.errmsg,
  242. icon: 'none'
  243. })
  244. }
  245. } else {
  246. uni.navigateTo({
  247. url: `/pages/login/index`
  248. })
  249. }
  250. },
  251. // 加数量
  252. async toCount(e) {
  253. const that = this;
  254. that.$set(that, `buy_num`, e)
  255. },
  256. // 选择规格
  257. async toSpecs(e) {
  258. const that = this;
  259. let specs = that.specList;
  260. let dataIndex = specs.findIndex(i => i._id == e._id);
  261. that.$set(that, `is_specs`, dataIndex);
  262. that.$set(that, `specsInfo`, e)
  263. that.$set(that, `buy_num`, 1);
  264. if (e.num <= 0) that.$set(that, `is_zero`, true)
  265. else that.$set(that, `is_zero`, false)
  266. },
  267. async searchOther() {
  268. const that = this;
  269. const res = await that.$api(`/Cart/num`, 'GET', {
  270. user: that.user._id
  271. })
  272. if (res.errcode == '0') that.$set(that.options[1], `info`, res.data);
  273. },
  274. toClose() {
  275. const that = this;
  276. that.searchOther()
  277. that.$refs.popup.close();
  278. },
  279. }
  280. }
  281. </script>
  282. <style lang="scss">
  283. .content {
  284. display: flex;
  285. flex-direction: column;
  286. width: 100vw;
  287. height: 100vh;
  288. .one {
  289. position: relative;
  290. flex-grow: 1;
  291. .one_1 {
  292. border-bottom: 0.5vw solid var(--f9Color);
  293. swiper {
  294. height: 44vh !important;
  295. }
  296. .list {
  297. border-radius: 5px;
  298. .image {
  299. width: 100%;
  300. height: 100%;
  301. border-radius: 5px;
  302. background-color: #fff;
  303. }
  304. }
  305. }
  306. .one_2 {
  307. border-bottom: 0.5vw solid var(--f9Color);
  308. padding: 2vw;
  309. .money {
  310. font-size: var(--font20Size);
  311. padding: 0 1vw 0 0;
  312. color: var(--fF0Color);
  313. font-weight: bold;
  314. text {
  315. font-size: var(--font14Size);
  316. }
  317. }
  318. }
  319. .one_3 {
  320. display: flex;
  321. flex-wrap: wrap;
  322. padding: 1vw;
  323. border-bottom: 0.5vw solid var(--f9Color);
  324. }
  325. .one_4 {
  326. border-bottom: 0.5vw solid var(--f9Color);
  327. padding: 2vw;
  328. .name {
  329. width: 100%;
  330. overflow: hidden;
  331. text-overflow: ellipsis;
  332. word-break: break-all;
  333. font-size: var(--font17Size);
  334. font-weight: bold;
  335. margin: 0 0 2vw 0;
  336. }
  337. .brief {
  338. font-size: var(--font14Size);
  339. color: var(--f85Color);
  340. margin: 0 0 1vw 0;
  341. }
  342. }
  343. .one_5 {
  344. text-align: center;
  345. margin: 0 0 15vw 0;
  346. .list {
  347. .image {
  348. border-radius: 5px;
  349. background-color: #fff;
  350. }
  351. }
  352. }
  353. }
  354. .bottom {
  355. width: 100vw;
  356. position: fixed;
  357. bottom: 0;
  358. left: var(--window-left);
  359. right: var(--window-right);
  360. }
  361. }
  362. .scroll-view {
  363. position: absolute;
  364. top: 0;
  365. left: 0;
  366. right: 0;
  367. bottom: 0;
  368. .list-scroll-view {
  369. display: flex;
  370. flex-direction: column;
  371. }
  372. }
  373. .uni-popup {
  374. z-index: 9999 !important;
  375. }
  376. .popup {
  377. display: flex;
  378. flex-direction: column;
  379. width: 100vw;
  380. height: 60vh;
  381. .close {
  382. text-align: right;
  383. padding: 2vw;
  384. }
  385. .specs_1 {
  386. position: relative;
  387. display: flex;
  388. flex-direction: column;
  389. height: 54vh;
  390. .info_1 {
  391. position: relative;
  392. flex-grow: 1;
  393. .one {
  394. .one_1 {
  395. display: flex;
  396. margin: 0 0 2vw 0;
  397. padding: 0 0 2vw 0;
  398. border-bottom: 0.5vw solid var(--f9Color);
  399. .l {
  400. width: 25vw;
  401. height: 25vw;
  402. .image {
  403. width: 100%;
  404. height: 100%;
  405. border-radius: 5px;
  406. }
  407. }
  408. .r {
  409. width: 70vw;
  410. padding: 0 0 0 2vw;
  411. .money {
  412. margin: 0 0 2vw 0;
  413. .money_1 {
  414. font-size: var(--font20Size);
  415. color: var(--fF0Color);
  416. padding: 0 2vw 0 0;
  417. text {
  418. font-size: var(--font14Size);
  419. }
  420. }
  421. }
  422. .other_1 {
  423. font-size: var(--font15Size);
  424. color: var(--f85Color);
  425. text:last-child {
  426. color: var(--f00Color);
  427. }
  428. }
  429. }
  430. }
  431. .one_2 {
  432. margin: 0 0 2vw 0;
  433. border-bottom: 0.5vw solid var(--f9Color);
  434. .one_2_1 {
  435. font-size: var(--font14Size);
  436. margin: 0 0 2vw 0;
  437. }
  438. .one_2_2 {
  439. display: flex;
  440. flex-wrap: wrap;
  441. .list {
  442. background-color: var(--f5Color);
  443. margin: 0 2vw 2vw 0;
  444. padding: 0.5vw 1vw;
  445. border-radius: 5px;
  446. text {
  447. font-size: var(--font14Size);
  448. color: var(--f00Color);
  449. }
  450. }
  451. .huilist {
  452. background-color: var(--fDCColor);
  453. text {
  454. color: var(--f85Color);
  455. }
  456. }
  457. .redlist {
  458. background-color: var(--f3CColor);
  459. text {
  460. color: var(--mainColor);
  461. }
  462. }
  463. .huiilist {
  464. background-color: var(--f80Color);
  465. text {
  466. color: var(--fcColor);
  467. }
  468. }
  469. }
  470. }
  471. .one_3 {
  472. display: flex;
  473. .one_3_1 {
  474. margin: 0 2vw 0 0;
  475. text {
  476. font-size: 14px;
  477. color: var(--f85Color);
  478. }
  479. .limit {
  480. color: var(--fF0Color);
  481. padding: 0 0 0 2vw;
  482. }
  483. }
  484. }
  485. }
  486. }
  487. .info_2 {
  488. .button {
  489. background-color: var(--f3CColor);
  490. color: var(--mainColor);
  491. border-radius: 0;
  492. }
  493. }
  494. }
  495. }
  496. </style>