detail.vue 11 KB

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