edit.vue 32 KB

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