index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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(JSON.parse(uni.getStorageSync('userInfo')).setMealCode != 0){
  111. if(!this.form.account) return uni.showToast({
  112. title:'请输入充值账号',
  113. icon:'none'
  114. })
  115. let that = this
  116. uni.getSystemInfo({
  117. success(res){
  118. console.log(res.osName);
  119. if(res.osName == 'ios'){
  120. that.show = false
  121. that.iosShow = true
  122. }else{
  123. let info = {
  124. goodsId:that.chooseInfo.mainId,
  125. goodsName:that.chooseInfo.name,
  126. realPrice:that.chooseInfo.calcPrice,
  127. goodsImg:that.chooseInfo.mainImg,
  128. goodsDescribe:that.chooseInfo.catalogName,
  129. shopId:SHOP_ID,
  130. extend:JSON.stringify({account:that.form.account})
  131. }
  132. uni.navigateTo({
  133. url:`/detail/virtualGoods/pay`,
  134. success: function(res) {
  135. // 通过eventChannel向被打开页面传送数据
  136. res.eventChannel.emit('pay', info)
  137. }
  138. })
  139. }
  140. }
  141. })
  142. }else{
  143. uni.showModal({
  144. title:'此商品需要开通会员才能购买',
  145. cancelText:'下次再说',
  146. confirmText:'立即开通',
  147. success(res) {
  148. if(res.confirm){
  149. uni.navigateTo({
  150. url:'/my/memberCenter/index'
  151. })
  152. }
  153. }
  154. })
  155. }
  156. } else {
  157. uni.showModal({
  158. title:'请登录',
  159. confirmText:'去登录',
  160. success(res){
  161. console.log(res);
  162. if(res.confirm){
  163. uni.navigateTo({
  164. url:'/login/login/login?redirect=/detail/virtualGoods/index'
  165. })
  166. }
  167. }
  168. })
  169. }
  170. }
  171. },
  172. created() {
  173. this.getVirtuallist()
  174. },
  175. }
  176. </script>
  177. <style lang="scss" >
  178. .virtual {
  179. padding: 0 24rpx 80rpx;
  180. background: #fff;
  181. .title-box {
  182. display: flex;
  183. align-items: center;
  184. padding: 24rpx 0;
  185. .icon {
  186. width: 40rpx;
  187. height: 40rpx;
  188. border-radius: 50%;
  189. background: red;
  190. }
  191. .title {
  192. font-size: 32rpx;
  193. color: #222222;
  194. font-weight: bold;
  195. margin-left: 12rpx;
  196. }
  197. }
  198. .u-grid{
  199. .item{
  200. width: 218rpx;
  201. height: 218rpx;
  202. background: rgba(249,249,249,0.39);
  203. border: 2rpx solid #F0F0F0;
  204. border-radius: 16rpx;
  205. padding: 26rpx;
  206. box-sizing: border-box;
  207. margin-bottom: 24rpx;
  208. display: flex;
  209. flex-direction: column;
  210. justify-content: space-between;
  211. .item-title{
  212. font-size: 24rpx;
  213. color: #000000;
  214. font-weight: bold;
  215. margin-top: 14rpx;
  216. text-align: center;
  217. }
  218. .price{
  219. font-size: 40rpx;
  220. font-weight: bold;
  221. color: #A97D3C;
  222. margin-top: 16rpx;
  223. text-align: center;
  224. justify-self: flex-end;
  225. }
  226. }
  227. }
  228. .goods-item{
  229. display: flex;
  230. border-bottom: 2rpx solid #F0F0F0;
  231. padding: 28rpx 0;
  232. margin-top: 28rpx;
  233. .icon{
  234. width: 160rpx;
  235. height: 160rpx;
  236. border-radius: 16rpx;
  237. background: #F0F0F0;
  238. }
  239. .goods-info{
  240. display: flex;
  241. flex-direction: column;
  242. justify-content: center;
  243. flex: 1;
  244. margin-left: 20rpx;
  245. .goods-title{
  246. font-weight: 600;
  247. font-size: 32rpx;
  248. color: #222222;
  249. }
  250. .goods-desc{
  251. font-weight: 300;
  252. font-size: 24rpx;
  253. color: #AAAAAA;
  254. margin-top: 20rpx;
  255. }
  256. }
  257. .price{
  258. font-weight: 600;
  259. font-size: 36rpx;
  260. color: $uni-color-primary;
  261. align-self: center;
  262. }
  263. }
  264. .content{
  265. padding: 24rpx;
  266. .popup-title{
  267. font-size: 32rpx;
  268. font-weight: bold;
  269. color: #222222;
  270. }
  271. .goods-box{
  272. display: flex;
  273. margin-top: 28rpx;
  274. .icon{
  275. width: 160rpx;
  276. height: 160rpx;
  277. border-radius: 16rpx;
  278. background: #F0F0F0;
  279. }
  280. .goods-info{
  281. display: flex;
  282. flex-direction: column;
  283. justify-content: space-around;
  284. flex: 1;
  285. margin-left: 20rpx;
  286. .goods-title{
  287. color: #222222;
  288. font-weight: bold;
  289. font-size: 36rpx;
  290. }
  291. .goods-desc{
  292. font-size: 28rpx;
  293. color: #AAAAAA;
  294. }
  295. }
  296. .price{
  297. color: $uni-color-primary;
  298. font-size: 36rpx;
  299. font-weight: bold;
  300. align-self: center;
  301. }
  302. }
  303. .notice{
  304. font-size: 24rpx;
  305. color: #AAAAAA;
  306. padding: 26rpx 0;
  307. border-bottom: 2rpx solid #F0F0F0;
  308. }
  309. .goods-describe{
  310. color: #222222;
  311. font-size: 24rpx;
  312. max-height: 480rpx;
  313. padding-top: 28rpx;
  314. overflow: auto;
  315. }
  316. .btn{
  317. width: 688rpx;
  318. height: 80rpx;
  319. line-height: 80rpx;
  320. background: linear-gradient(283deg, #F8D48C 0%, #FBDDA6 100%);
  321. border-radius: 46rpx;
  322. margin-top: 54rpx;
  323. font-size: 28rpx;
  324. }
  325. }
  326. }
  327. </style>