salesDetail.vue 17 KB

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