edit.vue 18 KB

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