index.vue 10 KB

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