index.vue 9.6 KB

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