index.vue 12 KB

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