index.vue 6.7 KB

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