index.vue 8.6 KB

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