detail.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view">
  6. <view class="list-scroll-view">
  7. <view class="one_1">
  8. <banner :goodsInfo="goodsInfo" :goodsColect="goodsColect" @toGoodscolect="toGoodscolect">
  9. </banner>
  10. </view>
  11. </view>
  12. </scroll-view>
  13. </view>
  14. <view class="two">
  15. <uni-goods-nav :options="options" :button-group="buttonGroup" @click="toNavleft"
  16. @buttonClick="toNavright" />
  17. </view>
  18. </view>
  19. </mobile-frame>
  20. </template>
  21. <script>
  22. import banner from './parts/banner_1.vue';
  23. export default {
  24. components: {
  25. banner
  26. },
  27. data() {
  28. return {
  29. // 系统设置
  30. config: {},
  31. // 商品id
  32. id: '',
  33. // 分享人id
  34. inviter: '',
  35. // 当前用户信息
  36. user: {},
  37. // 是否关注商品
  38. goodsColect: false,
  39. // 是否关注店铺
  40. shopColect: false,
  41. // 评价数
  42. evaluate_num: 0,
  43. // 商品详情
  44. info: {},
  45. // 商品详情
  46. goodsInfo: {},
  47. // 规格
  48. infospecs: {},
  49. // 优惠
  50. discount: {},
  51. // 底部菜单
  52. options: [{
  53. icon: 'shop',
  54. text: '店铺',
  55. type: 'shop',
  56. route: 'pagesHome/shop/index',
  57. },
  58. {
  59. icon: 'cart',
  60. text: '购物车',
  61. type: 'market',
  62. route: 'pages/market/index',
  63. },
  64. ],
  65. buttonGroup: [{
  66. text: '加入购物车',
  67. backgroundColor: 'linear-gradient(90deg, #FFCD1E, #FF8A18)',
  68. color: '#fff',
  69. type: '0'
  70. },
  71. {
  72. text: '立即购买',
  73. backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
  74. color: '#fff',
  75. type: '1'
  76. }
  77. ],
  78. // 系统菜单
  79. barList: [],
  80. is_menu: false,
  81. // 规格弹框
  82. popupShow: '1',
  83. // 规格信息
  84. is_specs: 0,
  85. btn_type: '1',
  86. specsInfo: {},
  87. // 是否零库存
  88. is_zero: false,
  89. // 商品设置
  90. group_config: [],
  91. // 限制说明
  92. buyList: [],
  93. // 购买数量
  94. buy_num: 1,
  95. // 规格弹出框
  96. dialog: {
  97. show: false,
  98. type: '1'
  99. },
  100. };
  101. },
  102. onLoad: async function(e) {
  103. const that = this;
  104. that.$set(that, `id`, e.id || '');
  105. that.$set(that, `inviter`, e.inviter || '');
  106. await that.searchConfig();
  107. await that.search();
  108. await that.configShare();
  109. },
  110. onShow: async function() {
  111. const that = this;
  112. await that.watchLogin();
  113. },
  114. onUnload: function() {
  115. // 页面卸载,重新部署分享内容
  116. const that = this;
  117. if (that.config) {
  118. // 赋值默认值
  119. that.$config.share = {
  120. title: that.config.title,
  121. path: '/pages/index/index',
  122. imageUrl: that.config.config.share[0].url
  123. }
  124. }
  125. },
  126. methods: {
  127. // 查询系统设置
  128. searchConfig() {
  129. const that = this;
  130. uni.getStorage({
  131. key: 'config',
  132. success: function(res) {
  133. let data = res.data;
  134. that.$set(that, `config`, data);
  135. if (data.bottom_menu && data.bottom_menu.list.length > 0) {
  136. let list = data.bottom_menu.list.sort((a, b) => {
  137. return a.sort - b.sort
  138. });
  139. that.$set(that, `barList`, list)
  140. }
  141. }
  142. })
  143. },
  144. // 查询用户信息
  145. watchLogin() {
  146. const that = this;
  147. uni.getStorage({
  148. key: 'token',
  149. success: async function(res) {
  150. let user = that.$jwt(res.data);
  151. if (user) that.$set(that, `user`, user);
  152. },
  153. fail: function(err) {
  154. console.log('暂无用户信息');
  155. }
  156. })
  157. },
  158. // 查询其他信息
  159. async searchOther() {
  160. const that = this;
  161. let user = that.user;
  162. let res;
  163. // 是否关注商品
  164. res = await that.$api(`/storeGoods/check`, `GET`, {
  165. customer: user._id,
  166. goods: that.id
  167. });
  168. if (res.errcode == '0') that.$set(that, `goodsColect`, res.data);
  169. // 是否关注店铺
  170. res = await that.$api(`/storeShop/check`, `GET`, {
  171. customer: user._id,
  172. shop: that.info?.shop?._id
  173. });
  174. if (res.errcode == '0') that.$set(that, `shopColect`, res.data);
  175. // 商品设置
  176. res = await that.$api(`/goodsConfig`, `GET`, {
  177. goods: that.id,
  178. shop: that.info?.shop?._id
  179. }, 'group');
  180. if (res.errcode == '0' && res.total > 0) that.$set(that, `group_config`, res.data);
  181. // 限制说明
  182. res = await that.$api(`/dictData`, 'GET', {
  183. code: "buy_limit"
  184. });
  185. if (res.errcode == '0') that.$set(that, `buyList`, res.data)
  186. },
  187. // 查询商品信息
  188. async search() {
  189. const that = this;
  190. let id = that.id;
  191. if (id) {
  192. let res;
  193. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  194. id: id
  195. });
  196. if (res.errcode == '0') {
  197. let data = res.data;
  198. if (data.goods.brief) data.goods.brief = data.goods.brief.replace(/\<img/gi,
  199. '<img class="rich-img"');
  200. // 特价
  201. let act;
  202. act = data.act.find(i => i.type == '3')
  203. if (act) {
  204. for (let val of act.list) {
  205. for (let [index, arr] of data.specs.entries()) {
  206. if (val.spec == arr._id) arr.price = val.price
  207. }
  208. }
  209. }
  210. // 显示最低价格的规格信息,不考虑库存问题
  211. if (data.specs && data.specs.length > 0) {
  212. // 规格排序
  213. let indexSpecs = data.specs.sort(function(a, b) {
  214. let i, j;
  215. if (a.price) i = 'price'
  216. else i = 'sell_money'
  217. if (b.price) j = 'price'
  218. else j = 'sell_money'
  219. return a[i] - b[j];
  220. })
  221. that.$set(that, `infospecs`, indexSpecs[0])
  222. }
  223. that.$set(that, `info`, data);
  224. that.$set(that, `goodsInfo`, data?.goods);
  225. // 优惠
  226. act = data.act.find(i => i.type == '5')
  227. if (act) that.$set(that.discount, `full_decrement`, act.text.split(';'));
  228. act = data.act.find(i => i.type == '6')
  229. if (act) that.$set(that.discount, `full_fold`, act.text.split(';'));
  230. await that.searchOther();
  231. // 查询规格
  232. await that.searchSpecs(data.specs);
  233. // 查询评价数
  234. await that.searchRate(data);
  235. }
  236. } else {
  237. uni.showToast({
  238. title: '暂无商品信息',
  239. icon: 'none'
  240. })
  241. }
  242. },
  243. // 查询规格
  244. searchSpecs(e) {
  245. const that = this;
  246. if (e.length > 0) {
  247. let data = e.find(i => i.num > 0);
  248. let dataIndex = e.findIndex(i => i._id == data._id);
  249. if (data) {
  250. let specsInfo = that.group_config.find(i => i.spec._id == data._id)
  251. if (specsInfo?._id && that.user.is_leader == '0') data.can_group = '0'
  252. else data.can_group = '1'
  253. let limit = that.buyList.find((i) => i.value == data.buy_limit);
  254. if (limit) data.buy_name = limit.label
  255. that.$set(that, `specsInfo`, data);
  256. that.$set(that, `is_specs`, dataIndex);
  257. }
  258. }
  259. },
  260. // 查询评价数
  261. async searchRate(e) {
  262. const that = this;
  263. let res = await that.$api(`/goodsRate`, `GET`, {
  264. limit: 1,
  265. goods: e.goods._id
  266. })
  267. if (res.errcode == '0') that.$set(that, `evaluate_num`, res.total);
  268. },
  269. // 关注商品
  270. async toGoodscolect() {
  271. const that = this;
  272. let user = that.user;
  273. if (user && user._id) {
  274. let res = await that.$api(`/storeGoods`, `POST`, {
  275. customer: user._id,
  276. goods: that.id
  277. });
  278. if (res.errcode == '0') {
  279. uni.showToast({
  280. title: res.data.msg,
  281. icon: 'none'
  282. })
  283. that.$set(that, `goodsColect`, res.data.result)
  284. }
  285. } else {
  286. uni.showToast({
  287. title: '暂无账号,无法收藏商品',
  288. icon: 'none'
  289. })
  290. }
  291. },
  292. // 店铺,购物车
  293. toNavleft(e) {
  294. const that = this;
  295. if (e.content.type == 'shop') {
  296. that.toShop();
  297. } else if (e.content.type == 'market') {
  298. let obj = {
  299. route: e.content.route
  300. }
  301. that.toPath(obj)
  302. }
  303. },
  304. // 加入购物车,立即购买
  305. toNavright(e) {
  306. const that = this;
  307. that.$set(that, `popupShow`, '1');
  308. that.$set(that, `btn_type`, e.content.type);
  309. that.$refs.specShow.open();
  310. },
  311. // 配置分享内容
  312. configShare() {
  313. const that = this;
  314. let id = that.id;
  315. let inviter = that.user && that.user._id ? that.user._id : '';
  316. let title = that.info && that.info.goods ? that.info.goods.name : '';
  317. let imageUrl = that.info && that.info.goods ? that.info.goods.file[0].url : '';
  318. that.$config.share = {
  319. title: title,
  320. path: `/pagesHome/order/detail?id=${id}&inviter=${inviter}`,
  321. imageUrl: imageUrl
  322. }
  323. },
  324. }
  325. }
  326. </script>
  327. <style lang="scss">
  328. .main {
  329. display: flex;
  330. flex-direction: column;
  331. width: 100vw;
  332. height: 100vh;
  333. .one {
  334. position: relative;
  335. flex-grow: 1;
  336. }
  337. .two {
  338. width: 100vw;
  339. height: 8vh;
  340. overflow: hidden;
  341. }
  342. }
  343. .scroll-view {
  344. position: absolute;
  345. top: 0;
  346. left: 0;
  347. right: 0;
  348. bottom: 0;
  349. .list-scroll-view {
  350. display: flex;
  351. flex-direction: column;
  352. }
  353. }
  354. </style>