index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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. }
  231. res = await that.$api(`/Cart`, 'POST', obj)
  232. if (res.errcode == '0') {
  233. uni.showToast({
  234. title: `加入购物车成功`,
  235. icon: 'none'
  236. })
  237. that.toClose();
  238. } else {
  239. uni.showToast({
  240. title: res.errmsg,
  241. icon: 'none'
  242. })
  243. }
  244. } else {
  245. uni.navigateTo({
  246. url: `/pages/login/index`
  247. })
  248. }
  249. },
  250. // 加数量
  251. async toCount(e) {
  252. const that = this;
  253. that.$set(that, `buy_num`, e)
  254. },
  255. // 选择规格
  256. async toSpecs(e) {
  257. const that = this;
  258. let specs = that.specList;
  259. let dataIndex = specs.findIndex(i => i._id == e._id);
  260. that.$set(that, `is_specs`, dataIndex);
  261. that.$set(that, `specsInfo`, e)
  262. that.$set(that, `buy_num`, 1);
  263. if (e.num <= 0) that.$set(that, `is_zero`, true)
  264. else that.$set(that, `is_zero`, false)
  265. },
  266. async searchOther() {
  267. const that = this;
  268. const res = await that.$api(`/Cart/num`, 'GET', {
  269. user: that.user._id
  270. })
  271. if (res.errcode == '0') that.$set(that.options[1], `info`, res.data);
  272. },
  273. toClose() {
  274. const that = this;
  275. that.searchOther()
  276. that.$refs.popup.close();
  277. },
  278. }
  279. }
  280. </script>
  281. <style lang="scss">
  282. .content {
  283. display: flex;
  284. flex-direction: column;
  285. width: 100vw;
  286. height: 100vh;
  287. .one {
  288. position: relative;
  289. flex-grow: 1;
  290. .one_1 {
  291. border-bottom: 0.5vw solid var(--f9Color);
  292. swiper {
  293. height: 44vh !important;
  294. }
  295. .list {
  296. border-radius: 5px;
  297. .image {
  298. width: 100%;
  299. height: 100%;
  300. border-radius: 5px;
  301. background-color: #fff;
  302. }
  303. }
  304. }
  305. .one_2 {
  306. border-bottom: 0.5vw solid var(--f9Color);
  307. padding: 2vw;
  308. .money {
  309. font-size: var(--font20Size);
  310. padding: 0 1vw 0 0;
  311. color: var(--fF0Color);
  312. font-weight: bold;
  313. text {
  314. font-size: var(--font14Size);
  315. }
  316. }
  317. }
  318. .one_3 {
  319. display: flex;
  320. flex-wrap: wrap;
  321. padding: 1vw;
  322. border-bottom: 0.5vw solid var(--f9Color);
  323. }
  324. .one_4 {
  325. border-bottom: 0.5vw solid var(--f9Color);
  326. padding: 2vw;
  327. .name {
  328. width: 100%;
  329. overflow: hidden;
  330. text-overflow: ellipsis;
  331. word-break: break-all;
  332. font-size: var(--font17Size);
  333. font-weight: bold;
  334. margin: 0 0 2vw 0;
  335. }
  336. .brief {
  337. font-size: var(--font14Size);
  338. color: var(--f85Color);
  339. margin: 0 0 1vw 0;
  340. }
  341. }
  342. .one_5 {
  343. text-align: center;
  344. margin: 0 0 15vw 0;
  345. .list {
  346. .image {
  347. border-radius: 5px;
  348. background-color: #fff;
  349. }
  350. }
  351. }
  352. }
  353. .bottom {
  354. width: 100vw;
  355. position: fixed;
  356. bottom: 0;
  357. left: var(--window-left);
  358. right: var(--window-right);
  359. }
  360. }
  361. .scroll-view {
  362. position: absolute;
  363. top: 0;
  364. left: 0;
  365. right: 0;
  366. bottom: 0;
  367. .list-scroll-view {
  368. display: flex;
  369. flex-direction: column;
  370. }
  371. }
  372. .uni-popup {
  373. z-index: 9999 !important;
  374. }
  375. .popup {
  376. display: flex;
  377. flex-direction: column;
  378. width: 100vw;
  379. height: 60vh;
  380. .close {
  381. text-align: right;
  382. padding: 2vw;
  383. }
  384. .specs_1 {
  385. position: relative;
  386. display: flex;
  387. flex-direction: column;
  388. height: 54vh;
  389. .info_1 {
  390. position: relative;
  391. flex-grow: 1;
  392. .one {
  393. .one_1 {
  394. display: flex;
  395. margin: 0 0 2vw 0;
  396. padding: 0 0 2vw 0;
  397. border-bottom: 0.5vw solid var(--f9Color);
  398. .l {
  399. width: 25vw;
  400. height: 25vw;
  401. .image {
  402. width: 100%;
  403. height: 100%;
  404. border-radius: 5px;
  405. }
  406. }
  407. .r {
  408. width: 70vw;
  409. padding: 0 0 0 2vw;
  410. .money {
  411. margin: 0 0 2vw 0;
  412. .money_1 {
  413. font-size: var(--font20Size);
  414. color: var(--fF0Color);
  415. padding: 0 2vw 0 0;
  416. text {
  417. font-size: var(--font14Size);
  418. }
  419. }
  420. }
  421. .other_1 {
  422. font-size: var(--font15Size);
  423. color: var(--f85Color);
  424. text:last-child {
  425. color: var(--f00Color);
  426. }
  427. }
  428. }
  429. }
  430. .one_2 {
  431. margin: 0 0 2vw 0;
  432. border-bottom: 0.5vw solid var(--f9Color);
  433. .one_2_1 {
  434. font-size: var(--font14Size);
  435. margin: 0 0 2vw 0;
  436. }
  437. .one_2_2 {
  438. display: flex;
  439. flex-wrap: wrap;
  440. .list {
  441. background-color: var(--f5Color);
  442. margin: 0 2vw 2vw 0;
  443. padding: 0.5vw 1vw;
  444. border-radius: 5px;
  445. text {
  446. font-size: var(--font14Size);
  447. color: var(--f00Color);
  448. }
  449. }
  450. .huilist {
  451. background-color: var(--fDCColor);
  452. text {
  453. color: var(--f85Color);
  454. }
  455. }
  456. .redlist {
  457. background-color: var(--f3CColor);
  458. text {
  459. color: var(--mainColor);
  460. }
  461. }
  462. .huiilist {
  463. background-color: var(--f80Color);
  464. text {
  465. color: var(--fcColor);
  466. }
  467. }
  468. }
  469. }
  470. .one_3 {
  471. display: flex;
  472. .one_3_1 {
  473. margin: 0 2vw 0 0;
  474. text {
  475. font-size: 14px;
  476. color: var(--f85Color);
  477. }
  478. .limit {
  479. color: var(--fF0Color);
  480. padding: 0 0 0 2vw;
  481. }
  482. }
  483. }
  484. }
  485. }
  486. .info_2 {
  487. .button {
  488. background-color: var(--f3CColor);
  489. color: var(--mainColor);
  490. border-radius: 0;
  491. }
  492. }
  493. }
  494. }
  495. </style>