index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. <c-drawer :drawer="drawer" @toClose="toClose">
  33. <view class="drawer_one">
  34. <uni-forms ref="payForm" :model="payForm" :rules="rules">
  35. <uni-forms-item name="type">
  36. <view class="label">支付方式</view>
  37. <uni-data-checkbox v-model="payForm.type" :localdata="typeList"
  38. :map="{text:'label',value:'value'}" @change="typeChange"></uni-data-checkbox>
  39. </uni-forms-item>
  40. <uni-forms-item>
  41. <view class="label">支付图片</view>
  42. <view class="img">
  43. <image class="image"
  44. :src="payForm.img_url&&payForm.img_url.length>0?payForm.img_url[0].url:''"
  45. mode="aspectFit" @tap="imgView(payForm.img_url)">
  46. </image>
  47. </view>
  48. </uni-forms-item>
  49. <uni-forms-item name="pay_no">
  50. <view class="label">转账单号/订单号</view>
  51. <uni-easyinput type="number" v-model="payForm.pay_no" placeholder="请输入转账单号/订单号" />
  52. </uni-forms-item>
  53. <!-- <uni-forms-item name="pay_url">
  54. <view class="label">支付账单明细截图</view>
  55. <upload :list="payForm.pay_url" name="pay_url" :count="1" @uplSuc="uplSuc" @uplDel="uplDel">
  56. </upload>
  57. </uni-forms-item> -->
  58. </uni-forms>
  59. <view class="btn">
  60. <button size="mini" @tap="toSave()">提交支付信息</button>
  61. </view>
  62. <view class="other">
  63. <view class="other_1">
  64. 注:
  65. </view>
  66. <view class="other_2">
  67. <view class="tip">
  68. 1.转账单号(微信):我-服务-钱包-账单-账单详情
  69. </view>
  70. <view class="tip">
  71. 1.订单号(支付宝):我的-账单-账单详情
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </c-drawer>
  77. </view>
  78. </template>
  79. <script>
  80. import cDrawer from "../components/c-drawer.vue";
  81. import upload from "@/components/upload/index.vue";
  82. export default {
  83. components: {
  84. cDrawer,
  85. upload
  86. },
  87. data() {
  88. return {
  89. // 基本信息
  90. basicInfo: {},
  91. // 用户信息
  92. userInfo: {},
  93. // vip信息
  94. moneyList: [],
  95. form: {
  96. active: 0,
  97. mongy: 0
  98. },
  99. // 用戶协议
  100. agree: true,
  101. // 修改用户信息
  102. updateUser: {},
  103. // 抽屉
  104. drawer: {
  105. title: '支付',
  106. show: false,
  107. mode: 'right'
  108. },
  109. // 支付信息
  110. payForm: {
  111. type: '0',
  112. img_url: [],
  113. pay_url: []
  114. },
  115. rules: {
  116. pay_no: {
  117. rules: [{
  118. required: true,
  119. errorMessage: '请输入转账单号/订单号',
  120. }]
  121. },
  122. pay_url: {
  123. rules: [{
  124. required: false,
  125. errorMessage: '请上传支付账单明细截图',
  126. }]
  127. }
  128. },
  129. // 支付方式
  130. typeList: [{
  131. "value": 0,
  132. "text": "微信"
  133. }, {
  134. "value": 1,
  135. "text": "支付宝"
  136. }]
  137. }
  138. },
  139. onLoad() {
  140. const that = this;
  141. // 查询基本信息
  142. that.searchBasic();
  143. // 查询用户信息
  144. that.searchUser();
  145. // 查询其他信息
  146. that.searchOther();
  147. },
  148. methods: {
  149. // 查询基本信息
  150. searchBasic() {
  151. const that = this;
  152. uni.getStorage({
  153. key: 'basicInfo',
  154. success: (res) => {
  155. let data = res.data
  156. data.account_btn = data.account_btn.sort((a, b) => {
  157. return a.sort - b.sort
  158. });
  159. that.$set(that, `basicInfo`, data);
  160. // 支付方式默认值
  161. that.typeChange({
  162. detail: {
  163. value: '0'
  164. }
  165. })
  166. }
  167. })
  168. },
  169. // 查询用户信息
  170. searchUser() {
  171. const that = this;
  172. uni.getStorage({
  173. key: 'token',
  174. success: async (res) => {
  175. let user = that.$jwt(res.data);
  176. let arr = await that.$api(`user/${user._id}`, 'GET');
  177. if (arr.errcode == '0') {
  178. that.$set(that, `userInfo`, arr.data)
  179. }
  180. },
  181. fail: (err) => {
  182. console.log('暂无登录信息');
  183. }
  184. })
  185. },
  186. // 选择
  187. toChange(e, index) {
  188. const that = this;
  189. let form = {
  190. active: index,
  191. money: e.money,
  192. days: e.days
  193. }
  194. that.$set(that, `form`, form)
  195. },
  196. // 购买
  197. toBuy() {
  198. const that = this;
  199. let user = that.userInfo;
  200. let money = that.form.money;
  201. let days = that.form.days;
  202. // 1:是否同意协议
  203. if (that.agree == true) {
  204. if (user && user._id) {
  205. let updateUser;
  206. if (user && user.is_vip == '0') {
  207. let vip_start_time = that.$moment().format('YYYY-MM-DD HH:mm:ss');
  208. let vip_end_time = that.$moment().add(days, 'days').format('YYYY-MM-DD HH:mm:ss');
  209. updateUser = {
  210. id: user._id,
  211. is_vip: '1',
  212. vip_start_time: vip_start_time,
  213. vip_end_time: vip_end_time
  214. }
  215. // 用户基本信息修改
  216. that.$set(that, `updateUser`, updateUser);
  217. // 支付
  218. that.oneBuy({
  219. user_id: user._id,
  220. money: money
  221. })
  222. } else if (user && user.is_vip == '1') {
  223. let vip_end_time = that.$moment(user.vip_end_time).add(days, 'days').format(
  224. 'YYYY-MM-DD HH:mm:ss');
  225. updateUser = {
  226. id: user._id,
  227. vip_end_time: vip_end_time
  228. }
  229. // 用户基本信息修改
  230. that.$set(that, `updateUser`, updateUser);
  231. // 支付
  232. that.oneBuy({
  233. user_id: user._id,
  234. money: money
  235. })
  236. }
  237. } else {
  238. uni.showToast({
  239. title: '暂无用户信息,无法支付!',
  240. icon: 'none'
  241. })
  242. }
  243. } else {
  244. uni.showToast({
  245. title: '请阅读并同意“会员服务协议”',
  246. icon: 'none'
  247. })
  248. }
  249. },
  250. // 支付
  251. oneBuy() {
  252. const that = this;
  253. that.$set(that, `drawer`, {
  254. title: '支付',
  255. show: true,
  256. mode: 'right'
  257. })
  258. },
  259. typeChange(e) {
  260. const that = this;
  261. let basicInfo = that.basicInfo;
  262. let value = e.detail.value;
  263. if (value == '0') that.$set(that.payForm, `img_url`, basicInfo.pay_info.wx_url)
  264. else if (value == '1') that.$set(that.payForm, `img_url`, basicInfo.pay_info.zfb_url)
  265. },
  266. // 图片保存
  267. uplSuc(e) {
  268. const that = this;
  269. that.$set(that.payForm, `${e.name}`, [...that.payForm[e.name], e.data]);
  270. },
  271. // 图片删除
  272. uplDel(e) {
  273. const that = this;
  274. let data = that.payForm[e.name];
  275. let arr = data.filter((i, index) => index != e.data.index);
  276. that.$set(that.payForm, `${e.name}`, arr);
  277. },
  278. // 提交保存
  279. toSave() {
  280. const that = this;
  281. that.$refs.payForm.validate().then(res => {
  282. that.toPay()
  283. }).catch(err => {
  284. console.log('表单错误信息:', err);
  285. })
  286. },
  287. // 确认支付
  288. async toPay() {
  289. const that = this;
  290. // 支付成功-修改个人信息,创建支付记录
  291. let updateUser = that.updateUser;
  292. let form = that.form;
  293. let payForm = that.payForm;
  294. let object = {
  295. user_id: that.userInfo._id,
  296. user_name: that.userInfo.nick_name,
  297. money_no: 'NO' + that.$moment().valueOf(),
  298. type: 'VIP',
  299. create_time: that.$moment().format('YYYY-MM-DD HH:mm:ss'),
  300. money: form.money,
  301. pay_no: payForm.pay_no
  302. }
  303. let res;
  304. res = await that.$api(`user/${updateUser.id}`, 'POST', updateUser);
  305. if (res.errcode == '0') {
  306. res = await that.$api('moneylog', 'POST', object);
  307. if (res.errcode == '0') {
  308. uni.showToast({
  309. title: '开通成功',
  310. icon: 'success'
  311. })
  312. uni.navigateBack()
  313. } else {
  314. uni.showToast({
  315. title: res.errmsg,
  316. icon: 'error'
  317. })
  318. }
  319. }
  320. },
  321. // 关闭弹框
  322. toClose() {
  323. const that = this;
  324. that.$set(that, `drawer`, {
  325. title: '支付',
  326. show: false,
  327. mode: 'right'
  328. })
  329. },
  330. // 同意隐私协议
  331. changeAgree() {
  332. const that = this;
  333. let agree = true;
  334. if (that.agree) agree = false;
  335. that.$set(that, `agree`, agree);
  336. },
  337. // 查看会员服务协议
  338. toAgree() {
  339. const that = this;
  340. uni.navigateTo({
  341. url: `/pagesAccount/other/vipagree`
  342. })
  343. },
  344. // 查询其他信息
  345. async searchOther() {
  346. const that = this;
  347. let res;
  348. // 查询vip信息
  349. res = await that.$api('vipsetting', 'GET', {
  350. is_use: '0'
  351. })
  352. if (res.errcode == '0') {
  353. that.$set(that, `moneyList`, res.data);
  354. if (res.total > 0) {
  355. let form = {
  356. active: 0,
  357. money: res.data[0].money,
  358. days: res.data[0].days
  359. }
  360. that.$set(that, `form`, form)
  361. }
  362. }
  363. // 支付方式
  364. res = await that.$api('dictdata', 'GET', {
  365. type: 'app_pay_type'
  366. })
  367. if (res.errcode == '0') {
  368. that.$set(that, `typeList`, res.data)
  369. }
  370. },
  371. // 图片预览
  372. imgView(e) {
  373. const that = this;
  374. console.log(e);
  375. console.log(e[0].url);
  376. uni.previewImage({
  377. current: 0,
  378. urls: [e[0].url],
  379. });
  380. }
  381. }
  382. }
  383. </script>
  384. <style lang="scss">
  385. .content {
  386. background-color: var(--rgb000);
  387. padding: 0 2vw;
  388. overflow-y: auto;
  389. .one {
  390. margin: 10px 0;
  391. .money_scroll_view {
  392. white-space: nowrap;
  393. .list {
  394. display: inline-block;
  395. margin: 0 10px 0 0;
  396. background-color: var(--rgbfff);
  397. padding: 8px;
  398. border-radius: 5px;
  399. text-align: center;
  400. .title {
  401. font-size: 14px;
  402. font-weight: bold;
  403. margin: 0 0 10px 0;
  404. }
  405. .money {
  406. font-size: 16px;
  407. font-weight: bold;
  408. color: var(--rgbffd);
  409. margin: 0 0 10px 0;
  410. .fh {
  411. font-size: 12px;
  412. padding: 0 5px 0 0;
  413. }
  414. }
  415. .other {
  416. font-size: 12px;
  417. font-weight: bold;
  418. }
  419. }
  420. .list:last-child {
  421. margin: 0;
  422. }
  423. .active {
  424. background-color: var(--rgbfa4);
  425. }
  426. }
  427. }
  428. .two {
  429. .two_1 {
  430. margin: 0 0 15px 0;
  431. button {
  432. border-radius: 25px;
  433. color: var(--rgbffd);
  434. font-family: monospace;
  435. font-weight: bold;
  436. }
  437. }
  438. }
  439. .agree {
  440. text-align: center;
  441. font-size: 12px;
  442. margin: 0 0 2vw 0;
  443. color: var(--rgbfff);
  444. }
  445. }
  446. .drawer_one {
  447. .label {
  448. font-size: 14px;
  449. margin: 0 0 5px 0;
  450. font-weight: bold;
  451. }
  452. .img {
  453. width: 100%;
  454. text-align: center;
  455. .image {
  456. width: 100%;
  457. }
  458. }
  459. .uni-forms-item {
  460. margin: 0;
  461. }
  462. .btn {
  463. text-align: center;
  464. margin: 30px 0 10px 0;
  465. button {
  466. background-color: var(--rgb67c);
  467. color: var(--rgbfff);
  468. }
  469. }
  470. .other {
  471. .other_1 {
  472. font-size: 14px;
  473. font-weight: bold;
  474. margin: 0 0 10px 0;
  475. }
  476. .other_2 {
  477. .tip {
  478. font-size: 12px;
  479. font-weight: bold;
  480. color: var(--rgbfa4);
  481. margin: 0 0 5px 0;
  482. }
  483. }
  484. }
  485. }
  486. </style>