edit.vue 37 KB

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