index.vue 7.2 KB

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