index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div class="prepaidRefill">
  3. <div class="input_phone flex_r flex_jb flex_wrap">
  4. <textarea
  5. v-model="qda.phoneno"
  6. placeholder="请输入手机号"
  7. class="inp dinB"
  8. :auto-height="true"
  9. @input="inphone"
  10. @blur="inphone"
  11. @confirm="inphone"
  12. placeholder-class="inpc"
  13. />
  14. <div class="ico iconfont" @click="openContact">&#xe8fb;</div>
  15. <div class="phonemsg" v-if="gameArea">{{ gameArea }}</div>
  16. </div>
  17. <div class="items">
  18. <div class="tit">充话费</div>
  19. <div class="li flex_r">
  20. <div
  21. :class="{ li_it: 1, active: qda.cardnum == i }"
  22. v-for="(i, s) in CallingList"
  23. :key="s"
  24. @click="qda.cardnum = i"
  25. >
  26. {{ i }}元
  27. </div>
  28. </div>
  29. </div>
  30. <div class="money card">
  31. <div class="li flex_r flex_jb">
  32. <span>消费金额</span>
  33. <span>¥{{ cartTotal || 0 }}</span>
  34. </div>
  35. <div class="li flex_r flex_jb">
  36. <span
  37. >消费金抵扣<span class="corg">{{ Integral }}%</span></span
  38. >
  39. <span class="corg">-¥{{ deduction || 0 }}</span>
  40. </div>
  41. <div class="li flex_r flex_jb">
  42. <span>实付金额</span>
  43. <span>¥{{ actuallypaid || 0 }}</span>
  44. </div>
  45. </div>
  46. <div class="money card mar_b60">
  47. <div class="li flex_r flex_jb">
  48. <span>赠送茶宝</span>
  49. <span>{{ chabao || 0 }}</span>
  50. </div>
  51. </div>
  52. <div class="footbtn" @click="onpay">立即支付</div>
  53. </div>
  54. </template>
  55. <script>
  56. import { ToPayOpre } from "@/utils/reqTools.js";
  57. let toPayOpre = new ToPayOpre();
  58. import { post } from "@/request/api.js";
  59. export default {
  60. name: "prepaidRefill",
  61. props: {},
  62. components: {},
  63. data() {
  64. return {
  65. CallingList: [], //可充话费列表
  66. qda: {
  67. cardnum: 100,
  68. },
  69. isvalid: false,
  70. userinfo: uni.getStorageSync("userinfo"),
  71. gameArea: "",
  72. ratio: {},
  73. cartTotal: 0,
  74. Integral: 0,
  75. deduction: 0,
  76. actuallypaid: 0,
  77. chabao: 0,
  78. };
  79. },
  80. methods: {
  81. openContact() {
  82. let that = this;
  83. uni.chooseContact({
  84. success: (res) => {
  85. if (that.checkPhone(res.phoneNumber)) {
  86. that.qda.phoneno = res.phoneNumber;
  87. }
  88. },
  89. fail: (err) => {
  90. console.log("获取通讯录失败:", err);
  91. },
  92. });
  93. },
  94. getCallingList() {
  95. post("local/ofpay/getMoney").then((res) => {
  96. if (res.code == 0) {
  97. this.CallingList = res.data;
  98. this.qda.cardnum = res.data[0];
  99. this.inphone();
  100. }
  101. });
  102. },
  103. inphone() {
  104. if (this.checkPhone(this.qda.phoneno)) {
  105. post("local/ofpay/telCheck", this.qda).then((res) => {
  106. if (res.code == 0) {
  107. this.isvalid = true;
  108. post("local/ofpay/telQuery", this.qda).then((res) => {
  109. if (res.code == 0) {
  110. if (res.data.error_code == 0) {
  111. this.gameArea = res.data.result.game_area;
  112. this.getIntegral();
  113. }
  114. }
  115. });
  116. } else this.isvalid = false;
  117. });
  118. }
  119. },
  120. checkPhone(phone) {
  121. if (/^1[3456789]\d{9}$/.test(phone)) {
  122. return true;
  123. } else {
  124. return false;
  125. }
  126. },
  127. getIntegral() {
  128. post("local/getIntegral", { type: 6 }).then((res) => {
  129. if (res.code == 0) {
  130. this.ratio = res.data;
  131. this.computef();
  132. }
  133. });
  134. },
  135. computef() {
  136. let { integral, chabao } = this.ratio;
  137. let i1 = integral,
  138. i2 = chabao;
  139. this.cartTotal = this.qda.cardnum;
  140. this.Integral = this.$h.Mul(i1, 100);
  141. this.deduction = this.$h.Mul(this.cartTotal, i1);
  142. this.actuallypaid = this.$h.Sub(this.cartTotal, this.deduction);
  143. this.chabao = this.$h.Mul(this.actuallypaid, i2).toFixed(2);
  144. },
  145. onpay() {
  146. post("local/ofpay/onlineorde", this.qda).then((res) => {
  147. if (res.code == 0) {
  148. toPayOpre.toPay(res.data, (rea) => {
  149. if (!rea) {
  150. // 支付成功
  151. this.goto("/pagesB/orderingfood/orderlist");
  152. } else {
  153. // 支付失败
  154. }
  155. });
  156. }
  157. });
  158. },
  159. },
  160. onLoad(da) {
  161. this.qda.phoneno = this.userinfo.mobile;
  162. this.getCallingList();
  163. },
  164. watch: {
  165. 'qda.cardnum': {
  166. immediate: true,
  167. deep: true,
  168. handler(va) {
  169. this.computef();
  170. }
  171. }
  172. },
  173. onShow() {},
  174. mounted() {},
  175. };
  176. </script>
  177. <style scoped lang='scss'>
  178. .prepaidRefill {
  179. min-height: 100vh;
  180. background-color: #fff;
  181. padding: 28rpx 32rpx;
  182. }
  183. .input_phone {
  184. border-bottom: 1rpx solid rgba($color: #000, $alpha: 0.15);
  185. padding: 12rpx 16rpx;
  186. margin-bottom: 60rpx;
  187. .inp {
  188. font-size: 40rpx;
  189. }
  190. .ico{
  191. font-size: 50rpx;
  192. font-weight: bold;
  193. }
  194. .phonemsg {
  195. width: 100%;
  196. font-size: 24rpx;
  197. margin-top: 12rpx;
  198. color: #666;
  199. }
  200. }
  201. .items {
  202. margin-bottom: 60rpx;
  203. .tit {
  204. font-size: 26rpx;
  205. color: #666;
  206. margin-bottom: 20rpx;
  207. }
  208. .li {
  209. display: grid;
  210. justify-content: space-between;
  211. grid-template-columns: repeat(auto-fill, 210rpx);
  212. }
  213. .li_it {
  214. font-size: 38rpx;
  215. font-weight: 600;
  216. width: 210rpx;
  217. text-align: center;
  218. height: 120rpx;
  219. line-height: 120rpx;
  220. border-radius: 12rpx;
  221. border: 1rpx solid rgba($color: #000, $alpha: 0.15);
  222. margin-bottom: 16rpx;
  223. color: #555;
  224. &.active {
  225. color: #18bb88;
  226. border-color: #18bb88;
  227. box-shadow: 4rpx 4rpx 16rpx 10rpx rgba($color: #18bb88, $alpha: 0.1);
  228. }
  229. }
  230. }
  231. .money {
  232. .li {
  233. margin-bottom: 16rpx;
  234. &:last-child {
  235. margin-bottom: 0;
  236. }
  237. span {
  238. font-size: 30rpx;
  239. }
  240. }
  241. .corg {
  242. color: #18bb88;
  243. margin-left: 12rpx;
  244. }
  245. }
  246. .card {
  247. background-color: #fff;
  248. border-radius: 16rpx;
  249. margin-bottom: 30rpx;
  250. padding: 28rpx 30rpx;
  251. font-size: 32rpx;
  252. box-shadow: 4rpx 4rpx 16rpx 10rpx rgba($color: #000, $alpha: 0.15);
  253. &:last-child {
  254. margin-bottom: 0;
  255. }
  256. }
  257. .footbtn {
  258. width: calc(100% - 60rpx);
  259. height: 80rpx;
  260. background: #17bb87;
  261. border-radius: 45rpx;
  262. position: fixed;
  263. bottom: 50rpx;
  264. left: 30rpx;
  265. color: #fff;
  266. font-size: 36rpx;
  267. text-align: center;
  268. line-height: 80rpx;
  269. }
  270. </style>
  271. <style lang='scss'>
  272. .prepaidRefill {
  273. .inpc {
  274. font-size: 34rpx;
  275. }
  276. }
  277. </style>