renew.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <div class="s-page">
  3. <el-page-header @back="goBack" content="续费"></el-page-header>
  4. <el-divider></el-divider>
  5. <el-card class="goods">
  6. <div class="tishi">请选择需要购买的套餐并用微信扫码支付!</div>
  7. <div class="flex">
  8. <div
  9. class="item"
  10. v-for="(item, index) in goodsList"
  11. :key="index"
  12. @click="
  13. goodsIndex = index
  14. goodsId = item.id
  15. "
  16. >
  17. <div class="tj" v-if="item.isFirst == 1">推荐</div>
  18. <div class="year">{{ item.normName }}</div>
  19. <div class="new">
  20. <template v-if="item.id != '000'">
  21. <span style="font-size: 20px">¥</span>{{ (item.normAmount * 100 - item.discountAmount * 100) / 100 }}
  22. </template>
  23. <template v-else>
  24. <span style="font-size: 20px">¥</span
  25. >{{
  26. goodsId != '000'
  27. ? 0
  28. : serviceProductList
  29. .filter(item => !!~formgengduode.serviceProductList.indexOf(item.dictCode))
  30. .map(item => item.price)
  31. .reduce((accumulator, currentValue) => accumulator + currentValue, 0) * formgengduode.year
  32. }}
  33. </template>
  34. </div>
  35. <div v-if="item.id != '000'" class="old">¥{{ item.normAmount }}</div>
  36. <div :class="goodsIndex == index ? 'bottom active' : 'bottom'">立省¥{{ item.discountAmount }}</div>
  37. </div>
  38. </div>
  39. <div style="margin: 20px 0">
  40. <el-form ref="form" :model="formgengduode" label-width="160px">
  41. <el-form-item
  42. label="选择需要购买模块"
  43. style="text-align: left"
  44. prop="serviceProductList"
  45. :rules="[{ required: true, message: '请选择', trigger: 'blur' }]"
  46. >
  47. <el-checkbox-group v-model="formgengduode.serviceProductList">
  48. <el-checkbox
  49. :disabled="goodsId != '000'"
  50. v-for="(item, index) in serviceProductList"
  51. :key="index"
  52. :label="item.dictCode"
  53. name="type"
  54. >{{ item.dictValue }}(¥{{ item.price }})</el-checkbox
  55. >
  56. </el-checkbox-group>
  57. </el-form-item>
  58. <el-form-item
  59. label="选择需要购买年限"
  60. style="text-align: left"
  61. prop="year"
  62. :rules="[{ required: true, message: '请选择', trigger: 'blur' }]"
  63. >
  64. <el-input-number
  65. size="mini"
  66. style="width: 200px"
  67. v-model="formgengduode.year"
  68. :min="1"
  69. :max="100"
  70. label="描述文字"
  71. :disabled="goodsId != '000'"
  72. ></el-input-number
  73. ><span style="font-size: 16px; margin-left: 10px">年</span>
  74. </el-form-item>
  75. </el-form>
  76. </div>
  77. <div class="flex" style="justify-content: flex-start">
  78. <el-button style="margin-top: 30px" type="success" @click="confirmPay()">微信支付</el-button>
  79. </div>
  80. </el-card>
  81. <el-dialog
  82. title="确认支付"
  83. :visible.sync="is_pay"
  84. width="50%"
  85. :close-on-click-modal="false"
  86. :modal-append-to-body="false"
  87. @close="close"
  88. >
  89. <div class="pay" v-if="!isPaySuccess && goodsList[goodsIndex]">
  90. <div style="font-weight: bold; font-size: 22px">扫码支付</div>
  91. <div class="ewm" ref="payQRCode" />
  92. <div>
  93. <div class="flex" style="align-items: center">
  94. <div>
  95. <template v-if="goodsId != '000'">
  96. 实付:<span style="font-size: 20px; color: #ff6804">¥</span
  97. ><span style="font-size: 36px; color: #ff6804; font-weight: bold">{{
  98. (goodsList[goodsIndex].normAmount * 100 - goodsList[goodsIndex].discountAmount * 100) / 100
  99. }}</span>
  100. </template>
  101. <template v-else>
  102. 实付:<span style="font-size: 20px; color: #ff6804">¥</span
  103. ><span style="font-size: 36px; color: #ff6804; font-weight: bold">{{
  104. serviceProductList
  105. .filter(item => !!~formgengduode.serviceProductList.indexOf(item.dictCode))
  106. .map(item => item.price)
  107. .reduce((accumulator, currentValue) => accumulator + currentValue, 0) * formgengduode.year
  108. }}</span>
  109. </template>
  110. </div>
  111. <div v-if="goodsId != '000'" style="margin: 0 20px">
  112. 已优惠: <span style="font-size: 18px; color: #ff6804">¥</span
  113. ><span style="font-size: 20px; color: #ff6804">{{ goodsList[goodsIndex].discountAmount }}</span>
  114. </div>
  115. <el-tooltip effect="dark" placement="right-start">
  116. <div slot="content">
  117. 购买年限越大越优惠,优惠价格按年份增加折扣,第1年<br />
  118. 8.8折,第2年8折,第3年7折,第4年6折,第5年5折。<br />
  119. 举例: 原价1000元/年,张三购买了3年限套餐,所需支付<br />
  120. 价格为: 第1年880.00元+第2年800.00元+第三年700.00元,<br />
  121. 需支付金额: 2380.00元
  122. </div>
  123. <i class="el-icon-question icon-question"></i>
  124. </el-tooltip>
  125. </div>
  126. <div style="display: flex; align-items: center; justify-content: center; margin-top: 20px">
  127. <img style="width: 30px; height: 30px" src="@/assets/common/weixin.png" alt="" />
  128. <span>请使用微信扫码支付</span>
  129. </div>
  130. </div>
  131. </div>
  132. <div class="pay" v-else-if="goodsList[goodsIndex]">
  133. <img style="width: 60px; height: 60px" src="@/assets/common/weixin.png" alt="" />
  134. <div style="font-weight: bold; font-size: 22px; margin: 20px 0">支付成功</div>
  135. <div class="flex" style="align-items: center">
  136. <div style="font-size: 16px">
  137. <template v-if="goodsId != '000'">
  138. 支付金额: <span style="font-size: 20px; color: #ff6804">¥</span
  139. ><span style="font-size: 36px; color: #ff6804; font-weight: bold">{{
  140. (goodsList[goodsIndex].normAmount * 100 - goodsList[goodsIndex].discountAmount * 100) / 100
  141. }}</span>
  142. </template>
  143. <template v-else>
  144. 支付金额: <span style="font-size: 20px; color: #ff6804">¥</span
  145. ><span style="font-size: 36px; color: #ff6804; font-weight: bold">{{
  146. serviceProductList
  147. .filter(item => !!~formgengduode.serviceProductList.indexOf(item.dictCode))
  148. .map(item => item.price)
  149. .reduce((accumulator, currentValue) => accumulator + currentValue, 0) * formgengduode.year
  150. }}</span>
  151. </template>
  152. </div>
  153. </div>
  154. <div style="margin: 50px 0; font-size: 18px">
  155. 您的账号已续费成功,最新到期时间为:<span style="color: #169dff">{{ userInfo.companyExpireTime }}</span>
  156. </div>
  157. <div style="display: flex; justify-content: center">
  158. <el-button size="small" type="primary" @click="goBack">知道了</el-button>
  159. </div>
  160. </div>
  161. </el-dialog>
  162. </div>
  163. </template>
  164. <script>
  165. import { mapGetters } from 'vuex'
  166. import { getUserInfo } from '@/api/setting'
  167. import QRCode from 'qrcodejs2'
  168. import request from '@/utils/request'
  169. import { serviceProductList } from '@/api/serviceProductConfig.js'
  170. export default {
  171. data() {
  172. return {
  173. userInfo: {},
  174. goodsList: [],
  175. goodsId: '',
  176. goodsIndex: 0,
  177. timer: '',
  178. is_pay: false,
  179. is_submit: true,
  180. isPaySuccess: false,
  181. formgengduode: {
  182. year: 1,
  183. serviceProductList: []
  184. },
  185. serviceProductList: []
  186. }
  187. },
  188. computed: {
  189. ...mapGetters(['userid'])
  190. },
  191. watch: {
  192. goodsId() {
  193. if (this.goodsId == '000') {
  194. this.formgengduode.serviceProductList = []
  195. } else {
  196. this.formgengduode.serviceProductList = this.serviceProductList.map(item => item.dictCode)
  197. }
  198. this.formgengduode.year = this.goodsList.find(item => item.id === this.goodsId)?.year || 0
  199. }
  200. },
  201. created() {
  202. serviceProductList({
  203. pageNum: 1,
  204. pageSize: -1,
  205. params: [{ param: 'a.status', compare: '=', value: 'true' }]
  206. }).then(res => {
  207. this.getUserInfo()
  208. this.getBuyList()
  209. this.serviceProductList = res.data.records
  210. })
  211. },
  212. destroyed() {
  213. this.clear()
  214. },
  215. methods: {
  216. // 返回
  217. goBack() {
  218. this.is_pay = false
  219. this.clear()
  220. this.$emit('back')
  221. },
  222. close() {
  223. this.clear()
  224. },
  225. getUserInfo() {
  226. getUserInfo({ adminUserId: this.userid }).then(res => {
  227. this.userInfo = res.data
  228. })
  229. },
  230. getBuyList() {
  231. request({
  232. url: `/buy/service/config/list`,
  233. method: 'post',
  234. data: {}
  235. })
  236. .then(res => {
  237. this.goodsList = [
  238. ...res.data,
  239. {
  240. discountAmount: 0,
  241. id: '000',
  242. isFirst: 0,
  243. month: 0,
  244. normAmount: 0,
  245. normName: '自定义',
  246. remark: '',
  247. year: 1
  248. }
  249. ]
  250. this.goodsId = res.data[0].id
  251. })
  252. .catch(erro => {})
  253. },
  254. confirmPay() {
  255. if (!this.is_submit) {
  256. return false
  257. }
  258. this.is_submit = false
  259. setTimeout(() => {
  260. this.is_submit = true
  261. }, 3000)
  262. this.getCode()
  263. },
  264. checkPay(payId) {
  265. this.timer = setInterval(() => {
  266. request({
  267. url: `/buy/service/query/pay/code`,
  268. method: 'post',
  269. params: {
  270. companyName: this.userInfo.companyName,
  271. payId
  272. }
  273. })
  274. .then(res => {
  275. if (res.data == true) {
  276. this.getUserInfo()
  277. this.$refs.payQRCode.innerHTML = ''
  278. this.isPaySuccess = true
  279. this.clear()
  280. }
  281. })
  282. .catch(erro => {})
  283. }, 3000)
  284. },
  285. clear() {
  286. clearInterval(this.timer)
  287. },
  288. funcsss() {
  289. request({
  290. url: `/buy/service/generate/pay/code`,
  291. method: 'post',
  292. data: {
  293. id: this.userInfo.buyCompanyInfo,
  294. ...(() => {
  295. if (this.goodsId == '000') {
  296. return {
  297. year: this.formgengduode.year,
  298. serviceProductList: this.formgengduode.serviceProductList
  299. }
  300. } else {
  301. return {
  302. normId: this.goodsId
  303. }
  304. }
  305. })()
  306. }
  307. })
  308. .then(res => {
  309. if (res.code == 200) {
  310. this.$refs.payQRCode.innerHTML = ''
  311. this.$nextTick(() => {
  312. new QRCode(this.$refs.payQRCode, {
  313. text: res.data.codeUrl,
  314. width: 200,
  315. height: 200,
  316. colorDark: '#333333', // 二维码颜色
  317. colorLight: '#ffffff', // 二维码背景色
  318. correctLevel: QRCode.CorrectLevel.L // 容错率,L/M/H
  319. })
  320. this.checkPay(res.data.id)
  321. })
  322. }
  323. })
  324. .catch(erro => {})
  325. },
  326. getCode() {
  327. if (this.goodsId == '000') {
  328. this.$refs.form.validate(valid => {
  329. if (valid) {
  330. this.funcsss()
  331. this.is_pay = true
  332. } else {
  333. console.log('error submit!!')
  334. return false
  335. }
  336. })
  337. } else {
  338. this.funcsss()
  339. this.is_pay = true
  340. }
  341. }
  342. }
  343. }
  344. </script>
  345. <style scoped="scoped" lang="scss">
  346. .s-page {
  347. padding: 20px;
  348. background-color: #ffffff;
  349. }
  350. .tishi {
  351. height: 40px;
  352. padding-left: 40px;
  353. background-color: #eeeeee;
  354. text-align: left;
  355. font-weight: bold;
  356. line-height: 40px;
  357. margin-bottom: 50px;
  358. }
  359. .flex {
  360. display: flex;
  361. }
  362. .goods {
  363. box-sizing: border-box;
  364. text-align: center;
  365. .item {
  366. width: 200px;
  367. height: 200px;
  368. margin-right: 20px;
  369. background-color: #eeeeee;
  370. position: relative;
  371. padding-top: 40px;
  372. box-sizing: border-box;
  373. font-weight: bold;
  374. border-radius: 10px;
  375. border: 1px solid #dddddd;
  376. cursor: pointer;
  377. .year {
  378. font-size: 20px;
  379. color: #999999;
  380. }
  381. .new {
  382. font-size: 36px;
  383. color: #ff6804;
  384. }
  385. .old {
  386. font-size: 16px;
  387. color: #999999;
  388. text-decoration: line-through;
  389. }
  390. .bottom {
  391. width: 100%;
  392. padding: 10px 0;
  393. color: #b4916d;
  394. background-color: #e6e6e6;
  395. position: absolute;
  396. bottom: 0;
  397. left: 0;
  398. }
  399. .tj {
  400. padding: 6px 20px;
  401. position: absolute;
  402. top: 0;
  403. left: 0;
  404. font-size: 20px;
  405. font-weight: 500;
  406. color: #ffffff;
  407. border-radius: 0 0 26px 0;
  408. background-color: #ff554e;
  409. }
  410. .active {
  411. color: #ffffff;
  412. background-color: #ff953d;
  413. }
  414. }
  415. .ewm {
  416. width: 200px;
  417. height: 200px;
  418. }
  419. .icon-question {
  420. font-size: 20px;
  421. // color: #189dff;
  422. }
  423. }
  424. .pay {
  425. display: flex;
  426. flex-direction: column;
  427. align-items: center;
  428. text-align: center;
  429. .ewm {
  430. margin: 30px 0;
  431. }
  432. }
  433. </style>