edit.vue 39 KB

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