handleMonthly.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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
  20. class="handle-monthly-item"
  21. v-if="monthlyRuleObj.giveFlag && Number(monthlyRuleObj.giveFlag) === 1"
  22. :class="{ pb20: monthlyRuleObj.minMonth && form.month >= monthlyRuleObj.minMonth && Number(monthlyRuleObj.giveFlag) === 1 }"
  23. >
  24. <view>包月时长</view>
  25. <view class="handle-monthly-time-long">
  26. <button @click="reduceMonthNum()">-</button>
  27. <view>{{ form.month || 0 }}个月</view>
  28. <button @click="addMonthNum()">+</button>
  29. </view>
  30. <view
  31. class="handle-monthly-time-tips"
  32. v-if="monthlyRuleObj.minMonth && form.month >= monthlyRuleObj.minMonth && Number(monthlyRuleObj.giveFlag) === 1"
  33. >
  34. 赠送提示:可获得{{ freeMonthNum }}个月的免费停车时长
  35. </view>
  36. </view>
  37. <view class="handle-monthly-item" v-else>
  38. <view>包月时长</view>
  39. <view class="handle-monthly-time-long">
  40. <button @click="reduceMonthNum()">-</button>
  41. <view>{{ form.month || 0 }}个月</view>
  42. <button @click="addMonthNum()">+</button>
  43. </view>
  44. </view>
  45. <view class="handle-monthly-item">
  46. <view>有效期限</view>
  47. <view>{{ dateRange || '-' }}</view>
  48. </view>
  49. <view class="handle-monthly-explain">
  50. <u-parse :html="monthlyContent"></u-parse>
  51. </view>
  52. <view class="handle-monthly-confirm-button">
  53. <template v-if="carLicenseList.length && form.carLicense && form.carLicense.label">
  54. <u-button type="primary" :loading="loading" @click="submit()">确认包月</u-button>
  55. </template>
  56. <template v-else>
  57. <u-button>未选车牌</u-button>
  58. </template>
  59. </view>
  60. <!-- 选择支付 -->
  61. <choose-payment ref="choosePayment" :monthId="monthId" :jumpUrl="jumpUrl" :isMonthPay="true" @closePaymentMethod="closePaymentMethod" />
  62. <u-toast ref="uToast" />
  63. </view>
  64. </template>
  65. <script>
  66. import ChoosePayment from '../choosePayment/choosePayment.vue';
  67. export default {
  68. components: {
  69. ChoosePayment
  70. },
  71. data() {
  72. return {
  73. startTime: '',
  74. endTime: '',
  75. payUrl: '',
  76. monthId: '',
  77. vehicleNo: '',
  78. monthEndTime: '',
  79. monthStartTime: '',
  80. lastActiveDate: null,
  81. roadNo: null,
  82. parkNo: null,
  83. carLicenseList: [],
  84. isShowCarLicense: false,
  85. form: {
  86. energyType: [],
  87. monthAmount: 0,
  88. carLicense: {},
  89. month: 1,
  90. dateRange: ''
  91. },
  92. payWayPop: false,
  93. jumpUrl: undefined,
  94. monthlyContent: '',
  95. carLicenseDefaultValue: [0],
  96. wxEnv: false,
  97. loading: false,
  98. type: 'road',
  99. monthlyRuleObj: {},
  100. freeMonthNum: 0,
  101. radioCurrent: '',
  102. orderMoney: ''
  103. };
  104. },
  105. watch: {
  106. 'form.month': {
  107. handler(val) {
  108. this.calcFreeMonthNum(val);
  109. },
  110. deep: true,
  111. immediate: false
  112. }
  113. },
  114. onLoad(page) {
  115. this.getSysterms(0);
  116. if (page.vehicleNo && page.roadNo) {
  117. this.roadNo = page.roadNo;
  118. this.vehicleNo = page.vehicleNo;
  119. this.type = 'road';
  120. this.getMonthInfo();
  121. } else if (page.roadNo) {
  122. this.roadNo = page.roadNo;
  123. this.type = 'road';
  124. this.getMonthInfo();
  125. } else if (page.vehicleNo && page.parkNo) {
  126. this.parkNo = page.parkNo;
  127. this.vehicleNo = page.vehicleNo;
  128. this.type = 'park';
  129. this.getMonthInfo();
  130. } else if (page.parkNo) {
  131. this.parkNo = page.parkNo;
  132. this.type = 'park';
  133. this.getMonthInfo();
  134. }
  135. if (page.monthId) {
  136. this.monthId = page.monthId;
  137. // this.payWayPop = true;
  138. }
  139. if (page.roadNo) {
  140. this.monthlyRuleDetails();
  141. }
  142. // if (page.parkNo) {
  143. // this.monthlyRuleDetails();
  144. // }
  145. const baseUrl = window.location.href.split('#')[0];
  146. let jumpUrl = baseUrl + '#/pages/center/monthly/monthly?type=' + this.type;
  147. this.jumpUrl = jumpUrl;
  148. },
  149. methods: {
  150. /**
  151. * 获取几个月的日期范围
  152. * {date} Date 起始日期,往后推一天
  153. * {monthNum} Number 往后月数
  154. * */
  155. getMonthRange(date, monthNum) {
  156. let Date1 = this.lastActiveDate;
  157. Date1 = new Date(date || Date1);
  158. const year = Date1.getFullYear();
  159. const month = Date1.getMonth() + 1;
  160. const day = Date1.getDate();
  161. const hours = Date1.getHours();
  162. const minutes = Date1.getMinutes();
  163. const seconds = Date1.getSeconds();
  164. let days = new Date(year, month, 0);
  165. days = days.getDate(); //获取当前日期中的月的天数
  166. let year2 = year;
  167. let month2 = parseInt(month) + parseInt(monthNum);
  168. if (month2 > 12) {
  169. year2 = parseInt(year2) + parseInt(parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12);
  170. month2 = parseInt(month2) % 12;
  171. }
  172. let day2 = day;
  173. let days2 = new Date(year2, month2, 0);
  174. days2 = days2.getDate();
  175. if (day2 > days2) {
  176. day2 = days2;
  177. }
  178. if (month2 < 10) {
  179. month2 = '0' + month2;
  180. }
  181. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day);
  182. const t2 = year2 + '.' + month2 + '.' + (day2 > 9 ? day2 : '0' + day2);
  183. this.startTime = t1;
  184. this.endTime = t2;
  185. this.monthStartTime =
  186. year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hours + ':' + minutes + ':' + seconds;
  187. this.monthEndTime = year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' + seconds;
  188. return t1 + '-' + t2;
  189. },
  190. /**
  191. * 月操作 减1
  192. * */
  193. reduceMonthNum() {
  194. if (this.form.month > 1) {
  195. this.form.month -= 1;
  196. this.form.dateRange = this.getMonthRange(new Date(), this.form.month + this.freeMonthNum);
  197. }
  198. },
  199. /**
  200. * 月操作 加1
  201. * */
  202. addMonthNum() {
  203. if (this.form.month >= 24) {
  204. this.$refs.uToast.show({
  205. title: '最多24月',
  206. type: 'warning'
  207. });
  208. return;
  209. }
  210. this.form.month += 1;
  211. this.form.dateRange = this.getMonthRange(new Date(), this.form.month + this.freeMonthNum);
  212. },
  213. carLicenseListConfirm(item) {
  214. this.form.carLicense = item[0];
  215. this.vehicleNo = item[0].label;
  216. this.getMonthInfo();
  217. },
  218. /**
  219. * 获取包月信息
  220. * @date 2022-10-09
  221. * @returns {any}
  222. */
  223. getMonthInfo() {
  224. let paramsObj = {
  225. park: 'parkNo',
  226. road: 'roadNo'
  227. },
  228. params = {
  229. vehicleNo: this.vehicleNo
  230. };
  231. params[paramsObj[this.type]] = this[paramsObj[this.type]];
  232. this.$u.api
  233. .monthInfo(params)
  234. .then((res) => {
  235. if (res.code === 200 && res.data.vehicleList && res.data.vehicleList.length) {
  236. this.lastActiveDate = res.data.lastActiveDate;
  237. this.form.monthAmount = res.data.monthAmount;
  238. this.orderMoney = (Number(this.form.monthAmount) * Number(this.form.month)).toFixed(2);
  239. this.carLicenseList = [];
  240. let vehicleNoItem = null;
  241. res.data.vehicleList.forEach((item, index) => {
  242. const obj = {
  243. value: item.energyType,
  244. label: item.vehicleNo,
  245. energyType: item.energyType
  246. };
  247. if (this.vehicleNo == item.vehicleNo) {
  248. vehicleNoItem = obj;
  249. this.carLicenseDefaultValue = [index];
  250. }
  251. this.carLicenseList.push(obj);
  252. });
  253. // 判断是否url存在车牌号,存在则选中项默认选中
  254. if (vehicleNoItem) {
  255. this.form.carLicense = vehicleNoItem;
  256. } else {
  257. this.form.carLicense = this.carLicenseList[0];
  258. }
  259. if (this.monthId) {
  260. this.$nextTick(() => {
  261. this.$refs['choosePayment'].openPopup({ payAmount: Number(this.orderMoney) }, 'single', this.type);
  262. });
  263. }
  264. }
  265. })
  266. .catch((err) => {
  267. console.log(err);
  268. });
  269. },
  270. /**
  271. * 获取包月规则详情
  272. * @date 2022-12-20
  273. * @returns {any}
  274. */
  275. monthlyRuleDetails() {
  276. let paramsObj = {
  277. park: 'parkNo',
  278. road: 'roadNo'
  279. },
  280. params = {};
  281. params[paramsObj[this.type]] = this[paramsObj[this.type]];
  282. this.$u.api.monthlyRuleDetailsApi(params).then((res) => {
  283. if (res.code === 200) {
  284. this.monthlyRuleObj = res?.rows[0] ?? {};
  285. this.calcFreeMonthNum(this.form.month);
  286. }
  287. });
  288. },
  289. calcFreeMonthNum(val) {
  290. if (this.monthlyRuleObj.giveFlag && Number(this.monthlyRuleObj.giveFlag) === 1) {
  291. let timesNum = parseInt(Number(val) / Number(this.monthlyRuleObj.minMonth));
  292. if (timesNum > 0) {
  293. this.freeMonthNum = Number(timesNum) * Number(this.monthlyRuleObj.giveMonth);
  294. } else {
  295. this.freeMonthNum = 0;
  296. }
  297. }
  298. },
  299. /**
  300. * 提交包月信息
  301. * @date 2022-10-09
  302. * @param {any} roadNo
  303. * @returns {any}
  304. */
  305. submit() {
  306. this.loading = true;
  307. let paramsObj = {
  308. park: 'parkNo',
  309. road: 'roadNo'
  310. },
  311. params = {
  312. vehicleNo: this.form.carLicense.label,
  313. energyType: this.form.carLicense.energyType,
  314. monthStartTime: this.monthStartTime,
  315. monthEndTime: this.monthEndTime,
  316. monthCount: this.form.month
  317. };
  318. params[paramsObj[this.type]] = this[paramsObj[this.type]];
  319. this.$u.api
  320. .createMonth(params)
  321. .then((res) => {
  322. if (res.code === 200) {
  323. this.monthId = res.data.monthId;
  324. this.orderMoney = (Number(this.form.monthAmount) * Number(this.form.month)).toFixed(2);
  325. // this.payWayPop = true;
  326. this.$nextTick(() => {
  327. this.$refs['choosePayment'].openPopup({ payAmount: Number(this.orderMoney) }, 'single', this.type);
  328. });
  329. } else {
  330. this.$refs.uToast.show({
  331. title: res.msg,
  332. type: 'error'
  333. });
  334. }
  335. this.loading = false;
  336. })
  337. .catch((err) => {
  338. this.$refs.uToast.show({
  339. title: '程序错误!',
  340. type: 'error'
  341. });
  342. this.loading = false;
  343. });
  344. },
  345. /**
  346. * 获取包月说明
  347. * @date 2022-10-09
  348. * @param {any} termsType
  349. * @returns {any}
  350. */
  351. getSysterms(termsType) {
  352. this.$u.api
  353. .getSysterms({
  354. termsType: termsType
  355. })
  356. .then((res) => {
  357. if (res.code === 200) {
  358. this.monthlyContent = res.data?.content;
  359. } else {
  360. this.$refs.uToast.show({
  361. title: res.msg,
  362. type: 'error'
  363. });
  364. }
  365. })
  366. .catch((err) => {
  367. this.$refs.uToast.show({
  368. title: '系统错误!',
  369. type: 'error'
  370. });
  371. });
  372. },
  373. jumpMonthList() {
  374. this.$u.route({
  375. url: '/pages/center/monthly/monthly',
  376. type: 'redirect',
  377. params: {
  378. type: this.type
  379. }
  380. });
  381. },
  382. /**
  383. * @description: 关闭支付弹框
  384. * @return {*}
  385. */
  386. closePaymentMethod() {
  387. if (this.monthId) this.jumpMonthList();
  388. }
  389. },
  390. computed: {
  391. dateRange: function () {
  392. return this.getMonthRange(this.lastActiveDate, this.form.month + this.freeMonthNum);
  393. }
  394. },
  395. filters: {
  396. verifyStatusFilter(value) {
  397. if (value === 0) {
  398. return '-';
  399. } else if (value === 1) {
  400. return '汽油车';
  401. } else if (value === 2) {
  402. return '新能源';
  403. } else {
  404. return '-';
  405. }
  406. }
  407. }
  408. };
  409. </script>
  410. <style lang="scss" scoped>
  411. @import './handleMonthly.scss';
  412. @import '../paymentMethod/paymentMethod.scss';
  413. </style>