recharge.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div class="recharge">
  3. <scroller>
  4. <img class="ad-hide" src="http://odulvej8l.bkt.clouddn.com/%E5%85%85%E5%80%BC%E5%8D%A1.jpg" style="width: 100%;">
  5. <div class="recharge-title">充值余额</div>
  6. <group>
  7. <cell
  8. :title="('充值有好礼')"
  9. is-link
  10. value-align="left"
  11. :border-intent="false"
  12. :arrow-direction="isActive ? 'up' : 'down'"
  13. @click.native="isActive = !isActive"></cell>
  14. <p class="slide" :class="isActive?'animate':''">
  15. <span>充值1000--赠送:一挂式空调清洗</span>
  16. <span>充值3000--赠送:一床一沙发除螨</span>
  17. <span>充值5000--赠送:二床一沙发除螨</span>
  18. <span>充值10000--赠送:一冰箱清洗一挂式空调清洗一洗衣机清洗二床一沙发除螨</span>
  19. </p>
  20. </group>
  21. <ul class="ad-hide list-content list-recharge" style="padding-top: 5px;padding-bottom: 5px;padding-left: 10%;">
  22. <li v-for="(item,index) in rechargeLists" class="media" @click="btnRechargeList(item, index)"
  23. v-bind:class="{on: index === isShow}">
  24. <div v-if="item.denomination ===1 " >
  25. <div class="input-title">其他数额</div>
  26. <div class="input-rmb">RMB:</div>
  27. <input type="text" maxlength="8" name="" v-model="otherAmount" value="otherAmount" class="rechange-input" v-focus="isNum">
  28. </div>
  29. <div v-else>
  30. <div>RMB:{{ item.denomination }}</div>
  31. </div>
  32. </li>
  33. </ul>
  34. <div class="ad-hide" style="text-align: center;clear: both;margin-top: 9rem;"><span style="font-size: 0.6rem">点击立即充值,即表示您已经同意壹管家</span><span
  35. style="font-size: 0.6rem;font-weight: 600;display: block;"></span><span style="font-size: 0.6rem;">《<span
  36. class="pay-agreement" style="text-decoration: underline;color: #0A246A" @click="activity">充返活动协议</span>》</span>
  37. </div>
  38. <div class="btn-add-recharge" @click="btnRecharge">立即去充值</div>
  39. <div style="width: 100%;padding-bottom: 13%;"></div>
  40. </scroller>
  41. </div>
  42. </template>
  43. <script>
  44. import {Group, Cell} from 'vux'
  45. import axios from 'axios'
  46. import qs from 'qs'
  47. import config from '../config/config'
  48. export default {
  49. data () {
  50. return {
  51. isActive: false,
  52. isShow: -1,
  53. rechargeLists: [],
  54. rechargeItem: {},
  55. otherAmount: '',
  56. isNum: false
  57. }
  58. },
  59. components: {
  60. Group, Cell
  61. },
  62. computed: {},
  63. beforeCreate () {
  64. // 获取充值卡列表
  65. axios.get('o2o/recharge/rechargeList').then(res => {
  66. this.rechargeLists = res.data.data
  67. })
  68. },
  69. created () {
  70. // console.log(this.rechargeLists)
  71. },
  72. // 自定义指令
  73. directives: {
  74. // 听我瞎bb --north
  75. // focus 对DOM层操作 自定义 v-focus 使用方法 v-focus="value" 传入值进入 focus 中判断 当value为true 时 选中focus
  76. focus: {
  77. update: function (el, {value}) {
  78. if (value) {
  79. el.focus()
  80. }
  81. }
  82. }
  83. },
  84. watch: {
  85. 'otherAmount': function (val) {
  86. if (val !== undefined) {
  87. if (isNaN(val)) {
  88. // 弹出提示框
  89. this.otherAmount = ''
  90. this.$vux.alert.show({
  91. title: '输入错误',
  92. content: '请输入数字',
  93. onShow () {
  94. },
  95. onHide () {
  96. }
  97. })
  98. }
  99. }
  100. }
  101. },
  102. methods: {
  103. btnRechargeList (item, index) {
  104. if (index !== 4) {
  105. this.otherAmount = ''
  106. } else {
  107. this.isNum = !this.isNum
  108. }
  109. if (this.isShow === index) {
  110. this.isShow = -1
  111. } else {
  112. this.isShow = index
  113. }
  114. this.rechargeItem = item
  115. },
  116. btnRecharge () {
  117. // 选择充值类型
  118. if (this.rechargeItem.id === undefined) {
  119. // 弹出提示框
  120. this.otherAmount = ''
  121. this.$vux.alert.show({
  122. title: '金额错误',
  123. content: '请您先选择充值金额'
  124. })
  125. return
  126. }
  127. if (this.rechargeItem.denomination === 1 && this.otherAmount === '') {
  128. // 弹出提示框
  129. this.otherAmount = ''
  130. this.$vux.alert.show({
  131. title: '重新输入',
  132. content: '请输入您需要充值的金额'
  133. })
  134. return
  135. }
  136. let addRechargeOrder = {
  137. user_id: config.userId,
  138. value: this.otherAmount,
  139. recharge_id: this.rechargeItem.id
  140. }
  141. let payRecharge = {}
  142. axios.post('o2o/recharge/addRechargeorder', qs.stringify(addRechargeOrder)).then(res => {
  143. if (res.data.success) {
  144. console.log(res.data.data.price)
  145. let payValue = ''
  146. if (this.otherAmount === '' && this.isShow !== 4) {
  147. payValue = this.rechargeItem.denomination
  148. } else {
  149. payValue = this.otherAmount
  150. }
  151. payRecharge = {
  152. final_price: res.data.data.price,
  153. pay_channel: 'wx_pub',
  154. order_id: res.data.data._id.$id,
  155. products: '充值' + payValue + '元'
  156. }
  157. this.$router.push({path: '/pay', query: {payRecharge: payRecharge}})
  158. }
  159. })
  160. // axios 1.创建充值卡订单 user_id: user.id, value:inputVal,
  161. // 第二步
  162. },
  163. show (e) {
  164. if (this.index !== e) {
  165. this.isActive = e
  166. this.index = e
  167. } else {
  168. this.isActive = -1
  169. this.index = -1
  170. }
  171. },
  172. activity () {
  173. this.$router.push({path: '/activityText'})
  174. }
  175. }
  176. }
  177. </script>
  178. <style lang="less" scoped>
  179. img {
  180. display: block;
  181. }
  182. .recharge-title {
  183. padding-left: 15px;
  184. font-size: 20px;
  185. border-bottom: 1px solid rgba(0, 0, 0, 0.4);
  186. padding-bottom: 10px;
  187. padding-top: 11px;
  188. text-align: left;
  189. margin-bottom: -20px;
  190. }
  191. ul {
  192. padding-top: 5px;
  193. padding-bottom: 5px;
  194. padding-left: 10%;
  195. align-content: flex-start;
  196. li.media.on {
  197. border: 2px solid rgba(146, 118, 3, 1);
  198. font-size: 12px;
  199. }
  200. li.media {
  201. margin: 2%;
  202. float: left;
  203. height: 2.5rem;
  204. padding: 10px 0;
  205. width: 25.33%;
  206. cursor: pointer;
  207. font-size: 13px;
  208. border: 1px solid;
  209. text-align: center;
  210. div {
  211. line-height: 1.5rem;
  212. }
  213. &:nth-child(5) {
  214. padding: 15px;
  215. width: 55%;
  216. padding-top: 0.4rem;
  217. }
  218. .input-title {
  219. line-height: 1.5rem;
  220. font-size: 12px;
  221. width: 35%;
  222. float: left;
  223. }
  224. .input-rmb {
  225. float: left;
  226. width: 25%;
  227. }
  228. input {
  229. margin: 0;
  230. padding: 0;
  231. width: 40%;
  232. height: 25px;
  233. margin-top: 2%;
  234. text-align: center;
  235. }
  236. }
  237. &, li, div, input {
  238. -webkit-box-sizing: border-box;
  239. -moz-box-sizing: border-box;
  240. box-sizing: border-box;
  241. list-style: none;
  242. margin: 0;
  243. padding: 0;
  244. }
  245. }
  246. .btn-add-recharge {
  247. width: 80%;
  248. clear: both;
  249. color: white;
  250. padding: 15px;
  251. margin: 0 auto;
  252. border: 1px solid;
  253. text-align: center;
  254. background-color: rgba(146, 118, 3, 1);
  255. transition: all 2s;
  256. margin-top: 10px;
  257. }
  258. @media (max-width: 320px) {
  259. ul {
  260. li.media {
  261. &:nth-child(5) {
  262. padding: 10px 0;
  263. input{
  264. margin-top: -15px;
  265. width: 35%;
  266. }
  267. }
  268. }
  269. }
  270. }
  271. /*动画*/
  272. .slide {
  273. padding: 0 20px;
  274. overflow: hidden;
  275. max-height: 0;
  276. transition: max-height .5s cubic-bezier(0, 1, 0, 1) -.1s;
  277. span {
  278. display: block;
  279. text-align: left;
  280. font-size: 15px;
  281. }
  282. }
  283. .animate {
  284. max-height: 9999px;
  285. transition-timing-function: cubic-bezier(0.5, 0, 1, 0);
  286. transition-delay: 0s;
  287. }
  288. </style>