index.vue 12 KB

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