index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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="specInfo&&specInfo.file.length>0?specInfo.file[0].url:''"
  58. mode="aspectFill"></image>
  59. </view>
  60. <view class="r">
  61. <view class="money">
  62. <text class="money_1"><text>¥</text>{{specInfo.money}}</text>
  63. </view>
  64. <view class="other_1">
  65. <text>已选:</text>
  66. <text>{{specInfo.name||'暂无'}}</text>
  67. </view>
  68. <view class="other_1">
  69. <text>库存:</text>
  70. <text>{{specInfo.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 v-for="(item,index) in specList" :key="index" @tap="toSpecs(item)">
  80. <text>{{item.name}}</text>
  81. </view>
  82. </view>
  83. </view>
  84. <view class="one_3">
  85. <view class="one_3_1">
  86. <text>数量</text>
  87. </view>
  88. <view class="one_3_1">
  89. <uni-number-box v-model="buy_num" @change="toCount" :min="1"
  90. :max="specsInfo.num" />
  91. </view>
  92. <view class="one_3_1">
  93. <text>库存{{specsInfo.num||0}}</text>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. </scroll-view>
  99. </view>
  100. <view class="info_2">
  101. <button class="button" @tap="toMarket">加入购物车</button>
  102. </view>
  103. </view>
  104. </view>
  105. </uni-popup>
  106. </view>
  107. </template>
  108. <script>
  109. export default {
  110. data() {
  111. return {
  112. // 商品id
  113. id: '',
  114. // 当前用户信息
  115. user: {},
  116. // 商品详情
  117. info: {},
  118. // 轮播图
  119. fileList: [],
  120. // 规格弹框
  121. popupShow: '1',
  122. // 规格数组
  123. specList: [],
  124. specInfo: {},
  125. // 规格信息
  126. is_specs: 0,
  127. // 购买数量
  128. buy_num: 1,
  129. // 底部商品导航
  130. options: [{
  131. icon: 'shop',
  132. text: '店铺'
  133. },
  134. {
  135. icon: 'cart',
  136. text: '购物车',
  137. infoBackgroundColor: '#007aff',
  138. infoColor: "#f5f5f5"
  139. }
  140. ],
  141. buttonGroup: [{
  142. text: '加入购物车',
  143. backgroundColor: 'linear-gradient(90deg, #1E83FF, #0053B8)',
  144. color: '#fff'
  145. }]
  146. }
  147. },
  148. onLoad: async function(e) {
  149. const that = this;
  150. that.$set(that, `id`, e.id || '');
  151. that.searchToken();
  152. await that.search();
  153. },
  154. methods: {
  155. searchToken() {
  156. const that = this;
  157. try {
  158. const res = uni.getStorageSync('token');
  159. if (res) that.$set(that, `user`, res);
  160. } catch (e) {
  161. uni.showToast({
  162. title: err.errmsg,
  163. icon: 'error',
  164. duration: 2000
  165. });
  166. }
  167. },
  168. // 查询商品详情
  169. async search() {
  170. const that = this;
  171. let res;
  172. res = await that.$api(`/Good/${that.id}`, 'GET', {})
  173. if (res.errcode == '0') {
  174. const arr = await that.$api(`/Specs`, 'GET', {
  175. goods: res.data._id,
  176. is_use: '0'
  177. })
  178. if (arr.errcode == '0') {
  179. let data = arr.data.sort((a, b) => {
  180. return a.money - b.money
  181. })
  182. if (data) {
  183. res.data.money = data[0].money
  184. that.$set(that, `specInfo`, data[0]);
  185. that.$set(that, `specList`, data);
  186. }
  187. that.$set(that, `info`, res.data);
  188. that.$set(that, `fileList`, res.data.file);
  189. }
  190. }
  191. res = await that.$api(`/Cart/num`, 'GET', {
  192. user: that.user._id
  193. })
  194. if (res.errcode == '0') that.$set(that.options[1], `info`, res.data);
  195. },
  196. // 点击店铺或者购物车
  197. onClick(e) {
  198. uni.showToast({
  199. title: `点击${e.content.text}`,
  200. icon: 'none'
  201. })
  202. },
  203. // 加入购物车
  204. buttonClick(e) {
  205. const that = this;
  206. that.$set(that, `popupShow`, '1')
  207. that.$refs.popup.open();
  208. },
  209. // 加入购物车
  210. async toMarket(e) {},
  211. // 加数量
  212. async toCount(e) {},
  213. // 选择规格
  214. async toSpecs(e) {},
  215. toClose() {
  216. const that = this;
  217. that.$refs.popup.close();
  218. },
  219. }
  220. }
  221. </script>
  222. <style lang="scss">
  223. .content {
  224. display: flex;
  225. flex-direction: column;
  226. width: 100vw;
  227. height: 100vh;
  228. .one {
  229. position: relative;
  230. flex-grow: 1;
  231. .one_1 {
  232. border-bottom: 0.5vw solid var(--f9Color);
  233. swiper {
  234. height: 44vh !important;
  235. }
  236. .list {
  237. border-radius: 5px;
  238. .image {
  239. width: 100%;
  240. height: 100%;
  241. border-radius: 5px;
  242. background-color: #fff;
  243. }
  244. }
  245. }
  246. .one_2 {
  247. border-bottom: 0.5vw solid var(--f9Color);
  248. padding: 2vw;
  249. .money {
  250. font-size: 20px;
  251. padding: 0 1vw 0 0;
  252. color: var(--fF0Color);
  253. font-weight: bold;
  254. text {
  255. font-size: 14px;
  256. }
  257. }
  258. }
  259. .one_3 {
  260. display: flex;
  261. flex-wrap: wrap;
  262. padding: 1vw;
  263. border-bottom: 0.5vw solid var(--f9Color);
  264. }
  265. .one_4 {
  266. border-bottom: 0.5vw solid var(--f9Color);
  267. padding: 2vw;
  268. .name {
  269. width: 100%;
  270. overflow: hidden;
  271. text-overflow: ellipsis;
  272. word-break: break-all;
  273. font-size: 17px;
  274. font-weight: bold;
  275. margin: 0 0 2vw 0;
  276. }
  277. .brief {
  278. font-size: 14px;
  279. color: var(--f85Color);
  280. margin: 0 0 1vw 0;
  281. }
  282. }
  283. .one_5 {
  284. text-align: center;
  285. margin: 0 0 15vw 0;
  286. .list {
  287. .image {
  288. border-radius: 5px;
  289. background-color: #fff;
  290. }
  291. }
  292. }
  293. }
  294. .bottom {
  295. width: 100vw;
  296. position: fixed;
  297. bottom: 0;
  298. left: var(--window-left);
  299. right: var(--window-right);
  300. }
  301. }
  302. .scroll-view {
  303. position: absolute;
  304. top: 0;
  305. left: 0;
  306. right: 0;
  307. bottom: 0;
  308. .list-scroll-view {
  309. display: flex;
  310. flex-direction: column;
  311. }
  312. }
  313. .uni-popup {
  314. z-index: 9999 !important;
  315. }
  316. .popup {
  317. display: flex;
  318. flex-direction: column;
  319. width: 100vw;
  320. height: 60vh;
  321. .close {
  322. text-align: right;
  323. padding: 2vw;
  324. }
  325. .specs_1 {
  326. position: relative;
  327. display: flex;
  328. flex-direction: column;
  329. height: 54vh;
  330. .info_1 {
  331. position: relative;
  332. flex-grow: 1;
  333. .one {
  334. .one_1 {
  335. display: flex;
  336. margin: 0 0 2vw 0;
  337. padding: 0 0 2vw 0;
  338. border-bottom: 0.5vw solid var(--f9Color);
  339. .l {
  340. width: 25vw;
  341. height: 25vw;
  342. .image {
  343. width: 100%;
  344. height: 100%;
  345. border-radius: 5px;
  346. }
  347. }
  348. .r {
  349. width: 70vw;
  350. padding: 0 0 0 2vw;
  351. .money {
  352. margin: 0 0 2vw 0;
  353. .money_1 {
  354. font-size: var(--font20Size);
  355. color: var(--fF0Color);
  356. padding: 0 2vw 0 0;
  357. text {
  358. font-size: var(--font14Size);
  359. }
  360. }
  361. }
  362. .other_1 {
  363. font-size: var(--font15Size);
  364. color: var(--f85Color);
  365. text:last-child {
  366. color: var(--f00Color);
  367. }
  368. }
  369. }
  370. }
  371. .one_2 {
  372. margin: 0 0 2vw 0;
  373. border-bottom: 0.5vw solid var(--f9Color);
  374. .one_2_1 {
  375. font-size: 14px;
  376. margin: 0 0 2vw 0;
  377. }
  378. .one_2_2 {
  379. display: flex;
  380. flex-wrap: wrap;
  381. .list {
  382. background-color: #F5F5F5;
  383. margin: 0 2vw 2vw 0;
  384. padding: 0.5vw 1vw;
  385. border-radius: 5px;
  386. text {
  387. font-size: 14px;
  388. color: var(--f00Color);
  389. }
  390. }
  391. .huilist {
  392. background-color: #DCDCDC;
  393. text {
  394. color: var(--f85Color);
  395. }
  396. }
  397. .redlist {
  398. background-color: var(--fF0Color);
  399. text {
  400. color: #ffffff;
  401. }
  402. }
  403. .huiilist {
  404. background-color: #808080;
  405. text {
  406. color: #cccccc;
  407. }
  408. }
  409. }
  410. }
  411. .one_3 {
  412. display: flex;
  413. .one_3_1 {
  414. margin: 0 2vw 0 0;
  415. text {
  416. font-size: 14px;
  417. color: var(--f85Color);
  418. }
  419. .limit {
  420. color: var(--fF0Color);
  421. padding: 0 0 0 2vw;
  422. }
  423. }
  424. }
  425. }
  426. }
  427. .info_2 {
  428. border-bottom: 0.5vw solid var(--f9Color);
  429. .button {
  430. background-color: var(--f3CColor);
  431. color: var(--mainColor);
  432. }
  433. }
  434. }
  435. }
  436. </style>