edit.vue 33 KB

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