store.vue 10 KB

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