index.vue 9.4 KB

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