bill.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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 class="fontColor">¥{{ chooseTotalPayPrice }}</text>
  45. </view>
  46. <view v-if="chooseList.length > 0 && backDiscountVal&&backDiscountVal!=0">
  47. 折后:
  48. <text class="fontColor">¥{{ backDiscountPrice }}</text>
  49. </view>
  50. <view class="u-flex" v-if="chooseList.length > 0">
  51. <view>
  52. 折让:
  53. <text>¥{{ backDiscountVal || 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 type="number" :custom-style="{color:'#ffa500'}" v-model="discountVal" :border="true" :height="50" />
  95. </view>
  96. <view class="tip" v-if="discountVal*1 > chooseTotalPayPrice*1">折让金额不能大于待收金额,请重新输入</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" :show-cancel-button="true" :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,formatDecimal} from '@/libs/tools.js'
  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. backDiscountPrice:null,
  193. backDiscountVal:null
  194. };
  195. },
  196. onReady() {
  197. uni.setNavigationBarColor({
  198. frontColor: '#ffffff',
  199. backgroundColor: this.$config('primaryColor')
  200. });
  201. },
  202. onLoad(options) {
  203. //获取对账周期默认值
  204. if (uni.getStorageSync('curTab')) {
  205. this.curTab = uni.getStorageSync('curTab');
  206. } else {
  207. let systemList = this.$store.state.vuex_systemSetList;
  208. if(systemList){
  209. let cycleObj = systemList.find(item => {
  210. return item.remarks == 'sales_bill_period';
  211. });
  212. this.curTab = this.placeTab.findIndex(con => con.name == cycleObj.valueShow);
  213. }
  214. }
  215. this.cycleName = this.changeShowTime();
  216. // 获取选择客户
  217. if (options && options.data) {
  218. this.customerObj = JSON.parse(options.data);
  219. this.params.targetSn = this.customerObj.customerSn;
  220. }
  221. uni.$on('customerInfo', res => {
  222. this.customerObj = res;
  223. this.params.targetSn = res.customerSn;
  224. this.changeTime();
  225. });
  226. },
  227. onReady() {
  228. setTimeout(()=>{
  229. this.changeTime();
  230. },500)
  231. },
  232. onBackPress() {
  233. if (this.showSearch) {
  234. this.showSearch = false;
  235. } else {
  236. uni.removeStorageSync('curTab');
  237. uni.removeStorageSync('chooseList');
  238. }
  239. },
  240. onUnload() {
  241. uni.removeStorageSync('curTab');
  242. uni.removeStorageSync('chooseList');
  243. },
  244. computed: {
  245. //经销商信息
  246. userData() {
  247. return this.$store.state.vuex_userData;
  248. },
  249. totalPayPrice() {
  250. let totalPrice = 0;
  251. for (let i = 0; i < this.bill.length; i++) {
  252. this.bill[i].unsettleAmount = this.bill[i].unsettleAmount ? this.bill[i].unsettleAmount : 0;
  253. totalPrice += this.bill[i].unsettleAmount;
  254. }
  255. return formatDecimal(totalPrice,2);
  256. },
  257. chooseTotalPayPrice() {
  258. let price = 0;
  259. this.chooseList.forEach(item => {
  260. item.unsettleAmount = item.unsettleAmount ? item.unsettleAmount : 0;
  261. price += item.unsettleAmount;
  262. });
  263. return formatDecimal(price,2);
  264. },
  265. settlement() {
  266. let totalPrice=this.chooseTotalPayPrice?this.chooseTotalPayPrice:0;
  267. let discountPrice=this.discountVal?this.discountVal:0
  268. let priceNum=totalPrice - discountPrice;
  269. return formatDecimal(priceNum,2)
  270. }
  271. },
  272. methods: {
  273. chooseCycleData() {
  274. uni.setStorageSync('chooseList', this.chooseList);
  275. this.showSearch = true;
  276. },
  277. handleClean() {
  278. this.showSearch = false;
  279. let systemList = this.$store.state.vuex_systemSetList;
  280. let cycleObj = systemList.find(item => {
  281. return item.remarks == 'sales_bill_period';
  282. });
  283. this.curTab = this.placeTab.findIndex(con => con.name == cycleObj.valueShow);
  284. this.cycleName = this.changeShowTime();
  285. this.changeTime();
  286. },
  287. //选择客户
  288. goChooseCustomer() {
  289. uni.setStorageSync('curTab', this.curTab);
  290. this.jumpPage('/pages/sales/chooseCustomerBill');
  291. },
  292. changeTime() {
  293. if (this.curTab != 6 && this.curTab != 7) {
  294. this.params.bizBeginDate = this.getQueryDate().beginDate;
  295. this.params.bizEndDate = this.getQueryDate().endDate;
  296. this.cycleName = this.changeShowTime();
  297. this.dateArray = '';
  298. } else if (this.curTab == 7) {
  299. this.cycleName = this.placeTab[this.curTab].name;
  300. this.params.bizBeginDate = undefined;
  301. this.params.bizEndDate = undefined;
  302. }
  303. this.getList();
  304. },
  305. getList() {
  306. const _this = this;
  307. queryUnsettleSaleList(this.params).then(res => {
  308. if (res.status == 200) {
  309. let chooseArr = uni.getStorageSync('chooseList');
  310. if (chooseArr && chooseArr.length > 0) {
  311. res.data.forEach(item => {
  312. const row = chooseArr.findIndex(k => k.bizSn == item.bizSn);
  313. item.checked = row > -1;
  314. });
  315. }
  316. this.bill = res.data;
  317. this.$refs.bill.setData(res.data);
  318. this.getChooseList()
  319. }
  320. });
  321. },
  322. getChooseList(){
  323. this.chooseList=this.bill.filter(item=>item.checked);
  324. },
  325. // 时间 change
  326. dateChange(date) {
  327. this.dateArray = date.startDate + ' ~ ' + date.endDate;
  328. this.params.bizBeginDate = date.startDate + ' 00:00:00';
  329. this.params.bizEndDate = date.endDate + ' 23:59:59';
  330. this.cycleName = date.startDate + '至' + date.endDate;
  331. },
  332. // 更改日期格式显示
  333. changeShowTime() {
  334. const fun = [
  335. getDate.getTodayInfo,
  336. getDate.getYesterdayInfo,
  337. getDate.getCurrWeekDaysInfo,
  338. getDate.getLastWeekDaysInfo,
  339. getDate.getCurrLastMonthDaysInfo,
  340. getDate.getLastMonthDaysInfo
  341. ];
  342. return fun[this.curTab]();
  343. },
  344. tabChange(data) {
  345. this.curTab = data.val;
  346. },
  347. getQueryDate() {
  348. const fun = [getDate.getToday, getDate.getYesterday, getDate.getCurrWeekDays, getDate.getLastWeekDays, getDate.getCurrLastMonthDays, getDate.getLastMonthDays];
  349. return {
  350. beginDate: fun[this.curTab]().starttime,
  351. endDate: fun[this.curTab]().endtime
  352. };
  353. },
  354. handleSearch() {
  355. this.showSearch = false;
  356. this.changeTime();
  357. },
  358. jumpPage(url) {
  359. uni.navigateTo({
  360. url
  361. });
  362. },
  363. handleDisCount() {
  364. if (this.discountVal*1 > this.chooseTotalPayPrice*1) {
  365. uni.showToast({
  366. title: '折让金额不能大于待收金额,请重新输入',
  367. icon: 'none'
  368. });
  369. return;
  370. }
  371. let reg = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
  372. if (!reg.test(this.discountVal)) {
  373. uni.showToast({
  374. title: '折让金额格式不正确,请重新输入',
  375. icon: 'none'
  376. });
  377. return;
  378. }
  379. this.costShow = false;
  380. this.backDiscountPrice = this.settlement
  381. this.backDiscountVal = this.discountVal
  382. },
  383. submitOrder() {
  384. //发送对账单
  385. if (this.chooseList.length == 0) {
  386. uni.showToast({
  387. title: '请选择要发送的对账单',
  388. icon: 'none'
  389. });
  390. return;
  391. }
  392. this.shareShow = true;
  393. this.submitLoading = true;
  394. },
  395. allCheckeChange(e) {
  396. this.$refs.bill.allSelect(e.value);
  397. const list = this.$refs.bill.getAllData();
  398. list.map(item => {
  399. this.allCheckedCallback(true,item)
  400. })
  401. },
  402. // 选中事件
  403. allCheckedCallback(isAllChecked, row) {
  404. const has = this.chooseList.findIndex(k => k.bizSn == row.bizSn);
  405. // 在已选列表中
  406. if (has >= 0) {
  407. // 取消选中
  408. if (!row.checked) {
  409. this.chooseList.splice(has, 1);
  410. }
  411. } else {
  412. if (row.checked) {
  413. this.chooseList.push(row);
  414. }
  415. }
  416. this.discountVal = ''
  417. this.backDiscountPrice = this.settlement
  418. this.backDiscountVal = this.discountVal
  419. // 是否全选
  420. this.allChecked = isAllChecked;
  421. },
  422. // 分享图文
  423. handleShare() {
  424. this.submitLoading = false;
  425. let url = 'http://p.iscm.360arrow.com/dzd/index.html?userSn=' + this.userData.orgSn + '&verifySn='+this.verifySn + '&name='+this.userData.orgName;
  426. if (uni.getSystemInfoSync().platform == 'ios') {
  427. uni.share({
  428. provider: 'weixin',
  429. scene: 'WXSceneSession',
  430. type: 0,
  431. href: url,
  432. title: this.customerObj.customerName,
  433. summary: '共' + this.settlement + '元,请您查阅',
  434. imageUrl: '../../static/logo.png',
  435. success: (res)=> {
  436. this.setBillOrder();
  437. console.log('success:' + JSON.stringify(res));
  438. },
  439. fail: (err)=> {
  440. console.log('fail:' + JSON.stringify(err));
  441. }
  442. });
  443. } else {
  444. uni.shareWithSystem({
  445. summary: this.customerObj.customerName + '您好,您有一个对账单共' + this.settlement + '元,请您查阅',
  446. href: url,
  447. success:()=> {
  448. this.setBillOrder();
  449. console.log('调取微信列表成功,分享不一定成功')
  450. },
  451. fail:()=> {
  452. console.log('分享失败')
  453. }
  454. });
  455. }
  456. },
  457. // 生成历史对账单
  458. setBillOrder(){
  459. let obj = {
  460. detailNum: this.chooseList.length,
  461. totalAmount: this.chooseTotalPayPrice,
  462. discountAmount: this.discountVal || 0,
  463. settleAmount: this.settlement,
  464. detailList: this.chooseList
  465. };
  466. let ajaxData = Object.assign(this.params, obj);
  467. insert(ajaxData).then(res => {
  468. this.shareShow = false;
  469. if (res.status == 200) {
  470. this.verifySn = res.data.verifySn
  471. } else {
  472. uni.showToast({
  473. title: res.message,
  474. icon: 'none'
  475. });
  476. }
  477. });
  478. }
  479. }
  480. };
  481. </script>
  482. <style lang="scss" scoped>
  483. .content {
  484. width: 100%;
  485. height: 100vh;
  486. .header {
  487. width: 100%;
  488. .headerList {
  489. width: 100%;
  490. box-sizing: border-box;
  491. padding: 16rpx 20rpx;
  492. background: #fff;
  493. &:nth-child(2) {
  494. border-top: 1rpx solid #e4e7ed;
  495. }
  496. .list_l {
  497. width: 208rpx;
  498. text {
  499. font-size: 28rpx;
  500. color: #666666;
  501. margin-left: 10rpx;
  502. margin-right: 10rpx;
  503. }
  504. }
  505. .list_r {
  506. width: calc(100% - 208rpx);
  507. }
  508. }
  509. .statistical {
  510. padding: 20rpx;
  511. background: #fff;
  512. margin: 10rpx 0;
  513. .statisticalList {
  514. &:first-child {
  515. width: 210rpx;
  516. }
  517. }
  518. text {
  519. &:last-child {
  520. color: $uni-color-warning;
  521. font-weight: 600;
  522. }
  523. }
  524. }
  525. }
  526. .chooseCon {
  527. flex-grow: 1;
  528. flex-basis: 0;
  529. overflow: auto;
  530. background-color: #fff;
  531. }
  532. .footerCon {
  533. background-color: #f8f8f8;
  534. padding: 10rpx 20rpx;
  535. box-sizing: border-box;
  536. .f-mid {
  537. flex: 1;
  538. color: #666;
  539. font-size: 0.8rem;
  540. font-weight: 600;
  541. .fontColor {
  542. color: $uni-color-warning;
  543. vertical-align: middle;
  544. }
  545. .costBtn {
  546. width: 70rpx;
  547. height: 40rpx;
  548. line-height: 40rpx;
  549. text-align: center;
  550. color: #fff;
  551. font-size: 20rpx;
  552. border-radius: 30rpx;
  553. background: #999;
  554. margin-left: 20rpx;
  555. }
  556. }
  557. }
  558. // 历史对账单弹窗
  559. .tabBox {
  560. height: 100vh;
  561. .tabs {
  562. flex-grow: 1;
  563. overflow: auto;
  564. padding: 20rpx;
  565. > view {
  566. flex-wrap: wrap;
  567. justify-content: space-between;
  568. > view {
  569. width: 45%;
  570. border: 1rpx solid #eee;
  571. padding: 15rpx;
  572. border-radius: 50rpx;
  573. text-align: center;
  574. margin-bottom: 15rpx;
  575. }
  576. .active {
  577. border: 0;
  578. background-color: #0485f6;
  579. color: #fff;
  580. }
  581. }
  582. }
  583. .form-item-inp {
  584. border-bottom: 1rpx solid #eee;
  585. }
  586. .form-footer-btn {
  587. margin: 30upx;
  588. display: flex;
  589. justify-content: space-between;
  590. }
  591. .form-footer-btn {
  592. display: flex;
  593. .handle-btn {
  594. font-size: 28upx;
  595. margin: 0 10upx;
  596. flex: 1;
  597. }
  598. }
  599. }
  600. //打折弹窗
  601. .costPopup {
  602. padding: 26rpx 20rpx 40rpx;
  603. box-sizing: border-box;
  604. .costPopupTit {
  605. text-align: center;
  606. font-weight: bold;
  607. }
  608. .costPopupCon {
  609. margin-top: 40rpx;
  610. .costList {
  611. margin-bottom: 20rpx;
  612. .label {
  613. color: $uni-text-color-grey;
  614. }
  615. }
  616. .tip {
  617. color: $uni-color-error;
  618. font-size: 20rpx;
  619. margin-left: 140rpx;
  620. }
  621. .costText {
  622. text-align: center;
  623. color: $uni-text-color-grey;
  624. font-size: 22rpx;
  625. margin-top: 40rpx;
  626. &:last-child {
  627. font-weight: bold;
  628. color: $uni-color-error;
  629. font-size: 32rpx;
  630. line-height: 60rpx;
  631. margin-top: 0rpx;
  632. margin-bottom: 50rpx;
  633. }
  634. }
  635. }
  636. }
  637. .slot-content {
  638. font-size: 28rpx;
  639. color: $u-content-color;
  640. padding: 60rpx 30rpx;
  641. text-align: center;
  642. }
  643. }
  644. </style>