index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <div class="prepaidRefill">
  3. <div class="input_phone">
  4. <div class="flex_r flex_jb flex_ac">
  5. <textarea v-model="qda.phoneno" placeholder="请输入手机号" @input="inphone" @confirm="inphone" :auto-height="true" class="inp dinB" placeholder-class="inpc" />
  6. <div class="ico iconfont" @click="openContact">&#xe8fb;</div>
  7. </div>
  8. <div class="phonemsg" v-if="gameArea">{{ gameArea }}</div>
  9. </div>
  10. <div class="items">
  11. <div class="tit">充话费</div>
  12. <div class="li flex_r">
  13. <div :class="{ li_it: 1, active: qda.cardnum == i.money }" v-for="(i, s) in CallingList" :key="s" @click="selectMoney(i)" >{{ i.money }}元</div>
  14. </div>
  15. </div>
  16. <div class="money card">
  17. <div class="li flex_r flex_jb">
  18. <span>消费金额</span>
  19. <span>¥{{ selectItem.custom_price == 0 ? selectItem.money : selectItem.custom_price }}</span>
  20. </div>
  21. <div class="li flex_r flex_jb">
  22. <span>消费券抵扣</span>
  23. <span class="corg">-¥{{ selectItem.custom_integral || 0 }}</span>
  24. </div>
  25. <div class="li flex_r flex_jb">
  26. <span>实付金额</span>
  27. <span>¥{{ selectItem.actual_price || 0 }}</span>
  28. </div>
  29. </div>
  30. <div class="money card mar_b60">
  31. <div class="li flex_r flex_jb">
  32. <span>赠送贡献值</span>
  33. <span>{{ selectItem.chabao || 0 }}</span>
  34. </div>
  35. </div>
  36. <div class="msgbar">
  37. <div class="tit">话费充值说明</div>
  38. <div class="msg_con">
  39. <p v-for="(i,s) in Desc" :key="s">{{ i }}</p>
  40. </div>
  41. </div>
  42. <div class="footbtn" @click="onpay">立即支付</div>
  43. </div>
  44. </template>
  45. <script>
  46. import { ToPayOpre } from "@/utils/reqTools.js";
  47. let toPayOpre = new ToPayOpre();
  48. import { post } from "@/request/api.js";
  49. export default {
  50. name: "prepaidRefill",
  51. props: {},
  52. components: {},
  53. data() {
  54. return {
  55. CallingList: [], //可充话费列表
  56. qda: {
  57. phoneno: "",
  58. cardnum: 100,
  59. },
  60. userinfo: uni.getStorageSync("userinfo"),
  61. gameArea: "",
  62. selectItem: {},
  63. Desc: {}, //充值说明
  64. };
  65. },
  66. methods: {
  67. openContact() {
  68. let that = this;
  69. uni.chooseContact({
  70. success: (res) => {
  71. setTimeout(() => {
  72. that.qda.phoneno = res.phoneNumber;
  73. that.inphone();
  74. }, 80);
  75. },
  76. fail: (err) => {
  77. console.log("获取通讯录失败:", err);
  78. },
  79. });
  80. },
  81. selectMoney(va){
  82. this.selectItem = va
  83. this.qda.cardnum = va.money
  84. this.qda.attachment = JSON.stringify(va)
  85. },
  86. getCallingList() {
  87. post("local/ofpay/getMoney").then((res) => {
  88. if (res.code == 0) {
  89. this.CallingList = res.data;
  90. this.selectMoney(res.data[0]);
  91. this.inphone();
  92. }
  93. });
  94. },
  95. inphone() {
  96. if (this.checkPhone(this.qda.phoneno)) {
  97. post("local/ofpay/telCheck", this.qda).then((res) => {
  98. if (res.code == 0) {
  99. post("local/ofpay/telQuery", this.qda).then((res) => {
  100. if (res.code == 0) {
  101. if (res.data.error_code == 0) {
  102. this.gameArea = res.data.result.game_area;
  103. }
  104. }
  105. });
  106. }
  107. });
  108. }
  109. },
  110. checkPhone(phone) {
  111. if (/^1[3456789]\d{9}$/.test(phone)) {
  112. return true;
  113. } else {
  114. return false;
  115. }
  116. },
  117. onpay() {
  118. let that = this
  119. let localInfo = uni.getStorageSync("localInfo");
  120. let um = localInfo.property;
  121. let str = um > this.selectItem.actual_price ? "将优先使用付宝抵扣" : "将使用付宝抵扣部分支付"
  122. if(um > 0){
  123. uni.showModal({
  124. title: "温馨提示",
  125. content: `您的可用付宝为 ${um},` + str,
  126. showCancel: true,
  127. confirmText: "确认",
  128. confirmColor: "#f02f2f",
  129. success(res) {
  130. if (res.confirm) {
  131. that.payok();
  132. }
  133. },
  134. });
  135. }else this.payok();
  136. },
  137. async payok(){
  138. let type = "";
  139. // #ifdef H5
  140. type = "H5";
  141. // #endif
  142. // #ifdef APP
  143. type = "app";
  144. // #endif
  145. // #ifdef MP-WEIXIN
  146. type = "jsapi";
  147. // #endif
  148. let adres = await uni.Location();
  149. this.qda.trade_type = type
  150. this.qda.location= "+"+adres.lat+'/+'+adres.lng
  151. post("local/ofpay/onlineorde", this.qda).then((res) => {
  152. if(res.data && res.data != 200){
  153. let data = {
  154. ...res.data,
  155. appId:res.data.app_id,
  156. nonceStr:res.data.nonce_str,
  157. package:res.data.package,
  158. signType:res.data.sign_type,
  159. paySign:res.data.pay_sign,
  160. timeStamp:res.data.time_stamp,
  161. prepayid:res.data.prepay_id
  162. }
  163. if (res.code == 0 && data.prepayid) {
  164. toPayOpre.toPay(data, (rea) => {
  165. if (!rea) {
  166. // 支付成功
  167. this.goto("/pagesB/orderingfood/orderlist");
  168. } else {
  169. // 支付失败
  170. }
  171. });
  172. }
  173. }else if (res.code == 0 && res.data == 200) this.goto("/pagesB/orderingfood/orderlist")
  174. });
  175. },
  176. getdesc() {
  177. post("local/ofpay/desc").then((res) => {
  178. if (res.code == 0) {
  179. this.Desc = res.data[0];
  180. }
  181. });
  182. },
  183. },
  184. onLoad(da) {
  185. this.qda.phoneno = this.userinfo.mobile;
  186. this.getCallingList();
  187. this.getdesc();
  188. },
  189. watch: {},
  190. onShow() {},
  191. mounted() {},
  192. };
  193. </script>
  194. <style scoped lang='scss'>
  195. .prepaidRefill {
  196. min-height: 100vh;
  197. background-color: #fff;
  198. padding: 28rpx 32rpx;
  199. }
  200. .input_phone {
  201. border-bottom: 1rpx solid rgba($color: #000, $alpha: 0.15);
  202. padding: 12rpx 16rpx;
  203. margin-bottom: 60rpx;
  204. .inp {
  205. font-size: 40rpx;
  206. }
  207. .ico{
  208. font-size: 50rpx;
  209. font-weight: bold;
  210. }
  211. .phonemsg {
  212. width: 100%;
  213. font-size: 24rpx;
  214. margin-top: 12rpx;
  215. color: #666;
  216. }
  217. }
  218. .items {
  219. margin-bottom: 60rpx;
  220. .tit {
  221. font-size: 26rpx;
  222. color: #666;
  223. margin-bottom: 20rpx;
  224. }
  225. .li {
  226. display: grid;
  227. justify-content: space-between;
  228. grid-template-columns: repeat(auto-fill, 210rpx);
  229. }
  230. .li_it {
  231. font-size: 38rpx;
  232. font-weight: 600;
  233. width: 210rpx;
  234. text-align: center;
  235. height: 120rpx;
  236. line-height: 120rpx;
  237. border-radius: 12rpx;
  238. border: 1rpx solid rgba($color: #000, $alpha: 0.15);
  239. margin-bottom: 16rpx;
  240. color: #555;
  241. &.active {
  242. color: #18bb88;
  243. border-color: #18bb88;
  244. box-shadow: 4rpx 4rpx 16rpx 10rpx rgba($color: #18bb88, $alpha: 0.1);
  245. }
  246. }
  247. }
  248. .money {
  249. .li {
  250. margin-bottom: 16rpx;
  251. &:last-child {
  252. margin-bottom: 0;
  253. }
  254. span {
  255. font-size: 30rpx;
  256. }
  257. }
  258. .corg {
  259. color: #18bb88;
  260. margin-left: 12rpx;
  261. }
  262. }
  263. .msgbar{
  264. padding-bottom: 160rpx;
  265. .tit{
  266. font-size: 32rpx;
  267. font-weight: bold;
  268. margin: 80rpx 0 20rpx;
  269. }
  270. .msg_con{
  271. font-size: 26rpx;
  272. p{
  273. margin-bottom: 10rpx;
  274. }
  275. }
  276. }
  277. .card {
  278. background-color: #fff;
  279. border-radius: 16rpx;
  280. margin-bottom: 30rpx;
  281. padding: 28rpx 30rpx;
  282. font-size: 32rpx;
  283. box-shadow: 4rpx 4rpx 8rpx 4rpx rgba(0, 0, 0, 0.12);
  284. &:last-child {
  285. margin-bottom: 0;
  286. }
  287. }
  288. .footbtn {
  289. width: calc(100% - 60rpx);
  290. height: 80rpx;
  291. background: #17bb87;
  292. border-radius: 45rpx;
  293. position: fixed;
  294. bottom: 50rpx;
  295. left: 30rpx;
  296. color: #fff;
  297. font-size: 36rpx;
  298. text-align: center;
  299. line-height: 80rpx;
  300. }
  301. </style>
  302. <style lang='scss'>
  303. .prepaidRefill {
  304. .inpc {
  305. font-size: 34rpx;
  306. }
  307. }
  308. </style>