store.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. this.t(() => {
  56. uni.getLocation({
  57. success: function (res) {
  58. self.longitude = res.longitude;
  59. self.latitude = res.latitude;
  60. self.loadData();
  61. },
  62. fail: function (res) {
  63. uni.showToast({
  64. title: '请开启手机位置权限',
  65. icon: 'none',
  66. duration: 1000,
  67. success: function () {
  68. }
  69. });
  70. },
  71. });
  72. });
  73. },
  74. onPullDownRefresh: function () {
  75. const self = this;
  76. self.keyword = '';
  77. self.toSearch = false;
  78. self.page = 1;
  79. this.t(() => {
  80. uni.getLocation({
  81. success: function (res) {
  82. self.longitude = res.longitude;
  83. self.latitude = res.latitude;
  84. self.loadData();
  85. },
  86. fail: function (res) {
  87. uni.showToast({
  88. title: '请开启手机位置权限',
  89. icon: 'none',
  90. duration: 1000,
  91. success: function () {
  92. }
  93. });
  94. },
  95. complete: function () {
  96. uni.stopPullDownRefresh();
  97. }
  98. });
  99. });
  100. },
  101. onShareAppMessage: function (e) {
  102. return this.$shareAppMessage({
  103. title: this.$children[0].navigationBarTitle,
  104. path: '/pages/store/store',
  105. params: {}
  106. });
  107. },
  108. onReachBottom: function () {
  109. const self = this;
  110. if (self.args || self.load)
  111. return;
  112. self.load = true;
  113. let page = self.page + 1;
  114. self.$request({
  115. url: self.url,
  116. data: {
  117. page: page,
  118. longitude: self.longitude,
  119. latitude: self.latitude,
  120. keyword: self.keyword,
  121. goods_id: self.goods_id,
  122. }
  123. }).then(info => {
  124. if (info.code === 0) {
  125. [self.page, self.args, self.list] = [page, info.data.list.length === 0, self.list.concat(self.forMatter(info.data.list))];
  126. }
  127. self.load = false;
  128. });
  129. },
  130. methods: {
  131. t(func) {
  132. // #ifdef MP-ALIPAY
  133. func();
  134. // #endif
  135. // #ifndef MP-ALIPAY
  136. const scope = 'scope.userLocation';
  137. uni.authorize({
  138. scope,
  139. success(res) {
  140. func();
  141. },
  142. fail(e) {
  143. uni.showModal({
  144. title: '提示',
  145. content: '您好,请先授权地理位置权限',
  146. showCancel: false,
  147. success(res) {
  148. if (res.confirm) {
  149. uni.openSetting({
  150. success(settingdata) {
  151. if (settingdata.authSetting[scope]) {
  152. func();
  153. }
  154. }
  155. })
  156. }
  157. }
  158. })
  159. }
  160. });
  161. // #endif
  162. },
  163. /*
  164. * update
  165. */
  166. forMatter(list) {
  167. list.forEach((v, k) => {
  168. v.pic_url = v.cover_url;
  169. let array = [];
  170. for (let i = 0; i < v.score; i++) {
  171. array.push(i);
  172. }
  173. v.score = array
  174. })
  175. return list;
  176. },
  177. //搜索
  178. bindConfirm: function (e) {
  179. this.loadData();
  180. },
  181. beSearch: function (e) {
  182. if (this.keyword.length === 0) {
  183. this.toSearch = !this.toSearch;
  184. this.getFocus = this.toSearch;
  185. }
  186. },
  187. cancelPrint() {
  188. this.keyword = '';
  189. this.toSearch = false;
  190. this.loadData();
  191. },
  192. bindInput: function (e) {
  193. this.keyword = e.detail.value;
  194. },
  195. loadData: function () {
  196. const self = this;
  197. self.$showLoading();
  198. self.$request({
  199. url: self.url,
  200. data: {
  201. keyword: self.keyword,
  202. longitude: self.longitude,
  203. latitude: self.latitude,
  204. goods_id: self.goods_id
  205. },
  206. }).then(info => {
  207. self.$hideLoading();
  208. if (info.code === 0) {
  209. self.list = self.forMatter(info.data.list);
  210. }
  211. }).catch(info => {
  212. self.$hideLoading();
  213. })
  214. },
  215. }
  216. }
  217. </script>
  218. <style scoped lang="scss">
  219. .store-head {
  220. height: #{88rpx};
  221. width: 100%;
  222. .search-content {
  223. height: #{56rpx};
  224. border-radius: #{28rpx};
  225. background: #fff;
  226. position: relative;
  227. width: 100%;
  228. margin: 0 #{24rpx};
  229. padding-left: #{24rpx};
  230. .input {
  231. height: #{56rpx};
  232. border-radius: #{28rpx};
  233. color: #353535;
  234. width: 90%;
  235. background-color: #ffffff;
  236. }
  237. .icon-search {
  238. background-image: url("../../static/image/icon/icon-search.png");
  239. height: #{24rpx};
  240. width: #{24rpx};
  241. background-size: 100% auto;
  242. margin-right: #{10rpx};
  243. background-repeat: no-repeat;
  244. }
  245. .close-word {
  246. height: #{56rpx};
  247. width: #{70rpx};
  248. position: absolute;
  249. right: 0;
  250. top: 0;
  251. z-index: 20;
  252. .icon-close {
  253. background-image: url("../../static/image/icon/icon-close.png");
  254. background-repeat: no-repeat;
  255. background-size: 100% auto;
  256. height: #{25rpx};
  257. width: #{25rpx};
  258. }
  259. }
  260. }
  261. .search-text {
  262. color: #b2b2b2;
  263. font-size: #{24rpx};
  264. margin: 0 #{5rpx};
  265. }
  266. .store-search {
  267. background-color: #ddd;
  268. border-radius: 0 #{10rpx} #{10rpx} 0;
  269. padding: 0 #{20rpx};
  270. }
  271. .store-icon {
  272. margin-bottom: #{10rpx};
  273. margin-right: #{10rpx};
  274. }
  275. }
  276. .shop-list {
  277. background: #FFFFFF;
  278. }
  279. </style>