index.vue 10 KB

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