edit.vue 18 KB

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