edit.vue 39 KB

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