handleMonthly.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. this.jumpUrl = location.origin + '/#/pages/center/monthly/monthly?type=' + this.type;
  143. },
  144. methods: {
  145. /**
  146. * 获取几个月的日期范围
  147. * {date} Date 起始日期,往后推一天
  148. * {monthNum} Number 往后月数
  149. * */
  150. getMonthRange(date, monthNum) {
  151. let Date1 = this.lastActiveDate;
  152. Date1 = new Date(date || Date1);
  153. const year = Date1.getFullYear();
  154. const month = Date1.getMonth() + 1;
  155. const day = Date1.getDate();
  156. const hours = Date1.getHours();
  157. const minutes = Date1.getMinutes();
  158. const seconds = Date1.getSeconds();
  159. let days = new Date(year, month, 0);
  160. days = days.getDate(); //获取当前日期中的月的天数
  161. let year2 = year;
  162. let month2 = parseInt(month) + parseInt(monthNum);
  163. if (month2 > 12) {
  164. year2 = parseInt(year2) + parseInt(parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12);
  165. month2 = parseInt(month2) % 12;
  166. }
  167. let day2 = day;
  168. let days2 = new Date(year2, month2, 0);
  169. days2 = days2.getDate();
  170. if (day2 > days2) {
  171. day2 = days2;
  172. }
  173. if (month2 < 10) {
  174. month2 = '0' + month2;
  175. }
  176. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day);
  177. const t2 = year2 + '.' + month2 + '.' + (day2 > 9 ? day2 : '0' + day2);
  178. this.startTime = t1;
  179. this.endTime = t2;
  180. this.monthStartTime =
  181. year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hours + ':' + minutes + ':' + seconds;
  182. this.monthEndTime = year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' + seconds;
  183. return t1 + '-' + t2;
  184. },
  185. /**
  186. * 月操作 减1
  187. * */
  188. reduceMonthNum() {
  189. if (this.form.month > 1) {
  190. this.form.month -= 1;
  191. this.form.dateRange = this.getMonthRange(new Date(), this.form.month + this.freeMonthNum);
  192. }
  193. },
  194. /**
  195. * 月操作 加1
  196. * */
  197. addMonthNum() {
  198. if (this.form.month >= 24) {
  199. this.$refs.uToast.show({
  200. title: '最多24月',
  201. type: 'warning'
  202. });
  203. return;
  204. }
  205. this.form.month += 1;
  206. this.form.dateRange = this.getMonthRange(new Date(), this.form.month + this.freeMonthNum);
  207. },
  208. carLicenseListConfirm(item) {
  209. this.form.carLicense = item[0];
  210. this.vehicleNo = item[0].label;
  211. this.getMonthInfo();
  212. },
  213. /**
  214. * 获取包月信息
  215. * @date 2022-10-09
  216. * @returns {any}
  217. */
  218. getMonthInfo() {
  219. let paramsObj = {
  220. park: 'parkNo',
  221. road: 'roadNo'
  222. },
  223. params = {
  224. vehicleNo: this.vehicleNo
  225. };
  226. params[paramsObj[this.type]] = this[paramsObj[this.type]];
  227. this.$u.api
  228. .monthInfo(params)
  229. .then((res) => {
  230. if (res.code === 200 && res.data.vehicleList && res.data.vehicleList.length) {
  231. this.lastActiveDate = res.data.lastActiveDate;
  232. this.form.monthAmount = res.data.monthAmount;
  233. this.orderMoney = (Number(this.form.monthAmount) * Number(this.form.month)).toFixed(2);
  234. this.carLicenseList = [];
  235. let vehicleNoItem = null;
  236. res.data.vehicleList.forEach((item, index) => {
  237. const obj = {
  238. value: item.energyType,
  239. label: item.vehicleNo,
  240. energyType: item.energyType
  241. };
  242. if (this.vehicleNo == item.vehicleNo) {
  243. vehicleNoItem = obj;
  244. this.carLicenseDefaultValue = [index];
  245. }
  246. this.carLicenseList.push(obj);
  247. });
  248. // 判断是否url存在车牌号,存在则选中项默认选中
  249. if (vehicleNoItem) {
  250. this.form.carLicense = vehicleNoItem;
  251. } else {
  252. this.form.carLicense = this.carLicenseList[0];
  253. }
  254. if (this.monthId) {
  255. this.$nextTick(() => {
  256. this.$refs['choosePayment'].openPopup({ payAmount: Number(this.orderMoney) }, 'single', this.type);
  257. });
  258. }
  259. }
  260. })
  261. .catch((err) => {
  262. console.log(err);
  263. });
  264. },
  265. /**
  266. * 获取包月规则详情
  267. * @date 2022-12-20
  268. * @returns {any}
  269. */
  270. monthlyRuleDetails() {
  271. let paramsObj = {
  272. park: 'parkNo',
  273. road: 'roadNo'
  274. },
  275. params = {};
  276. params[paramsObj[this.type]] = this[paramsObj[this.type]];
  277. this.$u.api.monthlyRuleDetailsApi(params).then((res) => {
  278. if (res.code === 200) {
  279. this.monthlyRuleObj = res?.rows[0] ?? {};
  280. this.calcFreeMonthNum(this.form.month);
  281. }
  282. });
  283. },
  284. calcFreeMonthNum(val) {
  285. if (this.monthlyRuleObj.giveFlag && Number(this.monthlyRuleObj.giveFlag) === 1) {
  286. let timesNum = parseInt(Number(val) / Number(this.monthlyRuleObj.minMonth));
  287. if (timesNum > 0) {
  288. this.freeMonthNum = Number(timesNum) * Number(this.monthlyRuleObj.giveMonth);
  289. } else {
  290. this.freeMonthNum = 0;
  291. }
  292. }
  293. },
  294. /**
  295. * 提交包月信息
  296. * @date 2022-10-09
  297. * @param {any} roadNo
  298. * @returns {any}
  299. */
  300. submit() {
  301. this.loading = true;
  302. let paramsObj = {
  303. park: 'parkNo',
  304. road: 'roadNo'
  305. },
  306. params = {
  307. vehicleNo: this.form.carLicense.label,
  308. energyType: this.form.carLicense.energyType,
  309. monthStartTime: this.monthStartTime,
  310. monthEndTime: this.monthEndTime,
  311. monthCount: this.form.month
  312. };
  313. params[paramsObj[this.type]] = this[paramsObj[this.type]];
  314. this.$u.api
  315. .createMonth(params)
  316. .then((res) => {
  317. if (res.code === 200) {
  318. this.monthId = res.data.monthId;
  319. this.orderMoney = (Number(this.form.monthAmount) * Number(this.form.month)).toFixed(2);
  320. // this.payWayPop = true;
  321. this.$nextTick(() => {
  322. this.$refs['choosePayment'].openPopup({ payAmount: Number(this.orderMoney) }, 'single', this.type);
  323. });
  324. } else {
  325. this.$refs.uToast.show({
  326. title: res.msg,
  327. type: 'error'
  328. });
  329. }
  330. this.loading = false;
  331. })
  332. .catch((err) => {
  333. this.loading = false;
  334. });
  335. },
  336. /**
  337. * 获取包月说明
  338. * @date 2022-10-09
  339. * @param {any} termsType
  340. * @returns {any}
  341. */
  342. getSysterms(termsType) {
  343. this.$u.api
  344. .getSysterms({
  345. termsType: termsType
  346. })
  347. .then((res) => {
  348. if (res.code === 200) {
  349. this.monthlyContent = res.data?.content;
  350. } else {
  351. this.$refs.uToast.show({
  352. title: res.msg,
  353. type: 'error'
  354. });
  355. }
  356. })
  357. .catch((err) => {
  358. this.$refs.uToast.show({
  359. title: '系统错误!',
  360. type: 'error'
  361. });
  362. });
  363. },
  364. jumpMonthList() {
  365. this.$u.route({
  366. url: '/pages/center/monthly/monthly',
  367. type: 'redirect',
  368. params: {
  369. type: this.type
  370. }
  371. });
  372. },
  373. /**
  374. * @description: 关闭支付弹框
  375. * @return {*}
  376. */
  377. closePaymentMethod() {
  378. if (this.monthId) this.jumpMonthList();
  379. }
  380. },
  381. computed: {
  382. dateRange: function () {
  383. return this.getMonthRange(this.lastActiveDate, this.form.month + this.freeMonthNum);
  384. }
  385. },
  386. filters: {
  387. verifyStatusFilter(value) {
  388. if (value === 0) {
  389. return '-';
  390. } else if (value === 1) {
  391. return '汽油车';
  392. } else if (value === 2) {
  393. return '新能源';
  394. } else {
  395. return '-';
  396. }
  397. }
  398. }
  399. };
  400. </script>
  401. <style lang="scss" scoped>
  402. @import './handleMonthly.scss';
  403. @import '../paymentMethod/paymentMethod.scss';
  404. </style>