edit.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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. @plAdd="plInsterProduct"
  222. :baseData="shelfInfo"
  223. :openModal="showShelfModal"
  224. @close="showShelfModal=false"></chooseShelfProduct>
  225. </div>
  226. </template>
  227. <script>
  228. import { commonMixin } from '@/utils/mixin'
  229. import { mapActions } from 'vuex'
  230. import { STable, VSelect } from '@/components'
  231. import queryPart from './queryPart.vue'
  232. import chooseCustomModal from './chooseCustomModal.vue'
  233. import importGuideModal from './importGuideModal.vue'
  234. import settleModal from '@/views/financialManagement/settleModal/settleModal.vue'
  235. import { stockByProductSn } from '@/api/stock'
  236. import { queryByCustomerSn } from '@/api/shelf'
  237. import { salesDetail, salesWriteSubmit, salesWriteDiscount, salesDetailPrint, salesDetailExport, salesDel } from '@/api/sales'
  238. import { salesDetailList, salesDetailInsert, salesDetailInsertBatch, salesDetailUpdatePrice, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll, salesDetailInsertImport } from '@/api/salesDetail'
  239. import outInDetialModal from '@/views/common/outInDetialModal.vue'
  240. import chooseShelfProduct from './chooseShelfProduct.vue'
  241. import Print from '@/views/common/print.vue'
  242. import { hdPrint } from '@/libs/JGPrint'
  243. export default {
  244. name: 'SalesEdit',
  245. components: { STable, VSelect, queryPart, chooseCustomModal, Print, importGuideModal, settleModal, outInDetialModal, chooseShelfProduct },
  246. mixins: [commonMixin],
  247. data () {
  248. return {
  249. showOutInModal: false, // 出入库明细
  250. showPage: false,
  251. spinning: false,
  252. orderId: null, // 销售单id
  253. salesBillSn: null, // 销售单sn
  254. disabled: false, // 查询、重置按钮是否可操作
  255. isInster: false, // 是否正在添加产品
  256. openModal: false, // 客户弹框
  257. openGuideModal: false, // 导入产品弹框
  258. openSettleModal: false, // 打开收款弹框
  259. enableFundAccount: false, // 是否开启资金账户管理
  260. showShelfModal: false, // 货架产品弹框
  261. delLoading: false,
  262. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  263. dataSource: [],
  264. productForm: {
  265. productName: '',
  266. productCode: '',
  267. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  268. },
  269. tbForm: [], // 同步操作
  270. printOrgCode: false, // 打印原创编码
  271. printAllName: false, // 打印全部名称
  272. // 加载数据方法 必须为 Promise 对象
  273. loadData: parameter => {
  274. this.disabled = true
  275. this.productForm.salesBillSn = this.$route.params.sn
  276. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  277. let data
  278. if (res.status == 200) {
  279. data = res.data
  280. const no = (data.pageNo - 1) * data.pageSize
  281. for (var i = 0; i < data.list.length; i++) {
  282. data.list[i].no = no + i + 1
  283. data.list[i].qtyBackups = data.list[i].qty
  284. data.list[i].priceBackups = data.list[i].price
  285. }
  286. this.disabled = false
  287. this.dataSource = data.list || []
  288. }
  289. return data
  290. })
  291. },
  292. printerType: 'NEEDLE', // 打印机类型
  293. isCosts: false, // 是否显示成本价
  294. shelfInfo: null // 是否有货架
  295. }
  296. },
  297. computed: {
  298. // 是否自建单据
  299. isOwerEdit () {
  300. return this.detailData && this.detailData.sourceType == 'SALES'
  301. },
  302. // 是否审核通过
  303. isAudit () {
  304. return this.detailData && (this.detailData.billStatus == 'WAIT_OUT_WAREHOUSE' || this.detailData.billStatus == 'FINISH')
  305. },
  306. columns () {
  307. const arr = [
  308. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  309. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '13%', scopedSlots: { customRender: 'productCode' }, align: 'center' },
  310. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '13%', align: 'center', scopedSlots: { customRender: 'productName' }, ellipsis: true },
  311. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  312. { title: '品牌', dataIndex: 'dealerProductEntity.productBrandName', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  313. // { title: '仓库', dataIndex: 'warehouseEntity.name', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  314. // { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  315. { title: '售价', dataIndex: 'price', scopedSlots: { customRender: 'price' }, width: '7%', align: 'center' },
  316. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: '7%', align: 'center' },
  317. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
  318. { title: '售价小计', dataIndex: 'totalAmount', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  319. { title: '折后小计', dataIndex: 'discountedAmount', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  320. { title: '操作', scopedSlots: { customRender: 'action' }, width: '7%', align: 'center' }
  321. ]
  322. // 下级创建,不显示仓库仓位
  323. if (!this.isOwerEdit) {
  324. arr.splice(5, 0, { title: '库存数量', dataIndex: 'currentStockQty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  325. } else {
  326. arr.splice(5, 0, { title: '仓库', dataIndex: 'warehouseEntity.name', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } })
  327. arr.splice(6, 0, { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: '8%', align: 'center', customRender: function (text) { return text || '--' } })
  328. }
  329. // 实际总成本
  330. if (this.isCosts) {
  331. arr.splice(!this.isOwerEdit ? 11 : 12, 0, { slots: { title: 'costTitle' }, dataIndex: 'totalCost', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  332. }
  333. return arr
  334. }
  335. },
  336. methods: {
  337. ...mapActions(['GetSettleAccountState']),
  338. // 打印预览/快捷打印
  339. handlePrint (type, printerType) {
  340. const _this = this
  341. _this.spinning = true
  342. let url = salesDetailPrint
  343. const params = { sn: this.outBizSn || this.$route.params.sn, printOrgCode: this.printOrgCode ? 1 : 0, printAllName: this.printAllName ? 1 : 0 }
  344. if (type == 'export') { // 导出
  345. url = salesDetailExport
  346. }
  347. // 打印或导出
  348. hdPrint(printerType, type, url, params, '销售单', function () {
  349. _this.spinning = false
  350. })
  351. },
  352. tbFormChange (e, val) {
  353. this.tbForm = []
  354. const tbTypes = ['AUDIT', 'STOCK_OUT', 'SETTLE']
  355. if (e.target.checked) {
  356. for (let i = val; i >= 0; i--) {
  357. this.tbForm.push(tbTypes[i])
  358. }
  359. } else {
  360. this.tbForm = []
  361. }
  362. },
  363. // 编辑客户信息
  364. handleEdit () {
  365. this.openModal = true
  366. this.$refs.custModal.editCust(this.detailData)
  367. },
  368. // 更新产品列表
  369. updateData (priceType) {
  370. // 价格类型变更
  371. if (priceType != this.$route.params.priceType) {
  372. this.$router.push({ name: 'salesEdit', params: { id: this.orderId, sn: this.salesBillSn, priceType: priceType } })
  373. } else {
  374. this.getOrderDetail(true)
  375. }
  376. },
  377. // 非下级创建的单据,修改数量时校验库存
  378. validStock (val, record) {
  379. const _this = this
  380. this.spinning = true
  381. // 校验库存
  382. stockByProductSn({ productSn: record.productSn }).then(res => {
  383. if (res.status == 200) {
  384. if (res.data && (!res.data.currentStockQty || val <= res.data.currentStockQty)) {
  385. _this.changeQty(record)
  386. } else {
  387. this.$confirm({
  388. title: '提示',
  389. content: '库存不足,确认添加为急件吗?',
  390. centered: true,
  391. closable: true,
  392. onOk () {
  393. _this.changeQty(record)
  394. },
  395. onCancel () {
  396. record.qty = record.qtyBackups
  397. _this.spinning = false
  398. }
  399. })
  400. }
  401. } else {
  402. this.spinning = false
  403. record.qty = record.qtyBackups
  404. }
  405. })
  406. },
  407. // 修改已选产品数量
  408. changeQty (record) {
  409. salesDetailUpdateQty({
  410. id: record.id,
  411. salesBillSn: record.salesBillSn,
  412. productSn: record.productSn,
  413. salesBillDetailSn: record.salesBillDetailSn,
  414. qty: record.qty,
  415. price: record.price
  416. }).then(res => {
  417. this.resetSearchForm(false)
  418. if (res.status == 200) {
  419. this.$message.info(res.message)
  420. }
  421. this.spinning = false
  422. })
  423. },
  424. // 已选产品 销售数量 input 输入框 blur
  425. qtyBlur (val, record) {
  426. this.dataSource = record || []
  427. if (val && val != record.qtyBackups) {
  428. // 自建的单据,修改数量时校验库存
  429. if (this.isOwerEdit) {
  430. this.validStock(val, record)
  431. } else {
  432. this.changeQty(record)
  433. }
  434. } else {
  435. record.qty = record.qtyBackups
  436. }
  437. },
  438. // 已选产品 售价 input 输入框 blur
  439. priceBlur (val, record) {
  440. this.dataSource = record || []
  441. // 光标移出,值发生改变再调用编辑接口
  442. if (val && val != record.priceBackups) {
  443. this.spinning = true
  444. salesDetailUpdatePrice({
  445. id: record.id,
  446. salesBillSn: record.salesBillSn,
  447. productSn: record.productSn,
  448. salesBillDetailSn: record.salesBillDetailSn,
  449. qty: record.qty,
  450. price: record.price
  451. }).then(res => {
  452. this.resetSearchForm(false)
  453. if (res.status == 200) {
  454. this.$message.info(res.message)
  455. this.spinning = false
  456. } else {
  457. this.spinning = false
  458. }
  459. })
  460. } else {
  461. record.price = record.priceBackups
  462. }
  463. },
  464. isCost (val) {
  465. this.isCosts = val
  466. },
  467. // 重置
  468. resetSearchForm (flag) {
  469. if (flag) { this.$refs.partQuery.onlyList = true }
  470. this.$refs.table.refresh(!!flag)
  471. this.getOrderDetail(false)
  472. },
  473. // 重置列表
  474. resetForm () {
  475. this.productForm = {
  476. productName: '',
  477. productCode: '',
  478. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  479. }
  480. this.$refs.table.refresh()
  481. },
  482. // 返回
  483. handleBack () {
  484. this.$router.push({ path: '/salesManagement/salesQuery/list' })
  485. },
  486. // 打折
  487. salesDiscount () {
  488. this.spinning = true
  489. salesWriteDiscount({
  490. discountAmount: this.detailData.discountAmount || 0,
  491. salesBillSn: this.detailData.salesBillSn,
  492. id: this.detailData.id
  493. }).then(res => {
  494. if (res.status == 200) {
  495. this.resetSearchForm(true)
  496. this.spinning = false
  497. } else {
  498. this.spinning = false
  499. }
  500. })
  501. },
  502. // 删除销售单
  503. delSalerOrder () {
  504. const _this = this
  505. this.$confirm({
  506. title: '提示',
  507. content: '确认删除该销售单吗?',
  508. centered: true,
  509. closable: true,
  510. onOk () {
  511. _this.spinning = true
  512. salesDel({ id: _this.orderId }).then(res => {
  513. if (res.status == 200) {
  514. _this.$message.success(res.message)
  515. _this.handleBack()
  516. }
  517. _this.spinning = false
  518. })
  519. }
  520. })
  521. },
  522. // 删除已选产品
  523. delSalerDetailAll () {
  524. const _this = this
  525. this.$confirm({
  526. title: '提示',
  527. content: '确认要整单删除吗?',
  528. centered: true,
  529. closable: true,
  530. onOk () {
  531. _this.delLoading = true
  532. _this.spinning = true
  533. salesDetailDelAll({ salesBillSn: _this.detailData.salesBillSn }).then(res => {
  534. if (res.status == 200) {
  535. _this.resetSearchForm(true)
  536. _this.productForm = {
  537. productName: '',
  538. productCode: '',
  539. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  540. }
  541. }
  542. _this.$message.info(res.message)
  543. _this.delLoading = false
  544. _this.spinning = false
  545. })
  546. }
  547. })
  548. },
  549. // 出入库明细
  550. handleViewDetail (row) {
  551. this.showOutInModal = true
  552. this.$refs.outInDetialModal.getData(row)
  553. },
  554. // 删除产品
  555. handleDel (row) {
  556. const _this = this
  557. this.$confirm({
  558. title: '提示',
  559. content: '确认要删除吗?',
  560. centered: true,
  561. closable: true,
  562. onOk () {
  563. _this.delLoading = true
  564. _this.spinning = true
  565. salesDetailDel({ id: row.id }).then(res => {
  566. if (res.status == 200) {
  567. _this.resetSearchForm(false)
  568. }
  569. _this.$message.info(res.message)
  570. _this.delLoading = false
  571. _this.spinning = false
  572. })
  573. }
  574. })
  575. },
  576. // 添加产品
  577. insterProduct (row) {
  578. // 防止多次添加产品
  579. if (this.isInster) { return }
  580. const _this = this
  581. // 判断是否已添加此产品
  582. if (this.dataSource && this.dataSource.length > 0) {
  583. const hasRow = this.dataSource.find(item => item.productSn == row.productSn)
  584. if (hasRow) {
  585. this.$message.info('该产品已在当前销售单中存在!')
  586. this.productForm = {
  587. productName: '',
  588. productCode: hasRow.dealerProductEntity && hasRow.dealerProductEntity.code || '',
  589. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  590. }
  591. this.$refs.table.refresh(true)
  592. return
  593. } else {
  594. this.productForm = {
  595. productName: '',
  596. productCode: '',
  597. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  598. }
  599. }
  600. }
  601. // 自建的单据显示库存不足时
  602. if (row.currentQty < row.salesNums && this.isOwerEdit) {
  603. _this.$confirm({
  604. title: '提示',
  605. content: '库存不足,确认添加为急件吗?',
  606. centered: true,
  607. closable: true,
  608. onOk () {
  609. _this.isPutCostDyPrice(row)
  610. }
  611. })
  612. } else {
  613. _this.isPutCostDyPrice(row)
  614. }
  615. },
  616. // 判断售价低于成本价
  617. isPutCostDyPrice (row) {
  618. const _this = this
  619. if (row.putCost > row.price) {
  620. // 销售价低于成本价
  621. _this.$confirm({
  622. title: '提示',
  623. content: '售价低于成本价,确认要添加吗?',
  624. centered: true,
  625. closable: true,
  626. onOk () {
  627. _this.saveNewProduct(row)
  628. }
  629. })
  630. } else {
  631. _this.saveNewProduct(row)
  632. }
  633. },
  634. // 保存添加的产品到销售列表
  635. saveNewProduct (row) {
  636. this.$message.loading('正在添加产品...', 1)
  637. this.isInster = true
  638. // this.spinning = true
  639. salesDetailInsert({
  640. buyerSn: this.detailData.buyerSn,
  641. productSn: row.productSn,
  642. cost: row.putCost,
  643. // productCode: row.productCode,
  644. // productOrigCode: row.productOrigCode,
  645. price: row.price,
  646. qty: row.salesNums,
  647. salesBillSn: this.detailData.salesBillSn,
  648. salesBillNo: this.detailData.salesBillNo,
  649. warehouseSn: row.warehouseSn,
  650. warehouseLocationSn: row.warehouseLocationSn,
  651. stockSn: row.stockSn
  652. }).then(res => {
  653. if (res.status == 200) {
  654. // this.resetSearchForm(true) // 不刷新库存
  655. this.$refs.table.refresh(true)
  656. this.getOrderDetail(false)
  657. if (this.showShelfModal) {
  658. this.$refs.chooseShelfProduct.reload()
  659. }
  660. }
  661. this.isInster = false
  662. // this.spinning = false
  663. })
  664. },
  665. // 批量添加接口
  666. plInsterProduct (list) {
  667. const params = []
  668. list.map(item => {
  669. params.push({
  670. buyerSn: this.detailData.buyerSn,
  671. productSn: item.productSn,
  672. cost: item.putCost,
  673. price: item.price,
  674. qty: item.salesNums,
  675. salesBillSn: this.detailData.salesBillSn,
  676. salesBillNo: this.detailData.salesBillNo,
  677. stockSn: item.stockSn
  678. })
  679. })
  680. this.$message.loading('正在批量添加产品...', 1)
  681. salesDetailInsertBatch(params).then(res => {
  682. if (res.status == 200) {
  683. this.$refs.table.refresh(true)
  684. this.getOrderDetail(false)
  685. if (this.showShelfModal) {
  686. this.$refs.chooseShelfProduct.reload()
  687. }
  688. }
  689. })
  690. },
  691. // 销售单详情
  692. getOrderDetail (flag) {
  693. salesDetail({ id: this.$route.params.id }).then(res => {
  694. if (res.status == 200) {
  695. this.detailData = res.data
  696. if (flag) {
  697. const vm = this
  698. const buyerSn = (vm.detailData && vm.detailData.buyerSn && vm.detailData.sourceType && vm.detailData.sourceType == 'PURCHASE') ? '' : vm.detailData.buyerSn
  699. const priceType = vm.$route.params.priceType
  700. vm.$refs.partQuery.pageInit(buyerSn, priceType, vm.salesBillSn)
  701. // 查询关联的客户
  702. if (vm.detailData && vm.detailData.buyerSn) {
  703. this.getShelfQueryByCustomer()
  704. }
  705. }
  706. }
  707. })
  708. },
  709. getShelfQueryByCustomer () {
  710. queryByCustomerSn({ sn: this.detailData.buyerSn }).then(res => {
  711. this.shelfInfo = Object.assign(res.data, { salePriceType: this.$route.params.priceType, salesBillSn: this.salesBillSn })
  712. })
  713. },
  714. // 提交销售单
  715. handleSubmit (params) {
  716. this.spinning = true
  717. const submitTypes = this.tbForm.join(',')
  718. salesWriteSubmit({ id: this.orderId, submitTypes: submitTypes, ...params }).then(res => {
  719. console.log(res)
  720. if (res.status == 200) {
  721. this.handleBack()
  722. this.$message.success(res.message)
  723. // this.spinning = false
  724. } else {
  725. this.spinning = false
  726. }
  727. })
  728. },
  729. // 开启结算账户功能收款, type:0 单条收款,1 批量收款
  730. handleSettleAcountPay (row, type) {
  731. this.openSettleModal = true
  732. const data = {
  733. totalAmount: this.detailData.discountedAmount,
  734. settleClientName: '',
  735. title: '收款',
  736. type,
  737. row
  738. }
  739. this.$nextTick(() => {
  740. this.$refs.settleModal.setData(data)
  741. })
  742. },
  743. // 去收款
  744. settleAcountPay (form, data) {
  745. const params = {}
  746. // 资金管理开启
  747. if (this.enableFundAccount) {
  748. params.settleStyleSn = form.settleStyleSn
  749. params.settleAccountSn = form.settleAccountSn
  750. }
  751. this.spinning = true
  752. this.handleSubmit(params)
  753. },
  754. // 确认导入明细
  755. hanldeImprotOk (obj) {
  756. this.spinning = true
  757. salesDetailInsertImport(obj).then(res => {
  758. if (res.status == 200) {
  759. this.$refs.table.refresh(true)
  760. this.getOrderDetail(false)
  761. }
  762. this.spinning = false
  763. })
  764. },
  765. pageInit () {
  766. const vm = this
  767. vm.$nextTick(() => {
  768. vm.orderId = vm.$route.params.id
  769. vm.salesBillSn = vm.$route.params.sn
  770. // 是否默认打印原厂编码
  771. vm.printOrgCode = localStorage.getItem('printOrgCode-' + this.$store.state.user.info.orgId) == 'true'
  772. vm.printAllName = localStorage.getItem('printAllName-' + this.$store.state.user.info.orgId) == 'true'
  773. vm.getOrderDetail(true)
  774. vm.$refs.table.refresh(true)
  775. })
  776. }
  777. },
  778. watch: {
  779. printOrgCode (newValue, oldValue) {
  780. localStorage.setItem('printOrgCode-' + this.$store.state.user.info.orgId, newValue)
  781. },
  782. printAllName (newValue, oldValue) {
  783. localStorage.setItem('printAllName-' + this.$store.state.user.info.orgId, newValue)
  784. }
  785. },
  786. mounted () {
  787. this.showPage = true
  788. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  789. this.pageInit()
  790. }
  791. },
  792. activated () {
  793. this.showPage = true
  794. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  795. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  796. this.pageInit()
  797. }
  798. // 结算账户状态查询
  799. if (this.$hasPermissions('M_fundAccountList') && this.$hasPermissions('B_fundAccountEnable')) {
  800. this.GetSettleAccountState().then(res => {
  801. if (res.status == 200) {
  802. this.enableFundAccount = res.data.functionEnableFlag == 1
  803. }
  804. })
  805. }
  806. },
  807. deactivated () {
  808. // this.dataSource = []
  809. // this.showPage = false
  810. },
  811. beforeRouteEnter (to, from, next) {
  812. next(vm => {})
  813. }
  814. }
  815. </script>
  816. <style lang="less">
  817. .salesEdit-wrap{
  818. position: relative;
  819. height: 100%;
  820. box-sizing: border-box;
  821. >.ant-spin-nested-loading{
  822. overflow-y: auto;
  823. height: 100%;
  824. }
  825. .salesEdit-cont{
  826. margin-top: 10px;
  827. }
  828. .total-bar{
  829. display: flex;
  830. align-items: center;
  831. justify-content: space-between;
  832. > div{
  833. &:last-child{
  834. display: flex;
  835. align-items: center;
  836. justify-content: space-between;
  837. > div{
  838. padding: 0 10px;
  839. }
  840. }
  841. }
  842. }
  843. .redBg-row{
  844. background-color: #f5cdc8;
  845. }
  846. }
  847. </style>