group.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <view class="one_1">
  6. <input type="text" v-model="searchInfo.goods" @input="toInput" placeholder="搜索商品">
  7. </view>
  8. <view class="one_2">
  9. <button size="mini" @tap="toDislog">筛选</button>
  10. </view>
  11. </view>
  12. <view class="two">
  13. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  14. <view class="list-scroll-view">
  15. <view class="list" v-for="(item,index) in list" :key="index">
  16. <view class="list_1">
  17. <view class="list_1_1">
  18. <view class="shopname">
  19. <text class="iconfont icon-shangdian"></text>
  20. <text>{{item.shop.name}}</text>
  21. </view>
  22. <view class="status">
  23. {{item.zhStatus||'暂无'}}
  24. </view>
  25. </view>
  26. <view class="list_1_2">
  27. <view class="goods">
  28. <view class="goods_1">
  29. <image class="image" v-if="item.spec.file&&item.spec.file.length>0"
  30. :src="item.spec.file&&item.spec.file.length>0?item.spec.file[0].url:''"
  31. mode=""></image>
  32. <image class="image" v-else
  33. :src="item.goods.file&&item.goods.file.length>0?item.goods.file[0].url:''"
  34. mode=""></image>
  35. </view>
  36. <view class="goods_2">
  37. <view class="goodsname textOver">
  38. {{item.goods.name}}
  39. </view>
  40. <view class="time" v-if="item.leader">
  41. 团长:{{item.leader.name}}
  42. </view>
  43. <view class="time">
  44. 开始时间:{{item.start_time}}
  45. </view>
  46. <view class="time">
  47. 结束时间:{{item.end_time}}
  48. </view>
  49. <view class="time">
  50. 人数限制:{{item.person_limit}}人
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="btn">
  57. <button type="default" size="mini" @tap.stop="toJion(item)">参加团购</button>
  58. </view>
  59. </view>
  60. <view class="is_bottom" v-if="is_bottom">
  61. <text>{{config.bottom_title}}</text>
  62. </view>
  63. </view>
  64. </scroll-view>
  65. </view>
  66. <view class="dialog" v-if="dialog.show==true">
  67. <view class="dialog_1" v-if="dialog.type=='1'">
  68. <uni-forms ref="form" :modelValue="searchInfo" :rules="rules" label-width="auto">
  69. <uni-forms-item label="团长名称" name="leader">
  70. <uni-easyinput type="text" v-model="searchInfo.leader" placeholder="请输入团长名称" />
  71. </uni-forms-item>
  72. <uni-forms-item label="人数限制" name="person_limit">
  73. <uni-easyinput type="number" v-model="searchInfo.person_limit" placeholder="请输入人数限制" />
  74. </uni-forms-item>
  75. <uni-forms-item label="开始时间" name="start_time">
  76. <uni-datetime-picker type="datetime" v-model="searchInfo.start_time" @change="startChange" />
  77. </uni-forms-item>
  78. <uni-forms-item label="结束时间" name="end_time">
  79. <uni-datetime-picker type="datetime" v-model="searchInfo.end_time" @change="endChange" />
  80. </uni-forms-item>
  81. </uni-forms>
  82. <view class="btn">
  83. <button type="primary" @click="onSubmit" size="mini">确定</button>
  84. <button type="primary" @click="dialogClose" size="mini">取消</button>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </mobile-frame>
  90. </template>
  91. <script>
  92. export default {
  93. data() {
  94. return {
  95. // 系统设置
  96. config: {},
  97. // 设备信息
  98. system: {},
  99. user: {},
  100. searchInfo: {},
  101. list: [],
  102. total: 0,
  103. skip: 0,
  104. limit: 6,
  105. page: 0,
  106. // 数据是否触底
  107. is_bottom: false,
  108. scrollTop: 0,
  109. // 字典表
  110. statusList: [],
  111. status_name: "",
  112. // 条件弹出框
  113. dialog: {
  114. show: false,
  115. type: '1'
  116. }
  117. };
  118. },
  119. onLoad: function(e) {
  120. const that = this;
  121. that.searchConfig();
  122. },
  123. onShow: async function(e) {
  124. const that = this;
  125. await that.searchOther();
  126. await that.watchlogin();
  127. await that.search();
  128. },
  129. onPullDownRefresh: async function() {
  130. const that = this;
  131. that.clearPage();
  132. await that.search();
  133. uni.stopPullDownRefresh();
  134. },
  135. methods: {
  136. // 查询基本设置
  137. searchConfig() {
  138. const that = this;
  139. uni.getStorage({
  140. key: 'config',
  141. success: function(res) {
  142. if (res.data) that.$set(that, `config`, res.data)
  143. // 设备平台信息
  144. let config = that.$config;
  145. that.$set(that, `system`, config.system);
  146. },
  147. fail: function(err) {
  148. console.log(err);
  149. }
  150. })
  151. },
  152. // 监听用户是否登录
  153. watchlogin() {
  154. const that = this;
  155. uni.getStorage({
  156. key: 'token',
  157. success: function(res) {
  158. let user = that.$jwt(res.data);
  159. if (user) that.$set(that, `user`, user)
  160. }
  161. })
  162. },
  163. // 开始时间选择
  164. startChange(e) {
  165. const that = this;
  166. that.$set(that.searchInfo, `start_time`, e);
  167. },
  168. // 结束时间选择
  169. endChange(e) {
  170. const that = this;
  171. that.$set(that.searchInfo, `end_time`, e);
  172. },
  173. async search() {
  174. const that = this;
  175. let info = {
  176. skip: that.skip,
  177. limit: that.limit,
  178. status: '0'
  179. }
  180. let res = await that.$api(`/group`, 'GET', {
  181. ...info,
  182. ...that.searchInfo
  183. }, 'group');
  184. if (res.errcode == '0') {
  185. let list = [...that.list, ...res.data];
  186. for (let val of list) {
  187. if (val.status) val.zhStatus = that.searchStatus(val.status)
  188. }
  189. that.$set(that, `list`, list);
  190. that.$set(that, `total`, res.total)
  191. } else {
  192. uni.showToast({
  193. title: res.errmsg,
  194. icon: 'none'
  195. })
  196. }
  197. },
  198. // 查询状态
  199. searchStatus(e) {
  200. const that = this;
  201. let data = that.statusList.find((i) => i.value == e);
  202. if (data) return data.label
  203. else return '暂无'
  204. },
  205. // 参加团购
  206. toJion(e) {
  207. const that = this;
  208. that.clearPage();
  209. uni.navigateTo({
  210. url: `/pagesHome/group/share?id=${e.goods._id}&group=${e._id}`
  211. })
  212. },
  213. // 分页
  214. toPage(e) {
  215. const that = this;
  216. let list = that.list;
  217. let limit = that.limit;
  218. if (that.total > list.length) {
  219. uni.showLoading({
  220. title: '加载中',
  221. mask: true
  222. })
  223. let page = that.page + 1;
  224. that.$set(that, `page`, page)
  225. let skip = page * limit;
  226. that.$set(that, `skip`, skip)
  227. that.search();
  228. uni.hideLoading();
  229. } else that.$set(that, `is_bottom`, true)
  230. },
  231. toScroll(e) {
  232. const that = this;
  233. let up = that.scrollTop;
  234. that.$set(that, `scrollTop`, e.detail.scrollTop);
  235. let num = Math.sign(up - e.detail.scrollTop);
  236. if (num == 1) that.$set(that, `is_bottom`, false);
  237. },
  238. // 查询条件
  239. toDislog() {
  240. const that = this;
  241. that.$set(that, `searchInfo`, {})
  242. that.$set(that, `status_name`, '')
  243. that.$set(that, `dialog`, {
  244. show: true,
  245. type: '1'
  246. })
  247. },
  248. // 状态选择
  249. statusChange(e) {
  250. const that = this;
  251. let data = that.statusList[e.detail.value];
  252. if (data) {
  253. that.$set(that.searchInfo, `status`, data.value);
  254. that.$set(that, `status_name`, data.label);
  255. }
  256. },
  257. // 关闭弹框
  258. dialogClose() {
  259. const that = this;
  260. that.clearPage();
  261. that.search();
  262. that.$set(that, `dialog`, {
  263. show: false,
  264. type: '1'
  265. })
  266. },
  267. // 查询
  268. onSubmit() {
  269. const that = this;
  270. that.clearPage();
  271. that.search();
  272. that.$set(that, `dialog`, {
  273. show: false,
  274. type: '1'
  275. })
  276. },
  277. // 查询其他信息
  278. async searchOther() {
  279. const that = this;
  280. let res;
  281. // 查询状态
  282. res = await that.$api(`/dictData`, 'GET', {
  283. code: 'group_status'
  284. })
  285. if (res.errcode == '0') that.$set(that, `statusList`, res.data);
  286. },
  287. // 输入框
  288. toInput(e) {
  289. const that = this;
  290. if (that.searchInfo.goods) that.$set(that.searchInfo, `goods`, e.detail.value)
  291. else that.$set(that, `searchInfo`, {})
  292. that.clearPage();
  293. that.search();
  294. },
  295. // 清空列表
  296. clearPage() {
  297. const that = this;
  298. that.$set(that, `list`, [])
  299. that.$set(that, `skip`, 0)
  300. that.$set(that, `limit`, 6)
  301. that.$set(that, `page`, 0)
  302. }
  303. },
  304. }
  305. </script>
  306. <style lang="scss">
  307. .main {
  308. display: flex;
  309. flex-direction: column;
  310. width: 100vw;
  311. height: 100vh;
  312. .one {
  313. display: flex;
  314. justify-content: center;
  315. align-items: center;
  316. padding: 2vw;
  317. .one_1 {
  318. padding: 0 2vw;
  319. width: 75vw;
  320. input {
  321. padding: 2vw;
  322. background-color: var(--f1Color);
  323. font-size: var(--font14Size);
  324. border-radius: 5px;
  325. }
  326. }
  327. button {
  328. background-color: #23B67A;
  329. color: #ffffff;
  330. }
  331. }
  332. .two {
  333. position: relative;
  334. flex-grow: 1;
  335. background-color: var(--f9Color);
  336. .list {
  337. background-color: #fff;
  338. border: 1px solid var(--f5Color);
  339. padding: 2vw;
  340. margin: 0 2vw 2vw 2vw;
  341. border-radius: 5px;
  342. .list_1 {
  343. .list_1_1 {
  344. display: flex;
  345. justify-content: space-between;
  346. margin: 0 0 2vw 0;
  347. .shopname {
  348. text:last-child {
  349. padding: 0 0 0 2vw;
  350. }
  351. }
  352. .status {
  353. color: var(--ff0Color);
  354. }
  355. }
  356. .list_1_2 {
  357. border-bottom: 1px solid #f1f1f1;
  358. .goods {
  359. display: flex;
  360. padding: 0 0 2vw 0;
  361. .goods_1 {
  362. width: 20vw;
  363. height: 20vw;
  364. .image {
  365. width: 100%;
  366. height: 100%;
  367. border-radius: 5px;
  368. }
  369. }
  370. .goods_2 {
  371. width: 70vw;
  372. padding: 0 0 0 2vw;
  373. .goodsname {
  374. font-size: 16px;
  375. margin: 0 0 1vw 0;
  376. }
  377. .time {
  378. font-size: 14px;
  379. color: #858585;
  380. }
  381. }
  382. }
  383. }
  384. .other {
  385. padding: 0 0 2vw 0;
  386. margin: 2vw 0;
  387. text-align: right;
  388. border-bottom: 1px solid #f1f1f1;
  389. text {
  390. font-size: 14px;
  391. padding: 0 0 0 2vw;
  392. }
  393. }
  394. }
  395. .btn {
  396. text-align: right;
  397. margin: 1vw 0 0 0;
  398. button {
  399. margin: 0 1vw 0 0;
  400. }
  401. }
  402. }
  403. }
  404. }
  405. .dialog {
  406. position: fixed;
  407. width: 96vw;
  408. height: 100vh;
  409. background-color: #ffffff;
  410. z-index: 99999;
  411. display: flex;
  412. flex-direction: column;
  413. padding: 2vw;
  414. .uni-input {
  415. border: #f1f1ff 1px solid;
  416. padding: 2vw 2vw;
  417. border-radius: 1vw;
  418. }
  419. .picker {
  420. border: 1px solid #3333;
  421. border-radius: 5px;
  422. padding: 2vw;
  423. }
  424. .btn {
  425. text-align: center;
  426. button {
  427. margin: 0 2vw 2vw 2vw;
  428. background-color: #23B67A;
  429. color: #ffffff;
  430. }
  431. .name {
  432. color: var(--f85Color);
  433. font-size: var(--font14Size);
  434. }
  435. }
  436. }
  437. .scroll-view {
  438. position: absolute;
  439. top: 0;
  440. left: 0;
  441. right: 0;
  442. bottom: 0;
  443. .list-scroll-view {
  444. display: flex;
  445. flex-direction: column;
  446. }
  447. }
  448. .is_bottom {
  449. text-align: center;
  450. text {
  451. padding: 2vw 0;
  452. display: inline-block;
  453. color: #858585;
  454. font-size: 14px;
  455. }
  456. }
  457. </style>