index.vue 9.0 KB

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