list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <app-layout>
  3. <view class="list-head">
  4. <view class="dir-left-nowrap cross-center mch-list-input">
  5. <view class="box-grow-1 box dir-left main-center cross-center">
  6. <view v-if="toSearch" class="search-content">
  7. <input class="input"
  8. :value="keyword"
  9. @input="bindInput"
  10. @confirm="bindConfirm"
  11. @blur="beSearch"
  12. confirm-type="search"
  13. :focus="getFocus"/>
  14. <view v-if="keyword.length" @click="cancelPrint" class="main-center cross-center close-word">
  15. <icon class="icon-close" type></icon>
  16. </view>
  17. </view>
  18. <view v-else @click="beSearch" class="main-center search-content cross-center">
  19. <icon class="icon-search" type></icon>
  20. <text class="search-text">搜索</text>
  21. </view>
  22. </view>
  23. <view @click="changeCat" class="cross-center">
  24. <icon class="icon-cats" type></icon>
  25. </view>
  26. </view>
  27. <view v-if="catModel" class="list-cat-model dir-left-wrap cross-center">
  28. <view v-for="(v,k) in cat_list" :key="k">
  29. <view @click="cat(v.id)">
  30. <view class="cat-name">{{v.name}}</view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="gap"></view>
  36. <view class="no-content" v-if="!list || list.length === 0">暂无店铺记录</view>
  37. <app-good-shop-recommendation v-else :theme="getTheme" :coupon_req="true" :mch_list="list" :show-goods="true"></app-good-shop-recommendation>
  38. </app-layout>
  39. </template>
  40. <script>
  41. import appGoodShopRecommendation
  42. from '../../../components/page-component/app-good-shop-recommendation/app-good-shop-recommendation.vue';
  43. import {mapGetters, mapState} from "vuex";
  44. export default {
  45. name: "list",
  46. components: {appGoodShopRecommendation},
  47. data() {
  48. return {
  49. catModel: false,
  50. toSearch: false,
  51. list: [],
  52. cat_list: [],
  53. page: 1,
  54. keyword: '',
  55. mch_common_cat_id: 0,
  56. load: false,
  57. args: false,
  58. latitude: 0,
  59. longitude: 0,
  60. page_loading: false,
  61. getFocus: false
  62. }
  63. },
  64. onLoad(options) { this.$commonLoad.onload(options);
  65. this.getLocation();
  66. this.getCats();
  67. },
  68. onReachBottom: function () {
  69. const self = this;
  70. if (self.args || self.load)
  71. return;
  72. self.load = true;
  73. let page = self.page + 1;
  74. self.$request({
  75. url: self.$api.mch.index,
  76. data: {
  77. keyword: self.keyword,
  78. latitude: self.latitude,
  79. longitude: self.longitude,
  80. mch_common_cat_id: self.mch_common_cat_id,
  81. page: page,
  82. }
  83. }).then(info => {
  84. if (info.code === 0) {
  85. [self.page, self.args, self.list] = [page, info.data.list.length === 0, self.list.concat(self.dataMap(info.data.list))];
  86. }
  87. self.load = false;
  88. });
  89. },
  90. // #ifdef MP
  91. onShareAppMessage() {
  92. return this.$shareAppMessage({
  93. title: `好店推荐`,
  94. path: '/plugins/mch/list/list',
  95. params: {}
  96. });
  97. },
  98. // #endif
  99. methods: {
  100. dataMap(list) {
  101. if (!list)
  102. return;
  103. list.forEach(item => {
  104. item.pic_url = item.store.cover_url;
  105. item.name = item.store.name;
  106. item.goods_num = item.goods_count;
  107. item.order_num = item.order_goods_count;
  108. item.goodsList = item.goods;
  109. item.goodsList.forEach(item1 => {
  110. item1.picUrl = item1.goodsWarehouse.cover_pic;
  111. })
  112. });
  113. return list;
  114. },
  115. getLocation() {
  116. const self = this;
  117. // #ifdef MP
  118. uni.getLocation({
  119. type: 'wgs84',
  120. success(res) {
  121. [self.latitude, self.longitude] = [res.latitude, res.longitude];
  122. },
  123. complete(res) {
  124. console.warn(res);
  125. self.loadData();
  126. }
  127. })
  128. // #endif
  129. // #ifdef H5
  130. this.$jwx.getLocation({
  131. success(res) {
  132. [self.latitude, self.longitude] = [res.latitude, res.longitude];
  133. self.loadData();
  134. },
  135. fail() {
  136. self.loadData();
  137. }
  138. });
  139. // #endif
  140. },
  141. loadData() {
  142. const self = this;
  143. self.$showLoading();
  144. self.$request({
  145. url: self.$api.mch.index,
  146. data: {
  147. keyword: self.keyword,
  148. latitude: self.latitude,
  149. longitude: self.longitude,
  150. mch_common_cat_id: self.mch_common_cat_id,
  151. }
  152. }).then(info => {
  153. self.$hideLoading();
  154. if (info.code === 0) {
  155. self.list = self.dataMap(info.data.list);
  156. }
  157. }).catch(info => {
  158. self.$hideLoading();
  159. })
  160. },
  161. //分类处理
  162. getCats() {
  163. const self = this;
  164. self.$request({
  165. url: self.$api.mch.category,
  166. }).then(info => {
  167. self.cat_list = info.data.list;
  168. });
  169. },
  170. navShop(mch_id) {
  171. uni.navigateTo({url: `/plugins/mch/shop/shop?mch_id=` + mch_id});
  172. },
  173. navGoods(mch_id, goods_id) {
  174. uni.navigateTo({url: `/plugins/mch/goods/goods?id=` + goods_id + `&mch_id=` + mch_id});
  175. },
  176. beSearch: function (e) {
  177. if (this.keyword.length === 0) {
  178. this.toSearch = !this.toSearch;
  179. this.getFocus = this.toSearch;
  180. }
  181. },
  182. //搜索
  183. bindConfirm() {
  184. [
  185. this.page,
  186. this.mch_common_cat_id,
  187. this.catModel,
  188. this.list
  189. ] = [
  190. 1,
  191. 0,
  192. false,
  193. []
  194. ]
  195. this.loadData();
  196. },
  197. cat(id) {
  198. [this.mch_common_cat_id, this.list, this.page, this.catModel] = [id, [], 1, false];
  199. this.loadData();
  200. },
  201. changeCat() {
  202. this.catModel = !this.catModel;
  203. },
  204. bindInput: function (e) {
  205. this.keyword = e.detail.value;
  206. },
  207. cancelPrint() {
  208. this.keyword = '';
  209. this.toSearch = false;
  210. this.bindConfirm();
  211. },
  212. },
  213. computed: {
  214. ...mapGetters('mallConfig', {
  215. getTheme: 'getTheme',
  216. }),
  217. },
  218. }
  219. </script>
  220. <style scoped lang="scss">
  221. .search-content {
  222. height: #{56rpx};
  223. border-radius: #{28rpx};
  224. background: #fff;
  225. position: relative;
  226. width: 100%;
  227. margin-left: #{24rpx};
  228. .input {
  229. height: #{56rpx};
  230. border-radius: #{28rpx};
  231. color: #353535;
  232. width: 90%;
  233. background-color: #ffffff;
  234. }
  235. .icon-search {
  236. background-image: url("../../../static/image/icon/icon-search.png");
  237. height: #{24rpx};
  238. width: #{24rpx};
  239. background-size: 100% auto;
  240. margin-right: #{10rpx};
  241. background-repeat: no-repeat;
  242. }
  243. }
  244. .search-text {
  245. color: #b2b2b2;
  246. font-size: #{24rpx};
  247. margin: 0 #{5rpx};
  248. }
  249. .list-head {
  250. position: fixed;
  251. top: 0;
  252. z-index: 1;
  253. width: 100%;
  254. }
  255. .no-content {
  256. color: #888;
  257. padding: #{100rpx} 0 0 0;
  258. text-align: center;
  259. }
  260. .mch-list-input {
  261. height: #{88rpx};
  262. padding: 0 #{24rpx};
  263. background: #EFEFF4;
  264. .box {
  265. margin-right: #{24rpx};
  266. height: #{56rpx};
  267. border-radius: #{28rpx};
  268. background: #FFFFFF;
  269. input {
  270. border-radius: #{28rpx};
  271. }
  272. }
  273. .icon-cats {
  274. background-image: url("./../image/list-cat.png");
  275. background-repeat: no-repeat;
  276. background-size: 100% auto;
  277. height: #{30rpx};
  278. width: #{38rpx};
  279. }
  280. .close-word {
  281. height: #{56rpx};
  282. width: #{70rpx};
  283. position: absolute;
  284. right: 0;
  285. top: 0;
  286. z-index: 20;
  287. .icon-close {
  288. background-image: url("../../../static/image/icon/icon-close.png");
  289. background-repeat: no-repeat;
  290. background-size: 100% auto;
  291. height: #{25rpx};
  292. width: #{25rpx};
  293. }
  294. }
  295. }
  296. .list-cat-model {
  297. padding-top: #{12rpx};
  298. padding-bottom: #{12rpx};
  299. padding-left: #{20rpx};
  300. background: #f7f7f7;
  301. .cat-name {
  302. color: #353535;
  303. font-size: #{24rpx};
  304. border: #{1rpx} solid #e7e7e7;
  305. border-radius: #{28rpx};
  306. line-height: #{56rpx};
  307. height: #{56rpx};
  308. background: #ffffff;
  309. padding: 0 #{24rpx};
  310. margin: #{10rpx} #{12rpx} #{10rpx} #{12rpx};
  311. }
  312. }
  313. .gap {
  314. height: #{88rpx};
  315. }
  316. .list-shop {
  317. margin: #{10rpx} #{20rpx};
  318. width: #{710rpx};
  319. background: #fff;
  320. border-radius: #{16rpx};
  321. }
  322. .list-shop .shop-info {
  323. padding-right: #{24rpx};
  324. }
  325. .list-shop .distance {
  326. align-self: flex-start;
  327. padding-top: #{36rpx};
  328. font-size: #{24rpx};
  329. color: #999999;
  330. padding-right: #{50rpx};
  331. }
  332. .list-shop .list-shop-icon {
  333. border-radius: #{8rpx};
  334. height: #{100rpx};
  335. width: #{100rpx};
  336. margin: #{24rpx};
  337. }
  338. .list-shop .name {
  339. color: #353535;
  340. font-size: #{28rpx};
  341. margin-bottom: #{24rpx};
  342. }
  343. .list-shop .shop {
  344. font-size: #{24rpx};
  345. color: #999;
  346. }
  347. .list-shop .goods-num {
  348. padding-right: #{32rpx};
  349. }
  350. .list-shop .goods {
  351. padding-bottom: #{24rpx};
  352. margin: 0 #{16rpx};
  353. }
  354. .list-shop .goods-box {
  355. margin: 0 #{8rpx};
  356. }
  357. .list-shop .goods-info {
  358. position: relative;
  359. height: #{210rpx};
  360. width: #{210rpx};
  361. }
  362. .list-shop .goods-info view {
  363. background: #fff;
  364. font-size: #{28rpx};
  365. opacity: 0.8;
  366. width: #{210rpx};
  367. color: #ff4544;
  368. height: #{50rpx};
  369. position: absolute;
  370. bottom: 0;
  371. }
  372. .list-shop .goods-info image {
  373. height: 100%;
  374. width: 100%;
  375. }
  376. </style>