edit.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <template>
  2. <div v-if="showPage" class="purchaseNewOrderEdit-wrap">
  3. <a-page-header :ghost="false" :backIcon="false" class="purchaseNewOrderEdit-cont">
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a id="purchaseNewOrderEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  7. <p class="billno">单号:{{ detail&&detail.purchaseBillNo }}</p>
  8. <a-button type="danger" ghost @click="isShowBisiceInfo=!isShowBisiceInfo" style="margin-left:30px;vertical-align:middle;">
  9. 基础信息
  10. <a-icon :type="isShowBisiceInfo ? 'up' : 'down'"/>
  11. </a-button>
  12. </template>
  13. <!-- 操作区,位于 title 行的行尾 -->
  14. <template slot="extra" v-if="$hasPermissions('B_purchasePrint')">
  15. <Print :disabled="localDataSource.length==0" @handlePrint="handlePrint"></Print>
  16. </template>
  17. </a-page-header>
  18. <!-- 产品列表 -->
  19. <div ref="tableSearch" class="choosedList-cont">
  20. <!-- 基础信息 -->
  21. <div style="padding:10px;" v-if="isShowBisiceInfo">
  22. <a-descriptions title="基础信息" size="small">
  23. <a-descriptions-item label="供应商">
  24. {{ detail&&detail.purchaseTargetName || '--' }}
  25. </a-descriptions-item>
  26. <a-descriptions-item label="支付方式">
  27. {{ detail&&detail.settleStyleSnDictValue || '--' }}
  28. </a-descriptions-item>
  29. <a-descriptions-item label="收货人">
  30. {{ detail&&detail.consigneeName || '--' }}({{ detail&&detail.consigneeTel || '--' }})
  31. </a-descriptions-item>
  32. <a-descriptions-item label="收货地址" span="3">
  33. <div v-if="detail&&(detail.shippingAddressProvinceName || detail.shippingAddressCityName || detail.shippingAddressCountyName || detail.shippingAddress)">
  34. {{ detail&&detail.shippingAddressProvinceName || '' }}
  35. {{ detail&&detail.shippingAddressCityName || '' }}
  36. {{ detail&&detail.shippingAddressCountyName || '' }}
  37. {{ detail&&detail.shippingAddress || '' }}
  38. <a-button type="link" @click="openAddrModal=true">更换地址 >></a-button>
  39. </div>
  40. <div v-else><a-button type="link" @click="openAddrModal=true">选择地址 >></a-button></div>
  41. </a-descriptions-item>
  42. </a-descriptions>
  43. </div>
  44. <!-- 添加产品 -->
  45. <chooseProductModal
  46. ref="chooseProduct"
  47. :isDealerUp="isDealerUp"
  48. :purchaseBillSn="$route.params.sn"
  49. :showModal="openChooseProduct"
  50. @close="openChooseProduct=false"
  51. @add="handleAdd"
  52. ></chooseProductModal>
  53. <!-- 上次缺货 -->
  54. <outStockModal :openModal="openOutStockModal" :paramsData="paramsData" @close="openOutStockModal=false" @ok="hanldeOkOutStock" />
  55. <!-- 购物车 -->
  56. <shopingCatModal :showModal="openShopCatModal" :paramsData="paramsData" @close="openShopCatModal=false" @ok="getOrderDetail(false, true)"></shopingCatModal>
  57. <!-- 已选产品 -->
  58. <div>
  59. <div class="chooseBox-title">
  60. <div class="sub-title" style="display: flex;">
  61. 已选产品
  62. <p class="tag-txt">注意:仅限采购【箭冠】产品。自建产品的采购入库请使用“散件入库”功能</p>
  63. </div>
  64. <div class="actions-button">
  65. <a-button v-if="detail&&detail.totalCategory" id="purchaseNewOrderEdit-add-btn" type="danger" @click="openChooseProduct=true"><a-icon type="plus-circle" />添加产品</a-button>
  66. <a-button id="purchaseNewOrderEdit-import-btn" type="danger" ghost @click="openGuideModal=true"><a-icon type="import" />产品导入</a-button>
  67. <a-button id="purchaseNewOrderEdit-outStock-btn" type="danger" ghost @click="handleOutStock"><a-icon type="funnel-plot" />上次缺货</a-button>
  68. <a-button id="purchaseNewOrderEdit-cart-btn" v-if="$hasPermissions('M_shoppingCart')" type="danger" ghost @click="hanldCart"><a-icon type="shopping" />购物车</a-button>
  69. </div>
  70. </div>
  71. <div class="choosed-table" v-if="detail&&detail.totalCategory">
  72. <!-- 搜索条件 -->
  73. <div class="table-page-search-wrapper">
  74. <a-row :gutter="15">
  75. <a-col :span="24">
  76. <a-form-model :model="productForm" layout="inline" @keyup.enter.native="$refs.purchaseTable.refresh(true)" >
  77. <a-row :gutter="15">
  78. <a-col :md="6" :sm="24">
  79. <a-form-model-item label="产品编码">
  80. <a-input v-model.trim="productForm.productCode" allowClear placeholder="输入产品编码" />
  81. </a-form-model-item>
  82. </a-col>
  83. <a-col :md="6" :sm="24">
  84. <a-form-model-item label="产品名称">
  85. <a-input v-model.trim="productForm.productName" allowClear placeholder="输入产品名称" />
  86. </a-form-model-item>
  87. </a-col>
  88. <a-col :md="8" :sm="24">
  89. <a-form-model-item style="margin-bottom: 10px;">
  90. <a-button type="primary" @click="$refs.purchaseTable.refresh(true)" :disabled="purchaseDisabled" id="purchaseNewOrderEdit-refresh">查询</a-button>
  91. <a-button style="margin-left: 5px" @click="resetPurchaseForm" id="purchaseNewOrderEdit-reset">重置</a-button>
  92. </a-form-model-item>
  93. </a-col>
  94. </a-row>
  95. </a-form-model>
  96. </a-col>
  97. </a-row>
  98. </div>
  99. <!-- 列表 -->
  100. <s-table
  101. class="sTable"
  102. ref="purchaseTable"
  103. :style="{ height: tableHeight +'px', overflow: 'auto' }"
  104. size="small"
  105. :rowKey="(record) => record.id"
  106. :columns="chooseColumns"
  107. :data="chooseLoadData"
  108. :defaultLoadData="false"
  109. :showPagination="false"
  110. bordered>
  111. <!-- 采购数量 -->
  112. <template slot="storageQuantity" slot-scope="text, record">
  113. <a-input-number
  114. size="small"
  115. id="purchaseNewOrderEdit-qty"
  116. v-model="record.qty"
  117. :precision="0"
  118. :min="1"
  119. :max="999999"
  120. @blur="e => qtyBlur(e.target.value, record)"
  121. style="width: 100%;"
  122. placeholder="请输入" />
  123. </template>
  124. <!-- 操作 -->
  125. <template slot="action" slot-scope="text, record">
  126. <a-button
  127. size="small"
  128. type="link"
  129. class="button-error"
  130. :loading="delLoading"
  131. @click="handleDel(record)"
  132. id="purchaseNewOrderEdit-del-btn">删除</a-button>
  133. </template>
  134. </s-table>
  135. </div>
  136. <div v-else>
  137. <div v-if="!spinning&&localDataSource.length==0">
  138. <a-empty
  139. :image="simpleImage"
  140. :image-style="{
  141. height: '60px',
  142. }"
  143. >
  144. <span slot="description"> 暂无产品 </span>
  145. <a-button type="primary" class="button-error" @click="openChooseProduct=true"><a-icon type="plus-circle" />立即添加产品</a-button>
  146. </a-empty>
  147. </div>
  148. <div style="text-align: center;padding: 30px 50px;" v-if="spinning">
  149. <a-spin :spinning="spinning" tip="Loading..."></a-spin>
  150. </div>
  151. </div>
  152. </div>
  153. <!-- 底部栏 -->
  154. <div class="footer-cont">
  155. <!-- 总计 -->
  156. <div>
  157. <span style="color:#666;">
  158. 共计 {{ detail && (detail.totalCategory || detail.totalCategory==0) ? detail.totalCategory : '--' }} 款
  159. {{ detail && (detail.totalQty || detail.totalQty==0) ? detail.totalQty : '--' }} 件产品 ,
  160. </span>
  161. <div style="display: inline-block;" v-if="$hasPermissions('M_ShowAllCost')">
  162. 合计: <strong>{{ detail && (detail.discountedAmount || detail.discountedAmount==0) ?toThousands(detail.discountedAmount, 2) : '--' }}</strong>
  163. </div>
  164. </div>
  165. <div>
  166. <a-button
  167. type="primary"
  168. id="purchaseNewOrderEdit-submit-btn"
  169. size="large"
  170. class="button-primary"
  171. :loading="subLoading"
  172. @click="handleSubmit"
  173. style="padding: 0 60px;">提交</a-button>
  174. </div>
  175. </div>
  176. </div>
  177. <!-- 导入产品 -->
  178. <importGuideModal :openModal="openGuideModal" :params="{purchaseBillSn: $route.params.sn}" @close="openGuideModal=false" @ok="hanldeOks" />
  179. <!-- 选择地址 -->
  180. <choose-address-modal :openModal="openAddrModal" @ok="handleAddrOk" @close="openAddrModal=false" />
  181. </div>
  182. </template>
  183. <script>
  184. import { Empty } from 'ant-design-vue'
  185. import { commonMixin } from '@/utils/mixin'
  186. import { STable, VSelect } from '@/components'
  187. import ImportGuideModal from './importGuideModal.vue'
  188. import outStockModal from './outStockModal.vue'
  189. import chooseAddressModal from '@/views/common/receivingAddress/chooseAddressModal.vue'
  190. import { purchaseDetailBySn, purchaseWriteSubmit, purchaseDetailPrint, purchaseDetailExport, purchaseDetailAddress } from '@/api/purchase'
  191. import { purchaseDetailList, purchaseDetailSave, purchaseDetailDel, purchaseDetailCount, purchaseDetailCancelList } from '@/api/purchaseDetail'
  192. // 选择产品
  193. import chooseProductModal from './chooseProductModal.vue'
  194. // 打印
  195. import Print from '@/views/common/print.vue'
  196. import { hdPrint } from '@/libs/JGPrint'
  197. const shopingCatModal = () => import(/* webpackChunkName: "shopingCatModal" */ '@/views/common/shopingCatModal.vue')
  198. export default {
  199. name: 'PurchaseEdit',
  200. components: { STable, VSelect, ImportGuideModal, outStockModal, Print, chooseAddressModal, chooseProductModal, shopingCatModal },
  201. mixins: [commonMixin],
  202. data () {
  203. return {
  204. isShowBisiceInfo: false,
  205. showPage: false,
  206. spinning: false,
  207. detail: null, // 详细信息
  208. openChooseProduct: false,
  209. openShopCatModal: false,
  210. tableHeight: 0,
  211. simpleImage: Empty.PRESENTED_IMAGE_SIMPLE,
  212. // -------已选产品-------------
  213. subLoading: false,
  214. orderCountData: null,
  215. delLoading: false,
  216. productForm: {
  217. productName: '',
  218. productCode: '',
  219. orderBy: 'purchase_bill_detail.CREATE_DATE desc'
  220. },
  221. purchaseDisabled: false, // 查询、重置按钮是否可操作
  222. // 加载数据方法 必须为 Promise 对象
  223. chooseLoadData: parameter => {
  224. this.disabled = true
  225. this.spinning = true
  226. // 查询总计
  227. const params = Object.assign({ pageNo: 1, pageSize: 5000 }, this.productForm, { purchaseBillSn: this.$route.params.sn })
  228. return purchaseDetailList(params).then(res => {
  229. const data = res.data
  230. const no = (data.pageNo - 1) * data.pageSize
  231. for (var i = 0; i < data.list.length; i++) {
  232. data.list[i].no = no + i + 1
  233. data.list[i].qtyBackups = data.list[i].qty
  234. }
  235. this.localDataSource = data.list
  236. this.disabled = false
  237. this.spinning = false
  238. return data
  239. })
  240. },
  241. localDataSource: [],
  242. openGuideModal: false, // 导入产品引导
  243. openOutStockModal: false,
  244. paramsData: null,
  245. openAddrModal: false // 选择地址弹框是否显示
  246. }
  247. },
  248. computed: {
  249. isDealerUp () {
  250. return this.detail && this.detail.purchaseTargetType == 'DEALER_UP'
  251. },
  252. chooseColumns () {
  253. const _this = this
  254. const arr = [
  255. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  256. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '20%', align: 'center' },
  257. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '35%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  258. { title: '采购数量', scopedSlots: { customRender: 'storageQuantity' }, width: '8%', align: 'center' },
  259. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  260. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  261. ]
  262. if (this.$hasPermissions('M_ShowAllCost')) {
  263. arr.splice(3, 0, { title: '采购单价', dataIndex: 'discountedPrice', width: '8%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } })
  264. arr.splice(6, 0, { title: '采购金额', dataIndex: 'discountedAmount', width: '8%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } })
  265. }
  266. return arr
  267. }
  268. },
  269. methods: {
  270. // 获取采购单基本信息
  271. getOrderDetail (noRefashTable, isReset, flag) {
  272. this.spinning = true
  273. purchaseDetailBySn({ sn: this.$route.params.sn }).then(res => {
  274. if (res.status == 200) {
  275. this.detail = res.data
  276. if (!noRefashTable) {
  277. if (this.detail.totalCategory) {
  278. if (isReset) {
  279. this.resetPurchaseForm()
  280. } else {
  281. this.$refs.purchaseTable.refresh(!!flag)
  282. }
  283. } else {
  284. this.localDataSource = []
  285. this.spinning = false
  286. }
  287. } else {
  288. this.spinning = false
  289. }
  290. } else {
  291. this.spinning = false
  292. }
  293. })
  294. },
  295. // 删除产品
  296. handleDel (row) {
  297. const _this = this
  298. this.$confirm({
  299. title: '提示',
  300. content: '确认要删除吗?',
  301. centered: true,
  302. closable: true,
  303. onOk () {
  304. _this.delLoading = true
  305. purchaseDetailDel({ id: row.id }).then(res => {
  306. if (res.status == 200) {
  307. _this.getOrderDetail(false, false, true)
  308. _this.$message.success(res.message)
  309. _this.delLoading = false
  310. } else {
  311. _this.delLoading = false
  312. }
  313. })
  314. }
  315. })
  316. },
  317. // 修改数量后
  318. qtyBlur (val, record) {
  319. // 光标移出,值发生改变再调用编辑接口
  320. if (val != record.qtyBackups) {
  321. this.handleAdd(record, 1)
  322. }
  323. },
  324. // 重置已选产品列表
  325. resetPurchaseForm () {
  326. this.productForm.productName = ''
  327. this.productForm.productCode = ''
  328. this.$nextTick(() => {
  329. this.$refs.purchaseTable.refresh(true)
  330. })
  331. },
  332. // 添加或修改
  333. handleAdd (row, type) {
  334. let params = {}
  335. if (type == 0 && !row.qty) {
  336. this.$message.warning('请输入数量后再添加!')
  337. this.$refs.chooseProduct.spinning = false
  338. return
  339. }
  340. // 添加
  341. if (type == 0) {
  342. params.productSn = row.productSn
  343. params.purchaseBillSn = this.detail.purchaseBillSn
  344. params.purchaseBillNo = this.detail.purchaseBillNo
  345. params.price = row.purchasePrice
  346. params.qty = row.qty
  347. } else { // 编辑
  348. // 清空成本价或数量时,值应保持未清空前的值,因成本价和数量都不可为空
  349. if (!row.qty) {
  350. row.qty = row.qtyBackups
  351. return
  352. }
  353. params = row
  354. }
  355. this.addLoading = true
  356. purchaseDetailSave(params).then(res => {
  357. if (res.status == 200) {
  358. if (type == 0) {
  359. this.getOrderDetail(false, true, true)
  360. }
  361. this.$message.success(res.message)
  362. } else {
  363. row.qty = row.qtyBackups
  364. }
  365. this.addLoading = false
  366. this.$refs.chooseProduct.spinning = false
  367. })
  368. },
  369. // 提交
  370. handleSubmit () {
  371. const _this = this
  372. if (_this.detail && !_this.detail.totalCategory) {
  373. this.$message.info('请添加产品')
  374. return false
  375. }
  376. this.subLoading = true
  377. purchaseWriteSubmit({ id: this.detail.id }).then(res => {
  378. if (res.status == 200) {
  379. this.$message.success(res.message)
  380. setTimeout(() => {
  381. _this.handleBack()
  382. }, 1000)
  383. }
  384. _this.subLoading = false
  385. })
  386. },
  387. // 导入产品
  388. hanldeOks () {
  389. this.getOrderDetail(false, true, true)
  390. },
  391. // 打开购物车
  392. hanldCart () {
  393. this.paramsData = {
  394. purchaseBillSn: this.$route.params.sn,
  395. purchaseBillNo: this.detail && this.detail.purchaseBillNo ? this.detail.purchaseBillNo : undefined
  396. }
  397. this.openShopCatModal = true
  398. },
  399. // 上次缺货
  400. handleOutStock () {
  401. // 校验是否存在历史采购单,且上次采购存在缺货产品
  402. purchaseDetailCancelList({ pageNo: 1, pageSize: 5 }).then(res => {
  403. if (res.status == 200) {
  404. this.paramsData = {
  405. purchaseBillSn: this.$route.params.sn,
  406. purchaseBillNo: this.detail && this.detail.purchaseBillNo ? this.detail.purchaseBillNo : undefined
  407. }
  408. this.openOutStockModal = true
  409. }
  410. })
  411. },
  412. // 地址保存
  413. handleAddrOk (data) {
  414. const params = {
  415. purchaseBillSn: this.$route.params.sn,
  416. shippingAddressProvinceName: data.provinceName,
  417. shippingAddressCityName: data.cityName,
  418. shippingAddressCountyName: data.countyName,
  419. shippingAddress: data.addr,
  420. consigneeName: data.consigneeName,
  421. consigneeTel: data.consigneeTel
  422. }
  423. purchaseDetailAddress(params).then(res => {
  424. if (res.status == 200) {
  425. this.openAddrModal = false
  426. this.getOrderDetail(true)
  427. }
  428. })
  429. },
  430. // 上次缺货 导入成功
  431. hanldeOkOutStock () {
  432. this.getOrderDetail(false, true, true)
  433. this.paramsData = null
  434. this.openOutStockModal = false
  435. },
  436. // 打印预览/快捷打印
  437. handlePrint (type, printerType) {
  438. const _this = this
  439. if (type == 'preview') {
  440. _this.openChooseProduct = false
  441. _this.openOutStockModal = false
  442. }
  443. _this.$store.state.app.printLoading = true
  444. let url = purchaseDetailPrint
  445. let params = { sn: this.$route.params.sn, type: printerType }
  446. if (type == 'export') { // 导出
  447. url = purchaseDetailExport
  448. params = { sn: this.$route.params.sn }
  449. }
  450. // 打印或导出
  451. hdPrint(printerType, type, url, params, '采购单', function () {
  452. _this.$store.state.app.printLoading = false
  453. })
  454. },
  455. // 返回列表
  456. handleBack () {
  457. this.$router.push({ name: 'purchaseOrderNewList' })
  458. },
  459. setTableH () {
  460. this.tableHeight = window.innerHeight - (this.isShowBisiceInfo ? 440 : 310)
  461. },
  462. pageInit () {
  463. this.$nextTick(() => {
  464. this.setTableH()
  465. this.getOrderDetail(false, true)
  466. })
  467. }
  468. },
  469. watch: {
  470. isShowBisiceInfo (newValue, oldValue) {
  471. this.setTableH()
  472. }
  473. },
  474. mounted () {
  475. this.showPage = true
  476. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  477. this.pageInit()
  478. }
  479. },
  480. activated () {
  481. this.showPage = true
  482. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  483. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  484. this.pageInit()
  485. }
  486. },
  487. beforeRouteEnter (to, from, next) {
  488. next(vm => {})
  489. }
  490. }
  491. </script>
  492. <style lang="less">
  493. .purchaseNewOrderEdit-wrap{
  494. position: relative;
  495. height: 100%;
  496. box-sizing: border-box;
  497. .billno{
  498. margin: 0 0 0 30px;
  499. font-size: 18px;
  500. font-weight: 600;
  501. display: inline-block;
  502. vertical-align: middle;
  503. color: #666;
  504. }
  505. .choosedList-cont{
  506. position: relative;
  507. background-color: #fff;
  508. height: calc(100% - 60px);
  509. .chooseBox-title{
  510. display:flex;
  511. justify-content: space-between;
  512. align-items: center;
  513. border-top: 1px solid #eee;
  514. border-bottom: 1px solid #eee;
  515. padding: 8px 0;
  516. .actions-button{
  517. button{
  518. margin-left: 10px;
  519. margin-right: 10px;
  520. }
  521. }
  522. .import-btn{
  523. margin-left: 15px;
  524. }
  525. .sub-title{
  526. font-size: 14px;
  527. color: #333;
  528. margin-left: 10px;
  529. font-weight:bold;
  530. }
  531. .tag-txt{
  532. font-size: 12px;
  533. color: #ed1c24;
  534. margin: 0 15px;
  535. }
  536. }
  537. .choosed-table{
  538. padding:10px;
  539. }
  540. .footer-cont{
  541. position:absolute;
  542. width:100%;
  543. bottom:0;
  544. display:flex;
  545. justify-content: flex-end;
  546. align-items: center;
  547. padding: 8px;
  548. border-top: 1px solid #eee;
  549. > div{
  550. &:first-child{
  551. padding: 0 15px;
  552. strong{
  553. color: #ff8d00;
  554. font-size: 18px;
  555. }
  556. }
  557. }
  558. }
  559. .ant-input-number-sm input{
  560. text-align: center;
  561. }
  562. }
  563. .purchaseNewOrderEdit-cont{
  564. margin-bottom: 8px;
  565. .sub-title{
  566. font-size: 12px;
  567. color: #808695;
  568. margin-left: 10px;
  569. }
  570. }
  571. }
  572. </style>