index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <view class="list" @tap="toView">
  6. <image class="image" :src="goodsInfo.file&&goodsInfo.file.length>0?goodsInfo.file[0].url:''"
  7. mode="">
  8. </image>
  9. <view class="list_1_1">
  10. <view class="name">
  11. {{goodsInfo.name||'暂无'}}
  12. </view>
  13. <view class="specs">
  14. <text>规格:{{specsInfo.name}}</text>
  15. <text>店铺:{{shopInfo.name}}</text>
  16. </view>
  17. <view class="money">
  18. <text>¥</text>
  19. <text>{{specsInfo.sell_money}}</text>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="two">
  25. <button type="default" size="default" @click="toGroup">我要开团</button>
  26. </view>
  27. <view class="thr">
  28. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  29. <view class="list-scroll-view">
  30. <view class="list" v-for="(item, index) in list" :key="index">
  31. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="">
  32. </image>
  33. <view class="list_1">
  34. <view class="name">
  35. {{item.leader||'暂无'}}
  36. </view>
  37. <view class="some">
  38. <text>商品名称</text>
  39. <text>{{item.name||'暂无'}}</text>
  40. </view>
  41. <view class="some">
  42. <text>参团人数</text>
  43. <text>{{item.person_limit||0}}人</text>
  44. </view>
  45. <view class="other">
  46. <view class="other_1">
  47. <text>¥</text>
  48. <text>{{item.sell_money||0}}</text>
  49. </view>
  50. <view class="other_2">
  51. <view class="btn" @click="onSubmit(item)">
  52. <text>{{item.status||'开团中'}}</text>立即参团
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </scroll-view>
  60. </view>
  61. </view>
  62. <uni-popup ref="popup" background-color="#fff" type="bottom">
  63. <view class="content">
  64. <view class="one">
  65. <text>数量</text>
  66. <view class="count">
  67. <uni-number-box :min="1" :max="specsInfo.num" v-model="num" @change="toCount">
  68. </uni-number-box>
  69. </view>
  70. <text>库存{{specsInfo.num||0}}</text>
  71. </view>
  72. <view class="btn">
  73. <text @click="onSubmit" class="button">确认开团</text>
  74. </view>
  75. </view>
  76. </uni-popup>
  77. </mobile-frame>
  78. </template>
  79. <script>
  80. export default {
  81. data() {
  82. return {
  83. query: {},
  84. user: {},
  85. // 商品详情
  86. goodsInfo: {},
  87. // 规格详情
  88. specsInfo: {},
  89. // 店铺详情
  90. shopInfo: {},
  91. // 参团列表
  92. list: [],
  93. num: 1,
  94. total: 0,
  95. skip: 0,
  96. limit: 6,
  97. page: 0
  98. };
  99. },
  100. onLoad: async function(e) {
  101. const that = this;
  102. that.$set(that, `query`, {
  103. goods_id: e.goods_id || '6343878989bdcb128d846990',
  104. specs_id: e.specs_id || '634394bc32c3065a80eb14ad'
  105. });
  106. },
  107. onShow: function() {
  108. const that = this;
  109. that.watchLogin();
  110. that.search();
  111. },
  112. methods: {
  113. // 开团
  114. async toGroup() {
  115. const that = this;
  116. that.$refs.popup.open();
  117. },
  118. // 计数器
  119. toCount(e) {
  120. const that = this;
  121. that.num = e;
  122. },
  123. // 确认开团 立即参团
  124. async onSubmit(e) {
  125. const that = this;
  126. let user = that.user;
  127. if (user._id) {
  128. let data = {
  129. customer: user._id,
  130. shop: that.shopInfo._id,
  131. goods: that.goodsInfo._id,
  132. goodsSpec: that.specsInfo._id,
  133. num: that.num,
  134. type: '1'
  135. }
  136. if (e._id) {
  137. data.group_id = e._id
  138. }
  139. let arr = await that.$api(`/util/checkCanBuy`, 'POST', data)
  140. if (arr.errcode == '0') {
  141. if (arr.data.result == true) {
  142. uni.navigateTo({
  143. url: `/pagesHome/order/order?key=${arr.data.key}`
  144. })
  145. } else {
  146. uni.showToast({
  147. title: arr.data.msg,
  148. icon: 'none'
  149. })
  150. }
  151. } else {
  152. uni.showToast({
  153. title: arr.errmsg,
  154. icon: 'none'
  155. })
  156. }
  157. } else {
  158. uni.navigateTo({
  159. url: `/pages/login/index`
  160. })
  161. }
  162. },
  163. // 监听用户是否登录
  164. watchLogin() {
  165. const that = this;
  166. uni.getStorage({
  167. key: 'token',
  168. success: function(res) {
  169. let user = that.$jwt(res.data);
  170. that.$set(that, `user`, user);
  171. },
  172. fail: function(err) {}
  173. })
  174. },
  175. // 查询列表
  176. async search() {
  177. const that = this;
  178. let res;
  179. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  180. id: that.query.goods_id
  181. });
  182. if (res.errcode == '0') {
  183. that.$set(that, `goodsInfo`, res.data.goods)
  184. that.$set(that, `shopInfo`, res.data.shop)
  185. }
  186. res = await that.$api(`/goodsSpec/${that.query.specs_id}`, 'GET')
  187. if (res.errcode == '0') {
  188. that.$set(that, `specsInfo`, res.data);
  189. }
  190. let info = {
  191. skip: that.skip,
  192. limit: that.limit,
  193. }
  194. res = await that.$api(`/group`, 'GET', {
  195. ...info
  196. })
  197. if (res.errcode == '0') {
  198. let list = [...that.list, ...res.data];
  199. that.$set(that, `list`, list);
  200. that.$set(that, `total`, res.total)
  201. }
  202. },
  203. // 分页
  204. toPage(e) {
  205. const that = this;
  206. let list = that.list;
  207. let limit = that.limit;
  208. if (that.total > list.length) {
  209. uni.showLoading({
  210. title: '加载中',
  211. mask: true
  212. })
  213. let page = that.page + 1;
  214. that.$set(that, `page`, page)
  215. let skip = page * limit;
  216. that.$set(that, `skip`, skip)
  217. that.search();
  218. uni.hideLoading();
  219. } else uni.showToast({
  220. title: '没有更多数据了'
  221. });
  222. },
  223. // 清空列表
  224. clearPage() {
  225. const that = this;
  226. that.$set(that, `list`, [])
  227. that.$set(that, `skip`, 0)
  228. that.$set(that, `limit`, 6)
  229. that.$set(that, `page`, 0)
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="scss">
  235. .main {
  236. display: flex;
  237. flex-direction: column;
  238. width: 100vw;
  239. height: 100vh;
  240. .one {
  241. .list {
  242. display: flex;
  243. flex-direction: row;
  244. justify-content: space-between;
  245. width: 91vw;
  246. border: 0.5vw dashed var(--ff0Color);
  247. margin: 2vw 2vw 0 2vw;
  248. padding: 2vw;
  249. border-radius: 5px;
  250. .image {
  251. width: 25vw;
  252. height: 25vw;
  253. border-radius: 5px;
  254. margin: 0 2vw 0 0;
  255. }
  256. .list_1_1 {
  257. display: flex;
  258. flex-direction: column;
  259. justify-content: space-between;
  260. flex-grow: 1;
  261. padding: 2vw 0;
  262. .name {
  263. font-size: var(--font16Size);
  264. margin: 0 0 1vw 0;
  265. }
  266. .specs {
  267. display: flex;
  268. justify-content: space-between;
  269. color: var(--f85Color);
  270. font-size: var(--font12Size);
  271. }
  272. .money {
  273. color: var(--fFB1Color);
  274. font-size: var(--font14Size);
  275. margin: 0 0 1vw 0;
  276. text:last-child {
  277. font-size: var(--font16Size);
  278. }
  279. }
  280. }
  281. }
  282. }
  283. .two {
  284. margin: 4vw 0 0 0;
  285. button {
  286. margin: 0 2vw 2vw 2vw;
  287. background-color: #FFA500;
  288. color: var(--fffColor);
  289. }
  290. }
  291. .thr {
  292. position: relative;
  293. flex-grow: 1;
  294. .list {
  295. display: flex;
  296. flex-direction: row;
  297. justify-content: space-between;
  298. align-items: center;
  299. width: 91vw;
  300. border: 1px solid var(--f1Color);
  301. margin: 2vw 2vw 0 2vw;
  302. padding: 0 2vw;
  303. border-radius: 5px;
  304. .image {
  305. width: 25vw;
  306. height: 25vw;
  307. border-radius: 5px;
  308. margin: 0 2vw 0 0;
  309. }
  310. .list_1 {
  311. display: flex;
  312. flex-direction: column;
  313. flex-grow: 1;
  314. padding: 2vw 0;
  315. .name {
  316. font-size: var(--font16Size);
  317. margin: 0 0 1vw 0;
  318. }
  319. .some {
  320. color: var(--f85Color);
  321. font-size: var(--font14Size);
  322. margin: 0 0 1vw 0;
  323. text:last-child {
  324. margin: 0 0 0 1vw;
  325. color: var(--f00Color);
  326. }
  327. }
  328. .other {
  329. display: flex;
  330. justify-content: space-between;
  331. align-items: center;
  332. .other_1 {
  333. font-size: var(--font14Size);
  334. color: var(--f85Color);
  335. text {
  336. font-weight: bold;
  337. padding: 0 1vw 0 0;
  338. color: var(--ff0Color);
  339. }
  340. }
  341. .other_2 {
  342. .btn {
  343. display: flex;
  344. flex-direction: column;
  345. align-items: center;
  346. margin: 0 2vw;
  347. padding: 2vw 3vw;
  348. background-color: var(--ff0Color);
  349. color: var(--fffColor);
  350. border-radius: 2vw;
  351. font-size: var(--font14Size);
  352. text {
  353. font-size: var(--font12Size);
  354. }
  355. }
  356. }
  357. }
  358. }
  359. }
  360. }
  361. }
  362. .scroll-view {
  363. position: absolute;
  364. top: 0;
  365. left: 0;
  366. right: 0;
  367. bottom: 0;
  368. .list-scroll-view {
  369. display: flex;
  370. flex-direction: column;
  371. }
  372. }
  373. .content {
  374. height: 60vw;
  375. .one {
  376. display: flex;
  377. justify-content: flex-start;
  378. align-items: center;
  379. margin: 0 2vw;
  380. padding: 2vw 0;
  381. text {
  382. margin: 0 2vw 0 0;
  383. }
  384. text:last-child {
  385. margin: 0 0 0 2vw;
  386. font-size: var(--font12Size);
  387. color: var(--f85Color);
  388. }
  389. }
  390. .btn {
  391. display: flex;
  392. justify-content: space-between;
  393. position: fixed;
  394. bottom: 0;
  395. .button {
  396. width: 100vw;
  397. padding: 4vw 0;
  398. background-color: var(--fFB1Color);
  399. text-align: center;
  400. font-size: var(--font18Szie);
  401. color: var(--mainColor);
  402. }
  403. }
  404. }
  405. </style>