handleMonthly.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <view class="handle-monthly">
  3. <view class="handle-monthly-item">
  4. <view>车牌选择</view>
  5. <view class="choose-license" @click="isShowCarLicense = true">
  6. <view>{{ form.carLicense.label || '未选车牌' }}</view>
  7. <u-icon name="arrow-down" color="#7B7B7B" size="30"></u-icon>
  8. </view>
  9. </view>
  10. <u-select v-model="isShowCarLicense" :list="carLicenseList" :default-value="carLicenseDefaultValue" @confirm="carLicenseListConfirm"></u-select>
  11. <view class="handle-monthly-item">
  12. <view>车辆信息</view>
  13. <view>{{ form.carLicense.value | verifyStatusFilter }}</view>
  14. </view>
  15. <view class="handle-monthly-item">
  16. <view>包月金额</view>
  17. <view class="handle-monthly-money">{{ form.monthAmount || 0 }}元</view>
  18. </view>
  19. <view class="handle-monthly-item">
  20. <view>包月时长</view>
  21. <view class="handle-monthly-time-long">
  22. <button @click="reduceMonthNum()">-</button>
  23. <view>{{ form.month || 0 }}个月</view>
  24. <button @click="addMonthNum()">+</button>
  25. </view>
  26. </view>
  27. <view class="handle-monthly-item">
  28. <view>有效期限</view>
  29. <view>{{ dateRange || '-' }}</view>
  30. </view>
  31. <view class="handle-monthly-explain">
  32. <u-parse :html="monthlyContent"></u-parse>
  33. </view>
  34. <view class="handle-monthly-confirm-button">
  35. <template v-if="carLicenseList.length && form.carLicense && form.carLicense.label">
  36. <u-button type="primary" :loading="loading" @click="submit(roadNo)">确认包月</u-button>
  37. </template>
  38. <template v-else>
  39. <u-button>未选车牌</u-button>
  40. </template>
  41. </view>
  42. <u-modal v-model="payWayPop" :title-style="{ color: '#404040' }" title="缴费方式" :show-confirm-button="false" :show-cancel-button="false">
  43. <view class="slot-content">
  44. <view class="pay-way-new">
  45. <!-- <view class="pay-way-item pay-way-item-hy" @click="gyBankPay">
  46. <image src="../../static/img/guiyang-bank-icon.png" mode=""></image>
  47. <view class="title">贵州银行</view>
  48. </view>
  49. <view class="pay-way-item pay-way-item-jh" @click="juhePay">
  50. <image src="../../static/img/juhe-icon.png" mode=""></image>
  51. <view class="title">聚合支付</view>
  52. </view> -->
  53. <view class="pay-way-item pay-way-item-hy" @click="$u.debounce(gyBankPay, 1000, (immediate = true))">
  54. <image src="/static/img/gyyh-icon.svg" mode=""></image>
  55. <view class="title">贵州银行</view>
  56. </view>
  57. <!-- #ifdef H5 || MP-WEIXIN -->
  58. <!-- <view class="pay-way-item pay-way-item-wx" @click="$u.debounce(wechatPay, 1000, (immediate = true))" v-if="wxEnv">
  59. <image src="/static/img/weixin-icon.svg" mode=""></image>
  60. <view class="title">微信支付</view>
  61. </view> -->
  62. <!-- #endif -->
  63. <view class="pay-way-item pay-way-item-jh" @click="$u.debounce(juhePay, 1000, (immediate = true))">
  64. <image src="/static/img/juhe-icon.svg" mode=""></image>
  65. <view class="title">聚合支付</view>
  66. </view>
  67. </view>
  68. <view class="pay-way-subtitle">
  69. <view class="pay-way-subtitle-item">前三个月每天首次一分钱,长期八折优惠</view>
  70. <!-- #ifdef H5 || MP-WEIXIN -->
  71. <!-- <view class="pay-way-subtitle-item" v-if="wxEnv">&nbsp;</view> -->
  72. <!-- #endif -->
  73. <view class="pay-way-subtitle-item">&nbsp;</view>
  74. </view>
  75. <button class="pay-way-close-btn" @click="payWayPop = false">关闭</button>
  76. </view>
  77. </u-modal>
  78. <u-toast ref="uToast" />
  79. </view>
  80. </template>
  81. <script>
  82. import { getEnvIsWx } from '@/utils/judgEnvironment.js';
  83. import $wxPay from '@/utils/wxPay.js';
  84. export default {
  85. data() {
  86. return {
  87. startTime: '',
  88. endTime: '',
  89. payUrl: '',
  90. monthId: '',
  91. vehicleNo: '',
  92. monthEndTime: '',
  93. monthStartTime: '',
  94. lastActiveDate: null,
  95. roadNo: null,
  96. carLicenseList: [],
  97. isShowCarLicense: false,
  98. form: {
  99. energyType: [],
  100. monthAmount: 0,
  101. carLicense: {},
  102. month: 1,
  103. dateRange: ''
  104. },
  105. label: '',
  106. payWayPop: false,
  107. jumpUrl: undefined,
  108. monthlyContent: '',
  109. carLicenseDefaultValue: [0],
  110. wxEnv: false,
  111. loading: false
  112. };
  113. },
  114. onLoad(page) {
  115. this.wxEnv = getEnvIsWx();
  116. this.getSysterms(0);
  117. if (page.vehicleNo && page.vehicleNo) {
  118. this.roadNo = page.roadNo;
  119. this.vehicleNo = page.vehicleNo;
  120. this.getMonthInfo(this.roadNo, this.vehicleNo);
  121. } else if (page.roadNo) {
  122. this.roadNo = page.roadNo;
  123. this.getMonthInfo(this.roadNo);
  124. }
  125. const baseUrl = window.location.href.split('#')[0];
  126. let jumpUrl = baseUrl + '#/pages/center/monthly/monthly';
  127. this.jumpUrl = jumpUrl;
  128. },
  129. methods: {
  130. /**
  131. * 获取几个月的日期范围
  132. * {date} Date 起始日期,往后推一天
  133. * {monthNum} Number 往后月数
  134. * */
  135. getMonthRange(date, monthNum) {
  136. let Date1 = this.lastActiveDate;
  137. Date1 = new Date(Date1);
  138. const year = Date1.getFullYear();
  139. const month = Date1.getMonth() + 1;
  140. const day = Date1.getDate();
  141. const hours = Date1.getHours();
  142. const minutes = Date1.getMinutes();
  143. const seconds = Date1.getSeconds();
  144. let days = new Date(year, month, 0);
  145. days = days.getDate(); //获取当前日期中的月的天数
  146. let year2 = year;
  147. let month2 = parseInt(month) + parseInt(monthNum);
  148. if (month2 > 12) {
  149. year2 = parseInt(year2) + parseInt(parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12);
  150. month2 = parseInt(month2) % 12;
  151. }
  152. let day2 = day;
  153. let days2 = new Date(year2, month2, 0);
  154. days2 = days2.getDate();
  155. if (day2 > days2) {
  156. day2 = days2;
  157. }
  158. if (month2 < 10) {
  159. month2 = '0' + month2;
  160. }
  161. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day);
  162. const t2 = year2 + '.' + month2 + '.' + (day2 > 9 ? day2 : '0' + day2);
  163. this.startTime = t1;
  164. this.endTime = t2;
  165. this.monthStartTime =
  166. year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hours + ':' + minutes + ':' + seconds;
  167. this.monthEndTime = year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' + seconds;
  168. return t1 + '-' + t2;
  169. },
  170. /**
  171. * 月操作 减1
  172. * */
  173. reduceMonthNum() {
  174. if (this.form.month > 1) {
  175. this.form.month -= 1;
  176. this.form.dateRange = this.getMonthRange(new Date(), this.form.month);
  177. }
  178. },
  179. /**
  180. * 月操作 加1
  181. * */
  182. addMonthNum() {
  183. if (this.form.month >= 24) {
  184. this.$refs.uToast.show({
  185. title: '最多24月',
  186. type: 'warning'
  187. });
  188. return;
  189. }
  190. this.form.month += 1;
  191. this.form.dateRange = this.getMonthRange(new Date(), this.form.month);
  192. },
  193. carLicenseListConfirm(item) {
  194. this.form.carLicense = item[0];
  195. this.vehicleNo = item[0].label;
  196. this.getMonthInfo(this.roadNo, this.vehicleNo);
  197. },
  198. /**
  199. * 获取包月信息
  200. * @date 2022-10-09
  201. * @param {any} roadNo
  202. * @param {any} vehicleNo
  203. * @returns {any}
  204. */
  205. getMonthInfo(roadNo, vehicleNo) {
  206. this.$u.api
  207. .monthInfo({
  208. roadNo: roadNo,
  209. vehicleNo: vehicleNo
  210. })
  211. .then((res) => {
  212. if (res.code === 200 && res.data.vehicleList && res.data.vehicleList.length) {
  213. this.lastActiveDate = res.data.lastActiveDate;
  214. this.form.monthAmount = res.data.monthAmount;
  215. this.carLicenseList = [];
  216. let vehicleNoItem = null;
  217. res.data.vehicleList.forEach((item, index) => {
  218. const obj = {
  219. value: item.energyType,
  220. label: item.vehicleNo,
  221. energyType: item.energyType
  222. };
  223. if (this.vehicleNo == item.vehicleNo) {
  224. vehicleNoItem = obj;
  225. this.carLicenseDefaultValue = [index];
  226. }
  227. this.carLicenseList.push(obj);
  228. });
  229. // 判断是否url存在车牌号,存在则选中项默认选中
  230. if (vehicleNoItem) {
  231. this.form.carLicense = vehicleNoItem;
  232. } else {
  233. this.form.carLicense = this.carLicenseList[0];
  234. }
  235. }
  236. });
  237. },
  238. /**
  239. * 提交包月信息
  240. * @date 2022-10-09
  241. * @param {any} roadNo
  242. * @returns {any}
  243. */
  244. submit(roadNo) {
  245. this.loading = true;
  246. this.$u.api
  247. .createMonth({
  248. roadNo,
  249. vehicleNo: this.form.carLicense.label,
  250. energyType: this.form.carLicense.energyType,
  251. monthStartTime: this.monthStartTime,
  252. monthEndTime: this.monthEndTime,
  253. monthCount: this.form.month
  254. })
  255. .then((res) => {
  256. console.log('createMonth', res);
  257. if (res.code === 200) {
  258. this.monthId = res.data.monthId;
  259. console.log(this.monthId);
  260. this.payWayPop = true;
  261. } else {
  262. this.$refs.uToast.show({
  263. title: res.msg,
  264. type: 'error'
  265. });
  266. }
  267. this.loading = false;
  268. })
  269. .catch((err) => {
  270. this.$refs.uToast.show({
  271. title: '程序错误!',
  272. type: 'error'
  273. });
  274. this.loading = false;
  275. });
  276. },
  277. /**
  278. * 贵州银行包月支付
  279. * @date 2022-10-09
  280. * @returns {any}
  281. */
  282. gyBankPay() {
  283. this.$u.api
  284. .monthPay({
  285. monthId: this.monthId,
  286. jumpUrl: this.jumpUrl
  287. })
  288. .then((res) => {
  289. if (res.code === 200) {
  290. window.location.href = res.data.url;
  291. } else {
  292. this.$refs.uToast.show({
  293. title: res.msg,
  294. type: 'error'
  295. });
  296. }
  297. });
  298. },
  299. /**
  300. * 聚合支付直接通过后台获取贵阳银行微信支付地址
  301. * @date 2022-10-09
  302. * @returns {any}
  303. */
  304. juhePay() {
  305. // 支付成功跳转到包月页面
  306. let params = {
  307. monthId: this.monthId,
  308. openid: '',
  309. jumpUrl: this.jumpUrl
  310. };
  311. this.$u.api
  312. .monthlyWxPay(params)
  313. .then((res) => {
  314. if (res.code === 200) {
  315. localStorage.setItem('jumpUrl', this.jumpUrl);
  316. location.href = res.data.qrCodeUrl;
  317. } else {
  318. this.$refs.uToast.show({
  319. title: res.msg,
  320. type: 'error'
  321. });
  322. }
  323. })
  324. .catch((err) => {
  325. this.$refs.uToast.show({
  326. title: '无法调起微信支付!',
  327. type: 'error'
  328. });
  329. });
  330. },
  331. /**
  332. * 微信支付
  333. * @date 2022-10-09
  334. * @returns {any}
  335. */
  336. wechatPay() {
  337. this.$u.api
  338. .wechatMonthlyPayapi({
  339. orderList: this.curOrderList,
  340. openid: this.vuex_wxinfo.openId
  341. })
  342. .then((r) => {
  343. if (r.code === 200) {
  344. $wxPay.wexinPay(r.data.wx).then((res) => {
  345. switch (Number(res.code)) {
  346. case 0: // 成功
  347. //#ifdef H5
  348. // window.location.reload();
  349. location.href = this.jumpUrl;
  350. //#endif
  351. break;
  352. case 1: // 取消
  353. this.$refs.uToast.show({
  354. title: '已取消支付',
  355. type: 'info'
  356. });
  357. break;
  358. case 2: // 支付失败
  359. this.$refs.uToast.show({
  360. title: '支付失败,请检查!',
  361. type: 'error'
  362. });
  363. break;
  364. }
  365. });
  366. }
  367. });
  368. },
  369. /**
  370. * 获取包月说明
  371. * @date 2022-10-09
  372. * @param {any} termsType
  373. * @returns {any}
  374. */
  375. getSysterms(termsType) {
  376. this.$u.api
  377. .getSysterms({
  378. termsType: termsType
  379. })
  380. .then((res) => {
  381. if (res.code === 200) {
  382. this.monthlyContent = res.data?.content;
  383. } else {
  384. this.$refs.uToast.show({
  385. title: res.msg,
  386. type: 'error'
  387. });
  388. }
  389. })
  390. .catch((err) => {
  391. this.$refs.uToast.show({
  392. title: '系统错误!',
  393. type: 'error'
  394. });
  395. });
  396. }
  397. },
  398. computed: {
  399. dateRange: function () {
  400. return this.getMonthRange(this.lastActiveDate, this.form.month);
  401. }
  402. },
  403. filters: {
  404. verifyStatusFilter(value) {
  405. if (value === 0) {
  406. return '-';
  407. } else if (value === 1) {
  408. return '汽油车';
  409. } else if (value === 2) {
  410. return '新能源';
  411. } else {
  412. return '-';
  413. }
  414. }
  415. }
  416. };
  417. </script>
  418. <style lang="scss" scoped>
  419. @import './handleMonthly.scss';
  420. @import '../paymentMethod/paymentMethod.scss';
  421. </style>