index.vue 10 KB

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