edit.vue 38 KB

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