index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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.goods" :key="i.mainId" @click="handleItem(i,item.name)">
  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.name}}
  12. </view>
  13. </view>
  14. <view class="price">
  15. ¥{{i.calcPrice}}
  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. console.log(item,catalogName);
  72. this.chooseInfo = JSON.parse(JSON.stringify(item) )
  73. this.chooseInfo.catalogName = catalogName
  74. this.show = true
  75. this.getVirtualInfo(item.mainId)
  76. },
  77. open() {
  78. },
  79. close() {
  80. this.show = false
  81. },
  82. getVirtuallist(){
  83. getVirtuallist().then(res=>{
  84. if(res.state == 'Success'){
  85. this.goodsData = res.content
  86. }
  87. })
  88. },
  89. getVirtualInfo(commodityId){
  90. this.loadingPrice = true
  91. getVirtualInfo({commodityId}).then(res=>{
  92. this.loadingPrice = false
  93. if(res.state == 'Success'){
  94. this.chooseInfo.price = res.content.realPrice
  95. }
  96. })
  97. },
  98. // 创建订单
  99. handleBuy() {
  100. if (uni.getStorageSync('token')) {
  101. if(!this.form.account) return uni.showToast({
  102. title:'请输入充值账号',
  103. icon:'none'
  104. })
  105. let info = {
  106. goodsId:this.chooseInfo.mainId,
  107. goodsName:this.chooseInfo.name,
  108. realPrice:this.chooseInfo.calcPrice,
  109. goodsImg:this.chooseInfo.mainImg,
  110. goodsDescribe:this.chooseInfo.catalogName,
  111. shopId:SHOP_ID,
  112. extend:JSON.stringify({account:this.form.account})
  113. }
  114. uni.navigateTo({
  115. url:`/detail/virtualGoods/pay`,
  116. success: function(res) {
  117. // 通过eventChannel向被打开页面传送数据
  118. res.eventChannel.emit('pay', info)
  119. }
  120. })
  121. } else {
  122. uni.showModal({
  123. title:'请登录',
  124. confirmText:'去登录',
  125. success(res){
  126. console.log(res);
  127. if(res.confirm){
  128. uni.navigateTo({
  129. url:'/login/login/login?redirect=/detail/virtualGoods/index'
  130. })
  131. }
  132. }
  133. })
  134. }
  135. }
  136. },
  137. created() {
  138. this.getVirtuallist()
  139. },
  140. }
  141. </script>
  142. <style lang="scss" >
  143. .virtual {
  144. padding: 0 24rpx 80rpx;
  145. background: #fff;
  146. .title-box {
  147. display: flex;
  148. align-items: center;
  149. padding: 24rpx 0;
  150. .icon {
  151. width: 40rpx;
  152. height: 40rpx;
  153. border-radius: 50%;
  154. background: red;
  155. }
  156. .title {
  157. font-size: 32rpx;
  158. color: #222222;
  159. font-weight: bold;
  160. margin-left: 12rpx;
  161. }
  162. }
  163. .u-grid{
  164. .item{
  165. width: 218rpx;
  166. height: 218rpx;
  167. background: rgba(249,249,249,0.39);
  168. border: 2rpx solid #F0F0F0;
  169. border-radius: 16rpx;
  170. padding: 26rpx;
  171. box-sizing: border-box;
  172. margin-bottom: 24rpx;
  173. display: flex;
  174. flex-direction: column;
  175. justify-content: space-between;
  176. .item-title{
  177. font-size: 24rpx;
  178. color: #000000;
  179. font-weight: bold;
  180. margin-top: 14rpx;
  181. text-align: center;
  182. }
  183. .price{
  184. font-size: 40rpx;
  185. font-weight: bold;
  186. color: #A97D3C;
  187. margin-top: 16rpx;
  188. text-align: center;
  189. justify-self: flex-end;
  190. }
  191. }
  192. }
  193. .goods-item{
  194. display: flex;
  195. border-bottom: 2rpx solid #F0F0F0;
  196. padding: 28rpx 0;
  197. margin-top: 28rpx;
  198. .icon{
  199. width: 160rpx;
  200. height: 160rpx;
  201. border-radius: 16rpx;
  202. background: #F0F0F0;
  203. }
  204. .goods-info{
  205. display: flex;
  206. flex-direction: column;
  207. justify-content: center;
  208. flex: 1;
  209. margin-left: 20rpx;
  210. .goods-title{
  211. font-weight: 600;
  212. font-size: 32rpx;
  213. color: #222222;
  214. }
  215. .goods-desc{
  216. font-weight: 300;
  217. font-size: 24rpx;
  218. color: #AAAAAA;
  219. margin-top: 20rpx;
  220. }
  221. }
  222. .price{
  223. font-weight: 600;
  224. font-size: 36rpx;
  225. color: $uni-color-primary;
  226. align-self: center;
  227. }
  228. }
  229. .content{
  230. padding: 24rpx;
  231. .popup-title{
  232. font-size: 32rpx;
  233. font-weight: bold;
  234. color: #222222;
  235. }
  236. .goods-box{
  237. display: flex;
  238. margin-top: 28rpx;
  239. .icon{
  240. width: 160rpx;
  241. height: 160rpx;
  242. border-radius: 16rpx;
  243. background: #F0F0F0;
  244. }
  245. .goods-info{
  246. display: flex;
  247. flex-direction: column;
  248. justify-content: space-around;
  249. flex: 1;
  250. margin-left: 20rpx;
  251. .goods-title{
  252. color: #222222;
  253. font-weight: bold;
  254. font-size: 36rpx;
  255. }
  256. .goods-desc{
  257. font-size: 28rpx;
  258. color: #AAAAAA;
  259. }
  260. }
  261. .price{
  262. color: $uni-color-primary;
  263. font-size: 36rpx;
  264. font-weight: bold;
  265. align-self: center;
  266. }
  267. }
  268. .goods-describe{
  269. color: #222222;
  270. font-size: 24rpx;
  271. max-height: 480rpx;
  272. padding-top: 28rpx;
  273. overflow: auto;
  274. }
  275. .btn{
  276. width: 688rpx;
  277. height: 80rpx;
  278. line-height: 80rpx;
  279. background: linear-gradient(283deg, #F8D48C 0%, #FBDDA6 100%);
  280. border-radius: 46rpx;
  281. margin-top: 54rpx;
  282. font-size: 28rpx;
  283. }
  284. }
  285. }
  286. </style>