edit.vue 29 KB

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