index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <view class="virtual">
  3. <view class="box" v-for="(item,index) in goodsData" :key="index">
  4. <view class="goods-item" v-for="i in item.goodsInfos" :key="i.goodsId" @click="handleItem(i,item.catalogName)">
  5. <image class="icon" :src="i.mainImg" mode=""></image>
  6. <view class="goods-info">
  7. <view class="goods-title">
  8. {{i.name}}
  9. </view>
  10. <view class="goods-desc">
  11. {{item.catalogName}}
  12. </view>
  13. </view>
  14. <view class="price">
  15. ¥{{i.price}}
  16. </view>
  17. </view>
  18. </view>
  19. <u-popup :show="show" round="32rpx" mode="bottom" @close="close" @open="open">
  20. <view class="content">
  21. <view class="popup-title">会员充值</view>
  22. <view class="goods-box">
  23. <image class="icon" :src="chooseInfo.mainImg" mode=""></image>
  24. <view class="goods-info">
  25. <view class="goods-title">
  26. {{chooseInfo.name}}
  27. </view>
  28. <view class="goods-desc">
  29. {{chooseInfo.catalogName}}
  30. </view>
  31. </view>
  32. <view class="price">
  33. <u-loading-icon v-if="loadingPrice" text="获取价格中"></u-loading-icon>
  34. <template v-else>
  35. ¥{{chooseInfo.price}}
  36. </template>
  37. </view>
  38. </view>
  39. <u--form labelPosition="top" :model="form" ref="uForm" borderBottom labelWidth="180rpx" :labelStyle="{'color': '#222222',
  40. 'font-weight': 'bold','line-height':'60rpx','font-size': '28rpx'}">
  41. <u-form-item label="充值账号" prop="account" borderBottom ref="item1">
  42. <u--input v-model.trim="form.account" placeholder="请输入充值账号" border="none"></u--input>
  43. </u-form-item>
  44. </u--form>
  45. <view class="goods-describe">
  46. <rich-text :nodes="chooseInfo.goodsDescribe"></rich-text>
  47. </view>
  48. <button class="btn" type="default" :loading="loading" @click="handleBuy">确认</button>
  49. </view>
  50. </u-popup>
  51. </view>
  52. </template>
  53. <script>
  54. import {getVirtuallist,getVirtualInfo} from '@/api/goods.js'
  55. import {SHOP_ID} from '@/utils/config.js'
  56. export default {
  57. data() {
  58. return {
  59. show: false,
  60. goodsData:[],
  61. chooseInfo:null,
  62. loading:false,
  63. loadingPrice:false,
  64. form:{
  65. account:''
  66. },
  67. }
  68. },
  69. methods: {
  70. handleItem(item,catalogName) {
  71. this.chooseInfo = JSON.parse(JSON.stringify(item) )
  72. this.chooseInfo.catalogName = catalogName
  73. this.show = true
  74. this.getVirtualInfo(item.mainId)
  75. },
  76. open() {
  77. },
  78. close() {
  79. this.show = false
  80. },
  81. getVirtuallist(){
  82. getVirtuallist().then(res=>{
  83. if(res.state == 'Success'){
  84. this.goodsData = res.content
  85. }
  86. })
  87. },
  88. getVirtualInfo(commodityId){
  89. this.loadingPrice = true
  90. getVirtualInfo({commodityId}).then(res=>{
  91. this.loadingPrice = false
  92. if(res.state == 'Success'){
  93. this.chooseInfo.price = res.content.realPrice
  94. }
  95. })
  96. },
  97. // 创建订单
  98. handleBuy() {
  99. if (uni.getStorageSync('token')) {
  100. if(!this.form.account) return uni.showToast({
  101. title:'请输入充值账号',
  102. icon:'none'
  103. })
  104. let info = {
  105. goodsId:this.chooseInfo.goodsId,
  106. goodsName:this.chooseInfo.name,
  107. buyPrice:this.chooseInfo.price,
  108. goodsImg:this.chooseInfo.mainImg,
  109. shopId:SHOP_ID,
  110. extend:JSON.stringify({account:this.form.account})
  111. }
  112. uni.navigateTo({
  113. url:`/pay/pay`,
  114. success: function(res) {
  115. // 通过eventChannel向被打开页面传送数据
  116. res.eventChannel.emit('pay', info)
  117. }
  118. })
  119. } else {
  120. uni.showModal({
  121. title:'请登录',
  122. confirmText:'去登录',
  123. success(res){
  124. console.log(res);
  125. if(res.confirm){
  126. uni.navigateTo({
  127. url:'/login/login/login?redirect=/detail/virtualGoods/index'
  128. })
  129. }
  130. }
  131. })
  132. }
  133. }
  134. },
  135. created() {
  136. this.getVirtuallist()
  137. },
  138. }
  139. </script>
  140. <style lang="scss" >
  141. .virtual {
  142. padding: 0 24rpx 80rpx;
  143. background: #fff;
  144. .title-box {
  145. display: flex;
  146. align-items: center;
  147. padding: 24rpx 0;
  148. .icon {
  149. width: 40rpx;
  150. height: 40rpx;
  151. border-radius: 50%;
  152. background: red;
  153. }
  154. .title {
  155. font-size: 32rpx;
  156. color: #222222;
  157. font-weight: bold;
  158. margin-left: 12rpx;
  159. }
  160. }
  161. .u-grid{
  162. .item{
  163. width: 218rpx;
  164. height: 218rpx;
  165. background: rgba(249,249,249,0.39);
  166. border: 2rpx solid #F0F0F0;
  167. border-radius: 16rpx;
  168. padding: 26rpx;
  169. box-sizing: border-box;
  170. margin-bottom: 24rpx;
  171. display: flex;
  172. flex-direction: column;
  173. justify-content: space-between;
  174. .item-title{
  175. font-size: 24rpx;
  176. color: #000000;
  177. font-weight: bold;
  178. margin-top: 14rpx;
  179. text-align: center;
  180. }
  181. .price{
  182. font-size: 40rpx;
  183. font-weight: bold;
  184. color: #A97D3C;
  185. margin-top: 16rpx;
  186. text-align: center;
  187. justify-self: flex-end;
  188. }
  189. }
  190. }
  191. .goods-item{
  192. display: flex;
  193. border-bottom: 2rpx solid #F0F0F0;
  194. padding: 28rpx 0;
  195. margin-top: 28rpx;
  196. .icon{
  197. width: 160rpx;
  198. height: 160rpx;
  199. border-radius: 16rpx;
  200. background: #F0F0F0;
  201. }
  202. .goods-info{
  203. display: flex;
  204. flex-direction: column;
  205. justify-content: center;
  206. flex: 1;
  207. margin-left: 20rpx;
  208. .goods-title{
  209. font-weight: 600;
  210. font-size: 32rpx;
  211. color: #222222;
  212. }
  213. .goods-desc{
  214. font-weight: 300;
  215. font-size: 24rpx;
  216. color: #AAAAAA;
  217. margin-top: 20rpx;
  218. }
  219. }
  220. .price{
  221. font-weight: 600;
  222. font-size: 36rpx;
  223. color: #FF4D3A;
  224. align-self: center;
  225. }
  226. }
  227. .content{
  228. padding: 24rpx;
  229. .popup-title{
  230. font-size: 32rpx;
  231. font-weight: bold;
  232. color: #222222;
  233. }
  234. .goods-box{
  235. display: flex;
  236. margin-top: 28rpx;
  237. .icon{
  238. width: 160rpx;
  239. height: 160rpx;
  240. border-radius: 16rpx;
  241. background: #F0F0F0;
  242. }
  243. .goods-info{
  244. display: flex;
  245. flex-direction: column;
  246. justify-content: space-around;
  247. flex: 1;
  248. margin-left: 20rpx;
  249. .goods-title{
  250. color: #222222;
  251. font-weight: bold;
  252. font-size: 36rpx;
  253. }
  254. .goods-desc{
  255. font-size: 28rpx;
  256. color: #AAAAAA;
  257. }
  258. }
  259. .price{
  260. color: #FF4D3A;
  261. font-size: 36rpx;
  262. font-weight: bold;
  263. align-self: center;
  264. }
  265. }
  266. .goods-describe{
  267. color: #222222;
  268. font-size: 24rpx;
  269. max-height: 480rpx;
  270. padding-top: 28rpx;
  271. overflow: auto;
  272. }
  273. .btn{
  274. width: 688rpx;
  275. height: 80rpx;
  276. line-height: 80rpx;
  277. background: linear-gradient(283deg, #F8D48C 0%, #FBDDA6 100%);
  278. border-radius: 46rpx;
  279. margin-top: 54rpx;
  280. font-size: 28rpx;
  281. }
  282. }
  283. }
  284. </style>