buy.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <template>
  2. <view class="pd16_15">
  3. <view class="box pd16_15 flex">
  4. <image class="tuan-buy-l" :src="buydata.img" mode="aspectFill"></image>
  5. <view class="tuan-buy-r pl15">
  6. <view v-if="mid>0" class="ft14 ftw600 cl-main">{{buydata.name}}【单集购买】【ID:{{mid}} 】</view>
  7. <view v-else class="ft14 ftw600 cl-main">{{buydata.title}}</view>
  8. <view v-if="mid>0" class="mt12 alcenter">
  9. <view>
  10. <text class="ft14 cl-orange">单集会员价:</text>
  11. <text class="ft16 cl-orange ftw600">¥{{buydata.vippriced*1}}{{hbmc}}</text>
  12. </view>
  13. <view>
  14. <text class="ft14 cl-notice">单集普通价:</text>
  15. <text class="ft14 cl-notice">{{buydata.priced*1}}{{hbmc}}</text>
  16. </view>
  17. </view>
  18. <view v-else class="mt12 alcenter">
  19. <view>
  20. <text class="ft14 cl-orange">全集会员价:</text>
  21. <text class="ft16 cl-orange ftw600">¥{{buydata.vippriceq*1}}{{hbmc}}</text>
  22. </view>
  23. <view>
  24. <text class="ft14 cl-notice">全集普通价:</text>
  25. <text class="ft14 cl-notice">¥{{buydata.priceq*1}}{{hbmc}}</text>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="box mt16 pd16_15">
  31. <!-- <view class="flex alcenter center">
  32. <text class="iconfont iconbtn_plus ft32" @click="jianAct" style="color: #5C5E66;"></text>
  33. <view class="ft16 ftw600 cl-main" style="width: 100rpx; text-align: center;">{{num}}</view>
  34. <text class="iconfont iconbtn_add ft32" @click="jiaAct" :style="{color:tempColor}"></text>
  35. </view>
  36. <view class="bd-line mt16 mb16"></view>
  37. <view class="flex alcenter space">
  38. <text class="ft14 cl-info2">优惠券</text>
  39. <view>
  40. <select-coupon v-model="coupon_id" :coupons="coupons"></select-coupon>
  41. </view>
  42. </view>
  43. <view class="bd-line mt16 mb16"></view>
  44. <view class="flex alcenter space">
  45. <text class="ft14 cl-info2">会员优惠</text>
  46. <text class="ft16 cl-main ftw600">-¥20</text>
  47. </view>
  48. <view class="bd-line mt16 mb16"></view> -->
  49. <view class="flex alcenter space">
  50. <text class="ft14 cl-info2">需支付</text>
  51. <text class="ft16 cl-main ftw600 cl-orange">{{pricebuy*1}}</text>
  52. </view>
  53. </view>
  54. <view class="box mt16 pd16_15">
  55. <view class="ft16 pb16 ftw600 cl-main">支付方式</view>
  56. <view class="bd-line mt16"></view>
  57. <radio-group @change="changeType">
  58. <!-- #ifdef MP-TOUTIAO -->
  59. <view class="pt16 pb16 flex alcenter space" style="display: none;">
  60. <view class="flex alcenter">
  61. <text class="iconfont iconicon_pay_balance ft32 cl-green"></text>
  62. <text class="ml15 ft14 ftw500 cl-main">抖音支付</text>
  63. </view>
  64. <view>
  65. <radio value="TOUTIAO" :checked="payType == 'TOUTIAO'" :color="tempColor" />
  66. </view>
  67. </view>
  68. <view class="bd-line" style="display: none;"></view>
  69. <!-- #endif -->
  70. <!-- #ifdef MP-WEIXIN -->
  71. <view class="pt16 pb16 flex alcenter space" style="display: none;">
  72. <view class="flex alcenter">
  73. <text class="iconfont iconicon_pay_balance ft32 cl-green"></text>
  74. <text class="ml15 ft14 ftw500 cl-main">微信支付</text>
  75. </view>
  76. <view>
  77. <radio value="weixin" :checked="payType == 'weixin'" :color="tempColor" />
  78. </view>
  79. </view>
  80. <view class="bd-line" style="display: none;"></view>
  81. <!-- #endif -->
  82. <view class="pt16 flex alcenter space">
  83. <view class="flex alcenter">
  84. <text class="iconfont iconicon_pay_balance ft32" style="color: #FFBD1E;"></text>
  85. <text class="ml15 ft14 ftw500 cl-main">{{hbmc}}支付</text>
  86. <!-- <text class="ml10 ft12 cl-notice">余额为0,不可用</text> -->
  87. </view>
  88. <view>
  89. <radio value="money" :checked="payType == 'money'" :disabled="false" :color="tempColor" />
  90. </view>
  91. </view>
  92. </radio-group>
  93. </view>
  94. <view class="form-footer-h">
  95. <view class="form-footer form-footer-h">
  96. <view class="form-footer-main pd10_15">
  97. <button v-if="mid>0" class="btn-big" @click="okTap" :style="getBtnStyle">支付{{pricebuy*1}}</button>
  98. <button v-else class="btn-big" @click="okTap" :style="getBtnStyle">支付 {{pricebuy*1}}</button>
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. </template>
  104. <script>
  105. export default{
  106. data(){
  107. return {
  108. payType:'weixin',
  109. num:1,
  110. coupon_id:0,
  111. buydata:[],
  112. buytype:'微信',
  113. dataList:[],
  114. money:0,
  115. mid:0,
  116. openid:'',
  117. pricebuy:0,
  118. wxlx:'wxh5',
  119. hbmc:'',
  120. coupons:[
  121. {coupon_id:1,num:20},
  122. {coupon_id:2,num:30},
  123. {coupon_id:3,num:40},
  124. ],
  125. }
  126. },
  127. onLoad(option){
  128. this.hbmc=uni.getStorageSync("config").site.hbmc
  129. if(option.mid){
  130. this.mid=option.mid
  131. }
  132. this.buydata=uni.getStorageSync("buydata")
  133. if(this.mid>0 && this.buydata.isvip==2){
  134. this.pricebuy=this.buydata.vippriced
  135. }else if(this.mid>0 && this.buydata.isvip==1){
  136. this.pricebuy=this.buydata.priced
  137. }else if(this.mid==0 && this.buydata.isvip==2){
  138. this.pricebuy=this.buydata.vippriceq
  139. }else if(this.mid==0 && this.buydata.isvip==1){
  140. this.pricebuy=this.buydata.priceq
  141. }
  142. // #ifdef MP-TOUTIAO
  143. this.buytype='TOUTIAO'
  144. this.payType='TOUTIAO'
  145. // #endif
  146. //#ifdef MP-WEIXIN
  147. this.wxlx='wxxcx'
  148. this.wxlogin()
  149. //#endif
  150. //#ifdef H5
  151. var ua = window.navigator.userAgent.toLowerCase();
  152. if(ua.match(/MicroMessenger/i) == 'micromessenger'){
  153. this.wxlx = 'wxgzh';
  154. }
  155. //#endif
  156. },
  157. onShow() {
  158. if(uni.getStorageSync("userinfo").token){
  159. this.ongrzlTap()
  160. this.money=uni.getStorageSync("userinfo").money
  161. }else{
  162. uni.showModal({
  163. title: '温馨提示',
  164. content: '请先登录',
  165. showCancel: true,
  166. confirmText: "登录",
  167. success: function (res) {
  168. if (res.confirm) {
  169. uni.navigateTo({
  170. url:'/pages/login/login'
  171. })
  172. } else if (res.cancel) {
  173. uni.navigateBack();
  174. }
  175. }
  176. });
  177. }
  178. },
  179. computed:{
  180. getCouponMoney(){
  181. if(this.coupons.length > 0){
  182. for(var a in this.coupons){
  183. if(this.coupons[a].coupon_id == this.coupon_id){
  184. return this.coupons[a].num;
  185. }
  186. }
  187. }
  188. return 0;
  189. }
  190. },
  191. methods:{
  192. okTap(){
  193. var thia=this
  194. this.dataList=this.buydata;
  195. this.dataList.sum=1;
  196. this.dataList.buytype=this.buytype;
  197. //https://rw.gzzsw.cn/api/pay/index?token=a69720a4-6c4c-4baf-b269-d5260b821c7a
  198. let data = this.dataList;
  199. data.pricebuy=thia.pricebuy
  200. data.token = uni.getStorageSync("userinfo").token;
  201. data.uid = uni.getStorageSync("userinfo").id;
  202. if(this.mid>0){
  203. data.lx=2;//1 全章购买 2单集购买
  204. data.smid=this.mid;
  205. data.namet=data.name+'【单集购买】【ID:'+this.mid+' 】';
  206. }else{
  207. data.lx=1;//1 全章购买 2单集购买
  208. data.smid=0;
  209. data.namet=data.name
  210. }
  211. data.wxlx=this.wxlx;
  212. data.openid=this.openid;
  213. data.info=[];
  214. console.log(data)
  215. uni.request({
  216. url: this.configs.webUrl+'/api/pay/videopay',
  217. data: data,
  218. success: resa =>{
  219. //console.log(resa.data);
  220. if(thia.dataList.buytype=='微信'){
  221. if(this.wxlx=='wxxcx' && resa.data.code==1){
  222. //console.log(resa.data.code);
  223. this.wxxcx(resa.data.data);
  224. }else{
  225. // #ifdef APP-PLUS
  226. uni.navigateTo({
  227. url:'/pages/client/webva?url='+resa.data.data
  228. })
  229. //plus.runtime.openURL(res.data.data);
  230. // #endif
  231. // #ifdef H5
  232. window.open(resa.data.data, "_self")
  233. // #endif
  234. }
  235. }else if(thia.dataList.buytype=='余额'){
  236. if(resa.data.code==1){
  237. //pages/user/task/task
  238. uni.showModal({
  239. title: '提示',
  240. content: resa.data.msg,
  241. showCancel: false,
  242. success: res => {
  243. uni.setStorage({
  244. key: 'isbuy',
  245. data: 2
  246. })
  247. uni.navigateBack();
  248. // uni.navigateBack({
  249. // delta: 2
  250. // });
  251. }
  252. });
  253. }else{
  254. if(resa.data.msg=='余额不足'){
  255. uni.showModal({
  256. title: '提示',
  257. content: thia.hbmc+'不足',
  258. showCancel: true,
  259. confirmText: "充值",
  260. success: function (res) {
  261. if (res.confirm) {
  262. var pricebuy=thia.pricebuy
  263. uni.navigateTo({
  264. url:"/pages/client/vipcard/recharge?price="+pricebuy*1
  265. })
  266. } else if (res.cancel) {
  267. //uni.navigateBack();
  268. }
  269. }
  270. });
  271. }else{
  272. uni.showModal({
  273. title: '提示',
  274. content: resa.data.msg,
  275. showCancel: false,
  276. success: res => {
  277. uni.navigateBack();
  278. }
  279. });
  280. }
  281. }
  282. }else if(thia.dataList.buytype=='TOUTIAO'){
  283. if(resa.data.code==1){
  284. this.ttxcx(resa.data.data);
  285. }else{
  286. uni.showModal({
  287. title: '支付失败',
  288. content: JSON.stringify(resa.data.msg),
  289. showCancel: false,
  290. confirmText: "确定",
  291. success: function (ress) {
  292. if (res.confirm) {
  293. //uni.navigateBack();
  294. } else if (res.cancel) {
  295. }
  296. }
  297. });
  298. }
  299. }
  300. },
  301. fail: (data, code) => {
  302. console.log('fail' + JSON.stringify(data));
  303. }
  304. });
  305. },
  306. wxxcx(data){
  307. uni.requestPayment({
  308. "provider": 'wxpay',
  309. "appId": data.appId,
  310. "timeStamp": data.timeStamp+'',
  311. "nonceStr": data.nonceStr,
  312. "package": data.package,
  313. "signType": 'MD5',
  314. "paySign": data.sign,
  315. success: function (res1) {
  316. uni.showModal({
  317. title: '温馨提示',
  318. content: '支付成功',
  319. showCancel: false,
  320. confirmText: "确定",
  321. success: function (res) {
  322. if (res.confirm) {
  323. uni.setStorage({
  324. key: 'isbuy',
  325. data: 2
  326. })
  327. uni.navigateBack();
  328. } else if (res.cancel) {
  329. }
  330. }
  331. });
  332. //uni.showToast({ title: '支付成功',icon:"none" });
  333. console.log('success:' + JSON.stringify(res1));
  334. },
  335. fail: function (err1) {
  336. uni.showModal({
  337. title: '温馨提示',
  338. content: JSON.stringify(err1),
  339. showCancel: false,
  340. confirmText: "确定",
  341. success: function (res) {
  342. if (res.confirm) {
  343. //uni.navigateBack();
  344. } else if (res.cancel) {
  345. }
  346. }
  347. });
  348. //uni.showToast({ title: JSON.stringify(err1),icon:"none" });
  349. console.log('fail:' + JSON.stringify(err1));
  350. }
  351. });
  352. },
  353. async ongrzlTap(){
  354. let data = {};
  355. data.token = uni.getStorageSync("userinfo").token;
  356. data.uid = uni.getStorageSync("userinfo").id;
  357. uni.request({
  358. url: this.configs.webUrl+'/api/user/index',
  359. data: data,
  360. success: res =>{
  361. if(res.data.code==1){
  362. let ionfo=res.data.data
  363. ionfo.isLogin=true
  364. this.userinfo=ionfo
  365. uni.setStorage({//缓存配置信息
  366. key: 'userinfo',
  367. data: res.data.data
  368. })
  369. if(res.data.data.avatar){
  370. var str = res.data.data.avatar;
  371. if(str.indexOf("data:image") != -1){
  372. this.avatar='';
  373. }else{
  374. if(str.indexOf("http") != -1){
  375. this.avatar=res.data.data.avatar;
  376. }else{
  377. this.avatar=this.configs.imgUrl+res.data.data.avatar;
  378. }
  379. }
  380. }else{
  381. this.avatar='';
  382. }
  383. }else{
  384. uni.showToast({ title: res.data.msg,icon:"none" });
  385. }
  386. },
  387. fail: (data, code) => {
  388. //console.log('fail' + JSON.stringify(data));
  389. }
  390. });
  391. },
  392. jianAct(){
  393. if(this.num == 1) return;
  394. this.num = this.num - 1;
  395. },
  396. jiaAct(){
  397. if(this.num > 99) return; //后面改为库存数量
  398. this.num = this.num + 1;
  399. },
  400. changeType(e){
  401. this.payType = e.detail.value;
  402. if(e.detail.value=='money'){
  403. this.buytype = '余额';
  404. }
  405. if(e.detail.value=='weixin'){
  406. this.buytype = '微信';
  407. }
  408. if(e.detail.value=='TOUTIAO'){
  409. this.payType = 'TOUTIAO';
  410. this.buytype = 'TOUTIAO';
  411. }
  412. },
  413. wxlogin(){
  414. var this_=this
  415. uni.login({
  416. timeout: 10000,
  417. provider: 'weixin', //如果是uniapp,在这里需要标明平台的类型,支持的参数请查阅uniapp官网的uni.login()文档
  418. success: (res) => {
  419. console.log(res);
  420. //登陆成功的回调
  421. uni.request({
  422. url: this.configs.webUrl+'/api/user/getOpenid',
  423. method:'GET',
  424. data: {
  425. token: uni.getStorageSync("userinfo").token, //你的小程序的secret,
  426. code: res.code //wx.login 登录成功后的code
  427. },
  428. success: (cts) => {
  429. console.log(cts.data.code);
  430. if(cts.data.code==1){
  431. this_.openid=cts.data.data.openid
  432. }else{
  433. uni.showModal({
  434. title: '温馨提示',
  435. content: JSON.stringify(cts.data),
  436. showCancel: true,
  437. confirmText: "确定",
  438. success: function (res) {
  439. if (res.confirm) {
  440. uni.navigateBack();
  441. } else if (res.cancel) {
  442. }
  443. }
  444. });
  445. }
  446. },
  447. fail: (err1) => {
  448. console.log(err1);
  449. //失败的回调
  450. }
  451. });
  452. },
  453. fail: (err) => {
  454. console.log(err);
  455. //登陆失败的回调
  456. }
  457. })
  458. }
  459. }
  460. }
  461. </script>
  462. <style>
  463. .tuan-buy-l{
  464. width: 200rpx;
  465. height: 150rpx;
  466. background: #F2F2F2;
  467. }
  468. .tuan-buy-r{
  469. width: calc(100% - 200rpx);
  470. }
  471. </style>