index.vue 12 KB

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