index.vue 13 KB

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