store.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <app-layout>
  3. <view class="cross-center store-head">
  4. <view v-if="toSearch" class="search-content">
  5. <input class="input"
  6. :value="keyword"
  7. @input="bindInput"
  8. @confirm="bindConfirm"
  9. @blur="beSearch"
  10. confirm-type="search"
  11. :focus="getFocus"/>
  12. <view v-if="keyword.length" @click="cancelPrint" class="main-center cross-center close-word">
  13. <icon class="icon-close"></icon>
  14. </view>
  15. </view>
  16. <view v-else @click="beSearch" class="main-center search-content cross-center">
  17. <icon class="icon-search"></icon>
  18. <text class="search-text">搜索</text>
  19. </view>
  20. </view>
  21. <view class="shop-list">
  22. <app-shop :list="list"></app-shop>
  23. </view>
  24. </app-layout>
  25. </template>
  26. <script>
  27. import appShop from "../../components/page-component/app-shop/app-shop.vue";
  28. export default {
  29. name: "store",
  30. components: {appShop},
  31. data() {
  32. return {
  33. getFocus: false,
  34. longitude: 0,
  35. latitude: 0,
  36. url: '',
  37. keyword: '',
  38. goods_id: 0,
  39. list: null,
  40. args: false,
  41. load: false,
  42. page: 1,
  43. toSearch: false,
  44. }
  45. },
  46. onLoad: function (options) {
  47. const self = this;
  48. if (options.book_id) {
  49. self.url = self.$api.book.store_list;
  50. self.goods_id = options.book_id
  51. } else {
  52. self.url = self.$api.store.list;
  53. self.goods_id = 0
  54. }
  55. uni.getLocation({
  56. success: function (res) {
  57. self.longitude = res.longitude;
  58. self.latitude = res.latitude;
  59. self.loadData();
  60. },
  61. fail: function (res) {
  62. console.error(res);
  63. },
  64. })
  65. },
  66. onPullDownRefresh: function () {
  67. const self = this;
  68. self.keyword = '';
  69. self.toSearch = false;
  70. self.page = 1;
  71. uni.getLocation({
  72. success: function (res) {
  73. self.longitude = res.longitude;
  74. self.latitude = res.latitude;
  75. self.loadData();
  76. },
  77. complete: function () {
  78. uni.stopPullDownRefresh();
  79. }
  80. })
  81. },
  82. onShareAppMessage: function (e) {
  83. return this.$shareAppMessage({
  84. title: this.$children[0].navigationBarTitle,
  85. path: '/pages/store/store',
  86. params: {}
  87. });
  88. },
  89. onReachBottom: function () {
  90. const self = this;
  91. if (self.args || self.load)
  92. return;
  93. self.load = true;
  94. let page = self.page + 1;
  95. self.$request({
  96. url: self.url,
  97. data: {
  98. page: page,
  99. longitude: self.longitude,
  100. latitude: self.latitude,
  101. keyword: self.keyword,
  102. goods_id: self.goods_id,
  103. }
  104. }).then(info => {
  105. if (info.code === 0) {
  106. [self.page, self.args, self.list] = [page, info.data.list.length === 0, self.list.concat(self.forMatter(info.data.list))];
  107. }
  108. self.load = false;
  109. });
  110. },
  111. methods: {
  112. /*
  113. * update
  114. */
  115. forMatter(list) {
  116. list.forEach((v, k) => {
  117. v.pic_url = v.cover_url;
  118. let array = [];
  119. for (let i = 0; i < v.score; i++) {
  120. array.push(i);
  121. }
  122. v.score = array
  123. })
  124. return list;
  125. },
  126. //搜索
  127. bindConfirm: function (e) {
  128. this.loadData();
  129. },
  130. beSearch: function (e) {
  131. if (this.keyword.length === 0) {
  132. this.toSearch = !this.toSearch;
  133. this.getFocus = this.toSearch;
  134. }
  135. },
  136. cancelPrint() {
  137. this.keyword = '';
  138. this.toSearch = false;
  139. this.loadData();
  140. },
  141. bindInput: function (e) {
  142. this.keyword = e.detail.value;
  143. },
  144. loadData: function () {
  145. const self = this;
  146. self.$showLoading();
  147. self.$request({
  148. url: self.url,
  149. data: {
  150. keyword: self.keyword,
  151. longitude: self.longitude,
  152. latitude: self.latitude,
  153. goods_id: self.goods_id
  154. },
  155. }).then(info => {
  156. self.$hideLoading();
  157. if (info.code === 0) {
  158. self.list = self.forMatter(info.data.list);
  159. }
  160. }).catch(info => {
  161. self.$hideLoading();
  162. })
  163. },
  164. }
  165. }
  166. </script>
  167. <style scoped lang="scss">
  168. .store-head {
  169. height: #{88rpx};
  170. width: 100%;
  171. .search-content {
  172. height: #{56rpx};
  173. border-radius: #{28rpx};
  174. background: #fff;
  175. position: relative;
  176. width: 100%;
  177. margin: 0 #{24rpx};
  178. padding-left: #{24rpx};
  179. .input {
  180. height: #{56rpx};
  181. border-radius: #{28rpx};
  182. color: #353535;
  183. width: 90%;
  184. background-color: #ffffff;
  185. }
  186. .icon-search {
  187. background-image: url("../../static/image/icon/icon-search.png");
  188. height: #{24rpx};
  189. width: #{24rpx};
  190. background-size: 100% auto;
  191. margin-right: #{10rpx};
  192. background-repeat: no-repeat;
  193. }
  194. .close-word {
  195. height: #{56rpx};
  196. width: #{70rpx};
  197. position: absolute;
  198. right: 0;
  199. top: 0;
  200. z-index: 20;
  201. .icon-close {
  202. background-image: url("../../static/image/icon/icon-close.png");
  203. background-repeat: no-repeat;
  204. background-size: 100% auto;
  205. height: #{25rpx};
  206. width: #{25rpx};
  207. }
  208. }
  209. }
  210. .search-text {
  211. color: #b2b2b2;
  212. font-size: #{24rpx};
  213. margin: 0 #{5rpx};
  214. }
  215. .store-search {
  216. background-color: #ddd;
  217. border-radius: 0 #{10rpx} #{10rpx} 0;
  218. padding: 0 #{20rpx};
  219. }
  220. .store-icon {
  221. margin-bottom: #{10rpx};
  222. margin-right: #{10rpx};
  223. }
  224. }
  225. .shop-list {
  226. background: #FFFFFF;
  227. }
  228. </style>