bill.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. <template>
  2. <view class="content flex flex_column">
  3. <view class="header">
  4. <view class="headerList u-flex">
  5. <view class="list_l">
  6. <u-icon name="account" color="#00aaff" size="32"></u-icon>
  7. <text>客户名称</text>
  8. </view>
  9. <view class="list_r u-flex">
  10. <u-input v-model="customerObj.customerName" @click="goChooseCustomer" disabled placeholder="请选择客户名称" />
  11. <u-icon name="arrow-right" color="#999" size="30"></u-icon>
  12. </view>
  13. </view>
  14. <view class="headerList u-flex">
  15. <view class="list_l">
  16. <u-icon name="clock" color="#00aaff" size="32"></u-icon>
  17. <text>对账周期</text>
  18. <u-icon name="question-circle-fill" @click="tipShow = true" :color="wordColor" size="32"></u-icon>
  19. </view>
  20. <view class="list_r u-flex">
  21. <u-input v-model="cycleName" @click="chooseCycleData" disabled placeholder="请选择对账日期" />
  22. <u-icon name="arrow-right" color="#999" size="30"></u-icon>
  23. </view>
  24. </view>
  25. <view class="statistical u-flex">
  26. <view class="statisticalList">
  27. <text>总单数:</text>
  28. <text>{{ bill.length }}</text>
  29. </view>
  30. <view class="statisticalList">
  31. <text>待收金额合计:</text>
  32. <text>¥{{ totalPayPrice }}</text>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="chooseCon"><billList ref="bill" :showCheck="true" :list="bill" @allChecked="allCheckedCallback"></billList></view>
  37. <view class="footerCon u-flex">
  38. <view class="f-left">
  39. <u-checkbox @change="allCheckeChange" v-model="allChecked" shape="circle">{{ allChecked ? '取消全选' : '全选' }}</u-checkbox>
  40. </view>
  41. <view class="f-mid" @click="isDetailShow = !isDetailShow">
  42. <view>
  43. 待收:
  44. <text>¥{{ chooseTotalPayPrice }}</text>
  45. </view>
  46. <view v-if="chooseList.length > 0">
  47. 折后:
  48. <text>¥{{ settlement }}</text>
  49. </view>
  50. <view class="u-flex" v-if="chooseList.length > 0">
  51. <view>
  52. 折让:
  53. <text>¥{{ discountVal || 0 }}</text>
  54. </view>
  55. <view class="costBtn" @click="costShow = true">打折</view>
  56. </view>
  57. </view>
  58. <view class="f-btns">
  59. <u-button size="medium" @click="submitOrder" :custom-style="customBtnStyle" :loading="submitLoading" shape="circle" type="primary" hover-class="none">
  60. 发送对账单
  61. </u-button>
  62. </view>
  63. </view>
  64. <!-- 对账周期弹窗 -->
  65. <u-popup v-model="showSearch" mode="right" width="70%">
  66. <view class="tabBox">
  67. <view class="tabs">
  68. <view class="flex">
  69. <view :class="item.val == curTab ? 'active' : 'all'" v-for="item in placeTab" :key="item.val" @click="tabChange(item)">{{ item.name }}</view>
  70. </view>
  71. </view>
  72. <view class="flex align_center form-item-inp" style="padding: 0 30rpx;" v-if="curTab == 6">
  73. <u-input clearable v-model="dateArray" disabled placeholder="请选择时间段" input-align="center" @click="showDate = true" />
  74. </view>
  75. <view class="form-footer-btn">
  76. <u-button class="handle-btn" shape="circle" size="medium" hover-class="none" @click="handleClean">重置</u-button>
  77. <u-button class="handle-btn" shape="circle" size="medium" hover-class="none" :custom-style="customBtnStyle" @click="handleSearch">查询</u-button>
  78. </view>
  79. </view>
  80. </u-popup>
  81. <!-- 选择日期范围 -->
  82. <u-calendar v-model="showDate" ref="rangeDate" @change="dateChange" mode="range"></u-calendar>
  83. <!-- 打折弹窗 -->
  84. <u-popup v-model="costShow" mode="center" :border-radius="20" closeable width="82%">
  85. <view class="costPopup">
  86. <view class="costPopupTit">东莞市京步车证汽车服务中心</view>
  87. <view class="costPopupCon">
  88. <view class="costList">
  89. <text class="label">待收金额:</text>
  90. <text>¥{{ chooseTotalPayPrice }}</text>
  91. </view>
  92. <view class="costList u-flex">
  93. <view class="label">折让金额:</view>
  94. <u-input v-model="discountVal" :border="true" :height="50" />
  95. </view>
  96. <view class="tip" v-if="discountVal > chooseTotalPayPrice">折让金额不能大于待收金额,请重新输入</view>
  97. <view class="costText">折让后金额</view>
  98. <view class="costText">¥{{ settlement }}</view>
  99. </view>
  100. <u-button type="primary" :custom-style="customStyle" shape="circle" @click="handleDisCount">确定</u-button>
  101. </view>
  102. </u-popup>
  103. <!-- 对账周期弹窗 -->
  104. <u-modal v-model="tipShow" :show-title="false" confirm-text="知道了">
  105. <view class="slot-content"><rich-text :nodes="tipContent"></rich-text></view>
  106. </u-modal>
  107. <!-- 分享询问弹窗 -->
  108. <u-modal v-model="shareShow" :content="shareContent" @confirm="handleShare" @cancel="shareShow = false"></u-modal>
  109. </view>
  110. </template>
  111. <script>
  112. import billList from './billListComponent.vue';
  113. import { queryUnsettleSaleList, insert } from '@/api/verify.js';
  114. import getDate from '@/libs/getDate.js';
  115. import { toThousands } from '@/libs/tools'
  116. export default {
  117. components: { billList },
  118. data() {
  119. return {
  120. customBtnStyle: {
  121. // 自定义按钮样式
  122. borderColor: this.$config('primaryColor'),
  123. backgroundColor: this.$config('primaryColor'),
  124. color: '#fff',
  125. width: '180rpx'
  126. },
  127. wordColor: this.$config('infoColor'),
  128. customStyle: {
  129. borderColor: this.$config('primaryColor'),
  130. backgroundColor: this.$config('primaryColor'),
  131. color: '#fff'
  132. },
  133. allChecked: false,
  134. tipShow: false,
  135. discountVal: null, //折让金额
  136. tipContent: `账单周期指<br>销售单的创建时间`,
  137. shareContent: `是否同意发送对账单给微信好友?`,
  138. placeTab: [
  139. {
  140. name: '今日',
  141. val: '0'
  142. },
  143. {
  144. name: '昨日',
  145. val: '1'
  146. },
  147. {
  148. name: '本周',
  149. val: '2'
  150. },
  151. {
  152. name: '上周',
  153. val: '3'
  154. },
  155. {
  156. name: '本月',
  157. val: '4'
  158. },
  159. {
  160. name: '上月',
  161. val: '5'
  162. },
  163. {
  164. name: '自定义',
  165. val: '6'
  166. },
  167. {
  168. name: '全部',
  169. val: '7'
  170. }
  171. ],
  172. curTab: '0',
  173. showSearch: false,
  174. showDate: false,
  175. costShow: false,
  176. customerObj: {
  177. customerName: null
  178. },
  179. cycleName: '',
  180. params: {
  181. targetSn: undefined,
  182. bizBeginDate: undefined,
  183. bizEndDate: undefined
  184. },
  185. bill: [],
  186. dateArray: '',
  187. chooseList: [],
  188. isDetailShow: false,
  189. submitLoading: false,
  190. shareShow: false,
  191. verifySn:''
  192. };
  193. },
  194. onReady() {
  195. uni.setNavigationBarColor({
  196. frontColor: '#ffffff',
  197. backgroundColor: this.$config('primaryColor')
  198. });
  199. },
  200. onLoad(options) {
  201. //获取对账周期默认值
  202. if (uni.getStorageSync('curTab')) {
  203. this.curTab = uni.getStorageSync('curTab');
  204. } else {
  205. let systemList = this.$store.state.vuex_systemSetList;
  206. if(systemList){
  207. let cycleObj = systemList.find(item => {
  208. return item.remarks == 'sales_bill_period';
  209. });
  210. this.curTab = this.placeTab.findIndex(con => con.name == cycleObj.valueShow);
  211. }
  212. }
  213. this.cycleName = this.changeShowTime();
  214. // 获取选择客户
  215. if (options && options.data) {
  216. this.customerObj = JSON.parse(options.data);
  217. this.params.targetSn = this.customerObj.customerSn;
  218. }
  219. uni.$on('customerInfo', res => {
  220. this.customerObj = res;
  221. this.params.targetSn = res.customerSn;
  222. });
  223. this.changeTime();
  224. },
  225. onNavigationBarButtonTap() {
  226. uni.navigateTo({
  227. url: '/pages/sales/billHistory'
  228. });
  229. },
  230. onBackPress() {
  231. if (this.showSearch) {
  232. this.showSearch = false;
  233. } else {
  234. uni.removeStorageSync('curTab');
  235. uni.removeStorageSync('chooseList');
  236. }
  237. },
  238. onUnload() {
  239. uni.removeStorageSync('curTab');
  240. uni.removeStorageSync('chooseList');
  241. },
  242. computed: {
  243. //经销商信息
  244. userData() {
  245. return this.$store.state.vuex_userData;
  246. },
  247. totalPayPrice() {
  248. let totalPrice = 0;
  249. for (let i = 0; i < this.bill.length; i++) {
  250. this.bill[i].unsettleAmount = this.bill[i].unsettleAmount ? this.bill[i].unsettleAmount : 0;
  251. totalPrice += this.bill[i].unsettleAmount;
  252. }
  253. return toThousands(totalPrice,2);
  254. },
  255. chooseTotalPayPrice() {
  256. let price = 0;
  257. this.chooseList.forEach(item => {
  258. item.unsettleAmount = item.unsettleAmount ? item.unsettleAmount : 0;
  259. price += item.unsettleAmount;
  260. });
  261. return toThousands(price,2);
  262. },
  263. settlement() {
  264. let totalPrice=this.chooseTotalPayPrice?this.chooseTotalPayPrice:0;
  265. let discountPrice=this.discountVal?this.discountVal:0
  266. let priceNum=totalPrice - discountPrice;
  267. return toThousands(priceNum,2)
  268. }
  269. },
  270. methods: {
  271. chooseCycleData() {
  272. uni.setStorageSync('chooseList', this.chooseList);
  273. this.showSearch = true;
  274. },
  275. handleClean() {
  276. this.showSearch = false;
  277. let systemList = this.$store.state.vuex_systemSetList;
  278. let cycleObj = systemList.find(item => {
  279. return item.remarks == 'sales_bill_period';
  280. });
  281. this.curTab = this.placeTab.findIndex(con => con.name == cycleObj.valueShow);
  282. this.cycleName = this.changeShowTime();
  283. this.changeTime();
  284. },
  285. //选择客户
  286. goChooseCustomer() {
  287. uni.setStorageSync('curTab', this.curTab);
  288. this.jumpPage('/pages/sales/chooseCustomerBill');
  289. },
  290. changeTime() {
  291. if (this.curTab != 6 && this.curTab != 7) {
  292. this.params.bizBeginDate = this.getQueryDate().beginDate;
  293. this.params.bizEndDate = this.getQueryDate().endDate;
  294. this.cycleName = this.changeShowTime();
  295. } else if (this.curTab == 7) {
  296. this.cycleName = this.placeTab[this.curTab].name;
  297. this.params.bizBeginDate = undefined;
  298. this.params.bizEndDate = undefined;
  299. } else {
  300. this.dateArray = '';
  301. }
  302. this.getList();
  303. },
  304. getList() {
  305. const _this = this;
  306. queryUnsettleSaleList(this.params).then(res => {
  307. if (res.status == 200) {
  308. let chooseArr = uni.getStorageSync('chooseList');
  309. if (chooseArr && chooseArr.length > 0) {
  310. res.data.forEach(item => {
  311. const row = chooseArr.findIndex(k => k.bizSn == item.bizSn);
  312. item.checked = row > -1;
  313. });
  314. }
  315. this.bill = res.data;
  316. this.$refs.bill.setData(res.data);
  317. this.getChooseList()
  318. }
  319. });
  320. },
  321. getChooseList(){
  322. this.chooseList=this.bill.filter(item=>item.checked);
  323. },
  324. // 时间 change
  325. dateChange(date) {
  326. this.dateArray = date.startDate + ' ~ ' + date.endDate;
  327. this.params.bizBeginDate = date.startDate + ' 00:00:00';
  328. this.params.bizEndDate = date.endDate + ' 23:59:59';
  329. this.cycleName = date.startDate + '至' + date.endDate;
  330. },
  331. // 更改日期格式显示
  332. changeShowTime() {
  333. const fun = [
  334. getDate.getTodayInfo,
  335. getDate.getYesterdayInfo,
  336. getDate.getCurrWeekDaysInfo,
  337. getDate.getLastWeekDaysInfo,
  338. getDate.getCurrLastMonthDaysInfo,
  339. getDate.getLastMonthDaysInfo
  340. ];
  341. return fun[this.curTab]();
  342. },
  343. tabChange(data) {
  344. this.curTab = data.val;
  345. },
  346. getQueryDate() {
  347. const fun = [getDate.getToday, getDate.getYesterday, getDate.getCurrWeekDays, getDate.getLastWeekDays, getDate.getCurrLastMonthDays, getDate.getLastMonthDays];
  348. return {
  349. beginDate: fun[this.curTab]().starttime,
  350. endDate: fun[this.curTab]().endtime
  351. };
  352. },
  353. handleSearch() {
  354. this.showSearch = false;
  355. this.changeTime();
  356. },
  357. jumpPage(url) {
  358. uni.navigateTo({
  359. url
  360. });
  361. },
  362. handleDisCount() {
  363. if (this.discountVal > this.chooseTotalPayPrice) {
  364. uni.showToast({
  365. title: '折让金额不能大于待收金额,请重新输入',
  366. icon: 'none'
  367. });
  368. return;
  369. }
  370. let reg = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
  371. if (!reg.test(this.discountVal)) {
  372. uni.showToast({
  373. title: '折让金额格式不正确,请重新输入',
  374. icon: 'none'
  375. });
  376. return;
  377. }
  378. this.costShow = false;
  379. },
  380. submitOrder() {
  381. //发送对账单
  382. if (this.chooseList.length == 0) {
  383. uni.showToast({
  384. title: '请选择要发送的对账单',
  385. icon: 'none'
  386. });
  387. return;
  388. }
  389. let obj = {
  390. detailNum: this.chooseList.length,
  391. totalAmount: this.chooseTotalPayPrice,
  392. discountAmount: this.discountVal || 0,
  393. settleAmount: this.settlement,
  394. detailList: this.chooseList
  395. };
  396. let ajaxData = Object.assign(this.params, obj);
  397. this.submitLoading = true;
  398. insert(ajaxData).then(res => {
  399. if (res.status == 200) {
  400. this.submitLoading = false;
  401. this.shareShow = true;
  402. this.verifySn = res.data.verifySn
  403. } else {
  404. uni.showToast({
  405. title: res.message,
  406. icon: 'none'
  407. });
  408. }
  409. });
  410. },
  411. allCheckeChange(e) {
  412. this.$refs.bill.allSelect(e.value);
  413. const list = this.$refs.bill.getAllData();
  414. },
  415. // 选中事件
  416. allCheckedCallback(isAllChecked, row) {
  417. const has = this.chooseList.findIndex(k => k.bizSn == row.bizSn);
  418. // 在已选列表中
  419. if (has >= 0) {
  420. // 取消选中
  421. if (!row.checked) {
  422. this.chooseList.splice(has, 1);
  423. }
  424. } else {
  425. if (row.checked) {
  426. this.chooseList.push(row);
  427. }
  428. }
  429. // 是否全选
  430. this.allChecked = isAllChecked;
  431. },
  432. // 分享图文
  433. handleShare() {
  434. let url = 'http://p.iscm.360arrow.com/dzd/index.html?userSn=' + this.userData.orgSn + '&verifySn='+this.verifySn + '&name='+this.userData.orgName;
  435. if (uni.getSystemInfoSync().platform == 'ios') {
  436. uni.share({
  437. provider: 'weixin',
  438. scene: 'WXSceneSession',
  439. type: 0,
  440. href: url,
  441. title: this.customerObj.customerName,
  442. summary: '共' + this.settlement + '元,请您查阅',
  443. imageUrl: '../../static/logo.png',
  444. success: function(res) {
  445. console.log('success:' + JSON.stringify(res));
  446. },
  447. fail: function(err) {
  448. console.log('fail:' + JSON.stringify(err));
  449. }
  450. });
  451. } else {
  452. uni.shareWithSystem({
  453. summary: this.customerObj.customerName + '您好,您有一个对账单共' + this.settlement + '元,请您查阅',
  454. href: url,
  455. success() {
  456. console.log('调取微信列表成功,分享不一定成功')
  457. },
  458. fail() {
  459. console.log('分享失败')
  460. }
  461. });
  462. }
  463. }
  464. }
  465. };
  466. </script>
  467. <style lang="scss" scoped>
  468. .content {
  469. width: 100%;
  470. height: 100vh;
  471. .header {
  472. width: 100%;
  473. .headerList {
  474. width: 100%;
  475. box-sizing: border-box;
  476. padding: 16rpx 20rpx;
  477. background: #fff;
  478. &:nth-child(2) {
  479. border-top: 1rpx solid #e4e7ed;
  480. }
  481. .list_l {
  482. width: 208rpx;
  483. text {
  484. font-size: 28rpx;
  485. color: #666666;
  486. margin-left: 10rpx;
  487. margin-right: 10rpx;
  488. }
  489. }
  490. .list_r {
  491. width: calc(100% - 208rpx);
  492. }
  493. }
  494. .statistical {
  495. padding: 20rpx;
  496. background: #fff;
  497. margin: 10rpx 0;
  498. .statisticalList {
  499. &:first-child {
  500. width: 210rpx;
  501. }
  502. }
  503. text {
  504. &:last-child {
  505. color: $uni-color-warning;
  506. font-weight: 600;
  507. }
  508. }
  509. }
  510. }
  511. .chooseCon {
  512. flex-grow: 1;
  513. flex-basis: 0;
  514. overflow: auto;
  515. background-color: #fff;
  516. }
  517. .footerCon {
  518. background-color: #f8f8f8;
  519. padding: 10rpx 20rpx;
  520. box-sizing: border-box;
  521. .f-mid {
  522. flex: 1;
  523. color: #666;
  524. font-size: 0.8rem;
  525. > view {
  526. &:first-child {
  527. text {
  528. color: $uni-color-warning;
  529. vertical-align: middle;
  530. }
  531. }
  532. &:last-child {
  533. text {
  534. color: $uni-color-primary;
  535. vertical-align: middle;
  536. }
  537. }
  538. }
  539. .costBtn {
  540. width: 70rpx;
  541. height: 40rpx;
  542. line-height: 40rpx;
  543. text-align: center;
  544. color: #fff;
  545. font-size: 20rpx;
  546. border-radius: 30rpx;
  547. background: #999;
  548. margin-left: 20rpx;
  549. }
  550. }
  551. }
  552. // 历史对账单弹窗
  553. .tabBox {
  554. height: 100vh;
  555. .tabs {
  556. flex-grow: 1;
  557. overflow: auto;
  558. padding: 20rpx;
  559. > view {
  560. flex-wrap: wrap;
  561. justify-content: space-between;
  562. > view {
  563. width: 45%;
  564. border: 1rpx solid #eee;
  565. padding: 15rpx;
  566. border-radius: 50rpx;
  567. text-align: center;
  568. margin-bottom: 15rpx;
  569. }
  570. .active {
  571. border: 0;
  572. background-color: #0485f6;
  573. color: #fff;
  574. }
  575. }
  576. }
  577. .form-item-inp {
  578. border-bottom: 1rpx solid #eee;
  579. }
  580. .form-footer-btn {
  581. margin: 30upx;
  582. display: flex;
  583. justify-content: space-between;
  584. }
  585. .form-footer-btn {
  586. display: flex;
  587. .handle-btn {
  588. font-size: 28upx;
  589. margin: 0 10upx;
  590. flex: 1;
  591. }
  592. }
  593. }
  594. //打折弹窗
  595. .costPopup {
  596. padding: 26rpx 20rpx 40rpx;
  597. box-sizing: border-box;
  598. .costPopupTit {
  599. text-align: center;
  600. font-weight: bold;
  601. }
  602. .costPopupCon {
  603. margin-top: 40rpx;
  604. .costList {
  605. margin-bottom: 20rpx;
  606. .label {
  607. color: $uni-text-color-grey;
  608. }
  609. }
  610. .tip {
  611. color: $uni-color-error;
  612. font-size: 20rpx;
  613. text-align: right;
  614. }
  615. .costText {
  616. text-align: center;
  617. color: $uni-text-color-grey;
  618. font-size: 22rpx;
  619. margin-top: 40rpx;
  620. &:last-child {
  621. font-weight: bold;
  622. color: $uni-color-error;
  623. font-size: 32rpx;
  624. line-height: 60rpx;
  625. margin-top: 0rpx;
  626. margin-bottom: 50rpx;
  627. }
  628. }
  629. }
  630. }
  631. .slot-content {
  632. font-size: 28rpx;
  633. color: $u-content-color;
  634. padding: 60rpx 30rpx;
  635. text-align: center;
  636. }
  637. }
  638. </style>