edit.vue 43 KB

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