123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 |
- <template>
- <view class="sales-edit-wrap flex flex_column">
- <!-- 基础信息 -->
- <view class="sales-info-con">
- <u-section @click="infoModal=true" title="基础信息" sub-title="查看更多" :line-color="$config('primaryColor')"></u-section>
- <view class="info-item-box">
- <text class="info-item-tit color_6">销售单号</text>
- <text>{{detailData && detailData.salesBillNo || '--'}}</text>
- </view>
- <view class="info-item-box">
- <text class="info-item-tit color_6">客户名称</text>
- <text>{{detailData&&detailData.buyerNameCurrent?detailData.buyerName?detailData.buyerName==detailData.buyerNameCurrent?detailData.buyerNameCurrent:detailData.buyerNameCurrent+'('+detailData.buyerName+')':detailData.buyerNameCurrent:'--' }}</text>
- </view>
- </view>
- <!-- 产品列表 -->
- <view class="sales-product-con flex flex_column">
- <view>
- <!-- 标题 -->
- <view class="sales-product-header border-b flex align_center justify_between">
- <u-section title="产品列表" :right="pageData.type=='edit'" :line-color="$config('primaryColor')">
- <template slot="right" v-if="pageData.type=='edit'">
- <view class="sales-product-operation">
- <u-button @click="discountModal=true" size="mini" :hair-line="false" shape="circle" plain type="primary" hover-class="none">
- 打折
- <text v-if="detailData&&detailData.discountAmount">:¥{{detailData.discountAmount}}</text>
- </u-button>
- <u-button @click="handleProduct" size="mini" :hair-line="false" shape="circle" :custom-style="customBtnStyle" type="primary" hover-class="none">选择产品</u-button>
- </view>
- </template>
- </u-section>
- </view>
- <!-- 合计 -->
- <view ref="salesTotal" class="sales-total-box border-b font_13 flex justify_between">
- <view class="sales-total-con flex_1" :style="{height: toggle ? 'auto' : '44upx'}">
- <view>
- 总款数:<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>;
- </view>
- <view>
- 折扣金额:<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>;
- </view>
- <view>
- 急件总款数:<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>;
- </view>
- <view v-if="$hasPermissions('M_showCostPrice_mobile')">
- 总成本:<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>;
- </view>
- </view>
- <text class="sales-total-btn" @click="toggle=!toggle" :style="{color: $config('primaryColor')}">{{ toggle ? '收起' : '展开' }}</text>
- </view>
- </view>
- <!-- 产品列表 -->
- <view class="sales-list-box">
- <scroll-view class="sales-list-con" :style="{height:scrollH+'upx'}" scroll-y @scrolltolower="onreachBottom">
- <view class="sales-list-item border-b flex align_center justify_between" v-for="(item, index) in listData" :key="item.id">
- <view class="font_13 flex_1 flex justify_between">
- <view class="pimgs">
- <u-image :src="item.productMainImage?item.productMainImage:`../../static/${$config('themePath')}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
- <view v-if="(isOwerEdit && item.oosFlag == 1) || (isOwerEdit && item.oosFlag == 1)" class="sign" :style="{backgroundColor: $config('errorColor')}">急</view>
- <view v-if="item.price < item.cost" class="sign" :style="{backgroundColor: $config('warringColor')}">亏</view>
- <view v-if="!isOwerEdit&&!isAudit&&(!item.currentStockQty || item.currentStockQty < item.qty)" class="sign" :style="{backgroundColor: $config('errorColor')}">缺</view>
- </view>
- <view class="sales-item-main flex_1">
- <view class="sales-item-name">{{item.productName || '--'}}</view>
- <view class="sales-item-txt">{{item.productCode || '--'}}</view>
- <view class="sales-item-txt color_6" style="font-size: 24upx;" v-if="item.warehouseName">{{item.warehouseName}} > {{item.warehouseLocationName}}</view>
- <view class="sales-item-txt flex align_center justify_between">
- <view class="sales-item-priceInfo">
- <view :style="{color: $config('errorColor'), display: 'inline-block'}">¥<text style="font-size: 30upx;">{{toThousands(item.price||0, 2)}}</text></view>
- <text style="display: inline-block;margin: 0 10upx;">X</text>
- <text style="font-size: 30upx;">{{toThousands(item.qty||0)}}</text>
- {{item.productUnit}}
- </view>
- <view class="sales-item-price">¥{{toThousands(item.totalAmount||0, 2)}}</view>
- </view>
- <view class="sales-item-price" v-if="detailData&&detailData.discountAmount">折后:¥{{toThousands(item.discountedAmount||0, 2)}}</view>
- </view>
- </view>
- <!-- <view class="btn-box" style="padding-right: 0;">
- <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>
- </view> -->
- </view>
- <view v-if="listData && listData.length == 0">
- <u-empty :src="`/static/${$config('themePath')}/def_no_data@3x.png`" icon-size="150" :text="noDataText" mode="list" :margin-top="50"></u-empty>
- </view>
- <view style="padding: 20upx;">
- <u-loadmore v-if="totalNum>listData.length || status=='loading'" :status="status" />
- </view>
- </scroll-view>
- </view>
- </view>
- <!-- 操作按钮 -->
- <!-- <view class="sales-btn-box" v-if="detailData&&detailData.billStatus!='FINISH'">
- <view v-if="pageData.type=='edit'" class="flex align_center justify_between">
- <u-button class="handle-btn" shape="circle" size="medium" hover-class="none" @click="handleDel()">整单删除</u-button>
- <u-button class="handle-btn search-btn" shape="circle" @click="handleSubmit" size="medium" hover-class="none" :custom-style="customBtnStyle">提交</u-button>
- </view>
- <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>
- </view> -->
- <!-- 基础信息 -->
- <orderInfoModal :openModal="infoModal" :infoData="detailData" @close="infoModal=false" />
- <!-- 折扣 -->
- <discountModal :openModal="discountModal" :infoData="detailData" :amount="detailData&&detailData.discountAmount" @confirm="discountConfirm" @close="discountModal=false" />
- <!-- 删除产品/整单删除弹框 -->
- <common-modal :openModal="commonModal" :content="modalText" @confirm="handleCommon" @cancel="handleCancel" @close="commonModal=false" />
- <!-- 添加/编辑产品 -->
- <productModal :openModal="openProductModal" :infoData="productInfo" @confirm="productConfirm" @close="openProductModal=false" />
- </view>
- </template>
- <script>
- import commonModal from '@/pages/common/commonModal.vue'
- import OrderInfoModal from './orderInfoModal.vue'
- import DiscountModal from './discountModal.vue'
- import ProductModal from './productModal.vue'
- import { toThousands } from '@/libs/tools'
- import { stockByProductSn } from '@/api/stock'
- import { salesDetailList, salesDetailDel, salesDel, salesDetailBySn, salesSubmit, salesDiscount, salesDetailUpdate } from '@/api/sales'
- export default{
- components: { OrderInfoModal, DiscountModal, commonModal, ProductModal },
- data(){
- return{
- pageData: {
- type: 'edit',
- data: null
- },
- toggle: true,
- toThousands,
- customBtnStyle: { // 自定义按钮样式
- borderColor: this.$config('primaryColor'),
- backgroundColor: this.$config('primaryColor'),
- color: '#fff'
- },
- listData: [],
- pageNo: 1,
- pageSize: 6,
- totalNum: 0,
- status: 'loadmore',
- noDataText: '暂无数据',
- theme: '',
- scrollH: 916,
- infoModal: false,
- discountModal: false,
- commonModal: false,
- modalText: '确认要删除吗?',
- detailData: null, // 销售单详情
- openProductModal: false, // 编辑产品信息弹框是否显示
- productData: null, // 当前操作的产品信息
- productInfo: null, // 编辑产品需要的参数
- editInfo: null, // 添加/编辑 提交的值
- commonType: 1, // 公共弹框类型 1删除产品,2删除销售单,3编辑产品时库存不足
- }
- },
- onLoad(opt) {
- this.theme = getApp({ allowDefault: true }).globalData.theme
- if(opt){
- this.pageData = {
- type: opt.pageType || 'edit',
- data: opt.data ? JSON.parse(opt.data) : null
- }
- }
- this.init()
- // 监听整改完成后刷新事件
- uni.$on('refreshEditBL', this.init)
- },
- onUnload() {
- uni.$off('refreshEditBL')
- },
- computed: {
- // 是否自建单据
- isOwerEdit () {
- return this.detailData && this.detailData.sourceType == 'SALES'
- },
- // 是否审核通过
- isAudit () {
- return this.detailData ? (this.detailData.billStatus == 'WAIT_OUT_WAREHOUSE' || this.detailData.billStatus == 'FINISH') : false
- },
- },
- methods: {
- init(){
- this.getList(1)
- this.getDetail()
- },
- // 列表
- getList(pageNo){
- const _this = this
- if (pageNo) {
- this.pageNo = pageNo
- }
- let params = {
- pageNo: this.pageNo,
- pageSize: this.pageSize,
- salesBillSn: this.pageData.data && this.pageData.data.salesBillSn
- }
- this.status = "loading"
- salesDetailList(params).then(res => {
- if (res.status == 200) {
- if(res.data && res.data.list){
- res.data.list.map(item => {
- const productCode = (item.productEntity && item.productEntity.code) || (item.dealerProductEntity && item.dealerProductEntity.code)
- const productName = (item.productEntity && item.productEntity.name) || (item.dealerProductEntity && item.dealerProductEntity.name)
- const productOrigCode = (item.productEntity && item.productEntity.origCode) || (item.dealerProductEntity && item.dealerProductEntity.origCode) || '--'
- const productOrigUnit = (item.productEntity && item.productEntity.unit) || (item.dealerProductEntity && item.dealerProductEntity.unit)
- item.productCode = productCode || '--'
- item.productName = productName || '--'
- item.productOrigCode = productOrigCode || '--'
- item.productUnit = productOrigUnit || '--'
- item.warehouseName = item.warehouseEntity && item.warehouseEntity.name || '--'
- item.warehouseLocationName = item.warehouseLocationEntity && item.warehouseLocationEntity.name || '--'
- })
- if(this.pageNo>1){
- this.listData = this.listData.concat(res.data && res.data.list || [])
- }else{
- this.listData = res.data.list || []
- }
- }else{
- this.listData = []
- }
- this.totalNum = res.data && res.data.count || 0
- } else {
- this.listData = []
- this.totalNum = 0
- this.noDataText = res.message
- }
- this.status = "loadmore"
- })
- },
- // scroll-view到底部加载更多
- onreachBottom() {
- if(this.listData.length < this.totalNum){
- this.pageNo += 1
- this.getList()
- }
- },
- // 折扣金额
- discountConfirm(amount){
- let params = {
- discountAmount: amount,
- salesBillSn: this.detailData.salesBillSn,
- id: this.detailData.id
- }
- salesDiscount(params).then(res => {
- if(res.status == 200){
- this.init()
- this.discountModal = false
- }
- })
- },
- // 提交
- handleSubmit(){
- salesSubmit({ id: this.detailData.id }).then(res => {
- if(res.status == 200){
- this.toashMsg(res.message)
- uni.$emit('refreshSalesBL')
- uni.navigateBack()
- }
- })
- },
- // 编辑
- handleEdit(data){
- this.productInfo = {
- productName: data.productName,
- productMainImage: data.productMainImage,
- productCode: data.productCode,
- productOrigCode: data.productOrigCode,
- warehouseName: data.warehouseName,
- warehouseLocationName: data.warehouseLocationName,
- price: data.price,
- qty: data.qty
- }
- this.openProductModal = true
- this.productData = data
- },
- // 确认产品信息
- productConfirm(data){
- this.editInfo = data
- this.validateStock() //验证 库存是否不足
- },
- // 库存不足
- validateStock(){
- // 校验库存
- stockByProductSn({ productSn: this.productData.productSn }).then(res => {
- if (res.status == 200) {
- if (res.data && (!res.data.currentStockQty || this.editInfo.qty <= res.data.currentStockQty)) {
- this.editProduct()
- } else { // 库存不足
- this.commonType = 3
- this.modalText = '库存不足,将产生急件,确认修改吗?'
- this.commonModal = true
- }
- }
- })
- },
- // 编辑产品
- editProduct(){
- let params = {
- id: this.productData.id,
- qty: this.editInfo.qty,
- price: this.editInfo.price,
- productSn: this.productData.productSn,
- salesBillSn: this.detailData.salesBillSn,
- }
- salesDetailUpdate(params).then(res => {
- if(res.status == 200){
- this.toashMsg(res.message)
- this.init()
- this.commonModal = false
- this.openProductModal = false
- }
- })
- },
- // 删除
- handleDel(item){
- if(item){ // 删除产品
- this.commonType = 1
- this.productData = item
- this.modalText = '确认要删除吗?'
- this.commonModal = true
- }else{ // 整单删除
- this.commonType = 2
- this.productData = null
- this.modalText = '确认删除该销售单吗?'
- this.commonModal = true
- }
- },
- // 公共弹框 确定
- handleCommon(){
- if(this.commonType == 1){ // 删除产品
- this.delFun()
- }else if(this.commonType == 2){ // 整单删除
- this.delFun()
- }else if(this.commonType == 3){ // 编辑产品时库存不足
- this.editProduct()
- }
- },
- // 公共弹框 取消
- handleCancel(){
- this.openProductModal = false
- },
- // 删除
- delFun(){
- let url = salesDetailDel
- let params = {}
- console.log(this.commonType)
- if(this.commonType == 1){ // 删除产品
- url = salesDetailDel
- params = { id: this.productData.id }
- }else if(this.commonType == 2){ // 整单删除
- console.log('整单删除', this.detailData)
- url = salesDel
- params = { id: this.detailData && this.detailData.id }
- }
- url(params).then(res => {
- if (res.status == 200) {
- if(this.productData){ // 删除产品
- this.toashMsg(res.message)
- this.init()
- }else{ // 整单删除
- this.toashMsg(res.message)
- uni.$emit('refreshSalesBL')
- uni.navigateBack()
- }
- this.commonModal = false
- } else {
- this.commonModal = false
- }
- })
- },
- // 选择产品
- handleProduct(){
- uni.navigateTo({ url: '/pages/sales/chooseProduct?data='+JSON.stringify(this.detailData) })
- },
- // 编辑
- goPage(){
- uni.redirectTo({ url: '/pages/sales/edit?pageType=edit&data='+JSON.stringify(this.detailData) })
- },
- // 销售单详情
- getDetail(){
- salesDetailBySn({ salesBillSn: this.pageData.data.salesBillSn }).then(res => {
- console.log(res.data)
- if(res.status == 200){
- this.detailData = res.data
- }else{
- this.detailData = null
- }
- this.toggle = false
- })
- },
- changeScrollH(){
- const _this = this
- uni.getSystemInfo({
- success: function (res) {
- const winH = res.windowHeight * 2
- let totalH = _this.$refs.salesTotal && _this.$refs.salesTotal.$el && _this.$refs.salesTotal.$el.offsetHeight || 0
- if(_this.toggle){
- _this.scrollH = winH - 605 - totalH
- }else{
- _this.scrollH = winH - 468 - totalH
- }
- // if(_this.detailData&&_this.detailData.billStatus=='FINISH'){
- _this.scrollH = _this.scrollH + 100
- // }
- }
- })
- }
- },
- watch: {
- toggle (newValue, oldValue) {
- this.changeScrollH()
- }
- }
- }
- </script>
- <style lang="scss">
- .sales-edit-wrap{
- width: 100%;
- .color_6{
- color: #666;
- }
- .font_13{
- font-size: 26upx;
- }
- .border-b{
- border-bottom: 1px solid #e4e7ed;
- }
- .sales-info-con{
- background-color: #fff;
- margin-bottom: 6upx;
- padding: 0 20upx;
- >view{
- padding: 14upx 0;
- border-bottom: 1px solid #e4e7ed;
- }
- >view:last-child{
- border-bottom: none;
- }
- .info-item-box{
- .info-item-tit{
- display: inline-block;
- width: 20%;
- }
- }
- }
- .sales-product-con{
- background-color: #fff;
- padding: 0 20upx;
- flex-grow: 1;
- .sales-product-header{
- padding: 14upx 0;
- height: 80upx;
- .sales-product-operation{
- button{
- margin: 0 0 0 10upx;
- }
- }
- }
- .sales-total-box{
- align-items: flex-end;
- padding: 16upx 0;
- .sales-total-con{
- color: #666;
- overflow: hidden;
- view{
- padding: 4upx 0;
- .sales-total-num{
- font-size: 24upx;
- color: rgb(48, 49, 51);
- }
- }
- }
- .sales-total-btn{
- display: inline-block;
- margin-bottom: 6upx;
- }
- }
- .sales-list-box{
- flex-grow: 1;
- .sales-list-con{
- .sales-list-item{
- padding: 20upx 0;
- .pimgs{
- margin-right: 20upx;
- position: relative;
- .sign{
- position: absolute;
- right: -2upx;
- top: -2upx;
- color: #fff;
- border-radius: 50%;
- width: 40upx;
- height: 40upx;
- text-align: center;
- }
- }
- .sales-item-main{
- .sales-item-name{
- font-size: 28upx;
- color: rgb(48, 49, 51);
- font-weight: bold;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 1;
- }
- .sales-item-txt{
- margin: 8upx 0;
- }
- .sales-item-price{
- text-align: right;
- }
- }
- .btn-box{
- padding: 30upx 30upx;
- }
- }
- .sales-list-item:last-child{
- border: none;
- }
- }
- }
- }
- .sales-btn-box{
- background-color: #fff;
- padding: 12upx 50upx;
- .handle-btn{
- width: 47%;
- }
- .edit-btn{
- width: 100%;
- }
- }
- }
- </style>
|