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" :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 './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. if (this.isCosts) {
  288. arr.splice(7, 0, { slots: { title: 'costTitle' }, dataIndex: 'cost', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  289. }
  290. return arr
  291. }
  292. },
  293. methods: {
  294. ...mapActions(['GetSettleAccountState']),
  295. // 打印预览/快捷打印
  296. handlePrint (type, printerType) {
  297. const _this = this
  298. _this.spinning = true
  299. let url = salesDetailPrint
  300. const params = { sn: this.outBizSn || this.$route.params.sn, printOrgCode: this.printOrgCode ? 1 : 0 }
  301. if (type == 'export') { // 导出
  302. url = salesDetailExport
  303. }
  304. // 打印或导出
  305. hdPrint(printerType, type, url, params, '销售单', function () {
  306. _this.spinning = false
  307. })
  308. },
  309. tbFormChange (e, val) {
  310. this.tbForm = []
  311. const tbTypes = ['AUDIT', 'STOCK_OUT', 'SETTLE']
  312. if (e.target.checked) {
  313. for (let i = val; i >= 0; i--) {
  314. this.tbForm.push(tbTypes[i])
  315. }
  316. } else {
  317. this.tbForm = []
  318. }
  319. },
  320. // 编辑客户信息
  321. handleEdit () {
  322. this.openModal = true
  323. this.$refs.custModal.editCust(this.detailData)
  324. },
  325. // 更新产品列表
  326. updateData (priceType) {
  327. // 价格类型变更
  328. if (priceType != this.$route.params.priceType) {
  329. this.$router.push({ name: 'salesEdit', params: { id: this.orderId, sn: this.salesBillSn, priceType: priceType } })
  330. } else {
  331. this.getOrderDetail(true)
  332. }
  333. },
  334. // 非下级创建的单据,修改数量时校验库存
  335. validStock (val, record) {
  336. const _this = this
  337. this.spinning = true
  338. // 校验库存
  339. stockByProductSn({ productSn: record.productSn }).then(res => {
  340. if (res.status == 200) {
  341. if (res.data && (!res.data.currentStockQty || val <= res.data.currentStockQty)) {
  342. _this.changeQty(record)
  343. } else {
  344. this.$confirm({
  345. title: '提示',
  346. content: '库存不足,确认添加为急件吗?',
  347. centered: true,
  348. closable: true,
  349. onOk () {
  350. _this.changeQty(record)
  351. },
  352. onCancel () {
  353. record.qty = record.qtyBackups
  354. _this.spinning = false
  355. }
  356. })
  357. }
  358. } else {
  359. this.spinning = false
  360. record.qty = record.qtyBackups
  361. }
  362. })
  363. },
  364. // 修改已选产品数量
  365. changeQty (record) {
  366. salesDetailUpdateQty({
  367. id: record.id,
  368. salesBillSn: record.salesBillSn,
  369. productSn: record.productSn,
  370. salesBillDetailSn: record.salesBillDetailSn,
  371. qty: record.qty,
  372. price: record.price
  373. }).then(res => {
  374. this.resetSearchForm(false)
  375. if (res.status == 200) {
  376. this.$message.info(res.message)
  377. }
  378. this.spinning = false
  379. })
  380. },
  381. // 已选产品 销售数量 input 输入框 blur
  382. qtyBlur (val, record) {
  383. this.dataSource = record || []
  384. if (val && val != record.qtyBackups) {
  385. // 非下级创建的单据,修改数量时校验库存
  386. if (!this.isSuperEdit) {
  387. this.validStock(val, record)
  388. } else {
  389. this.changeQty(record)
  390. }
  391. } else {
  392. record.qty = record.qtyBackups
  393. }
  394. },
  395. // 已选产品 售价 input 输入框 blur
  396. priceBlur (val, record) {
  397. this.dataSource = record || []
  398. // 光标移出,值发生改变再调用编辑接口
  399. if (val && val != record.priceBackups) {
  400. this.spinning = true
  401. salesDetailUpdatePrice({
  402. id: record.id,
  403. salesBillSn: record.salesBillSn,
  404. productSn: record.productSn,
  405. salesBillDetailSn: record.salesBillDetailSn,
  406. qty: record.qty,
  407. price: record.price
  408. }).then(res => {
  409. this.resetSearchForm(false)
  410. if (res.status == 200) {
  411. this.$message.info(res.message)
  412. this.spinning = false
  413. } else {
  414. this.spinning = false
  415. }
  416. })
  417. } else {
  418. record.price = record.priceBackups
  419. }
  420. },
  421. isCost (val) {
  422. this.isCosts = val
  423. },
  424. // 重置
  425. resetSearchForm (flag) {
  426. if (flag) { this.$refs.partQuery.onlyList = true }
  427. this.$refs.table.refresh(!!flag)
  428. this.getOrderDetail(false)
  429. },
  430. // 重置列表
  431. resetForm () {
  432. this.productForm = {
  433. productName: '',
  434. productCode: '',
  435. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  436. }
  437. this.$refs.table.refresh()
  438. },
  439. // 返回
  440. handleBack () {
  441. this.$router.push({ path: '/salesManagement/salesQuery/list' })
  442. },
  443. // 打折
  444. salesDiscount () {
  445. if (this.detailData.discountAmount < 0) {
  446. return
  447. }
  448. this.spinning = true
  449. salesWriteDiscount({
  450. discountAmount: this.detailData.discountAmount,
  451. salesBillSn: this.detailData.salesBillSn,
  452. id: this.detailData.id
  453. }).then(res => {
  454. if (res.status == 200) {
  455. this.resetSearchForm(true)
  456. this.spinning = false
  457. } else {
  458. this.spinning = false
  459. }
  460. })
  461. },
  462. // 删除销售单
  463. delSalerOrder () {
  464. const _this = this
  465. this.$confirm({
  466. title: '提示',
  467. content: '确认删除该销售单吗?',
  468. centered: true,
  469. closable: true,
  470. onOk () {
  471. _this.spinning = true
  472. salesDel({ id: _this.orderId }).then(res => {
  473. if (res.status == 200) {
  474. _this.$message.success(res.message)
  475. _this.handleBack()
  476. }
  477. _this.spinning = false
  478. })
  479. }
  480. })
  481. },
  482. // 删除已选产品
  483. delSalerDetailAll () {
  484. const _this = this
  485. this.$confirm({
  486. title: '提示',
  487. content: '确认要整单删除吗?',
  488. centered: true,
  489. closable: true,
  490. onOk () {
  491. _this.delLoading = true
  492. _this.spinning = true
  493. salesDetailDelAll({ salesBillSn: _this.detailData.salesBillSn }).then(res => {
  494. if (res.status == 200) {
  495. _this.resetSearchForm(true)
  496. _this.productForm = {
  497. productName: '',
  498. productCode: '',
  499. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  500. }
  501. }
  502. _this.$message.info(res.message)
  503. _this.delLoading = false
  504. _this.spinning = false
  505. })
  506. }
  507. })
  508. },
  509. // 出入库明细
  510. handleViewDetail (row) {
  511. this.showOutInModal = true
  512. this.$refs.outInDetialModal.getData(row)
  513. },
  514. // 删除产品
  515. handleDel (row) {
  516. const _this = this
  517. this.$confirm({
  518. title: '提示',
  519. content: '确认要删除吗?',
  520. centered: true,
  521. closable: true,
  522. onOk () {
  523. _this.delLoading = true
  524. _this.spinning = true
  525. salesDetailDel({ id: row.id }).then(res => {
  526. if (res.status == 200) {
  527. _this.resetSearchForm(false)
  528. }
  529. _this.$message.info(res.message)
  530. _this.delLoading = false
  531. _this.spinning = false
  532. })
  533. }
  534. })
  535. },
  536. // 添加产品
  537. insterProduct (row) {
  538. // 防止多次添加产品
  539. if (this.isInster) { return }
  540. const _this = this
  541. // 判断是否已添加此产品
  542. if (this.dataSource && this.dataSource.length > 0) {
  543. const hasRow = this.dataSource.find(item => item.productSn == row.productSn)
  544. if (hasRow) {
  545. // this.$message.info('该产品已在当前销售单中存在!')
  546. this.productForm = {
  547. productName: '',
  548. productCode: hasRow.dealerProductEntity && hasRow.dealerProductEntity.code || '',
  549. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  550. }
  551. this.$refs.table.refresh(true)
  552. return
  553. } else {
  554. this.productForm = {
  555. productName: '',
  556. productCode: '',
  557. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  558. }
  559. }
  560. }
  561. // 库存不足时
  562. if (row.currentQty < row.salesNums && !this.isSuperEdit) {
  563. _this.$confirm({
  564. title: '提示',
  565. content: '库存不足,确认添加为急件吗?',
  566. centered: true,
  567. closable: true,
  568. onOk () {
  569. _this.isPutCostDyPrice(row)
  570. }
  571. })
  572. } else {
  573. _this.isPutCostDyPrice(row)
  574. }
  575. },
  576. // 判断售价低于成本价
  577. isPutCostDyPrice (row) {
  578. const _this = this
  579. if (row.putCost > row.price) {
  580. // 销售价低于成本价
  581. _this.$confirm({
  582. title: '提示',
  583. content: '售价低于成本价,确认要添加吗?',
  584. centered: true,
  585. closable: true,
  586. onOk () {
  587. _this.saveNewProduct(row)
  588. }
  589. })
  590. } else {
  591. _this.saveNewProduct(row)
  592. }
  593. },
  594. // 保存添加的产品到销售列表
  595. saveNewProduct (row) {
  596. this.$message.loading('正在添加产品...', 1)
  597. this.isInster = true
  598. // this.spinning = true
  599. salesDetailInsert({
  600. buyerSn: this.detailData.buyerSn,
  601. productSn: row.productSn,
  602. cost: row.putCost,
  603. // productCode: row.productCode,
  604. // productOrigCode: row.productOrigCode,
  605. price: row.price,
  606. qty: row.salesNums,
  607. salesBillSn: this.detailData.salesBillSn,
  608. salesBillNo: this.detailData.salesBillNo,
  609. warehouseSn: row.warehouseSn,
  610. warehouseLocationSn: row.warehouseLocationSn,
  611. stockSn: row.stockSn
  612. }).then(res => {
  613. if (res.status == 200) {
  614. // this.resetSearchForm(true) // 不刷新库存
  615. this.$refs.table.refresh(true)
  616. this.getOrderDetail(false)
  617. }
  618. this.isInster = false
  619. // this.spinning = false
  620. })
  621. },
  622. // 销售单详情
  623. getOrderDetail (flag) {
  624. salesDetail({ id: this.$route.params.id }).then(res => {
  625. if (res.status == 200) {
  626. this.detailData = res.data
  627. if (flag) {
  628. const vm = this
  629. const buyerSn = (vm.detailData && vm.detailData.buyerSn && vm.detailData.salesBillSource && vm.detailData.salesBillSource == 'PURCHASE') ? '' : vm.detailData.buyerSn
  630. const priceType = vm.$route.params.priceType
  631. vm.$refs.partQuery.pageInit(buyerSn, priceType)
  632. }
  633. }
  634. })
  635. },
  636. // 提交销售单
  637. handleSubmit (params) {
  638. this.spinning = true
  639. const submitTypes = this.tbForm.join(',')
  640. salesWriteSubmit({ id: this.orderId, submitTypes: submitTypes, ...params }).then(res => {
  641. console.log(res)
  642. if (res.status == 200) {
  643. this.handleBack()
  644. this.$message.success(res.message)
  645. // this.spinning = false
  646. } else {
  647. this.spinning = false
  648. }
  649. })
  650. },
  651. // 开启结算账户功能收款, type:0 单条收款,1 批量收款
  652. handleSettleAcountPay (row, type) {
  653. this.openSettleModal = true
  654. const data = {
  655. totalAmount: this.detailData.discountedAmount,
  656. settleClientName: '',
  657. title: '收款',
  658. type,
  659. row
  660. }
  661. this.$nextTick(() => {
  662. this.$refs.settleModal.setData(data)
  663. })
  664. },
  665. // 去收款
  666. settleAcountPay (form, data) {
  667. const params = {}
  668. // 资金管理开启
  669. if (this.enableFundAccount) {
  670. params.settleStyleSn = form.settleStyleSn
  671. params.settleAccountSn = form.settleAccountSn
  672. }
  673. this.spinning = true
  674. this.handleSubmit(params)
  675. },
  676. // 确认导入明细
  677. hanldeImprotOk (obj) {
  678. this.spinning = true
  679. salesDetailInsertImport(obj).then(res => {
  680. if (res.status == 200) {
  681. this.$refs.table.refresh(true)
  682. this.getOrderDetail(false)
  683. }
  684. this.spinning = false
  685. })
  686. },
  687. pageInit () {
  688. const vm = this
  689. vm.$nextTick(() => {
  690. vm.orderId = vm.$route.params.id
  691. vm.salesBillSn = vm.$route.params.sn
  692. // 是否默认打印原厂编码
  693. vm.printOrgCode = localStorage.getItem('printOrgCode-' + this.$store.state.user.info.orgId) == 'true'
  694. vm.getOrderDetail(true)
  695. vm.$refs.table.refresh(true)
  696. })
  697. }
  698. },
  699. watch: {
  700. printOrgCode (newValue, oldValue) {
  701. localStorage.setItem('printOrgCode-' + this.$store.state.user.info.orgId, newValue)
  702. }
  703. },
  704. mounted () {
  705. this.showPage = true
  706. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  707. this.pageInit()
  708. }
  709. },
  710. activated () {
  711. this.showPage = true
  712. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  713. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  714. this.pageInit()
  715. }
  716. // 结算账户状态查询
  717. if (this.$hasPermissions('M_fundAccountList') && this.$hasPermissions('B_fundAccountEnable')) {
  718. this.GetSettleAccountState().then(res => {
  719. if (res.status == 200) {
  720. this.enableFundAccount = res.data.functionEnableFlag == 1
  721. }
  722. })
  723. }
  724. },
  725. deactivated () {
  726. // this.dataSource = []
  727. // this.showPage = false
  728. },
  729. beforeRouteEnter (to, from, next) {
  730. next(vm => {})
  731. }
  732. }
  733. </script>
  734. <style lang="less">
  735. .salesEdit-wrap{
  736. position: relative;
  737. height: 100%;
  738. box-sizing: border-box;
  739. >.ant-spin-nested-loading{
  740. overflow-y: auto;
  741. height: 100%;
  742. }
  743. .salesEdit-cont{
  744. margin-top: 10px;
  745. }
  746. .total-bar{
  747. display: flex;
  748. align-items: center;
  749. justify-content: space-between;
  750. > div{
  751. &:last-child{
  752. display: flex;
  753. align-items: center;
  754. justify-content: space-between;
  755. > div{
  756. padding: 0 10px;
  757. }
  758. }
  759. }
  760. }
  761. .redBg-row{
  762. background-color: #f5cdc8;
  763. }
  764. }
  765. </style>