index.vue 9.3 KB

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