edit.vue 32 KB

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