edit.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. <template>
  2. <div v-if="showPage" class="salesEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" @back="handleBack" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="salesEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <a style="margin: 0 10px 0 20px;color: #666;font-size: 14px;font-weight: 600;">单号:{{ detailData&&detailData.salesBillNo || '--' }}</a>
  9. <span style="margin: 0 10px;color: #666;">客户名称:{{ detailData&&detailData.buyerNameCurrent?detailData.buyerName?detailData.buyerNameCurrent==detailData.buyerName?detailData.buyerNameCurrent:detailData.buyerNameCurrent+'('+detailData.buyerName+')':detailData.buyerNameCurrent:'--' }}</span>
  10. <a-button
  11. id="salesEdit-edit-btn"
  12. v-if="detailData&&detailData.salesTragetType != 'DEALER'"
  13. size="small"
  14. @click="handleEdit"
  15. style="margin-left:10px"
  16. key="0">编辑客户信息</a-button>
  17. <span style="margin-left:10px;color: #ED1C24;" v-if="detailData.sourceType==='XPRH_PURCHASE'">请注意:该销售单若为促销订单,增删改产品会影响促销活动</span>
  18. </template>
  19. <!-- 操作区,位于 title 行的行尾 -->
  20. <template slot="extra" v-if="$hasPermissions('B_salesPrint')">
  21. <a-checkbox v-model="printAllName" :checked="printAllName" id="salesEdit-printAllName">打印完整产品名称</a-checkbox>
  22. <a-checkbox v-model="printOrgCode" :checked="printOrgCode" id="salesEdit-printOrgCode">打印原厂编码</a-checkbox>
  23. <Print id="salesEdit-printBox" :disabled="dataSource.length==0" @handlePrint="handlePrint"></Print>
  24. </template>
  25. </a-page-header>
  26. <a-card size="small" :bordered="false" class="salesEdit-cont">
  27. <!-- 查询配件列表 -->
  28. <queryPart
  29. ref="partQuery"
  30. :newLoading="isInster"
  31. @add="insterProduct"
  32. @isCost="isCost"></queryPart>
  33. </a-card>
  34. <a-card size="small" :bordered="false" class="salesEdit-cont">
  35. <!-- 总计 -->
  36. <a-alert v-if="detailData" style="margin-bottom: 10px;" type="info">
  37. <div slot="message" class="total-bar">
  38. <div>
  39. 总售价:<strong>{{ detailData&&(detailData.totalAmount || detailData.totalAmount==0) ? toThousands(detailData.totalAmount) : '--' }}</strong>;
  40. 总款数:<strong>{{ detailData&&(detailData.totalCategory || detailData.totalCategory==0) ? detailData.totalCategory : '--' }}</strong>;
  41. 总数量:<strong>{{ detailData&&(detailData.totalQty || detailData.totalQty==0) ? detailData.totalQty : '--' }}</strong>;
  42. 赠品总数量:<strong>{{ detailData&&(detailData.giftQty || detailData.giftQty==0) ? detailData.giftQty : '--' }}</strong>;
  43. <span v-if="isCosts">
  44. 总成本价:<strong>{{ detailData&&(detailData.totalCost || detailData.totalCost==0) ? toThousands(detailData.totalCost) : '--' }}</strong>;
  45. 毛利:<strong>{{ detailData&&(detailData.grossProfit || detailData.grossProfit==0) ? toThousands(detailData.grossProfit) : '--' }}</strong>;
  46. </span>
  47. </div>
  48. <div>
  49. <div>
  50. 折扣金额:
  51. <a-input-number
  52. id="salesEdit-discount-input"
  53. size="small"
  54. v-model.trim="detailData.discountAmount"
  55. :min="0"
  56. :precision="2"
  57. :max="999999"/>
  58. <a-button id="salesEdit-discount-button" size="small" type="primary" class="button-primary" @click="salesDiscount">打折</a-button>
  59. </div>
  60. <div>
  61. 折扣:<strong>{{ detailData&&(detailData.discountRate || detailData.discountRate==0) ? detailData.discountRate+'%' : '--' }}</strong>;
  62. 折后总售价:<strong>{{ detailData&&(detailData.discountedAmount || detailData.discountedAmount==0) ? toThousands(detailData.discountedAmount) : '--' }}</strong>;
  63. </div>
  64. </div>
  65. </div>
  66. </a-alert>
  67. <!-- 搜索条件 -->
  68. <div class="table-page-search-wrapper">
  69. <a-row :gutter="15">
  70. <a-col :md="24" :lg="12">
  71. <a-form-model :model="productForm" ref="ruleForm" layout="inline" @keyup.enter.native="$refs.table.refresh(true)" >
  72. <a-row :gutter="15">
  73. <a-col :md="8" :sm="24">
  74. <a-form-model-item label="产品编码">
  75. <a-input id="salesEdit-productCode" v-model.trim="productForm.productCode" allowClear placeholder="输入产品编码" />
  76. </a-form-model-item>
  77. </a-col>
  78. <a-col :md="8" :sm="24">
  79. <a-form-model-item label="产品名称">
  80. <a-input id="salesEdit-productName" v-model.trim="productForm.productName" allowClear placeholder="输入产品名称" />
  81. </a-form-model-item>
  82. </a-col>
  83. <a-col :md="8" :sm="24">
  84. <a-form-model-item style="margin-bottom: 10px;">
  85. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesEdit-refresh">查询</a-button>
  86. <a-button style="margin-left: 5px" @click="resetForm" id="salesEdit-reset">重置</a-button>
  87. </a-form-model-item>
  88. </a-col>
  89. </a-row>
  90. </a-form-model>
  91. </a-col>
  92. <a-col :md="24" :lg="12">
  93. <div style="float:right;overflow: hidden;margin-bottom:10px;">
  94. <a-checkbox :value="0" :checked="tbForm.indexOf('AUDIT')>=0" @change="(e)=>{tbFormChange(e,0)}" id="salesEdit-tbsh">同步审核</a-checkbox>
  95. <a-checkbox :value="1" :checked="tbForm.indexOf('STOCK_OUT')>=0" @change="(e)=>{tbFormChange(e,1)}" id="salesEdit-tbck">同步出库</a-checkbox>
  96. <a-checkbox :value="2" :checked="tbForm.indexOf('SETTLE')>=0" @change="(e)=>{tbFormChange(e,2)}" id="salesEdit-tbsk">同步收款</a-checkbox>
  97. <a-button
  98. style="padding: 0 25px;"
  99. type="primary"
  100. :disabled="spinning"
  101. class="button-primary"
  102. @click="enableFundAccount && tbForm.length == 3 ? handleSettleAcountPay(null,0) : handleSubmit({})"
  103. id="salesEdit-handleSubmit">提交</a-button>
  104. <a-button
  105. type="default"
  106. @click="openGuideModal=true"
  107. style="margin-right:5px;"
  108. id="salesEdit-import">导入产品</a-button>
  109. <a-button
  110. type="default"
  111. v-if="shelfInfo&&shelfInfo.state=='ENABLE'"
  112. @click="showShelfModal=true"
  113. style="margin-right:5px;"
  114. id="salesEdit-shelf">货架产品</a-button>
  115. <a-button
  116. type="primary"
  117. ghost
  118. :disabled="dataSource.length==0"
  119. @click="delSalerOrder"
  120. :loading="delLoading"
  121. id="salesEdit-del-all">清空列表</a-button>
  122. </div>
  123. </a-col>
  124. </a-row>
  125. </div>
  126. <!-- 已选配件列表 -->
  127. <s-table
  128. class="sTable"
  129. ref="table"
  130. size="small"
  131. :rowKey="(record) => record.id"
  132. :columns="columns"
  133. :data="loadData"
  134. :defaultLoadData="false"
  135. :pageSize="5"
  136. :rowClassName="(record, index) => record.cost > record.price ? 'redBg-row':''"
  137. bordered>
  138. <div slot="costTitle">
  139. <a-tooltip placement="top">
  140. <template slot="title">
  141. 系统中不同批次的产品,成本价可能不同,此值是按照实际出库批次的成本计算得到。
  142. </template>
  143. <span style="margin-right: 5px;">实际总成本</span> <a-icon type="question-circle" />
  144. </a-tooltip>
  145. </div>
  146. <!-- 产品名称 -->
  147. <template slot="productName" slot-scope="text, record">
  148. <a-tag color="blue" v-if="record.shelfPlaceCode">{{ record.shelfPlaceCode }}</a-tag>
  149. <span :title="text">{{ text }}</span>
  150. </template>
  151. <!-- 产品编码 -->
  152. <template slot="productCode" slot-scope="text, record">
  153. <div v-if="detailData">
  154. <div v-if="isOwerEdit">
  155. <a-badge count="急" v-if="record.oosFlag == 1">
  156. <div style="padding-right: 15px;">{{ text }}</div>
  157. </a-badge>
  158. <span v-else>{{ text }}</span>
  159. </div>
  160. <div v-else>
  161. <a-badge count="急" v-if="isAudit&&record.oosFlag == 1">
  162. <div style="padding-right: 15px;">{{ text }}</div>
  163. </a-badge>
  164. <a-badge count="缺" v-else-if="!isAudit&&(!record.currentStockQty || record.currentStockQty < record.qty)">
  165. <div style="padding-right: 15px;">{{ text }}</div>
  166. </a-badge>
  167. <span v-else>{{ text }}</span>
  168. </div>
  169. </div>
  170. </template>
  171. <!-- 售价 -->
  172. <template slot="price" slot-scope="text, record">
  173. <a-input-number
  174. :id="'salesEdit-price-'+record.productSn"
  175. size="small"
  176. v-model="record.price"
  177. :precision="2"
  178. :min="0"
  179. :max="999999"
  180. placeholder="请输入"
  181. @blur="e => priceBlur(e.target.value, record)"
  182. style="width: 100%;" />
  183. </template>
  184. <!-- 销售数量 -->
  185. <template slot="salesNums" slot-scope="text, record">
  186. <a-input-number
  187. :id="'salesEdit-salesNums-'+record.productSn"
  188. size="small"
  189. v-model="record.qty"
  190. :precision="0"
  191. :min="1"
  192. :max="999999"
  193. placeholder="请输入"
  194. @blur="e => qtyBlur(e.target.value, record)"
  195. style="width: 100%;" />
  196. </template>
  197. <!-- 操作 -->
  198. <template slot="action" slot-scope="text, record">
  199. <a-button
  200. :id="'salesEdit-outDetail-'+record.productSn"
  201. size="small"
  202. v-if="record.oosFlag == 0 && isOwerEdit"
  203. type="link"
  204. class="button-primary"
  205. @click="handleViewDetail(record)">出库明细</a-button>
  206. <a-button
  207. :id="'salesEdit-del-'+record.productSn"
  208. size="small"
  209. type="link"
  210. :loading="delLoading"
  211. class="button-error"
  212. @click="handleDel(record)">删除</a-button>
  213. </template>
  214. </s-table>
  215. </a-card>
  216. </a-spin>
  217. <!-- 选择客户弹框 -->
  218. <choose-custom-modal ref="custModal" :show="openModal" @updateData="updateData" @cancel="openModal=false" />
  219. <!-- 导入产品 -->
  220. <importGuideModal :openModal="openGuideModal" :params="{salesBillSn: $route.params.sn, salesBillNo:detailData?detailData.salesBillNo:''}" @close="openGuideModal=false" @ok="hanldeImprotOk" />
  221. <!-- 收付款弹框 -->
  222. <settleModal ref="settleModal" @ok="settleAcountPay" :openModal="openSettleModal" @close="openSettleModal=false"></settleModal>
  223. <!-- 出库明细 -->
  224. <outInDetialModal ref="outInDetialModal" outBizType="SALES" :openModal="showOutInModal" @close="showOutInModal=false"></outInDetialModal>
  225. <!-- 选择货架产品 -->
  226. <chooseShelfProduct
  227. v-if="showShelfModal"
  228. ref="chooseShelfProduct"
  229. @add="insterProduct"
  230. @plAdd="plInsterProduct"
  231. :baseData="shelfInfo"
  232. :openModal="showShelfModal"
  233. @close="showShelfModal=false"></chooseShelfProduct>
  234. </div>
  235. </template>
  236. <script>
  237. import { commonMixin } from '@/utils/mixin'
  238. import { mapActions } from 'vuex'
  239. import Print from '@/views/common/print.vue'
  240. import { hdPrint } from '@/libs/JGPrint'
  241. // 组件
  242. import { STable, VSelect } from '@/components'
  243. import queryPart from './queryPart.vue'
  244. import chooseCustomModal from './chooseCustomModal.vue'
  245. import importGuideModal from './importGuideModal.vue'
  246. import settleModal from '@/views/financialManagement/settleModal/settleModal.vue'
  247. import outInDetialModal from '@/views/common/outInDetialModal.vue'
  248. import chooseShelfProduct from './chooseShelfProduct.vue'
  249. // 接口
  250. import { stockByProductSn } from '@/api/stock'
  251. import { queryByCustomerSn } from '@/api/shelf'
  252. import { salesDetail, salesWriteSubmit, salesWriteDiscount, salesDetailPrint, salesDetailExport, salesDel } from '@/api/sales'
  253. import { salesDetailList, salesDetailInsert, salesDetailInsertBatch, salesDetailUpdatePrice, salesDetailUpdateQty, salesDetailDel, salesDetailInsertImport } from '@/api/salesDetail'
  254. export default {
  255. name: 'SalesEdit',
  256. components: { STable, VSelect, queryPart, chooseCustomModal, Print, importGuideModal, settleModal, outInDetialModal, chooseShelfProduct },
  257. mixins: [commonMixin],
  258. data () {
  259. return {
  260. showOutInModal: false, // 出入库明细
  261. showPage: false, // 是否显示当前页面
  262. spinning: false, // loading
  263. orderId: null, // 销售单id
  264. salesBillSn: null, // 销售单sn
  265. disabled: false, // 查询、重置按钮是否可操作
  266. isInster: false, // 是否正在添加产品
  267. openModal: false, // 客户弹框
  268. openGuideModal: false, // 导入产品弹框
  269. openSettleModal: false, // 打开收款弹框
  270. enableFundAccount: false, // 是否开启资金账户管理
  271. showShelfModal: false, // 货架产品弹框
  272. delLoading: false, // 删除按钮loading
  273. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  274. dataSource: [], // 原始列表数据
  275. productForm: { // 查询条件
  276. productName: '', // 产品名称
  277. productCode: '', // 产品编码
  278. orderBy: 'sales_bill_detail.CREATE_DATE desc' // 排序
  279. },
  280. tbForm: [], // 同步操作
  281. printOrgCode: false, // 打印原创编码
  282. printAllName: false, // 打印全部名称
  283. // 加载数据方法 必须为 Promise 对象
  284. loadData: parameter => {
  285. this.disabled = true
  286. this.productForm.salesBillSn = this.$route.params.sn
  287. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  288. let data
  289. if (res.status == 200) {
  290. data = res.data
  291. const no = (data.pageNo - 1) * data.pageSize
  292. for (var i = 0; i < data.list.length; i++) {
  293. data.list[i].no = no + i + 1
  294. data.list[i].qtyBackups = data.list[i].qty
  295. data.list[i].priceBackups = data.list[i].price
  296. }
  297. this.disabled = false
  298. this.dataSource = data.list || []
  299. }
  300. return data
  301. })
  302. },
  303. printerType: 'NEEDLE', // 打印机类型
  304. isCosts: false, // 是否显示成本价
  305. shelfInfo: null // 是否有货架
  306. }
  307. },
  308. computed: {
  309. // 是否自建单据
  310. isOwerEdit () {
  311. return this.detailData && this.detailData.sourceType == 'SALES'
  312. },
  313. // 是否审核通过
  314. isAudit () {
  315. return this.detailData && (this.detailData.billStatus == 'WAIT_OUT_WAREHOUSE' || this.detailData.billStatus == 'FINISH')
  316. },
  317. // 列定义
  318. columns () {
  319. const _this = this
  320. const arr = [
  321. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  322. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '10%', scopedSlots: { customRender: 'productCode' }, align: 'center' },
  323. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '15%', align: 'left', scopedSlots: { customRender: 'productName' }, ellipsis: true },
  324. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  325. { title: '品牌', dataIndex: 'dealerProductEntity.productBrandName', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  326. // { title: '仓库', dataIndex: 'warehouseEntity.name', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  327. // { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  328. { title: '售价', dataIndex: 'price', scopedSlots: { customRender: 'price' }, width: '7%', align: 'center' },
  329. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: '7%', align: 'center' },
  330. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
  331. { title: '售价小计', dataIndex: 'totalAmount', width: '5%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  332. { title: '折后小计', dataIndex: 'discountedAmount', width: '5%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  333. { title: '操作', scopedSlots: { customRender: 'action' }, width: '7%', align: 'center' }
  334. ]
  335. // 下级创建,不显示仓库仓位
  336. if (!this.isOwerEdit) {
  337. arr.splice(7, 0, { title: '库存数量', dataIndex: 'currentStockQty', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  338. } else {
  339. arr.splice(5, 0, { title: '仓库', dataIndex: 'warehouseEntity.name', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } })
  340. arr.splice(6, 0, { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: '8%', align: 'center', customRender: function (text) { return text || '--' } })
  341. }
  342. if (this.detailData && this.detailData.sourceType && this.detailData.sourceType === 'XPRH_PURCHASE') {
  343. arr.splice(11, 0, { title: <a-tooltip placement="bottom" title='返券金额以销售单完结时的活动规则为准'>返券金额&nbsp;<a-icon type="question-circle" /></a-tooltip>, dataIndex: 'giveAmount', width: '6%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } })
  344. }
  345. // 实际总成本
  346. if (this.isCosts) {
  347. arr.splice(!this.isOwerEdit ? 11 : 12, 0, { slots: { title: 'costTitle' }, dataIndex: 'totalCost', width: '8%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } })
  348. }
  349. return arr
  350. }
  351. },
  352. methods: {
  353. ...mapActions(['GetSettleAccountState']),
  354. // 返回列表
  355. handleBack () {
  356. this.$router.push({ path: '/salesManagement/salesQuery/list' })
  357. },
  358. // 打印预览/快捷打印
  359. handlePrint (type, printerType) {
  360. const _this = this
  361. _this.spinning = true
  362. let url = salesDetailPrint
  363. const params = { sn: this.outBizSn || this.$route.params.sn, printOrgCode: this.printOrgCode ? 1 : 0, printAllName: this.printAllName ? 1 : 0, remarksShowFlag: 0, priceFlag: 1, printNo: 1 }
  364. if (type == 'export') { // 导出
  365. url = salesDetailExport
  366. }
  367. // 打印或导出
  368. hdPrint(printerType, type, url, params, '销售单', function () {
  369. _this.spinning = false
  370. })
  371. },
  372. // 选择同步选框
  373. tbFormChange (e, val) {
  374. this.tbForm = []
  375. const tbTypes = ['AUDIT', 'STOCK_OUT', 'SETTLE']
  376. if (e.target.checked) {
  377. for (let i = val; i >= 0; i--) {
  378. this.tbForm.push(tbTypes[i])
  379. }
  380. } else {
  381. this.tbForm = []
  382. }
  383. },
  384. // 编辑客户信息
  385. handleEdit () {
  386. this.openModal = true
  387. this.$refs.custModal.editCust(this.detailData)
  388. },
  389. // 更新产品列表
  390. updateData (priceType) {
  391. // 价格类型变更
  392. if (priceType != this.$route.params.priceType) {
  393. this.getOrderDetail(true)
  394. this.$router.push({ name: 'salesEdit', params: { id: this.orderId, sn: this.salesBillSn, priceType: priceType } })
  395. } else {
  396. this.getOrderDetail(true)
  397. }
  398. },
  399. // 非下级创建的单据,修改数量时校验库存
  400. validStock (val, record) {
  401. const _this = this
  402. this.spinning = true
  403. // 校验库存
  404. stockByProductSn({ productSn: record.productSn }).then(res => {
  405. if (res.status == 200) {
  406. if (res.data && (!res.data.currentStockQty || val <= res.data.currentStockQty)) {
  407. _this.changeQty(record)
  408. } else {
  409. this.$confirm({
  410. title: '提示',
  411. content: '库存不足,确认添加为急件吗?',
  412. centered: true,
  413. closable: true,
  414. onOk () {
  415. _this.changeQty(record)
  416. },
  417. onCancel () {
  418. record.qty = record.qtyBackups
  419. _this.spinning = false
  420. }
  421. })
  422. }
  423. } else {
  424. this.spinning = false
  425. record.qty = record.qtyBackups
  426. }
  427. })
  428. },
  429. // 修改已选产品数量
  430. changeQty (record) {
  431. salesDetailUpdateQty({
  432. id: record.id,
  433. salesBillSn: record.salesBillSn,
  434. productSn: record.productSn,
  435. salesBillDetailSn: record.salesBillDetailSn,
  436. qty: record.qty,
  437. price: record.price
  438. }).then(res => {
  439. this.resetSearchForm(false)
  440. if (res.status == 200) {
  441. this.$message.info(res.message)
  442. }
  443. this.spinning = false
  444. })
  445. },
  446. // 已选产品 销售数量 input 输入框 blur
  447. qtyBlur (val, record) {
  448. this.dataSource = record || []
  449. if (val && val != record.qtyBackups) {
  450. // 自建的单据,修改数量时校验库存
  451. if (this.isOwerEdit) {
  452. this.validStock(val, record)
  453. } else {
  454. this.changeQty(record)
  455. }
  456. } else {
  457. record.qty = record.qtyBackups
  458. }
  459. },
  460. // 已选产品 售价 input 输入框 blur
  461. priceBlur (val, record) {
  462. this.dataSource = record || []
  463. // 光标移出,值发生改变再调用编辑接口
  464. if (val && val != record.priceBackups) {
  465. this.spinning = true
  466. salesDetailUpdatePrice({
  467. id: record.id,
  468. salesBillSn: record.salesBillSn,
  469. productSn: record.productSn,
  470. salesBillDetailSn: record.salesBillDetailSn,
  471. qty: record.qty,
  472. price: record.price
  473. }).then(res => {
  474. this.resetSearchForm(false)
  475. if (res.status == 200) {
  476. this.$message.info(res.message)
  477. this.spinning = false
  478. } else {
  479. this.spinning = false
  480. }
  481. })
  482. } else {
  483. record.price = record.priceBackups
  484. }
  485. },
  486. // 成本显示
  487. isCost (val) {
  488. this.isCosts = val
  489. },
  490. // 重置
  491. resetSearchForm (flag) {
  492. if (flag) { this.$refs.partQuery.onlyList = true }
  493. this.$refs.table.refresh(!!flag)
  494. this.getOrderDetail(false)
  495. },
  496. // 重置列表
  497. resetForm () {
  498. this.productForm = {
  499. productName: '',
  500. productCode: '',
  501. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  502. }
  503. this.$refs.table.refresh()
  504. },
  505. // 打折
  506. salesDiscount () {
  507. this.spinning = true
  508. salesWriteDiscount({
  509. discountAmount: this.detailData.discountAmount || 0,
  510. salesBillSn: this.detailData.salesBillSn,
  511. id: this.detailData.id
  512. }).then(res => {
  513. if (res.status == 200) {
  514. this.resetSearchForm(true)
  515. this.spinning = false
  516. } else {
  517. this.spinning = false
  518. }
  519. })
  520. },
  521. // 删除销售单
  522. delSalerOrder () {
  523. const _this = this
  524. this.$confirm({
  525. title: '提示',
  526. content: '确认要清空已选产品列表吗?',
  527. centered: true,
  528. closable: true,
  529. onOk () {
  530. _this.spinning = true
  531. salesDel({ id: _this.orderId }).then(res => {
  532. if (res.status == 200) {
  533. _this.$message.success(res.message)
  534. _this.resetSearchForm(true)
  535. }
  536. _this.spinning = false
  537. })
  538. }
  539. })
  540. },
  541. // 出入库明细
  542. handleViewDetail (row) {
  543. this.showOutInModal = true
  544. this.$refs.outInDetialModal.getData(row)
  545. },
  546. // 删除产品
  547. handleDel (row) {
  548. const _this = this
  549. this.$confirm({
  550. title: '提示',
  551. content: '确认要删除吗?',
  552. centered: true,
  553. closable: true,
  554. onOk () {
  555. _this.delLoading = true
  556. _this.spinning = true
  557. salesDetailDel({ id: row.id }).then(res => {
  558. if (res.status == 200) {
  559. _this.resetSearchForm(false)
  560. }
  561. _this.$message.info(res.message)
  562. _this.delLoading = false
  563. _this.spinning = false
  564. })
  565. }
  566. })
  567. },
  568. // 添加产品
  569. insterProduct (row) {
  570. // 防止多次添加产品
  571. if (this.isInster) { return }
  572. const _this = this
  573. // 自建的单据显示库存不足时
  574. if (row.currentQty < row.salesNums && this.isOwerEdit) {
  575. _this.$confirm({
  576. title: '提示',
  577. content: '库存不足,确认添加为急件吗?',
  578. centered: true,
  579. closable: true,
  580. onOk () {
  581. _this.isPutCostDyPrice(row)
  582. }
  583. })
  584. } else {
  585. _this.isPutCostDyPrice(row)
  586. }
  587. },
  588. // 判断售价低于成本价
  589. isPutCostDyPrice (row) {
  590. const _this = this
  591. if (row.putCost > row.price) {
  592. // 销售价低于成本价
  593. _this.$confirm({
  594. title: '提示',
  595. content: '售价低于成本价,确认要添加吗?',
  596. centered: true,
  597. closable: true,
  598. onOk () {
  599. _this.saveNewProduct(row)
  600. }
  601. })
  602. } else {
  603. _this.saveNewProduct(row)
  604. }
  605. },
  606. // 保存添加的产品到销售列表
  607. saveNewProduct (row) {
  608. this.$message.loading('正在添加产品...', 1)
  609. this.isInster = true
  610. salesDetailInsert({
  611. buyerSn: this.detailData.buyerSn,
  612. productSn: row.productSn,
  613. cost: row.putCost,
  614. // productCode: row.productCode,
  615. // productOrigCode: row.productOrigCode,
  616. price: row.price,
  617. priceLevel: row.priceLevel,
  618. qty: row.salesNums,
  619. salesBillSn: this.detailData.salesBillSn,
  620. salesBillNo: this.detailData.salesBillNo,
  621. warehouseSn: row.warehouseSn,
  622. warehouseLocationSn: row.warehouseLocationSn,
  623. stockSn: row.stockSn
  624. }).then(res => {
  625. if (res.status == 200) {
  626. this.resetForm()
  627. // this.resetSearchForm(true) // 不刷新库存
  628. // this.$refs.table.refresh(true)
  629. this.getOrderDetail(false)
  630. if (this.showShelfModal) {
  631. this.$refs.chooseShelfProduct.reload()
  632. }
  633. } else {
  634. if (res.errCode == 'VALID_F_00001') {
  635. this.productForm = {
  636. productName: '',
  637. productCode: row.productCode || '',
  638. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  639. }
  640. this.$refs.table.refresh(true)
  641. }
  642. }
  643. this.isInster = false
  644. })
  645. },
  646. // 批量添加接口
  647. plInsterProduct (list) {
  648. const params = []
  649. list.map(item => {
  650. params.push({
  651. buyerSn: this.detailData.buyerSn,
  652. productSn: item.productSn,
  653. cost: item.putCost,
  654. priceLevel: item.priceLevel,
  655. price: item.price,
  656. qty: item.salesNums,
  657. salesBillSn: this.detailData.salesBillSn,
  658. salesBillNo: this.detailData.salesBillNo,
  659. stockSn: item.stockSn
  660. })
  661. })
  662. this.$message.loading('正在批量添加产品...', 1)
  663. salesDetailInsertBatch(params).then(res => {
  664. if (res.status == 200) {
  665. this.$refs.table.refresh(true)
  666. this.getOrderDetail(false)
  667. if (this.showShelfModal) {
  668. this.$refs.chooseShelfProduct.reload()
  669. }
  670. }
  671. })
  672. },
  673. // 销售单详情
  674. getOrderDetail (flag) {
  675. salesDetail({ id: this.$route.params.id }).then(res => {
  676. if (res.status == 200) {
  677. this.detailData = res.data
  678. if (flag) {
  679. const vm = this
  680. // 客户sn
  681. const buyerSn = (vm.detailData && vm.detailData.buyerSn && vm.detailData.sourceType && vm.detailData.sourceType == 'PURCHASE') ? '' : vm.detailData.buyerSn
  682. const priceType = vm.$route.params.priceType // 价格类型
  683. vm.$refs.partQuery.pageInit(buyerSn, priceType, vm.salesBillSn, vm.detailData.sourceType)
  684. // 查询关联的客户
  685. if (vm.detailData && vm.detailData.buyerSn) {
  686. this.getShelfQueryByCustomer()
  687. }
  688. }
  689. }
  690. })
  691. },
  692. // 查询关联的客户,获取货架信息
  693. getShelfQueryByCustomer () {
  694. queryByCustomerSn({ sn: this.detailData.buyerSn }).then(res => {
  695. if (res.data) {
  696. this.shelfInfo = Object.assign(res.data, { salePriceType: this.$route.params.priceType, salesBillSn: this.salesBillSn })
  697. } else {
  698. this.shelfInfo = null
  699. }
  700. })
  701. },
  702. // 提交销售单
  703. handleSubmit (params) {
  704. this.spinning = true
  705. const submitTypes = this.tbForm.join(',') // 同步操作选项
  706. salesWriteSubmit({ id: this.orderId, submitTypes: submitTypes, ...params }).then(res => {
  707. if (res.status == 200) {
  708. this.handleBack()
  709. this.$message.success(res.message)
  710. }
  711. this.spinning = false
  712. })
  713. },
  714. // 开启结算账户功能收款, type:0 单条收款,1 批量收款
  715. handleSettleAcountPay (row, type) {
  716. this.openSettleModal = true
  717. const data = {
  718. totalAmount: this.detailData.discountedAmount,
  719. settleClientName: '',
  720. title: '收款',
  721. type,
  722. row
  723. }
  724. this.$nextTick(() => {
  725. this.$refs.settleModal.setData(data)
  726. })
  727. },
  728. // 去收款
  729. settleAcountPay (form, data) {
  730. const params = {}
  731. // 资金管理开启
  732. if (this.enableFundAccount) {
  733. params.settleStyleSn = form.settleStyleSn
  734. params.settleAccountSn = form.settleAccountSn
  735. }
  736. this.spinning = true
  737. this.handleSubmit(params)
  738. },
  739. // 确认导入明细
  740. hanldeImprotOk (obj) {
  741. this.spinning = true
  742. salesDetailInsertImport(obj).then(res => {
  743. if (res.status == 200) {
  744. this.$refs.table.refresh(true)
  745. this.getOrderDetail(false)
  746. }
  747. this.spinning = false
  748. })
  749. },
  750. // 页面初始化
  751. pageInit () {
  752. const vm = this
  753. vm.$nextTick(() => {
  754. vm.orderId = vm.$route.params.id
  755. vm.salesBillSn = vm.$route.params.sn
  756. // 是否默认打印原厂编码
  757. vm.printOrgCode = localStorage.getItem('printOrgCode-' + this.$store.state.user.info.orgId) == 'true'
  758. vm.printAllName = localStorage.getItem('printAllName-' + this.$store.state.user.info.orgId) == 'true'
  759. // 获取销售单详情
  760. vm.getOrderDetail(true)
  761. vm.$refs.table.refresh(true)
  762. })
  763. }
  764. },
  765. watch: {
  766. // 是否打印产品原厂编码
  767. printOrgCode (newValue, oldValue) {
  768. localStorage.setItem('printOrgCode-' + this.$store.state.user.info.orgId, newValue)
  769. },
  770. // 是否打印产品全名称
  771. printAllName (newValue, oldValue) {
  772. localStorage.setItem('printAllName-' + this.$store.state.user.info.orgId, newValue)
  773. }
  774. },
  775. mounted () {
  776. this.showPage = true
  777. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  778. this.pageInit()
  779. }
  780. },
  781. activated () {
  782. this.showPage = true
  783. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  784. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  785. this.pageInit()
  786. }
  787. // 结算账户状态查询
  788. if (this.$hasPermissions('M_fundAccountList') && this.$hasPermissions('B_fundAccountEnable')) {
  789. this.GetSettleAccountState().then(res => {
  790. if (res.status == 200) {
  791. this.enableFundAccount = res.data.functionEnableFlag == 1
  792. }
  793. })
  794. }
  795. },
  796. beforeRouteEnter (to, from, next) {
  797. next(vm => {})
  798. }
  799. }
  800. </script>
  801. <style lang="less">
  802. .salesEdit-wrap{
  803. position: relative;
  804. height: 100%;
  805. box-sizing: border-box;
  806. >.ant-spin-nested-loading{
  807. overflow-y: auto;
  808. height: 100%;
  809. }
  810. .salesEdit-cont{
  811. margin-top: 6px;
  812. }
  813. .total-bar{
  814. display: flex;
  815. align-items: center;
  816. justify-content: space-between;
  817. > div{
  818. &:last-child{
  819. display: flex;
  820. align-items: center;
  821. justify-content: space-between;
  822. > div{
  823. padding: 0 10px;
  824. }
  825. }
  826. }
  827. }
  828. .redBg-row{
  829. background-color: #f5cdc8;
  830. }
  831. }
  832. </style>