index.vue 10 KB

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