index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <scroll-view :scroll-x="true" class="money_scroll_view">
  5. <view :class="['list',form.active==index?'active':'']" v-for="(item,index) in moneyList" :key="index"
  6. @tap="toChange(item,index)">
  7. <view class="title">
  8. {{item.title}}
  9. </view>
  10. <view class="money">
  11. <span class="fh">¥</span>{{item.money}}
  12. </view>
  13. <view class="other">
  14. 有效期:{{item.days}}天
  15. </view>
  16. </view>
  17. </scroll-view>
  18. </view>
  19. <view class="two">
  20. <view class="two_1">
  21. <button @tap="toBuy">确认协议并立即以{{form.money}}元支付</button>
  22. </view>
  23. <view class="agree">
  24. <checkbox-group @change="changeAgree">
  25. <label>
  26. <checkbox :checked="agree" />
  27. <text @tap.stop="toAgree()">我已阅读并同意“会员服务协议”</text>
  28. </label>
  29. </checkbox-group>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. // 用户信息
  39. userInfo: {},
  40. // vip信息
  41. moneyList: [],
  42. form: {
  43. active: 0,
  44. mongy: 0
  45. },
  46. // 用戶协议
  47. agree: true,
  48. // 修改用户信息
  49. updateUser: {},
  50. }
  51. },
  52. onLoad() {
  53. const that = this;
  54. // 查询用户信息
  55. that.searchUser();
  56. // 查询其他信息
  57. that.searchOther();
  58. },
  59. methods: {
  60. // 查询用户信息
  61. searchUser() {
  62. const that = this;
  63. uni.getStorage({
  64. key: 'token',
  65. success: async (res) => {
  66. let user = that.$jwt(res.data);
  67. let arr = await that.$api(`user/${user._id}`, 'GET');
  68. if (arr.errcode == '0') {
  69. that.$set(that, `userInfo`, arr.data)
  70. }
  71. },
  72. fail: (err) => {
  73. console.log('暂无登录信息');
  74. }
  75. })
  76. },
  77. // 选择
  78. toChange(e, index) {
  79. const that = this;
  80. let form = {
  81. active: index,
  82. money: e.money,
  83. days: e.days
  84. }
  85. that.$set(that, `form`, form)
  86. },
  87. // 购买
  88. toBuy() {
  89. const that = this;
  90. let user = that.userInfo;
  91. let money = that.form.money;
  92. let days = that.form.days;
  93. // 1:是否同意协议
  94. if (that.agree == true) {
  95. if (user && user._id) {
  96. let updateUser;
  97. if (user && user.is_vip == '0') {
  98. let vip_start_time = that.$moment().format('YYYY-MM-DD HH:mm:ss');
  99. let vip_end_time = that.$moment().add(days, 'days').format('YYYY-MM-DD HH:mm:ss');
  100. updateUser = {
  101. id: user._id,
  102. is_vip: '1',
  103. vip_start_time: vip_start_time,
  104. vip_end_time: vip_end_time
  105. }
  106. // 用户基本信息修改
  107. that.$set(that, `updateUser`, updateUser);
  108. // 支付
  109. that.oneBuy({
  110. user_id: user._id,
  111. money: money
  112. })
  113. } else if (user && user.is_vip == '1') {
  114. let vip_end_time = that.$moment(user.vip_end_time).add(days, 'days').format(
  115. 'YYYY-MM-DD HH:mm:ss');
  116. updateUser = {
  117. id: user._id,
  118. vip_end_time: vip_end_time
  119. }
  120. // 用户基本信息修改
  121. that.$set(that, `updateUser`, updateUser);
  122. // 支付
  123. that.oneBuy({
  124. user_id: user._id,
  125. money: money
  126. })
  127. }
  128. } else {
  129. uni.showToast({
  130. title: '暂无用户信息,无法支付!',
  131. icon: 'none'
  132. })
  133. }
  134. } else {
  135. uni.showToast({
  136. title: '请阅读并同意“会员服务协议”',
  137. icon: 'none'
  138. })
  139. }
  140. },
  141. // 支付
  142. oneBuy(e) {
  143. const that = this;
  144. // uni.requestPayment--支付
  145. uni.showModal({
  146. title: '支付',
  147. content: `您确认要支付${e.money}元吗?`,
  148. success: function(res) {
  149. if (res.confirm) {
  150. console.log('确认支付');
  151. that.toPay(e)
  152. } else if (res.cancel) {
  153. console.log('取消支付');
  154. }
  155. }
  156. });
  157. },
  158. // 确认支付
  159. async toPay(e) {
  160. const that = this;
  161. // 支付成功-修改个人信息,创建支付记录
  162. let updateUser = that.updateUser;
  163. let form = {
  164. user_id: that.userInfo._id,
  165. user_name: that.userInfo.nick_name,
  166. money_no: 'NO' + that.$moment().valueOf(),
  167. type: 'VIP',
  168. create_time: that.$moment().format('YYYY-MM-DD HH:mm:ss'),
  169. money: e.money
  170. }
  171. let res;
  172. res = await that.$api(`user/${updateUser.id}`, 'POST', updateUser);
  173. if (res.errcode == '0') {
  174. res = await that.$api('moneylog', 'POST', form);
  175. if (res.errcode == '0') {
  176. uni.showToast({
  177. title: '开通成功',
  178. icon: 'success'
  179. })
  180. uni.navigateBack()
  181. } else {
  182. uni.showToast({
  183. title: res.errmsg,
  184. icon: 'error'
  185. })
  186. }
  187. }
  188. },
  189. // 同意隐私协议
  190. changeAgree() {
  191. const that = this;
  192. let agree = true;
  193. if (that.agree) agree = false;
  194. that.$set(that, `agree`, agree);
  195. },
  196. // 查看会员服务协议
  197. toAgree() {
  198. const that = this;
  199. uni.navigateTo({
  200. url: `/pagesAccount/other/vipagree`
  201. })
  202. },
  203. // 查询其他信息
  204. async searchOther() {
  205. const that = this;
  206. let res;
  207. // 查询vip信息
  208. res = await that.$api('vipsetting', 'GET', {
  209. is_use: '0'
  210. })
  211. if (res.errcode == '0') {
  212. that.$set(that, `moneyList`, res.data);
  213. if (res.total > 0) {
  214. let form = {
  215. active: 0,
  216. money: res.data[0].money,
  217. days: res.data[0].days
  218. }
  219. console.log(form);
  220. that.$set(that, `form`, form)
  221. }
  222. }
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang="scss">
  228. .content {
  229. background-color: var(--rgb000);
  230. padding: 0 2vw;
  231. overflow-y: auto;
  232. .one {
  233. margin: 10px 0;
  234. .money_scroll_view {
  235. white-space: nowrap;
  236. .list {
  237. display: inline-block;
  238. margin: 0 10px 0 0;
  239. background-color: var(--rgbfff);
  240. padding: 8px;
  241. border-radius: 5px;
  242. text-align: center;
  243. .title {
  244. font-size: 14px;
  245. font-weight: bold;
  246. margin: 0 0 10px 0;
  247. }
  248. .money {
  249. font-size: 16px;
  250. font-weight: bold;
  251. color: var(--rgbffd);
  252. margin: 0 0 10px 0;
  253. .fh {
  254. font-size: 12px;
  255. padding: 0 5px 0 0;
  256. }
  257. }
  258. .other {
  259. font-size: 12px;
  260. font-weight: bold;
  261. }
  262. }
  263. .list:last-child {
  264. margin: 0;
  265. }
  266. .active {
  267. background-color: var(--rgbfa4);
  268. }
  269. }
  270. }
  271. .two {
  272. .two_1 {
  273. margin: 0 0 15px 0;
  274. button {
  275. border-radius: 25px;
  276. color: var(--rgbffd);
  277. font-family: monospace;
  278. font-weight: bold;
  279. }
  280. }
  281. }
  282. .agree {
  283. text-align: center;
  284. font-size: 12px;
  285. margin: 0 0 2vw 0;
  286. color: var(--rgbfff);
  287. }
  288. }
  289. </style>