edit.vue 33 KB

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