123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571 |
- <template>
- <div class="salesEdit-wrap">
- <a-spin :spinning="spinning" tip="Loading...">
- <a-page-header :ghost="false" :backIcon="false" @back="handleBack" >
- <!-- 自定义的二级文字标题 -->
- <template slot="subTitle">
- <a id="salesEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
- <span style="margin: 0 15px;color: #666;">客户名称:{{ detailData&&detailData.buyerName || '--' }}</span>
- </template>
- <!-- 操作区,位于 title 行的行尾 -->
- <template slot="extra" v-if="$hasPermissions('B_salesPrint')">
- <Print :disabled="dataSource.length==0" @handlePrint="handlePrint"></Print>
- </template>
- </a-page-header>
- <a-card size="small" :bordered="false" class="salesEdit-cont">
- <!-- 查询配件列表 -->
- <queryPart
- ref="partQuery"
- :newLoading="isInster"
- @add="insterProduct"
- @isCost="isCost"></queryPart>
- </a-card>
- <a-card size="small" :bordered="false" class="salesEdit-cont">
- <!-- 总计 -->
- <a-alert v-if="detailData" style="margin-bottom: 10px;" type="info">
- <div slot="message" class="total-bar">
- <div>
- 总售价:<strong>{{ detailData&&(detailData.totalAmount || detailData.totalAmount==0) ? '¥'+detailData.totalAmount : '--' }}</strong>;
- 总款数:<strong>{{ detailData&&(detailData.totalCategory || detailData.totalCategory==0) ? detailData.totalCategory : '--' }}</strong>;
- 总数量:<strong>{{ detailData&&(detailData.totalQty || detailData.totalQty==0) ? detailData.totalQty : '--' }}</strong>;
- 赠品总数量:<strong>{{ detailData&&(detailData.giftQty || detailData.giftQty==0) ? detailData.giftQty : '--' }}</strong>;
- <span v-if="isCosts">
- 总成本价:<strong>{{ detailData&&(detailData.totalCost || detailData.totalCost==0) ? detailData.totalCost : '--' }}</strong>;
- 毛利:<strong>{{ detailData&&(detailData.grossProfit || detailData.grossProfit==0) ? detailData.grossProfit : '--' }}</strong>;
- </span>
- </div>
- <div>
- <div>
- 折扣金额:
- <a-input-number
- id="discount"
- size="small"
- v-model="detailData.discountAmount"
- :min="0"
- :precision="2"
- :max="999999"/>
- <a-button size="small" type="primary" @click="salesDiscount" class="button-info">打折</a-button>
- </div>
- <div>
- 折扣:<strong>{{ detailData&&(detailData.discountRate || detailData.discountRate==0) ? detailData.discountRate+'%' : '--' }}</strong>;
- 折后总售价:<strong>{{ detailData&&(detailData.discountedAmount || detailData.discountedAmount==0) ? '¥'+detailData.discountedAmount : '--' }}</strong>;
- </div>
- </div>
- </div>
- </a-alert>
- <!-- 搜索条件 -->
- <div class="table-page-search-wrapper">
- <a-row :gutter="15">
- <a-col :span="18">
- <a-form-model :model="productForm" ref="ruleForm" layout="inline" @keyup.enter.native="$refs.table.refresh(true)" >
- <a-row :gutter="15">
- <a-col :md="8" :sm="24">
- <a-form-model-item label="产品编码">
- <a-input v-model="productForm.productCode" allowClear placeholder="输入产品编码" />
- </a-form-model-item>
- </a-col>
- <a-col :md="8" :sm="24">
- <a-form-model-item label="产品名称">
- <a-input v-model="productForm.productName" allowClear placeholder="输入产品名称" />
- </a-form-model-item>
- </a-col>
- <a-col :md="8" :sm="24">
- <a-form-model-item style="margin-bottom: 10px;">
- <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesEdit-refresh">查询</a-button>
- <a-button style="margin-left: 5px" @click="resetForm" id="salesEdit-reset">重置</a-button>
- </a-form-model-item>
- </a-col>
- </a-row>
- </a-form-model>
- </a-col>
- <a-col :span="6">
- <div style="float:right;overflow: hidden;">
- <a-button
- size="small"
- type="primary"
- @click="delSalerDetailAll"
- :loading="delLoading"
- style="margin-left: 10px"
- id="salesEdit-del-all">整单删除</a-button>
- </div>
- </a-col>
- </a-row>
- </div>
- <!-- 已选配件列表 -->
- <s-table
- class="sTable"
- ref="table"
- size="small"
- :rowKey="(record) => record.id"
- :columns="columns"
- :data="loadData"
- :scroll="{ y: 300 }"
- :defaultLoadData="false"
- :rowClassName="(record, index) => record.cost > record.price ? 'redBg-row':''"
- bordered>
- <!-- 产品编码 -->
- <template slot="productCode" slot-scope="text, record">
- <a-badge count="急" v-if="record.oosFlag == 1">
- <div style="padding-right: 15px;">{{ text }}</div>
- </a-badge>
- <span v-else>{{ text }}</span>
- </template>
- <!-- 售价 -->
- <template slot="price" slot-scope="text, record">
- <a-input-number
- id="salesEdit-price"
- size="small"
- v-model="record.price"
- :precision="2"
- :min="0"
- :max="999999"
- placeholder="请输入"
- @blur="e => priceBlur(e.target.value, record)"
- style="width: 100%;" />
- </template>
- <!-- 销售数量 -->
- <template slot="salesNums" slot-scope="text, record">
- <a-input-number
- id="salesEdit-salesNums"
- size="small"
- v-model="record.qty"
- :precision="0"
- :min="1"
- :max="999999"
- placeholder="请输入"
- @blur="e => qtyBlur(e.target.value, record)"
- style="width: 100%;" />
- </template>
- <!-- 操作 -->
- <template slot="action" slot-scope="text, record">
- <a-button
- size="small"
- type="primary"
- :loading="delLoading"
- class="button-error"
- @click="handleDel(record)"
- id="productInfoList-Del">删除</a-button>
- </template>
- </s-table>
- </a-card>
- </a-spin>
- <div class="affix-cont">
- <a-button
- size="large"
- style="padding: 0 60px;"
- type="primary"
- :disabled="spinning"
- class="button-primary"
- @click="handleSubmit()"
- id="productInfoList-handleSubmit">提交</a-button>
- </div>
- <!-- 选择客户弹框 -->
- <choose-custom-modal ref="custModal" :show="openModal" @updateData="updateData" @cancel="openModal=false" />
- </div>
- </template>
- <script>
- import { STable, VSelect } from '@/components'
- import queryPart from './queryPart.vue'
- import chooseCustomModal from './chooseCustomModal.vue'
- import { stockByProductSn } from '@/api/stock'
- import { salesDetail, salesWriteSubmit, salesWriteDiscount, salesDetailPrint, salesDetailExport } from '@/api/sales'
- import { salesDetailList, salesDetailInsert, salesDetailUpdatePrice, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll } from '@/api/salesDetail'
- import Print from '@/views/common/print.vue'
- import { hdPrint } from '@/libs/JGPrint'
- export default {
- name: 'SalesDetail',
- components: { STable, VSelect, queryPart, chooseCustomModal, Print },
- data () {
- return {
- spinning: false,
- orderId: null, // 销售单id
- salesBillSn: null, // 销售单sn
- disabled: false, // 查询、重置按钮是否可操作
- isInster: false, // 是否正在添加产品
- openModal: false, // 客户弹框
- delLoading: false,
- detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
- dataSource: [],
- productForm: {
- productName: '',
- productCode: ''
- },
- // 表头
- columns: [
- { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
- { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '13%', scopedSlots: { customRender: 'productCode' }, align: 'center', sorter: true },
- { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '13%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
- { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
- { title: '品牌', dataIndex: 'dealerProductEntity.productBrandName', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
- { title: '仓库', dataIndex: 'warehouseEntity.name', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
- { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
- { title: '售价', dataIndex: 'price', scopedSlots: { customRender: 'price' }, width: '7%', align: 'center' },
- { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: '7%', align: 'center' },
- { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
- { title: '售价小计', dataIndex: 'totalAmount', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
- { title: '折后小计', dataIndex: 'discountedAmount', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
- { title: '操作', scopedSlots: { customRender: 'action' }, width: '7%', align: 'center' }
- ],
- // 加载数据方法 必须为 Promise 对象
- loadData: parameter => {
- this.disabled = true
- this.productForm.salesBillSn = this.$route.params.sn
- return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
- const data = res.data
- const no = (data.pageNo - 1) * data.pageSize
- for (var i = 0; i < data.list.length; i++) {
- data.list[i].no = no + i + 1
- data.list[i].qtyBackups = data.list[i].qty
- data.list[i].priceBackups = data.list[i].price
- }
- this.disabled = false
- this.dataSource = data.list || []
- return data
- })
- },
- printerType: 'NEEDLE', // 打印机类型
- isCosts: false
- }
- },
- methods: {
- // 打印预览/快捷打印
- handlePrint (type, printerType) {
- const _this = this
- _this.spinning = true
- let url = salesDetailPrint
- const params = { sn: this.outBizSn || this.$route.params.sn }
- if (type == 'export') { // 导出
- url = salesDetailExport
- }
- // 打印或导出
- hdPrint(printerType, type, url, params, '销售单', function () {
- _this.spinning = false
- })
- },
- // 已选产品 销售数量 blur
- qtyBlur (val, record) {
- const _this = this
- this.dataSource = record || []
- if (val && val != record.qtyBackups) {
- this.spinning = true
- // 校验库存
- stockByProductSn({ productSn: record.productSn }).then(res => {
- if (res.status == 200) {
- if (res.data && (!res.data.currentStockQty || val <= res.data.currentStockQty)) {
- _this.changeQty(record)
- } else {
- this.$confirm({
- title: '提示',
- content: '库存不足,确认添加为急件吗?',
- centered: true,
- closable: true,
- onOk () {
- _this.changeQty(record)
- },
- onCancel () {
- record.qty = record.qtyBackups
- _this.spinning = false
- }
- })
- }
- } else {
- this.spinning = false
- record.qty = record.qtyBackups
- }
- })
- } else {
- record.qty = record.qtyBackups
- }
- },
- changeQty (record) {
- salesDetailUpdateQty({
- id: record.id,
- qty: record.qty
- }).then(res => {
- this.resetSearchForm(true)
- if (res.status == 200) {
- this.$message.info(res.message)
- }
- this.spinning = false
- })
- },
- // 已选产品 售价 blur
- priceBlur (val, record) {
- this.dataSource = record || []
- // 光标移出,值发生改变再调用编辑接口
- if (val && val != record.priceBackups) {
- this.spinning = true
- salesDetailUpdatePrice({
- salesBillSn: record.salesBillSn,
- productSn: record.productSn,
- price: record.price
- }).then(res => {
- this.resetSearchForm(true)
- if (res.status == 200) {
- this.$message.info(res.message)
- this.spinning = false
- } else {
- this.spinning = false
- }
- })
- } else {
- record.price = record.priceBackups
- }
- },
- isCost (val) {
- this.isCosts = val
- },
- // 更新产品列表
- updateData (priceType) {
- // 价格类型变更
- if (priceType != this.$route.params.priceType) {
- this.$router.push({ name: 'salesEdit', params: { id: this.orderId, sn: this.salesBillSn, priceType: priceType } })
- } else {
- this.getOrderDetail()
- }
- },
- // 重置
- resetSearchForm (flag) {
- if (flag) { this.$refs.partQuery.onlyList = true }
- this.$refs.table.refresh(!!flag)
- this.getOrderDetail()
- },
- // 重置列表
- resetForm () {
- this.productForm = {
- productName: '',
- productCode: ''
- }
- this.$refs.table.refresh()
- },
- // 返回
- handleBack () {
- this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
- },
- // 打折
- salesDiscount () {
- if (this.detailData.discountAmount < 0) {
- return
- }
- this.spinning = true
- salesWriteDiscount({
- discountAmount: this.detailData.discountAmount,
- salesBillSn: this.detailData.salesBillSn,
- id: this.detailData.id
- }).then(res => {
- if (res.status == 200) {
- this.resetSearchForm(true)
- this.spinning = false
- } else {
- this.spinning = false
- }
- })
- },
- // 整单删除
- delSalerDetailAll () {
- const _this = this
- this.$confirm({
- title: '提示',
- content: '确认要整单删除吗?',
- centered: true,
- closable: true,
- onOk () {
- _this.delLoading = true
- _this.spinning = true
- salesDetailDelAll({ salesBillSn: _this.detailData.salesBillSn }).then(res => {
- if (res.status == 200) {
- _this.resetSearchForm(true)
- _this.productForm = {
- productName: '',
- productCode: ''
- }
- }
- _this.$message.info(res.message)
- _this.delLoading = false
- _this.spinning = false
- })
- }
- })
- },
- // 删除产品
- handleDel (row) {
- const _this = this
- this.$confirm({
- title: '提示',
- content: '确认要删除吗?',
- centered: true,
- closable: true,
- onOk () {
- _this.delLoading = true
- _this.spinning = true
- salesDetailDel({ id: row.id }).then(res => {
- if (res.status == 200) {
- _this.resetSearchForm(true)
- }
- _this.$message.info(res.message)
- _this.delLoading = false
- _this.spinning = false
- })
- }
- })
- },
- // 添加产品
- insterProduct (row) {
- // 防止多次添加产品
- if (this.isInster) { return }
- const _this = this
- // 判断是否已添加此产品
- if (this.dataSource && this.dataSource.length > 0) {
- const hasRow = this.dataSource.find(item => item.productSn == row.productSn && item.warehouseSn == row.warehouseSn && item.warehouseLocationSn == row.warehouseLocationSn)
- if (hasRow) {
- // this.$message.info('该产品已在当前销售单中存在!')
- this.productForm = {
- productName: '',
- productCode: hasRow.dealerProductEntity && hasRow.dealerProductEntity.code || ''
- }
- this.$refs.table.refresh(true)
- return
- } else {
- this.productForm = {
- productName: '',
- productCode: ''
- }
- }
- }
- // 库存不足时
- if (row.currentQty < row.salesNums) {
- this.$confirm({
- title: '提示',
- content: '库存不足,确认添加为急件吗?',
- centered: true,
- closable: true,
- onOk () {
- _this.saveNewProduct(row)
- }
- })
- } else if (row.putCost > row.salePrice) {
- // 销售价低于成本价
- this.$confirm({
- title: '提示',
- content: '售价低于成本价,确认要添加吗?',
- centered: true,
- closable: true,
- onOk () {
- _this.saveNewProduct(row)
- }
- })
- } else {
- this.saveNewProduct(row)
- }
- },
- // 保存添加的产品到销售列表
- saveNewProduct (row) {
- this.$message.loading('正在添加产品...', 1)
- this.isInster = true
- this.spinning = true
- salesDetailInsert({
- buyerSn: this.detailData.buyerSn,
- productSn: row.productSn,
- cost: row.putCost,
- // productCode: row.productCode,
- // productOrigCode: row.productOrigCode,
- price: row.salePrice,
- qty: row.salesNums,
- salesBillSn: this.detailData.salesBillSn,
- salesBillNo: this.detailData.salesBillNo,
- warehouseSn: row.warehouseSn,
- warehouseLocationSn: row.warehouseLocationSn,
- stockSn: row.stockSn
- }).then(res => {
- if (res.status == 200) {
- this.resetSearchForm(true)
- this.$message.success('产品添加成功', 2.5)
- }
- this.isInster = false
- this.spinning = false
- })
- },
- // 销售单详情
- getOrderDetail () {
- salesDetail({ id: this.$route.params.id }).then(res => {
- if (res.status == 200) {
- this.detailData = res.data
- const vm = this
- const buyerSn = (vm.detailData && vm.detailData.buyerSn && vm.detailData.salesBillSource && vm.detailData.salesBillSource == 'PURCHASE') ? '' : vm.detailData.buyerSn
- const priceType = vm.$route.params.priceType
- vm.$refs.partQuery.pageInit(buyerSn, priceType)
- }
- })
- },
- // 提交销售单
- handleSubmit () {
- this.spinning = true
- salesWriteSubmit({ id: this.orderId }).then(res => {
- if (res.status == 200) {
- this.handleBack()
- this.$message.success(res.message)
- this.spinning = false
- } else {
- this.spinning = false
- }
- })
- },
- pageInit () {
- const vm = this
- vm.orderId = vm.$route.params.id
- vm.salesBillSn = vm.$route.params.sn
- vm.getOrderDetail()
- vm.$refs.table.refresh(true)
- }
- },
- mounted () {
- if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
- this.pageInit()
- }
- },
- activated () {
- // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
- if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
- this.pageInit()
- }
- },
- beforeRouteEnter (to, from, next) {
- next(vm => {})
- }
- }
- </script>
- <style lang="less">
- .salesEdit-wrap{
- position: relative;
- height: 100%;
- padding-bottom: 51px;
- box-sizing: border-box;
- >.ant-spin-nested-loading{
- overflow-y: scroll;
- height: 100%;
- }
- .salesEdit-cont{
- margin-top: 10px;
- }
- .total-bar{
- display: flex;
- align-items: center;
- justify-content: space-between;
- > div{
- &:last-child{
- display: flex;
- align-items: center;
- justify-content: space-between;
- > div{
- padding: 0 10px;
- }
- }
- }
- }
- .redBg-row{
- background-color: #f5cdc8;
- }
- }
- </style>
|