index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <app-layout>
  3. <view class="book-index">
  4. <view class="page-width quick-navigation">
  5. <app-quick-navigation></app-quick-navigation>
  6. </view>
  7. <view class="page-width head-nav-list" v-if="is_show_cat === 1">
  8. <app-head-nav-list
  9. v-bind:catList="catList"
  10. @click="changeStatus"
  11. v-bind:cat_id="cat_id"
  12. :theme="getTheme"
  13. ></app-head-nav-list>
  14. </view>
  15. <view class="page-width" :class="is_show_cat === 1 ? 'product-list' : ''" v-if="goods_list.length > 0">
  16. <app-product-list :theme="getTheme" v-bind:goodsList="goods_list"
  17. @route_go="route_go"></app-product-list>
  18. </view>
  19. <view class="page-width no-goods" v-else>
  20. <app-no-goods background="#f7f7f7"></app-no-goods>
  21. </view>
  22. </view>
  23. </app-layout>
  24. </template>
  25. <script>
  26. import appHeadNavList from '../components/app-head-nav-list.vue';
  27. import appProductList from '../components/app-product-list.vue';
  28. import appQuickNavigation from "../../../components/page-component/app-quick-navigation/app-quick-navigation.vue";
  29. import appNoGoods from '../../../components/page-component/app-no-goods/app-no-goods.vue';
  30. import {mapGetters, mapState} from "vuex";
  31. export default {
  32. name: "index",
  33. data() {
  34. return {
  35. catList: [],
  36. cat_id: 0,
  37. page: 1,
  38. goods_list: [],
  39. page_count: 1,
  40. is_show_cat: 0,
  41. text: '123123123'
  42. }
  43. },
  44. onLoad(option) { this.$commonLoad.onload(option);
  45. // #ifdef H5
  46. if (!this.$jwx.isWechat()) {
  47. uni.getLocation({
  48. success: function () {
  49. },
  50. fail: function () {
  51. window.location.reload();
  52. },
  53. });
  54. }
  55. // #endif
  56. this.requestCats().then(() => {
  57. if (option.cat_id) {
  58. this.cat_id = option.cat_id;
  59. } else {
  60. this.cat_id = this.catList[0].id;
  61. }
  62. this.requestList();
  63. });
  64. // #ifdef MP-WEIXIN
  65. wx.showShareMenu({
  66. menus: ['shareAppMessage', 'shareTimeline']
  67. })
  68. // #endif
  69. },
  70. methods: {
  71. async requestCats() {
  72. this.$showLoading();
  73. const e = await this.$request({
  74. url: this.$api.book.cats,
  75. method: 'get'
  76. });
  77. this.$hideLoading();
  78. if (e.code === 0) {
  79. this.catList = e.data.cat;
  80. this.is_show_cat = e.data.is_show_cat;
  81. }
  82. },
  83. async requestList(status) {
  84. const res = await this.$request({
  85. url: this.$api.book.list,
  86. data: {
  87. page: this.page,
  88. cat_id: this.cat_id,
  89. }
  90. });
  91. if (res.code === 0) {
  92. if (status) this.goods_list = [];
  93. this.dataProcessing(res.data);
  94. }
  95. },
  96. changeStatus(status) {
  97. this.page = 1;
  98. this.cat_id = status;
  99. this.requestList(true);
  100. },
  101. dataProcessing(data) {
  102. for (let i = 0; i < data.list.length; i += 2) {
  103. if (i + 1 !== data.list.length) {
  104. this.goods_list.push([data.list[i], data.list[i + 1]]);
  105. } else {
  106. this.goods_list.push([data.list[i]]);
  107. }
  108. }
  109. this.page_count = data.pagination.page_count;
  110. },
  111. route_go(data) {
  112. let _this = this;
  113. // #ifndef MP-BAIDU
  114. if (data.video_url && this.getVideo == 1) {
  115. // #ifdef MP
  116. uni.navigateTo({
  117. url: `/pages/goods/video?goods_id=${data.goods_id}&sign=booking`
  118. });
  119. // #endif
  120. // #ifdef H5
  121. if (this.$jwx.isWechat()) {
  122. this.$jwx.getLocation({
  123. success: function() {
  124. uni.navigateTo({
  125. url: `/plugins/book/goods/goods?goods_id=${data.goods_id}`,
  126. });
  127. },
  128. fail: function() {
  129. uni.showToast({
  130. title: '请开启位置权限',
  131. icon: 'none',
  132. duration: 1000,
  133. success: function () {
  134. }
  135. });
  136. }
  137. })
  138. } else {
  139. uni.getLocation({
  140. type: 'wgs84',
  141. success: function () {
  142. uni.navigateTo({
  143. url: `/plugins/book/goods/goods?goods_id=${data.goods_id}`,
  144. });
  145. },
  146. fail: function (res) {
  147. uni.showToast({
  148. title: '请开启位置权限',
  149. icon: 'none',
  150. duration: 1000,
  151. success: function () {
  152. }
  153. });
  154. },
  155. });
  156. }
  157. // #endif
  158. } else {
  159. // #ifndef H5
  160. uni.getLocation({
  161. type: 'wgs84',
  162. success: function () {
  163. uni.navigateTo({
  164. url: `/plugins/book/goods/goods?goods_id=${data.goods_id}`,
  165. });
  166. },
  167. fail: function () {
  168. uni.showToast({
  169. title: '请开启位置权限',
  170. icon: 'none',
  171. duration: 1000,
  172. success: function () {
  173. }
  174. });
  175. },
  176. });
  177. // #endif
  178. // #ifdef H5
  179. if (this.$jwx.isWechat()) {
  180. this.$jwx.getLocation({
  181. success: function() {
  182. uni.navigateTo({
  183. url: `/plugins/book/goods/goods?goods_id=${data.goods_id}`,
  184. });
  185. },
  186. fail: function() {
  187. uni.showToast({
  188. title: '请开启位置权限',
  189. icon: 'none',
  190. duration: 1000,
  191. success: function () {
  192. }
  193. });
  194. }
  195. })
  196. } else {
  197. uni.navigateTo({
  198. url: `/plugins/book/goods/goods?goods_id=${data.goods_id}`,
  199. });
  200. // uni.getLocation({
  201. // success: function () {
  202. // uni.navigateTo({
  203. // url: `/plugins/book/goods/goods?goods_id=${data.goods_id}`,
  204. // });
  205. // },
  206. // fail: function () {
  207. // uni.showModal({
  208. // title: '提示',
  209. // content: '定位失败,确保定位服务已开启',
  210. // success: function (res) {
  211. // if (res.confirm) {
  212. // window.location.reload();
  213. // } else if (res.cancel) {
  214. // let pages = getCurrentPages();
  215. // if (pages.length > 1) {
  216. // uni.navigateBack();
  217. // } else {
  218. // uni.navigateTo({
  219. // url: 'pages/index/index'
  220. // });
  221. // }
  222. // }
  223. // }
  224. // });
  225. // },
  226. // });
  227. }
  228. // #endif
  229. }
  230. // #endif
  231. // #ifdef MP-BAIDU
  232. uni.getLocation({
  233. type: 'wgs84',
  234. success: function () {
  235. uni.navigateTo({
  236. url: `/plugins/book/goods/goods?goods_id=${data.goods_id}`,
  237. });
  238. },
  239. fail: function () {
  240. uni.showToast({
  241. title: '请开启位置权限',
  242. icon: 'none',
  243. duration: 1000,
  244. success: function () {
  245. }
  246. });
  247. },
  248. });
  249. // #endif
  250. }
  251. },
  252. onReachBottom() {
  253. if (this.page < this.page_count) {
  254. this.page++;
  255. this.requestList();
  256. }
  257. },
  258. computed: {
  259. ...mapGetters('mallConfig', {
  260. getTheme: 'getTheme',
  261. }),
  262. ...mapState({
  263. platform: function(state) {
  264. return state.gConfig.systemInfo.platform;
  265. }
  266. })
  267. },
  268. // #ifdef MP
  269. onShareAppMessage() {
  270. return this.$shareAppMessage({
  271. path: '/plugins/book/index/index',
  272. title: this.$children[0].navigationBarTitle,
  273. });
  274. },
  275. // #endif
  276. // #ifdef MP-WEIXIN
  277. onShareTimeline() {
  278. // 分享朋友圈beta
  279. return this.$shareTimeline({
  280. title: this.$children[0].navigationBarTitle,
  281. query: {} // 此处填写页面的参数
  282. });
  283. },
  284. // #endif
  285. components: {
  286. 'app-head-nav-list': appHeadNavList,
  287. 'app-product-list': appProductList,
  288. 'app-quick-navigation': appQuickNavigation,
  289. 'app-no-goods': appNoGoods,
  290. },
  291. }
  292. </script>
  293. <style scoped lang="scss">
  294. .head-nav-list {
  295. position: fixed;
  296. top: 0;
  297. left: 0;
  298. z-index: 1500;
  299. }
  300. .product-list {
  301. margin-top: #{100rpx};
  302. }
  303. .no-goods {
  304. margin-top: #{150rpx};
  305. }
  306. </style>