edit.vue 20 KB

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