edit.vue 32 KB

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