index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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. type: '0'
  137. },
  138. {
  139. icon: 'cart',
  140. text: '购物车',
  141. infoBackgroundColor: '#007aff',
  142. infoColor: "#f5f5f5"
  143. }
  144. ],
  145. buttonGroup: [{
  146. text: '加入购物车',
  147. backgroundColor: 'linear-gradient(90deg, #1E83FF, #0053B8)',
  148. color: '#fff'
  149. }]
  150. }
  151. },
  152. onLoad: async function(e) {
  153. const that = this;
  154. that.$set(that, `id`, e.id || '');
  155. that.searchToken();
  156. await that.search();
  157. },
  158. onShow() {
  159. const that = this;
  160. that.searchOther()
  161. },
  162. methods: {
  163. searchToken() {
  164. const that = this;
  165. try {
  166. const res = uni.getStorageSync('token');
  167. if (res) that.$set(that, `user`, res);
  168. } catch (e) {
  169. uni.showToast({
  170. title: err.errmsg,
  171. icon: 'error',
  172. duration: 2000
  173. });
  174. }
  175. },
  176. // 查询商品详情
  177. async search() {
  178. const that = this;
  179. let res;
  180. res = await that.$api(`/Good/${that.id}`, 'GET', {})
  181. if (res.errcode == '0') {
  182. const arr = await that.$api(`/Specs`, 'GET', {
  183. goods: res.data._id,
  184. is_use: '0'
  185. })
  186. if (arr.errcode == '0') {
  187. let data = arr.data.sort((a, b) => {
  188. return a.money - b.money
  189. })
  190. if (data) {
  191. res.data.money = data[0].money
  192. that.$set(that, `specsInfo`, data[0]);
  193. that.$set(that, `specList`, data);
  194. }
  195. that.$set(that, `info`, res.data);
  196. that.$set(that, `fileList`, res.data.file);
  197. }
  198. }
  199. res = await that.$api(`/Cart/num`, 'GET', {
  200. user: that.user._id
  201. })
  202. if (res.errcode == '0') that.$set(that.options[1], `info`, res.data);
  203. },
  204. // 点击店铺或者购物车
  205. onClick(e) {
  206. const that = this;
  207. if (e.content.text == '购物车') {
  208. uni.reLaunch({
  209. url: 'pages/market/index'
  210. })
  211. }
  212. },
  213. // 加入购物车
  214. buttonClick(e) {
  215. const that = this;
  216. that.$set(that, `popupShow`, '1')
  217. that.$refs.popup.open();
  218. },
  219. // 加入购物车
  220. async toMarket(e) {
  221. const that = this;
  222. let user = that.user;
  223. let info = that.info;
  224. let specsInfo = that.specsInfo;
  225. if (user && user._id) {
  226. let res;
  227. let obj = {
  228. user: user._id,
  229. supplier_id: info.supplier_id,
  230. spec: specsInfo._id,
  231. goods: info._id,
  232. num: that.buy_num,
  233. money: specsInfo.money,
  234. total_money: that.$multiply(specsInfo.money, that.buy_num)
  235. }
  236. res = await that.$api(`/Cart`, 'POST', obj)
  237. if (res.errcode == '0') {
  238. uni.showToast({
  239. title: `加入购物车成功`,
  240. icon: 'none'
  241. })
  242. that.toClose();
  243. } else {
  244. uni.showToast({
  245. title: res.errmsg,
  246. icon: 'none'
  247. })
  248. }
  249. } else {
  250. uni.navigateTo({
  251. url: `/pages/login/index`
  252. })
  253. }
  254. },
  255. // 加数量
  256. async toCount(e) {
  257. const that = this;
  258. that.$set(that, `buy_num`, e)
  259. },
  260. // 选择规格
  261. async toSpecs(e) {
  262. const that = this;
  263. let specs = that.specList;
  264. let dataIndex = specs.findIndex(i => i._id == e._id);
  265. that.$set(that, `is_specs`, dataIndex);
  266. that.$set(that, `specsInfo`, e)
  267. that.$set(that, `buy_num`, 1);
  268. if (e.num <= 0) that.$set(that, `is_zero`, true)
  269. else that.$set(that, `is_zero`, false)
  270. },
  271. async searchOther() {
  272. const that = this;
  273. const res = await that.$api(`/Cart/num`, 'GET', {
  274. user: that.user._id
  275. })
  276. if (res.errcode == '0') that.$set(that.options[1], `info`, res.data);
  277. },
  278. toClose() {
  279. const that = this;
  280. that.searchOther()
  281. that.$refs.popup.close();
  282. },
  283. }
  284. }
  285. </script>
  286. <style lang="scss">
  287. .content {
  288. display: flex;
  289. flex-direction: column;
  290. width: 100vw;
  291. height: 100vh;
  292. .one {
  293. position: relative;
  294. flex-grow: 1;
  295. .one_1 {
  296. border-bottom: 0.5vw solid var(--f9Color);
  297. swiper {
  298. height: 44vh !important;
  299. }
  300. .list {
  301. border-radius: 5px;
  302. .image {
  303. width: 100%;
  304. height: 100%;
  305. border-radius: 5px;
  306. background-color: #fff;
  307. }
  308. }
  309. }
  310. .one_2 {
  311. border-bottom: 0.5vw solid var(--f9Color);
  312. padding: 2vw;
  313. .money {
  314. font-size: var(--font20Size);
  315. padding: 0 1vw 0 0;
  316. color: var(--fF0Color);
  317. font-weight: bold;
  318. text {
  319. font-size: var(--font14Size);
  320. }
  321. }
  322. }
  323. .one_3 {
  324. display: flex;
  325. flex-wrap: wrap;
  326. padding: 1vw;
  327. border-bottom: 0.5vw solid var(--f9Color);
  328. }
  329. .one_4 {
  330. border-bottom: 0.5vw solid var(--f9Color);
  331. padding: 2vw;
  332. .name {
  333. width: 100%;
  334. overflow: hidden;
  335. text-overflow: ellipsis;
  336. word-break: break-all;
  337. font-size: var(--font17Size);
  338. font-weight: bold;
  339. margin: 0 0 2vw 0;
  340. }
  341. .brief {
  342. font-size: var(--font14Size);
  343. color: var(--f85Color);
  344. margin: 0 0 1vw 0;
  345. }
  346. }
  347. .one_5 {
  348. text-align: center;
  349. margin: 0 0 15vw 0;
  350. .list {
  351. .image {
  352. border-radius: 5px;
  353. background-color: #fff;
  354. }
  355. }
  356. }
  357. }
  358. .bottom {
  359. width: 100vw;
  360. position: fixed;
  361. bottom: 0;
  362. left: var(--window-left);
  363. right: var(--window-right);
  364. }
  365. }
  366. .scroll-view {
  367. position: absolute;
  368. top: 0;
  369. left: 0;
  370. right: 0;
  371. bottom: 0;
  372. .list-scroll-view {
  373. display: flex;
  374. flex-direction: column;
  375. }
  376. }
  377. .uni-popup {
  378. z-index: 9999 !important;
  379. }
  380. .popup {
  381. display: flex;
  382. flex-direction: column;
  383. width: 100vw;
  384. height: 60vh;
  385. .close {
  386. text-align: right;
  387. padding: 2vw;
  388. }
  389. .specs_1 {
  390. position: relative;
  391. display: flex;
  392. flex-direction: column;
  393. height: 54vh;
  394. .info_1 {
  395. position: relative;
  396. flex-grow: 1;
  397. .one {
  398. .one_1 {
  399. display: flex;
  400. margin: 0 0 2vw 0;
  401. padding: 0 0 2vw 0;
  402. border-bottom: 0.5vw solid var(--f9Color);
  403. .l {
  404. width: 25vw;
  405. height: 25vw;
  406. .image {
  407. width: 100%;
  408. height: 100%;
  409. border-radius: 5px;
  410. }
  411. }
  412. .r {
  413. width: 70vw;
  414. padding: 0 0 0 2vw;
  415. .money {
  416. margin: 0 0 2vw 0;
  417. .money_1 {
  418. font-size: var(--font20Size);
  419. color: var(--fF0Color);
  420. padding: 0 2vw 0 0;
  421. text {
  422. font-size: var(--font14Size);
  423. }
  424. }
  425. }
  426. .other_1 {
  427. font-size: var(--font15Size);
  428. color: var(--f85Color);
  429. text:last-child {
  430. color: var(--f00Color);
  431. }
  432. }
  433. }
  434. }
  435. .one_2 {
  436. margin: 0 0 2vw 0;
  437. border-bottom: 0.5vw solid var(--f9Color);
  438. .one_2_1 {
  439. font-size: var(--font14Size);
  440. margin: 0 0 2vw 0;
  441. }
  442. .one_2_2 {
  443. display: flex;
  444. flex-wrap: wrap;
  445. .list {
  446. background-color: var(--f5Color);
  447. margin: 0 2vw 2vw 0;
  448. padding: 0.5vw 1vw;
  449. border-radius: 5px;
  450. text {
  451. font-size: var(--font14Size);
  452. color: var(--f00Color);
  453. }
  454. }
  455. .huilist {
  456. background-color: var(--fDCColor);
  457. text {
  458. color: var(--f85Color);
  459. }
  460. }
  461. .redlist {
  462. background-color: var(--f3CColor);
  463. text {
  464. color: var(--mainColor);
  465. }
  466. }
  467. .huiilist {
  468. background-color: var(--f80Color);
  469. text {
  470. color: var(--fcColor);
  471. }
  472. }
  473. }
  474. }
  475. .one_3 {
  476. display: flex;
  477. .one_3_1 {
  478. margin: 0 2vw 0 0;
  479. text {
  480. font-size: 14px;
  481. color: var(--f85Color);
  482. }
  483. .limit {
  484. color: var(--fF0Color);
  485. padding: 0 0 0 2vw;
  486. }
  487. }
  488. }
  489. }
  490. }
  491. .info_2 {
  492. .button {
  493. background-color: var(--f3CColor);
  494. color: var(--mainColor);
  495. border-radius: 0;
  496. }
  497. }
  498. }
  499. }
  500. </style>