index.vue 10 KB

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