edit.vue 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. <template>
  2. <div v-if="showPage" class="jg-page-wrap salesEdit-news-wrap">
  3. <a-page-header :ghost="false" :backIcon="false" class="header-bar">
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a class="billno" style="margin-right:15px;">单号:{{ detailData&&detailData.salesBillNo || '--' }}</a>
  7. <a-tag color="green" v-if="detailData.billStatusDictValue">{{ detailData.billStatusDictValue }}</a-tag>
  8. <a-tag color="orange" v-if="detailData.financialStatusDictValue">{{ detailData.financialStatusDictValue }}</a-tag>
  9. <span style="margin-left: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. type="link"
  13. style="margin-left:10px"
  14. v-if="detailData&&detailData.salesTragetType != 'DEALER'"
  15. size="small"
  16. class="button-info"
  17. @click="handleEdit"
  18. key="0"><a-icon type="edit" /> 编辑</a-button>
  19. <a-button id="purchaseNewOrderEdit-back-btn" type="link" @click="handleBack" class="button-default"> <a-icon type="rollback" /> 返回列表</a-button>
  20. </template>
  21. <!-- 操作区,位于 title 行的行尾 -->
  22. <template slot="extra" v-if="$hasPermissions('B_salesPrint')">
  23. <div style="margin-top: 5px;">
  24. <PrintPanel ref="printBox" :disabled="dataSource.length==0" @handlePrint="handlePrint">
  25. <div style="padding:10px;" slot="extendCons">
  26. <a-checkbox v-model="printAllName" :checked="printAllName" id="salesQuery-printAllName">打印完整产品名称</a-checkbox>
  27. <a-checkbox v-model="printOrgCode" :checked="printOrgCode" id="salesQuery-printOrgCode">打印原厂编码</a-checkbox>
  28. <a-checkbox v-model="printPrice" :checked="printPrice" id="salesQuery-printPrice">打印售价</a-checkbox>
  29. <a-checkbox v-model="printRemarks" :checked="printRemarks" id="salesQuery-printRemarks">打印备注</a-checkbox>
  30. </div>
  31. </PrintPanel>
  32. <a-divider type="vertical" v-if="detailData&&detailData.totalCategory" />
  33. <a-button type="link" v-if="detailData&&detailData.totalCategory" @click="showSearch=!showSearch" :class="showSearch?'button-error':'button-default'"> <a-icon type="search" /> 筛选</a-button>
  34. <a-divider type="vertical" v-if="detailData&&detailData.totalCategory" />
  35. <a-button v-if="detailData&&detailData.totalCategory" id="salesNewOrderEdit-add-btn" type="link" @click="openChooseProduct=true"><a-icon type="plus" />添加产品</a-button>
  36. <a-divider type="vertical" v-if="detailData&&detailData.totalCategory" />
  37. <a-dropdown v-model="showCell" v-if="$hasPermissions('M_ShowAllCost')&&detailData&&detailData.totalCategory">
  38. <a-button type="link" class="button-default"> <a-icon type="setting" /> 显示</a-button>
  39. <a-menu slot="overlay">
  40. <a-menu-item>
  41. <a-checkbox v-model="isCosts" id="salesQuery-edit-cost">成本价</a-checkbox>
  42. </a-menu-item>
  43. </a-menu>
  44. </a-dropdown>
  45. <a-divider type="vertical" v-if="$hasPermissions('M_ShowAllCost')"/>
  46. <a-dropdown>
  47. <a-menu slot="overlay" @click="handleActions">
  48. <a-menu-item key="4">
  49. <a-icon type="import" />导入产品
  50. </a-menu-item>
  51. <a-menu-item key="3" v-if="shelfInfo&&shelfInfo.state=='ENABLE'">
  52. <a-icon type="hdd"/>货架产品
  53. </a-menu-item>
  54. <a-menu-item key="2">
  55. <a-icon type="close-square"/>清空列表
  56. </a-menu-item>
  57. <a-menu-item key="1">
  58. <a-icon type="rest" style="font-size: 14px;" />{{ isOwerEdit?'删除急件':'删除缺货' }}
  59. </a-menu-item>
  60. </a-menu>
  61. <a-button type="link" class="button-default"> <a-icon type="unordered-list" /> 更多</a-button>
  62. </a-dropdown>
  63. </div>
  64. </template>
  65. </a-page-header>
  66. <!-- 已选产品 -->
  67. <div class="choosedList-cont">
  68. <div class="choosed-table" v-if="detailData&&detailData.totalCategory">
  69. <!-- 搜索条件 -->
  70. <div class="table-page-search-wrapper" style="margin-bottom:0;" v-if="showSearch">
  71. <a-form-model :model="productForm" ref="ruleForm" layout="inline" @keyup.enter.native="$refs.table.refresh(true)" >
  72. <a-row :gutter="10">
  73. <a-col :md="5" :sm="24">
  74. <a-form-model-item label="产品编码">
  75. <a-input v-model.trim="productForm.productCode" allowClear placeholder="输入产品编码" />
  76. </a-form-model-item>
  77. </a-col>
  78. <a-col :md="5" :sm="24">
  79. <a-form-model-item label="产品名称">
  80. <a-input v-model.trim="productForm.productName" allowClear placeholder="输入产品名称" />
  81. </a-form-model-item>
  82. </a-col>
  83. <a-col :md="4" :sm="24" v-if="isOwerEdit">
  84. <a-form-item label="是否为急件">
  85. <a-select allowClear v-model="productForm.oosFlag" placeholder="请选择是否">
  86. <a-select-option value="1">
  87. </a-select-option>
  88. <a-select-option value="0">
  89. </a-select-option>
  90. </a-select>
  91. </a-form-item>
  92. </a-col>
  93. <!-- <a-col :md="4" :sm="24" v-else>
  94. <a-form-item label="是否为缺货">
  95. <a-select allowClear v-model="productForm.oosFlag" placeholder="请选择是否">
  96. <a-select-option value="1">
  97. </a-select-option>
  98. <a-select-option value="0">
  99. </a-select-option>
  100. </a-select>
  101. </a-form-item>
  102. </a-col> -->
  103. <a-col :md="4" :sm="24">
  104. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesEdit-refresh">查询</a-button>
  105. <a-button style="margin-left: 5px" @click="resetForm" id="salesEdit-reset">重置</a-button>
  106. </a-col>
  107. </a-row>
  108. </a-form-model>
  109. </div>
  110. <div class="discount-box">
  111. </div>
  112. <!-- 已选配件列表 -->
  113. <s-table
  114. class="sTable"
  115. ref="table"
  116. size="small"
  117. :rowKey="(record) => record.id"
  118. :columns="columns"
  119. :data="loadData"
  120. :scroll="{ y: tableHeight }"
  121. :defaultLoadData="false"
  122. :pageSize="30"
  123. bordered>
  124. <div slot="costTitle">
  125. <a-tooltip placement="top">
  126. <template slot="title">
  127. 系统中不同批次的产品,成本价可能不同,此值是按照实际出库批次的成本计算得到。
  128. </template>
  129. <span style="margin-right: 5px;">实际总成本</span> <a-icon type="question-circle" />
  130. </a-tooltip>
  131. </div>
  132. <!-- 产品名称 -->
  133. <template slot="productName" slot-scope="text, record">
  134. <a-tag color="blue" v-if="record.shelfPlaceCode">{{ record.shelfPlaceCode }}</a-tag>
  135. <span :title="text">{{ text }}</span>
  136. </template>
  137. <!-- 产品编码 -->
  138. <template slot="productCode" slot-scope="text, record">
  139. <div v-if="detailData">
  140. <div v-if="isOwerEdit">
  141. <a-badge count="急" v-if="record.oosFlag == 1">
  142. <div style="padding-right: 15px;">{{ text }}</div>
  143. </a-badge>
  144. <span v-else>{{ text }}</span>
  145. </div>
  146. <div v-else>
  147. <a-badge count="急" v-if="isAudit&&record.oosFlag == 1">
  148. <div style="padding-right: 15px;">{{ text }}</div>
  149. </a-badge>
  150. <a-badge count="缺" v-else-if="!isAudit&&(!record.currentStockQty || record.currentStockQty < record.qty)">
  151. <div style="padding-right: 15px;">{{ text }}</div>
  152. </a-badge>
  153. <span v-else>{{ text }}</span>
  154. </div>
  155. </div>
  156. </template>
  157. <!-- 售价 -->
  158. <template slot="price" slot-scope="text, record">
  159. <div style="display:flex;align-items: center;" :class="record.cost > record.price?'redBg-row':''">
  160. <div v-if="record.cost > record.price">
  161. <a-tooltip placement="top">
  162. <template slot="title">
  163. 售价低于成本价
  164. </template>
  165. <a-icon type="warning" />
  166. </a-tooltip>
  167. </div>
  168. <a-input-number
  169. size="small"
  170. v-model="record.price"
  171. :precision="2"
  172. :min="0"
  173. :max="999999"
  174. placeholder="请输入"
  175. @blur="e => priceBlur(e.target.value, record)"
  176. style="flex-grow: 1;margin-left: 3px;text-align: right;"
  177. />
  178. </div>
  179. </template>
  180. <!-- 销售数量 -->
  181. <template slot="salesNums" slot-scope="text, record">
  182. <a-input-number
  183. id="salesEdit-salesNums"
  184. size="small"
  185. v-model="record.qty"
  186. :precision="0"
  187. :min="1"
  188. :max="999999"
  189. placeholder="请输入"
  190. @blur="e => qtyBlur(e.target.value, record)"
  191. style="width: 100%;" />
  192. </template>
  193. <!-- 操作 -->
  194. <template slot="action" slot-scope="text, record">
  195. <a-button size="small" v-if="record.oosFlag == 0" type="link" class="button-primary" @click="handleViewDetail(record)">出库明细</a-button>
  196. <a-button
  197. size="small"
  198. type="link"
  199. :loading="delLoading"
  200. class="button-error"
  201. @click="handleDel(record)"
  202. id="productInfoList-Del">删除</a-button>
  203. </template>
  204. </s-table>
  205. </div>
  206. <div class="choosed-table" v-else>
  207. <div v-if="!spinning&&detailData.totalCategory==0">
  208. <a-empty
  209. :image="simpleImage"
  210. :image-style="{
  211. height: '60px',
  212. }"
  213. >
  214. <span slot="description"> 暂无产品 </span>
  215. <a-button type="primary" class="button-error" @click="openChooseProduct=true"><a-icon type="plus" />立即添加产品</a-button>
  216. </a-empty>
  217. </div>
  218. <div style="text-align: center;padding: 30px 50px;" v-if="spinning">
  219. <a-spin :spinning="spinning" tip="Loading..."></a-spin>
  220. </div>
  221. </div>
  222. <!-- 底部栏 -->
  223. <div class="footer-bar" v-if="detailData&&detailData.totalCategory">
  224. <!-- 总计 -->
  225. <div v-if="detailData" class="total-bar">
  226. <div>
  227. 总款数:<span>{{ detailData&&(detailData.totalCategory || detailData.totalCategory==0) ? detailData.totalCategory : '--' }}</span>,
  228. 总数量:<span>{{ detailData&&(detailData.totalQty || detailData.totalQty==0) ? detailData.totalQty : '--' }}</span>,
  229. 赠品总数量:<span>{{ detailData&&(detailData.giftQty || detailData.giftQty==0) ? detailData.giftQty : '--' }}</span>,
  230. <template v-if="isCosts">
  231. 总成本价:<span class="red">{{ detailData&&(detailData.totalCost || detailData.totalCost==0) ? toThousands(detailData.totalCost) : '--' }}</span>,
  232. 毛利:<span class="red">{{ detailData&&(detailData.grossProfit || detailData.grossProfit==0) ? toThousands(detailData.grossProfit) : '--' }}</span>,
  233. </template>
  234. <div style="display: inline-block;">
  235. 总售价:<span class="red">{{ detailData&&(detailData.totalAmount || detailData.totalAmount==0) ? toThousands(detailData.totalAmount) : '--' }}</span>
  236. </div>
  237. </div>
  238. <div>
  239. <div style="display: inline-block;">
  240. 折扣金额:
  241. <a-input-number
  242. id="discount"
  243. size="small"
  244. v-model.trim="detailData.discountAmount"
  245. @blur="salesDiscount"
  246. :min="0"
  247. :precision="2"
  248. :max="999999"/>
  249. 折扣:<span class="red">{{ detailData&&(detailData.discountRate || detailData.discountRate==0) ? detailData.discountRate+'%' : '--' }}</span>,
  250. </div>
  251. <div class="totalPrice" style="display: inline-block;padding:0;">
  252. 折后合计:<strong>{{ detailData&&(detailData.discountedAmount || detailData.discountedAmount==0) ? toThousands(detailData.discountedAmount) : '--' }}</strong>
  253. </div>
  254. </div>
  255. </div>
  256. <div>
  257. <a-dropdown>
  258. <a-menu slot="overlay">
  259. <a-menu-item key="1"> <a-checkbox :value="0" :checked="tbForm.indexOf('AUDIT')>=0" @change="(e)=>{tbFormChange(e,0)}" id="salesQuery-tbsh">同步审核</a-checkbox> </a-menu-item>
  260. <a-menu-item key="2"> <a-checkbox :value="1" :checked="tbForm.indexOf('STOCK_OUT')>=0" @change="(e)=>{tbFormChange(e,1)}" id="salesQuery-tbck">同步出库</a-checkbox> </a-menu-item>
  261. <a-menu-item key="3"> <a-checkbox :value="2" :checked="tbForm.indexOf('SETTLE')>=0" @change="(e)=>{tbFormChange(e,2)}" id="salesQuery-tbsk">同步收款</a-checkbox></a-menu-item>
  262. </a-menu>
  263. <a-button style="margin-left: 8px" size="large"> 选择同步操作 <a-icon type="down" /> </a-button>
  264. </a-dropdown>
  265. </div>
  266. <div>
  267. <a-button
  268. type="primary"
  269. id="salesEdit-handleSubmit"
  270. size="large"
  271. class="button-primary"
  272. :loading="spinning"
  273. @click="enableFundAccount && tbForm.length == 3 ? handleSettleAcountPay(null,0) : handleSubmit({})"
  274. style="padding: 0 60px;">提交</a-button>
  275. </div>
  276. </div>
  277. </div>
  278. <!-- 选择客户弹框 -->
  279. <choose-custom-modal ref="custModal" :show="openModal" @updateData="updateData" @cancel="openModal=false" />
  280. <!-- 导入产品 -->
  281. <importGuideModal
  282. :openModal="openGuideModal"
  283. :params="{salesBillSn: $route.params.sn, salesBillNo:detailData?detailData.salesBillNo:''}"
  284. @close="openGuideModal=false"
  285. @ok="hanldeImprotOk"></importGuideModal>
  286. <!-- 收付款弹框 -->
  287. <settleModal ref="settleModal" @ok="settleAcountPay" :openModal="openSettleModal" @close="openSettleModal=false"></settleModal>
  288. <!-- 出库明细 -->
  289. <outInDetialModal ref="outInDetialModal" outBizType="SALES" :openModal="showOutInModal" @close="showOutInModal=false"></outInDetialModal>
  290. <!-- 销售记录 -->
  291. <product-salesRecord-modal ref="salseRecord" :openModal="openSalesRecordModal" @close="openSalesRecordModal=false" />
  292. <!-- 添加产品 -->
  293. <chooseProductModal
  294. ref="partQuery"
  295. :newLoading="isInster"
  296. :showModal="openChooseProduct"
  297. :checkedList="checkedProductList"
  298. @viewRecord="hanldSalesRecord"
  299. @close="openChooseProduct=false"
  300. @add="insterProduct"
  301. ></chooseProductModal>
  302. <!-- 选择货架产品 -->
  303. <chooseShelfProduct
  304. v-if="showShelfModal"
  305. ref="chooseShelfProduct"
  306. @viewRecord="hanldSalesRecord"
  307. @add="insterProduct"
  308. @plAdd="plInsterProduct"
  309. :baseData="shelfInfo"
  310. :openModal="showShelfModal"
  311. @close="showShelfModal=false"></chooseShelfProduct>
  312. </div>
  313. </template>
  314. <script>
  315. import { commonMixin } from '@/utils/mixin'
  316. import { mapActions } from 'vuex'
  317. import { Empty } from 'ant-design-vue'
  318. import { STable, VSelect } from '@/components'
  319. import chooseProductModal from './chooseProductModal.vue'
  320. import chooseCustomModal from './chooseCustomModal.vue'
  321. import importGuideModal from './importGuideModal.vue'
  322. import settleModal from '@/views/financialManagement/settleModal/settleModal.vue'
  323. import productSalesRecordModal from './productSalesRecordModal.vue'
  324. import { stockByProductSn } from '@/api/stock'
  325. import { queryByCustomerSn } from '@/api/shelf'
  326. import { salesDetail, salesWriteSubmit, salesWriteDiscount, salesDetailPrint, salesDetailExport, salesDel } from '@/api/sales'
  327. import { salesDetailList, salesDetailInsert, salesDetailInsertBatch, salesDetailUpdatePrice, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll, salesDetailInsertImport, queryCheckedList } from '@/api/salesDetail'
  328. import outInDetialModal from './outInDetialModal.vue'
  329. import chooseShelfProduct from './chooseShelfProduct.vue'
  330. import PrintPanel from '@/views/common/printPanel.vue'
  331. import { hdPrint } from '@/libs/JGPrint'
  332. export default {
  333. name: 'SalesEdit',
  334. components: { STable, VSelect, chooseProductModal, chooseCustomModal, PrintPanel, importGuideModal, settleModal, outInDetialModal, chooseShelfProduct, productSalesRecordModal },
  335. mixins: [commonMixin],
  336. data () {
  337. return {
  338. simpleImage: Empty.PRESENTED_IMAGE_SIMPLE,
  339. tableHeight: 0,
  340. showOutInModal: false, // 出入库明细
  341. showCell: false,
  342. showPage: false,
  343. spinning: false,
  344. showSearch: false,
  345. openChooseProduct: false,
  346. orderId: null, // 销售单id
  347. salesBillSn: null, // 销售单sn
  348. disabled: false, // 查询、重置按钮是否可操作
  349. isInster: false, // 是否正在添加产品
  350. openModal: false, // 客户弹框
  351. openSalesRecordModal: false, // 销售记录
  352. openGuideModal: false, // 导入产品弹框
  353. openSettleModal: false, // 打开收款弹框
  354. enableFundAccount: false, // 是否开启资金账户管理
  355. showShelfModal: false, // 货架产品弹框
  356. checkedProductList: [], // 已选所有产品
  357. delLoading: false,
  358. detailData: { discountAmount: 0, id: null, salesBillSn: '' }, // 订单基础数据
  359. dataSource: [],
  360. productForm: {
  361. productName: '',
  362. productCode: '',
  363. oosFlag: undefined,
  364. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  365. },
  366. tbForm: [], // 同步操作
  367. printOrgCode: false, // 打印原创编码
  368. printAllName: false, // 打印全部名称
  369. printRemarks: false, // 打印备注
  370. printPrice: false,
  371. // 加载数据方法 必须为 Promise 对象
  372. loadData: parameter => {
  373. this.disabled = true
  374. this.spinning = true
  375. this.productForm.salesBillSn = this.$route.params.sn
  376. this.getChoosedList({ salesBillSn: this.$route.params.sn })
  377. return salesDetailList(Object.assign(parameter, this.productForm)).then(res => {
  378. let data
  379. if (res.status == 200) {
  380. data = res.data
  381. const no = (data.pageNo - 1) * data.pageSize
  382. for (var i = 0; i < data.list.length; i++) {
  383. data.list[i].no = no + i + 1
  384. data.list[i].qtyBackups = data.list[i].qty
  385. data.list[i].priceBackups = data.list[i].price
  386. }
  387. this.disabled = false
  388. this.dataSource = data.list || []
  389. }
  390. this.spinning = false
  391. return data
  392. })
  393. },
  394. printerType: 'NEEDLE', // 打印机类型
  395. isCosts: false, // 是否显示成本价
  396. shelfInfo: null, // 是否有货架
  397. discountAmountBak: null
  398. }
  399. },
  400. computed: {
  401. // 是否自建单据
  402. isOwerEdit () {
  403. return this.detailData && this.detailData.sourceType == 'SALES'
  404. },
  405. // 是否审核通过
  406. isAudit () {
  407. return this.detailData && (this.detailData.billStatus == 'WAIT_OUT_WAREHOUSE' || this.detailData.billStatus == 'FINISH')
  408. },
  409. columns () {
  410. const _this = this
  411. const arr = [
  412. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  413. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '13%', scopedSlots: { customRender: 'productCode' }, align: 'center' },
  414. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '13%', align: 'center', scopedSlots: { customRender: 'productName' }, ellipsis: true },
  415. { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  416. { title: '品牌', dataIndex: 'dealerProductEntity.productBrandName', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  417. // { title: '仓库', dataIndex: 'warehouseEntity.name', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  418. // { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  419. { title: '售价', dataIndex: 'price', scopedSlots: { customRender: 'price' }, width: '7%', align: 'center' },
  420. { title: '销售数量', scopedSlots: { customRender: 'salesNums' }, width: '7%', align: 'center' },
  421. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
  422. { title: '售价小计', dataIndex: 'totalAmount', width: '5%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  423. { title: '折后小计', dataIndex: 'discountedAmount', width: '5%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  424. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  425. ]
  426. // 下级创建,不显示仓库仓位
  427. if (!this.isOwerEdit) {
  428. arr.splice(7, 0, { title: '库存数量', dataIndex: 'currentStockQty', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  429. } else {
  430. arr.splice(5, 0, { title: '仓库', dataIndex: 'warehouseEntity.name', width: '8%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } })
  431. arr.splice(6, 0, { title: '仓位', dataIndex: 'warehouseLocationEntity.name', width: '8%', align: 'center', customRender: function (text) { return text || '--' } })
  432. }
  433. // 实际总成本
  434. if (this.isCosts) {
  435. 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) : '--') } })
  436. }
  437. return arr
  438. }
  439. },
  440. methods: {
  441. ...mapActions(['GetSettleAccountState']),
  442. handleActions (e) {
  443. if (e.key == 4) {
  444. this.openGuideModal = true
  445. }
  446. if (e.key == 3) {
  447. this.showShelfModal = true
  448. }
  449. if (e.key == 2) { // 清空列表
  450. this.delSalerOrder()
  451. }
  452. if (e.key == 1) { // 删除急件
  453. this.delSalerOrder(this.isOwerEdit ? 1 : 2)
  454. }
  455. },
  456. // 打印预览/快捷打印
  457. handlePrint (type, printerType) {
  458. const _this = this
  459. _this.spinning = true
  460. let url = salesDetailPrint
  461. const params = {
  462. sn: this.outBizSn || this.$route.params.sn,
  463. printOrgCode: this.printOrgCode ? 1 : 0,
  464. printAllName: this.printAllName ? 1 : 0,
  465. remarksShowFlag: this.printRemarks ? 1 : 0,
  466. priceFlag: this.printPrice ? 1 : 0
  467. }
  468. if (type == 'export') { // 导出
  469. url = salesDetailExport
  470. }
  471. // 打印或导出
  472. hdPrint(printerType, type, url, params, '销售单', function () {
  473. _this.spinning = false
  474. _this.$refs.printBox.hovered = false
  475. })
  476. },
  477. tbFormChange (e, val) {
  478. this.tbForm = []
  479. const tbTypes = ['AUDIT', 'STOCK_OUT', 'SETTLE']
  480. if (e.target.checked) {
  481. for (let i = val; i >= 0; i--) {
  482. this.tbForm.push(tbTypes[i])
  483. }
  484. } else {
  485. this.tbForm = []
  486. }
  487. },
  488. // 编辑客户信息
  489. handleEdit () {
  490. this.openModal = true
  491. this.$refs.custModal.editCust(this.detailData)
  492. },
  493. // 查看销售记录
  494. hanldSalesRecord (row) {
  495. console.log(row)
  496. this.openSalesRecordModal = true
  497. this.$refs.salseRecord.getDetail(this.detailData.buyerSn, row.productSn, row)
  498. },
  499. // 查询已选所以产品
  500. getChoosedList (params) {
  501. this.isInster = true
  502. queryCheckedList(params).then(res => {
  503. this.checkedProductList = res.data || []
  504. this.isInster = false
  505. })
  506. },
  507. // 更新产品列表
  508. updateData (priceType) {
  509. // 价格类型变更
  510. if (priceType != this.$route.params.priceType) {
  511. this.getOrderDetail(true)
  512. this.$router.push({ name: 'salesNewEdit', params: { id: this.orderId, sn: this.salesBillSn, priceType: priceType } })
  513. } else {
  514. this.getOrderDetail(true)
  515. }
  516. },
  517. // 非下级创建的单据,修改数量时校验库存
  518. validStock (val, record) {
  519. const _this = this
  520. this.spinning = true
  521. // 校验库存
  522. stockByProductSn({ productSn: record.productSn }).then(res => {
  523. if (res.status == 200) {
  524. if (res.data && (!res.data.currentStockQty || val <= res.data.currentStockQty)) {
  525. _this.changeQty(record)
  526. } else {
  527. this.$confirm({
  528. title: '提示',
  529. content: '库存不足,确认添加为急件吗?',
  530. centered: true,
  531. closable: true,
  532. onOk () {
  533. _this.changeQty(record)
  534. },
  535. onCancel () {
  536. record.qty = record.qtyBackups
  537. _this.spinning = false
  538. }
  539. })
  540. }
  541. } else {
  542. this.spinning = false
  543. record.qty = record.qtyBackups
  544. }
  545. })
  546. },
  547. // 修改已选产品数量
  548. changeQty (record) {
  549. salesDetailUpdateQty({
  550. id: record.id,
  551. salesBillSn: record.salesBillSn,
  552. productSn: record.productSn,
  553. salesBillDetailSn: record.salesBillDetailSn,
  554. qty: record.qty,
  555. price: record.price
  556. }).then(res => {
  557. this.getOrderDetail(false, true)
  558. if (res.status == 200) {
  559. this.$message.info(res.message)
  560. }
  561. this.spinning = false
  562. })
  563. },
  564. // 已选产品 销售数量 input 输入框 blur
  565. qtyBlur (val, record) {
  566. this.dataSource = record || []
  567. if (val && val != record.qtyBackups) {
  568. // 自建的单据,修改数量时校验库存
  569. if (this.isOwerEdit) {
  570. this.validStock(val, record)
  571. } else {
  572. this.changeQty(record)
  573. }
  574. } else {
  575. record.qty = record.qtyBackups
  576. }
  577. },
  578. // 已选产品 售价 input 输入框 blur
  579. priceBlur (val, record) {
  580. this.dataSource = record || []
  581. // 光标移出,值发生改变再调用编辑接口
  582. if (val && val != record.priceBackups) {
  583. this.spinning = true
  584. salesDetailUpdatePrice({
  585. id: record.id,
  586. salesBillSn: record.salesBillSn,
  587. productSn: record.productSn,
  588. salesBillDetailSn: record.salesBillDetailSn,
  589. qty: record.qty,
  590. price: record.price
  591. }).then(res => {
  592. this.getOrderDetail(false, true)
  593. if (res.status == 200) {
  594. this.$message.info(res.message)
  595. this.spinning = false
  596. } else {
  597. this.spinning = false
  598. }
  599. })
  600. } else {
  601. record.price = record.priceBackups
  602. }
  603. },
  604. // 重置列表
  605. resetForm () {
  606. this.productForm = {
  607. productName: '',
  608. productCode: '',
  609. oosFlag: undefined,
  610. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  611. }
  612. this.$nextTick(() => {
  613. this.$refs.table.refresh()
  614. })
  615. },
  616. // 返回
  617. handleBack () {
  618. this.$router.push({ name: 'salesNewList' })
  619. },
  620. // 打折
  621. salesDiscount () {
  622. if (this.discountAmountBak == this.detailData.discountAmount) {
  623. return false
  624. }
  625. this.spinning = true
  626. salesWriteDiscount({
  627. discountAmount: this.detailData.discountAmount || 0,
  628. salesBillSn: this.detailData.salesBillSn,
  629. id: this.detailData.id
  630. }).then(res => {
  631. if (res.status == 200) {
  632. this.getOrderDetail(true)
  633. } else {
  634. this.spinning = false
  635. }
  636. })
  637. },
  638. // 清空已选产品
  639. delSalerOrder (flag) {
  640. const _this = this
  641. this.$confirm({
  642. title: '提示',
  643. content: !flag ? '确认要清空已选产品列表吗?' : (flag == 1 ? '确认要删除所有急件吗?删除后不可恢复。' : '确认要删除所有缺货吗?删除后不可恢复。'),
  644. centered: true,
  645. closable: true,
  646. onOk () {
  647. _this.spinning = true
  648. const params = { id: _this.orderId, oosFlag: !flag ? undefined : 1 }
  649. salesDel(params).then(res => {
  650. if (res.status == 200) {
  651. _this.getOrderDetail(true)
  652. if (!flag) {
  653. _this.dataSource = []
  654. }
  655. _this.$message.success(res.message)
  656. }
  657. _this.spinning = false
  658. })
  659. }
  660. })
  661. },
  662. // 出入库明细
  663. handleViewDetail (row) {
  664. this.showOutInModal = true
  665. this.$refs.outInDetialModal.getData(row)
  666. },
  667. // 删除产品
  668. handleDel (row) {
  669. row
  670. const _this = this
  671. this.$confirm({
  672. title: '提示',
  673. content: '确认要删除吗?',
  674. centered: true,
  675. closable: true,
  676. onOk () {
  677. _this.delLoading = true
  678. _this.spinning = true
  679. salesDetailDel({ id: row.id }).then(res => {
  680. if (res.status == 200) {
  681. _this.getOrderDetail(false, true)
  682. }
  683. _this.$message.info(res.message)
  684. _this.delLoading = false
  685. _this.spinning = false
  686. })
  687. }
  688. })
  689. },
  690. // 添加产品
  691. insterProduct (row) {
  692. // 防止多次添加产品
  693. if (this.isInster) { return }
  694. const _this = this
  695. // 自建的单据显示库存不足时
  696. if (row.currentQty < row.salesNums && this.isOwerEdit) {
  697. _this.$confirm({
  698. title: '提示',
  699. content: '库存不足,确认添加为急件吗?',
  700. centered: true,
  701. closable: true,
  702. onOk () {
  703. _this.isPutCostDyPrice(row)
  704. }
  705. })
  706. } else {
  707. _this.isPutCostDyPrice(row)
  708. }
  709. },
  710. // 判断售价低于成本价
  711. isPutCostDyPrice (row) {
  712. const _this = this
  713. if (row.putCost > row.price) {
  714. // 销售价低于成本价
  715. _this.$confirm({
  716. title: '提示',
  717. content: '售价低于成本价,确认要添加吗?',
  718. centered: true,
  719. closable: true,
  720. onOk () {
  721. _this.saveNewProduct(row)
  722. }
  723. })
  724. } else {
  725. _this.saveNewProduct(row)
  726. }
  727. },
  728. // 保存添加的产品到销售列表
  729. saveNewProduct (row) {
  730. this.$message.loading('正在添加产品...', 1)
  731. this.isInster = true
  732. // this.spinning = true
  733. salesDetailInsert({
  734. buyerSn: this.detailData.buyerSn,
  735. productSn: row.productSn,
  736. cost: row.putCost,
  737. // productCode: row.productCode,
  738. // productOrigCode: row.productOrigCode,
  739. price: row.price,
  740. qty: row.salesNums,
  741. salesBillSn: this.detailData.salesBillSn,
  742. salesBillNo: this.detailData.salesBillNo,
  743. warehouseSn: row.warehouseSn,
  744. warehouseLocationSn: row.warehouseLocationSn,
  745. stockSn: row.stockSn
  746. }).then(res => {
  747. if (res.status == 200) {
  748. this.getOrderDetail(true)
  749. if (this.showShelfModal) {
  750. this.$refs.chooseShelfProduct.reload()
  751. }
  752. } else {
  753. if (res.errCode == 'VALID_F_00001') {
  754. this.productForm = {
  755. productName: '',
  756. productCode: row.productCode || '',
  757. orderBy: 'sales_bill_detail.CREATE_DATE desc'
  758. }
  759. this.showSearch = true
  760. this.$refs.table.refresh(true)
  761. }
  762. this.isInster = false
  763. }
  764. // this.spinning = false
  765. })
  766. },
  767. // 批量添加接口
  768. plInsterProduct (list) {
  769. const params = []
  770. list.map(item => {
  771. params.push({
  772. buyerSn: this.detailData.buyerSn,
  773. productSn: item.productSn,
  774. cost: item.putCost,
  775. price: item.price,
  776. qty: item.salesNums,
  777. salesBillSn: this.detailData.salesBillSn,
  778. salesBillNo: this.detailData.salesBillNo,
  779. stockSn: item.stockSn
  780. })
  781. })
  782. this.$message.loading('正在批量添加产品...', 1)
  783. salesDetailInsertBatch(params).then(res => {
  784. if (res.status == 200) {
  785. this.getOrderDetail(true)
  786. if (this.showShelfModal) {
  787. this.$refs.chooseShelfProduct.reload()
  788. }
  789. }
  790. })
  791. },
  792. // 销售单详情
  793. getOrderDetail (flag, resetTable) {
  794. const vm = this
  795. vm.spinning = true
  796. salesDetail({ id: vm.$route.params.id }).then(res => {
  797. if (res.status == 200) {
  798. vm.detailData = res.data
  799. vm.discountAmountBak = vm.detailData.discountAmount
  800. if (res.data.delFlag == 1) {
  801. vm.$message.info('该销售单已删除')
  802. vm.handleBack()
  803. return false
  804. }
  805. if (flag) {
  806. const buyerSn = (vm.detailData && vm.detailData.buyerSn && vm.detailData.sourceType && vm.detailData.sourceType == 'PURCHASE') ? '' : vm.detailData.buyerSn
  807. const priceType = vm.$route.params.priceType
  808. vm.$refs.partQuery.pageInit(buyerSn, priceType, vm.salesBillSn)
  809. if (vm.detailData.totalCategory) {
  810. vm.resetForm()
  811. } else {
  812. vm.spinning = false
  813. vm.checkedProductList = []
  814. }
  815. // 查询关联的客户货架信息
  816. if (vm.detailData && vm.detailData.buyerSn) {
  817. vm.getShelfQueryByCustomer()
  818. }
  819. } else {
  820. if (resetTable) {
  821. vm.$refs.table.refresh()
  822. } else {
  823. vm.spinning = false
  824. }
  825. }
  826. }
  827. })
  828. },
  829. // 查询关联的客户货架信息
  830. getShelfQueryByCustomer () {
  831. queryByCustomerSn({ sn: this.detailData.buyerSn }).then(res => {
  832. if (res.data) {
  833. this.shelfInfo = Object.assign(res.data, { salePriceType: this.$route.params.priceType, salesBillSn: this.salesBillSn })
  834. } else {
  835. this.shelfInfo = null
  836. }
  837. })
  838. },
  839. // 提交销售单
  840. handleSubmit (params) {
  841. this.spinning = true
  842. const submitTypes = this.tbForm.join(',')
  843. salesWriteSubmit({ id: this.orderId, submitTypes: submitTypes, ...params }).then(res => {
  844. console.log(res)
  845. if (res.status == 200) {
  846. this.handleBack()
  847. this.$message.success(res.message)
  848. this.spinning = false
  849. } else {
  850. this.spinning = false
  851. }
  852. })
  853. },
  854. // 开启结算账户功能收款, type:0 单条收款,1 批量收款
  855. handleSettleAcountPay (row, type) {
  856. this.openSettleModal = true
  857. const data = {
  858. totalAmount: this.detailData.discountedAmount,
  859. settleClientName: '',
  860. title: '收款',
  861. type,
  862. row
  863. }
  864. this.$nextTick(() => {
  865. this.$refs.settleModal.setData(data)
  866. })
  867. },
  868. // 去收款
  869. settleAcountPay (form, data) {
  870. const params = {}
  871. // 资金管理开启
  872. if (this.enableFundAccount) {
  873. params.settleStyleSn = form.settleStyleSn
  874. params.settleAccountSn = form.settleAccountSn
  875. }
  876. this.spinning = true
  877. this.handleSubmit(params)
  878. },
  879. // 确认导入明细
  880. hanldeImprotOk (obj) {
  881. this.spinning = true
  882. salesDetailInsertImport(obj).then(res => {
  883. if (res.status == 200) {
  884. this.getOrderDetail(true)
  885. }
  886. this.spinning = false
  887. })
  888. },
  889. setTableH () {
  890. this.tableHeight = window.innerHeight - (this.showSearch ? 42 : 0) - 300
  891. },
  892. pageInit () {
  893. const vm = this
  894. vm.$nextTick(() => {
  895. vm.setTableH()
  896. vm.orderId = vm.$route.params.id
  897. vm.salesBillSn = vm.$route.params.sn
  898. // 是否默认打印原厂编码
  899. vm.printOrgCode = localStorage.getItem('printOrgCode-' + this.$store.state.user.info.orgId) == 'true'
  900. vm.printAllName = localStorage.getItem('printAllName-' + this.$store.state.user.info.orgId) == 'true'
  901. vm.printRemarks = localStorage.getItem('printRemarks-' + this.$store.state.user.info.orgId) == 'true'
  902. vm.printPrice = localStorage.getItem('printPrice-' + this.$store.state.user.info.orgId) == 'true'
  903. vm.getOrderDetail(true)
  904. })
  905. }
  906. },
  907. watch: {
  908. printOrgCode (newValue, oldValue) {
  909. localStorage.setItem('printOrgCode-' + this.$store.state.user.info.orgId, newValue)
  910. },
  911. printAllName (newValue, oldValue) {
  912. localStorage.setItem('printAllName-' + this.$store.state.user.info.orgId, newValue)
  913. },
  914. printPrice (newValue, oldValue) {
  915. localStorage.setItem('printPrice-' + this.$store.state.user.info.orgId, newValue)
  916. },
  917. printRemarks (newValue, oldValue) {
  918. localStorage.setItem('printRemarks-' + this.$store.state.user.info.orgId, newValue)
  919. },
  920. showSearch (newValue, oldValue) {
  921. this.setTableH()
  922. },
  923. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  924. this.setTableH()
  925. }
  926. },
  927. mounted () {
  928. this.showPage = true
  929. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  930. this.pageInit()
  931. }
  932. },
  933. activated () {
  934. this.showPage = true
  935. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  936. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  937. this.pageInit()
  938. }
  939. // 结算账户状态查询
  940. if (this.$hasPermissions('M_fundAccountList') && this.$hasPermissions('B_fundAccountEnable')) {
  941. this.GetSettleAccountState().then(res => {
  942. if (res.status == 200) {
  943. this.enableFundAccount = res.data.functionEnableFlag == 1
  944. }
  945. })
  946. }
  947. },
  948. beforeRouteEnter (to, from, next) {
  949. next(vm => {})
  950. }
  951. }
  952. </script>
  953. <style lang="less">
  954. .salesEdit-news-wrap{
  955. position: relative;
  956. height: 100%;
  957. box-sizing: border-box;
  958. .choosedList-cont{
  959. position: relative;
  960. background-color: #fff;
  961. height: calc(100% - 60px);
  962. .choosed-table{
  963. position: relative;
  964. }
  965. .redBg-row{
  966. color: #f5452e;
  967. input{
  968. color: #f5452e;
  969. }
  970. }
  971. .discount-box{
  972. position: absolute;
  973. left: 15px;
  974. bottom: 15px;
  975. .red{
  976. color: #f5452e;
  977. font-size: 14px;
  978. }
  979. }
  980. }
  981. .total-bar{
  982. > div{
  983. text-align: right;
  984. &:first-child{
  985. span{
  986. color: #666;
  987. }
  988. .red{
  989. color: #f5452e;
  990. font-size: 14px;
  991. }
  992. }
  993. &:last-child{
  994. display: flex;
  995. align-items: center;
  996. justify-content: flex-end;
  997. }
  998. }
  999. }
  1000. }
  1001. </style>