edit.vue 39 KB

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