salesDetail.vue 17 KB

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