index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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="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. val.persons = val.persons.filter(i => i.status == '0')
  213. let status = that.statusList.find(i => i.value == val.status)
  214. if (status) val.zhStatus = status.label;
  215. val.time = moment(val.meta.createdAt).format('YYYY-MM-DD HH:mm:ss')
  216. }
  217. that.$set(that, `list`, list);
  218. that.$set(that, `total`, res.total)
  219. }
  220. },
  221. // 分页
  222. toPage(e) {
  223. const that = this;
  224. let list = that.list;
  225. let limit = that.limit;
  226. if (that.total > list.length) {
  227. uni.showLoading({
  228. title: '加载中',
  229. mask: true
  230. })
  231. let page = that.page + 1;
  232. that.$set(that, `page`, page)
  233. let skip = page * limit;
  234. that.$set(that, `skip`, skip)
  235. that.search();
  236. uni.hideLoading();
  237. } else uni.showToast({
  238. title: '没有更多数据了'
  239. });
  240. },
  241. // 清空列表
  242. clearPage() {
  243. const that = this;
  244. that.$set(that, `list`, [])
  245. that.$set(that, `skip`, 0)
  246. that.$set(that, `limit`, 6)
  247. that.$set(that, `page`, 0)
  248. }
  249. }
  250. }
  251. </script>
  252. <style lang="scss">
  253. .main {
  254. display: flex;
  255. flex-direction: column;
  256. width: 100vw;
  257. height: 100vh;
  258. .one {
  259. .list {
  260. display: flex;
  261. flex-direction: row;
  262. justify-content: space-between;
  263. width: 91vw;
  264. border: 0.5vw dashed var(--ff0Color);
  265. margin: 2vw 2vw 0 2vw;
  266. padding: 2vw;
  267. border-radius: 5px;
  268. .image {
  269. width: 25vw;
  270. height: 25vw;
  271. border-radius: 5px;
  272. margin: 0 2vw 0 0;
  273. }
  274. .list_1_1 {
  275. display: flex;
  276. flex-direction: column;
  277. justify-content: space-between;
  278. flex-grow: 1;
  279. padding: 2vw 0;
  280. .name {
  281. font-size: var(--font16Size);
  282. margin: 0 0 1vw 0;
  283. }
  284. .specs {
  285. display: flex;
  286. justify-content: space-between;
  287. color: var(--f85Color);
  288. font-size: var(--font12Size);
  289. }
  290. .money {
  291. color: var(--fFB1Color);
  292. font-size: var(--font14Size);
  293. margin: 0 0 1vw 0;
  294. text:last-child {
  295. font-size: var(--font16Size);
  296. }
  297. }
  298. }
  299. }
  300. }
  301. .two {
  302. margin: 4vw 0 0 0;
  303. button {
  304. margin: 0 2vw 2vw 2vw;
  305. background-color: #FFA500;
  306. color: var(--fffColor);
  307. }
  308. }
  309. .thr {
  310. position: relative;
  311. flex-grow: 1;
  312. .list {
  313. display: flex;
  314. flex-direction: row;
  315. justify-content: space-between;
  316. align-items: center;
  317. width: 91vw;
  318. border: 1px solid var(--f1Color);
  319. margin: 2vw 2vw 0 2vw;
  320. padding: 0 2vw;
  321. border-radius: 5px;
  322. .image {
  323. display: flex;
  324. flex-wrap: wrap;
  325. justify-content: center;
  326. align-items: center;
  327. width: 27vw;
  328. height: 27vw;
  329. border-radius: 5px;
  330. margin: 0 2vw 0 0;
  331. .file {
  332. width: 9vw;
  333. height: 9vw;
  334. }
  335. }
  336. .list_1 {
  337. display: flex;
  338. flex-direction: column;
  339. flex-grow: 1;
  340. padding: 2vw 0;
  341. width: 35vw;
  342. .name {
  343. font-size: var(--font16Size);
  344. margin: 0 0 1vw 0;
  345. }
  346. .some {
  347. color: var(--f85Color);
  348. font-size: var(--font14Size);
  349. text:last-child {
  350. margin: 0 0 0 1vw;
  351. color: var(--f00Color);
  352. }
  353. }
  354. }
  355. .other {
  356. .btn {
  357. display: flex;
  358. flex-direction: column;
  359. align-items: center;
  360. margin: 0 2vw;
  361. padding: 2vw 3vw;
  362. background-color: var(--ff0Color);
  363. color: var(--fffColor);
  364. border-radius: 2vw;
  365. font-size: var(--font14Size);
  366. text {
  367. font-size: var(--font12Size);
  368. }
  369. }
  370. }
  371. }
  372. }
  373. }
  374. .scroll-view {
  375. position: absolute;
  376. top: 0;
  377. left: 0;
  378. right: 0;
  379. bottom: 0;
  380. .list-scroll-view {
  381. display: flex;
  382. flex-direction: column;
  383. }
  384. }
  385. .content {
  386. height: 60vw;
  387. .one {
  388. display: flex;
  389. justify-content: flex-start;
  390. align-items: center;
  391. margin: 0 2vw;
  392. padding: 2vw 0;
  393. text {
  394. margin: 0 2vw 0 0;
  395. }
  396. text:last-child {
  397. margin: 0 0 0 2vw;
  398. font-size: var(--font12Size);
  399. color: var(--f85Color);
  400. }
  401. }
  402. .btn {
  403. display: flex;
  404. justify-content: space-between;
  405. position: fixed;
  406. bottom: 0;
  407. .button {
  408. width: 100vw;
  409. padding: 4vw 0;
  410. background-color: var(--fFB1Color);
  411. text-align: center;
  412. font-size: var(--font18Szie);
  413. color: var(--mainColor);
  414. }
  415. }
  416. }
  417. </style>