salesDetail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <view class="sales-edit-wrap flex flex_column">
  3. <!-- 基础信息 -->
  4. <view class="sales-info-con">
  5. <u-section @click="infoModal=true" title="基础信息" sub-title="查看更多" :line-color="$config('primaryColor')"></u-section>
  6. <view class="info-item-box">
  7. <text class="info-item-tit color_6">销售单号</text>
  8. <text>{{detailData && detailData.salesBillNo || '--'}}</text>
  9. </view>
  10. <view class="info-item-box">
  11. <text class="info-item-tit color_6">客户名称</text>
  12. <text>{{detailData && detailData.buyerName || '--'}}</text>
  13. </view>
  14. </view>
  15. <!-- 产品列表 -->
  16. <view class="sales-product-con">
  17. <!-- 标题 -->
  18. <view class="sales-product-header">
  19. <u-tabs :show-bar="false" :active-item-style="activeItemStyle" :list="tabsList" :is-scroll="false" :current="current" @change="changeTabs"></u-tabs>
  20. </view>
  21. <view class="flex flex_column" v-show="current == 0">
  22. <!-- 合计 -->
  23. <view ref="salesTotal" class="sales-total-box border-b font_13 flex justify_between">
  24. <view class="sales-total-con flex_1" :style="{height: toggle ? 'auto' : '44upx'}">
  25. <view>
  26. 总款数:<text class="sales-total-num" :style="{ color: $config('warringColor') }">
  27. {{ detailData && (detailData.totalCategory || detailData.totalCategory == 0) ? toThousands(detailData.totalCategory) : '--' }}</text>;总数量:<text class="sales-total-num" :style="{ color: $config('warringColor') }">
  28. {{ detailData && (detailData.totalQty || detailData.totalQty == 0) ? toThousands(detailData.totalQty) : '--' }}
  29. </text>;
  30. </view>
  31. <view>
  32. 总售价:<text class="sales-total-num" :style="{ color: $config('warringColor') }">
  33. ¥{{ detailData && (detailData.totalAmount || detailData.totalAmount == 0) ? toThousands(detailData.totalAmount, 2) : '--' }}
  34. </text>;折后总售价:<text class="sales-total-num" :style="{ color: $config('warringColor') }">
  35. ¥{{ detailData && (detailData.discountedAmount || detailData.discountedAmount == 0) ? toThousands(detailData.discountedAmount, 2) : '--' }}
  36. </text>;
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 产品列表 -->
  41. <view class="sales-list-box">
  42. <scroll-view class="sales-list-con" :style="{height:scrollH+'upx'}" scroll-y @scrolltolower="onreachBottom">
  43. <view class="sales-list-item border-b flex align_center justify_between" v-for="(item, index) in listData" :key="item.id">
  44. <view class="font_13 flex_1 flex justify_between">
  45. <view class="pimgs">
  46. <u-image :src="item.productMainImage?item.productMainImage:`../../static/${$config('themePath')}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
  47. <view v-if="item.oosFlag == 1" class="sign" :style="{backgroundColor: $config('errorColor')}">急</view>
  48. <view v-if="item.price < item.cost" class="sign" :style="{backgroundColor: $config('errorColor')}">亏</view>
  49. <view v-if="item.price == 0" class="sign" :style="{backgroundColor: $config('errorColor')}">赠</view>
  50. </view>
  51. <view class="sales-item-main flex_1">
  52. <view class="sales-item-name">{{item.productName || '--'}}</view>
  53. <view class="sales-item-txt">{{item.productCode || '--'}}</view>
  54. <view class="sales-item-txt color_6" style="font-size: 24upx;" v-if="item.warehouseEntity&&item.warehouseEntity.name || item.warehouseLocationEntity&&item.warehouseLocationEntity.name">{{item.warehouseEntity&&item.warehouseEntity.name}} > {{item.warehouseLocationEntity&&item.warehouseLocationEntity.name}}</view>
  55. <view class="sales-item-txt flex align_center justify_between">
  56. <view class="sales-item-priceInfo">
  57. <view :style="{color: $config('errorColor'), display: 'inline-block'}">¥<text style="font-size: 30upx;">{{toThousands(item.price||0, 2)}}</text></view>
  58. <text style="display: inline-block;margin: 0 10upx;">X</text>
  59. <text style="font-size: 30upx;">{{toThousands(item.qty||0)}}</text>
  60. {{item.productUnit}}
  61. </view>
  62. <view class="sales-item-price">¥{{toThousands(item.totalAmount||0, 2)}}</view>
  63. </view>
  64. <view class="sales-item-price" v-if="detailData&&detailData.discountAmount">折后:¥{{toThousands(item.discountedAmount||0, 2)}}</view>
  65. </view>
  66. </view>
  67. </view>
  68. <view v-if="listData && listData.length == 0">
  69. <u-empty :src="`/static/${$config('themePath')}/def_no_data@3x.png`" icon-size="150" :text="noDataText" mode="list" :margin-top="50"></u-empty>
  70. </view>
  71. <view style="padding: 20upx;">
  72. <u-loadmore v-if="totalNum>listData.length || status=='loading'" :status="status" />
  73. </view>
  74. </scroll-view>
  75. </view>
  76. </view>
  77. <view class="flex flex_column" v-show="current == 1">
  78. <!-- 合计 -->
  79. <view ref="salesTotal" class="sales-total-box border-b font_13 flex justify_between">
  80. <view class="sales-total-con flex_1" :style="{height: toggle ? 'auto' : '44upx'}">
  81. 应收:<text class="sales-total-num" :style="{color: $config('warringColor')}">{{detailData && (detailData.totalCategory || detailData.totalCategory==0) ? toThousands(detailData.totalCategory) : '--'}}</text>;已收:<text class="sales-total-num" :style="{color: $config('warringColor')}">{{detailData && (detailData.totalQty || detailData.totalQty==0) ? toThousands(detailData.totalQty) : '--'}}</text>;待收:<text class="sales-total-num" :style="{color: $config('warringColor')}">¥{{detailData && (detailData.discountAmount || detailData.discountAmount==0) ? toThousands(detailData.discountAmount, 2) : '--'}}</text>;
  82. </view>
  83. </view>
  84. <!-- 产品列表 -->
  85. <view class="sales-list-box">
  86. <scroll-view class="sales-list-con" :style="{height:scrollH+'upx'}" scroll-y @scrolltolower="onreachBottom">
  87. <view class="sales-list-item flex align_center justify_between">
  88. <view class="sales-list-l">
  89. <view>2022-11-30 9:12:25</view>
  90. <view>微信支付(线上)</view>
  91. </view>
  92. <view class="sales-list-r income" >
  93. +¥32.00
  94. </view>
  95. </view>
  96. <view v-if="false">
  97. <u-empty :src="`/static/${$config('themePath')}/def_no_data@3x.png`" icon-size="150" :text="noDataText" mode="list" :margin-top="50"></u-empty>
  98. </view>
  99. <view style="padding: 20upx;">
  100. <u-loadmore v-if="totalNum>listData.length || status=='loading'" :status="status" />
  101. </view>
  102. </scroll-view>
  103. </view>
  104. </view>
  105. </view>
  106. <!-- 基础信息 -->
  107. <orderInfoModal :infoFlag="true" :openModal="infoModal" :infoData="detailData" @close="infoModal=false" />
  108. </view>
  109. </template>
  110. <script>
  111. import commonModal from '@/pages/common/commonModal.vue'
  112. import OrderInfoModal from './orderInfoModal.vue'
  113. import DiscountModal from './discountModal.vue'
  114. import ProductModal from './productModal.vue'
  115. import { toThousands } from '@/libs/tools'
  116. import { stockByProductSn } from '@/api/stock'
  117. import { salesDetailList, salesDetailDel, salesDel, salesDetailBySn, salesSubmit, salesDiscount, salesDetailUpdate } from '@/api/sales'
  118. export default{
  119. components: { OrderInfoModal, DiscountModal, commonModal, ProductModal },
  120. data(){
  121. return{
  122. tabsList:[{
  123. name:'产品列表'
  124. },{
  125. name:'收款记录'
  126. }],
  127. current:0,
  128. activeItemStyle:{
  129. color:this.$config('primaryColor'),
  130. borderBottom:'4rpx solid '+this.$config('primaryColor')
  131. },
  132. pageData: {
  133. type: 'edit',
  134. data: null
  135. },
  136. toggle: true,
  137. toThousands,
  138. customBtnStyle: { // 自定义按钮样式
  139. borderColor: this.$config('primaryColor'),
  140. backgroundColor: this.$config('primaryColor'),
  141. color: '#fff'
  142. },
  143. listData: [],
  144. pageNo: 1,
  145. pageSize: 6,
  146. totalNum: 0,
  147. status: 'loadmore',
  148. noDataText: '暂无数据',
  149. scrollH: 916,
  150. infoModal: false,
  151. discountModal: false,
  152. commonModal: false,
  153. modalText: '确认要删除吗?',
  154. detailData: null, // 销售单详情
  155. openProductModal: false, // 编辑产品信息弹框是否显示
  156. productData: null, // 当前操作的产品信息
  157. productInfo: null, // 编辑产品需要的参数
  158. editInfo: null, // 添加/编辑 提交的值
  159. commonType: 1, // 公共弹框类型 1删除产品,2删除销售单,3编辑产品时库存不足
  160. }
  161. },
  162. onLoad(options) {
  163. if(options && options.salesBillId){
  164. this.salesBillSn = options.salesBillId;
  165. this.init();
  166. }
  167. },
  168. onUnload() {
  169. uni.$off('refreshEditBL')
  170. },
  171. methods: {
  172. changeTabs(index){
  173. this.current= index
  174. },
  175. init(){
  176. this.getList(1)
  177. this.getDetail()
  178. },
  179. // 列表
  180. getList(pageNo){
  181. const _this = this
  182. if (pageNo) {
  183. this.pageNo = pageNo
  184. }
  185. let params = {
  186. pageNo: this.pageNo,
  187. pageSize: this.pageSize,
  188. salesBillSn: this.salesBillSn
  189. }
  190. this.status = "loading"
  191. salesDetailList(params).then(res => {
  192. if (res.status == 200) {
  193. if(res.data && res.data.list){
  194. res.data.list.map(item => {
  195. item.productName = item.productEntity && item.productEntity.name || item.dealerProductEntity && item.dealerProductEntity.name
  196. item.productCode = item.productEntity && item.productEntity.code || item.dealerProductEntity && item.dealerProductEntity.code
  197. item.productUnit = item.productEntity && item.productEntity.unit || item.dealerProductEntity && item.dealerProductEntity.unit
  198. })
  199. if(this.pageNo>1){
  200. this.listData = this.listData.concat(res.data && res.data.list || [])
  201. }else{
  202. this.listData = res.data.list || []
  203. }
  204. }else{
  205. this.listData = []
  206. }
  207. this.totalNum = res.data && res.data.count || 0
  208. } else {
  209. this.listData = []
  210. this.totalNum = 0
  211. this.noDataText = res.message
  212. }
  213. this.status = "loadmore"
  214. })
  215. },
  216. // scroll-view到底部加载更多
  217. onreachBottom() {
  218. if(this.listData.length < this.totalNum){
  219. this.pageNo += 1
  220. this.getList()
  221. }
  222. },
  223. // 折扣金额
  224. discountConfirm(amount){
  225. let params = {
  226. discountAmount: amount,
  227. salesBillSn: this.detailData.salesBillSn,
  228. id: this.detailData.id
  229. }
  230. salesDiscount(params).then(res => {
  231. if(res.status == 200){
  232. this.init()
  233. this.discountModal = false
  234. }
  235. })
  236. },
  237. // 提交
  238. handleSubmit(){
  239. salesSubmit({ id: this.detailData.id }).then(res => {
  240. if(res.status == 200){
  241. this.toashMsg(res.message)
  242. uni.$emit('refreshSalesBL')
  243. uni.navigateBack()
  244. }
  245. })
  246. },
  247. // 编辑
  248. handleEdit(data){
  249. this.productInfo = {
  250. productName: data.productName,
  251. productMainImage: data.productMainImage,
  252. productCode: data.productCode,
  253. productOrigCode: data.productOrigCode,
  254. warehouseName: data.warehouseEntity && data.warehouseEntity.name,
  255. warehouseLocationName: data.warehouseLocationEntity && data.warehouseLocationEntity.name,
  256. price: data.price,
  257. qty: data.qty
  258. }
  259. this.openProductModal = true
  260. this.productData = data
  261. },
  262. // 确认产品信息
  263. productConfirm(data){
  264. this.editInfo = data
  265. this.validateStock() //验证 库存是否不足
  266. },
  267. // 库存不足
  268. validateStock(){
  269. // 校验库存
  270. stockByProductSn({ productSn: this.productData.productSn }).then(res => {
  271. if (res.status == 200) {
  272. if (res.data && (!res.data.currentStockQty || this.editInfo.qty <= res.data.currentStockQty)) {
  273. this.editProduct()
  274. } else { // 库存不足
  275. this.commonType = 3
  276. this.modalText = '库存不足,将产生急件,确认修改吗?'
  277. this.commonModal = true
  278. }
  279. }
  280. })
  281. },
  282. // 编辑产品
  283. editProduct(){
  284. let params = {
  285. id: this.productData.id,
  286. qty: this.editInfo.qty,
  287. price: this.editInfo.price,
  288. productSn: this.productData.productSn,
  289. salesBillSn: this.detailData.salesBillSn,
  290. }
  291. salesDetailUpdate(params).then(res => {
  292. if(res.status == 200){
  293. this.toashMsg(res.message)
  294. this.init()
  295. this.commonModal = false
  296. this.openProductModal = false
  297. }
  298. })
  299. },
  300. // 删除
  301. handleDel(item){
  302. if(item){ // 删除产品
  303. this.commonType = 1
  304. this.productData = item
  305. this.modalText = '确认要删除吗?'
  306. this.commonModal = true
  307. }else{ // 整单删除
  308. this.commonType = 2
  309. this.productData = null
  310. this.modalText = '确认删除该销售单吗?'
  311. this.commonModal = true
  312. }
  313. },
  314. // 公共弹框 确定
  315. handleCommon(){
  316. if(this.commonType == 1){ // 删除产品
  317. this.delFun()
  318. }else if(this.commonType == 2){ // 整单删除
  319. this.delFun()
  320. }else if(this.commonType == 3){ // 编辑产品时库存不足
  321. this.editProduct()
  322. }
  323. },
  324. // 公共弹框 取消
  325. handleCancel(){
  326. this.openProductModal = false
  327. },
  328. // 删除
  329. delFun(){
  330. let url = salesDetailDel
  331. let params = {}
  332. console.log(this.commonType)
  333. if(this.commonType == 1){ // 删除产品
  334. url = salesDetailDel
  335. params = { id: this.productData.id }
  336. }else if(this.commonType == 2){ // 整单删除
  337. console.log('整单删除', this.detailData)
  338. url = salesDel
  339. params = { id: this.detailData && this.detailData.id }
  340. }
  341. url(params).then(res => {
  342. if (res.status == 200) {
  343. if(this.productData){ // 删除产品
  344. this.toashMsg(res.message)
  345. this.init()
  346. }else{ // 整单删除
  347. this.toashMsg(res.message)
  348. uni.$emit('refreshSalesBL')
  349. uni.navigateBack()
  350. }
  351. this.commonModal = false
  352. } else {
  353. this.commonModal = false
  354. }
  355. })
  356. },
  357. // 选择产品
  358. handleProduct(){
  359. uni.navigateTo({ url: '/pages/sales/chooseProduct?data='+JSON.stringify(this.detailData) })
  360. },
  361. // 编辑
  362. goPage(){
  363. uni.redirectTo({ url: '/pages/sales/edit?pageType=edit&data='+JSON.stringify(this.detailData) })
  364. },
  365. // 销售单详情
  366. getDetail(){
  367. salesDetailBySn({ salesBillSn: this.salesBillSn }).then(res => {
  368. if(res.status == 200){
  369. this.detailData = res.data
  370. }else{
  371. this.detailData = null
  372. }
  373. this.toggle = false
  374. })
  375. },
  376. changeScrollH(){
  377. const _this = this
  378. uni.getSystemInfo({
  379. success: function (res) {
  380. const winH = res.windowHeight * 2
  381. let totalH = _this.$refs.salesTotal && _this.$refs.salesTotal.$el && _this.$refs.salesTotal.$el.offsetHeight || 0
  382. if(_this.toggle){
  383. _this.scrollH = winH - 656 - totalH
  384. }else{
  385. _this.scrollH = winH - 522 - totalH
  386. }
  387. // if(_this.detailData&&_this.detailData.billStatus=='FINISH'){
  388. _this.scrollH = _this.scrollH + 100
  389. // }
  390. }
  391. })
  392. }
  393. },
  394. watch: {
  395. toggle (newValue, oldValue) {
  396. this.changeScrollH()
  397. }
  398. }
  399. }
  400. </script>
  401. <style lang="scss">
  402. .sales-edit-wrap{
  403. width: 100%;
  404. .color_6{
  405. color: #666;
  406. }
  407. .font_13{
  408. font-size: 26upx;
  409. }
  410. .border-b{
  411. border-bottom: 1px solid #e4e7ed;
  412. }
  413. .sales-info-con{
  414. background-color: #fff;
  415. margin-bottom: 6upx;
  416. >view{
  417. padding: 14upx 20rpx;
  418. border-bottom: 1px solid #e4e7ed;
  419. }
  420. >view:last-child{
  421. border-bottom: none;
  422. }
  423. .info-item-box{
  424. .info-item-tit{
  425. display: inline-block;
  426. width: 20%;
  427. }
  428. }
  429. }
  430. .sales-product-con{
  431. background-color: #fff;
  432. .sales-product-header{
  433. /deep/.u-tab-item{
  434. border-bottom:1rpx solid #e4e7ed;
  435. }
  436. }
  437. .sales-total-box{
  438. align-items: flex-end;
  439. padding: 16upx 20rpx;
  440. .sales-total-con{
  441. color: #666;
  442. overflow: hidden;
  443. view{
  444. padding: 4upx 0;
  445. .sales-total-num{
  446. font-size: 24upx;
  447. color: rgb(48, 49, 51);
  448. }
  449. }
  450. }
  451. .sales-total-btn{
  452. display: inline-block;
  453. margin-bottom: 6upx;
  454. }
  455. }
  456. .sales-list-box{
  457. flex-grow: 1;
  458. .sales-list-con{
  459. .sales-list-item{
  460. padding: 20upx;
  461. .pimgs{
  462. margin-right: 20upx;
  463. position: relative;
  464. .sign{
  465. position: absolute;
  466. right: -2upx;
  467. top: -2upx;
  468. color: #fff;
  469. border-radius: 50%;
  470. width: 40upx;
  471. height: 40upx;
  472. text-align: center;
  473. }
  474. }
  475. .sales-item-main{
  476. .sales-item-name{
  477. font-size: 28upx;
  478. color: rgb(48, 49, 51);
  479. font-weight: bold;
  480. overflow: hidden;
  481. text-overflow: ellipsis;
  482. display: -webkit-box;
  483. -webkit-box-orient: vertical;
  484. -webkit-line-clamp: 1;
  485. }
  486. .sales-item-txt{
  487. margin: 8upx 0;
  488. }
  489. .sales-item-price{
  490. text-align: right;
  491. }
  492. }
  493. .btn-box{
  494. padding: 30upx 30upx;
  495. }
  496. .sales-list-l{
  497. font-size: 20rpx;
  498. view{
  499. &:last-child{
  500. font-size: 26rpx;
  501. margin-top:10rpx;
  502. }
  503. }
  504. }
  505. .sales-list-r.spending{
  506. color:$uni-color-error;
  507. }
  508. .sales-list-r.income{
  509. color:$uni-color-success;
  510. }
  511. }
  512. .sales-list-item:last-child{
  513. border: none;
  514. }
  515. }
  516. }
  517. }
  518. .sales-btn-box{
  519. background-color: #fff;
  520. padding: 12upx 50upx;
  521. .handle-btn{
  522. width: 47%;
  523. }
  524. .edit-btn{
  525. width: 100%;
  526. }
  527. }
  528. }
  529. </style>