edit.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <div class="purchaseOrderEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="purchaseOrderEdit-cont">
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="purchaseOrderEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <p class="billno">单号:{{ detail&&detail.purchaseBillNo }}</p>
  9. </template>
  10. <!-- 操作区,位于 title 行的行尾 -->
  11. <template slot="extra" v-if="$hasPermissions('B_purchasePrint')">
  12. <a-radio-group key="3" v-model="printerType">
  13. <a-radio value="NEEDLE">针式</a-radio>
  14. <a-radio value="INK">喷墨</a-radio>
  15. </a-radio-group>
  16. <a-button key="2" id="purchaseOrderEdit-preview-btn" :disabled="localDataSource.length==0" @click="handlePrint('preview')">打印预览</a-button>
  17. <a-button key="1" type="primary" id="purchaseOrderEdit-print-btn" :disabled="localDataSource.length==0" @click="handlePrint('print')">快捷打印</a-button>
  18. </template>
  19. </a-page-header>
  20. <!-- 基础信息 -->
  21. <a-card size="small" :bordered="false" class="purchaseOrderEdit-cont">
  22. <a-collapse :activeKey="['1']">
  23. <a-collapse-panel key="1">
  24. <template slot="header">
  25. 基础信息
  26. <!-- <a-button
  27. type="primary"
  28. shape="circle"
  29. size="small"
  30. icon="edit"
  31. class="edit-circle-btn"
  32. id="purchaseOrderEdit-edit-circle-btn"
  33. @click.stop="handleEditInfo" /> -->
  34. </template>
  35. <a-descriptions :column="2">
  36. <a-descriptions-item label="供应商">{{ detail&&detail.purchaseTargetName }}</a-descriptions-item>
  37. <a-descriptions-item label="支付方式">{{ detail&&detail.settleStyleEntity.name }}</a-descriptions-item>
  38. <a-descriptions-item label="收货人">{{ detail&&detail.consigneeName }}({{ detail&&detail.consigneeTel }})</a-descriptions-item>
  39. <a-descriptions-item label="收货地址">
  40. {{ detail&&detail.shippingAddressProvinceName }} -
  41. {{ detail&&detail.shippingAddressCityName }} -
  42. {{ detail&&detail.shippingAddressCountyName }} -
  43. {{ detail&&detail.shippingAddress }}
  44. </a-descriptions-item>
  45. </a-descriptions>
  46. </a-collapse-panel>
  47. </a-collapse>
  48. </a-card>
  49. <!-- 选择产品 -->
  50. <a-card size="small" :bordered="false" class="purchaseOrderEdit-cont">
  51. <a-collapse :activeKey="['1']">
  52. <a-collapse-panel key="1">
  53. <template slot="header">
  54. 选择产品<span class="sub-title">①输入查询条件--->②查找到需要采购的产品--->③录入采购数量--->④点击“添加”</span>
  55. <p class="tag-txt">注意:仅限采购【箭冠】产品。自建产品的采购入库请使用“散件入库”功能</p>
  56. </template>
  57. <!-- 选择产品 -->
  58. <div>
  59. <!-- 搜索条件 -->
  60. <div class="table-page-search-wrapper">
  61. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  62. <a-row :gutter="15">
  63. <a-col :md="6" :sm="24">
  64. <a-form-item label="关键词">
  65. <a-input id="purchaseOrderEdit-bundleName" v-model.trim="queryParam.queryWord" allowClear placeholder="产品名称/产品编码/原厂编码/适用车型"/>
  66. </a-form-item>
  67. </a-col>
  68. <a-col :md="6" :sm="24">
  69. <a-form-item label="产品品牌">
  70. <ProductBrand id="purchaseOrderEdit-productBrand" v-model="queryParam.productBrandSn"></ProductBrand>
  71. </a-form-item>
  72. </a-col>
  73. <a-col :md="6" :sm="24">
  74. <a-form-item label="产品分类">
  75. <ProductType id="purchaseOrderEdit-productType" @change="changeProductType" v-model="productType"></ProductType>
  76. </a-form-item>
  77. </a-col>
  78. <!-- <template v-if="advanced">
  79. <a-col :md="6" :sm="24">
  80. <a-form-item label="适用车型">
  81. <a-cascader
  82. :options="typeData"
  83. expand-trigger="hover"
  84. id="purchaseOrderEdit-state"
  85. placeholder="请选择适用车型"
  86. allowClear
  87. v-model="queryParam.brand" />
  88. </a-form-item>
  89. </a-col>
  90. </template> -->
  91. <a-col :md="6" :sm="24">
  92. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="purchaseOrderEdit-refresh">查询</a-button>
  93. <a-button style="margin: 0 0 18px 8px" @click="resetSearchForm" :disabled="disabled" id="purchaseOrderEdit-reset">重置</a-button>
  94. <!-- <a @click="advanced=!advanced" style="margin-left: 8px">
  95. {{ advanced ? '收起' : '展开' }}
  96. <a-icon :type="advanced ? 'up' : 'down'"/>
  97. </a> -->
  98. </a-col>
  99. </a-row>
  100. </a-form>
  101. </div>
  102. <!-- 列表 -->
  103. <s-table
  104. class="sTable"
  105. ref="table"
  106. size="small"
  107. :rowKey="(record) => record.id"
  108. :columns="columns"
  109. :data="loadData"
  110. :scroll="{ x: 1190, y:300 }"
  111. :defaultLoadData="false"
  112. bordered>
  113. <!-- 采购数量 -->
  114. <template slot="storageQuantity" slot-scope="text, record">
  115. <a-input-number
  116. v-model="record.qty"
  117. :precision="0"
  118. :min="0"
  119. :max="999999"
  120. placeholder="请输入数量" />
  121. </template>
  122. <!-- 操作 -->
  123. <template slot="action" slot-scope="text, record">
  124. <a-button
  125. size="small"
  126. type="primary"
  127. class="button-info"
  128. :loading="addLoading"
  129. @click="handleAdd(record,0)"
  130. :disabled="record.purchasePrice<=0"
  131. id="purchaseOrderEdit-add-btn">添加</a-button>
  132. </template>
  133. </s-table>
  134. </div>
  135. </a-collapse-panel>
  136. </a-collapse>
  137. </a-card>
  138. <!-- 已选产品 -->
  139. <a-card size="small" :bordered="false" class="purchaseOrderEdit-cont">
  140. <a-collapse :activeKey="['1']">
  141. <a-collapse-panel key="1">
  142. <template slot="header">
  143. 已选产品
  144. <!-- <a-button size="small" class="import-btn" id="purchaseOrderEdit-import-btn" @click.stop="handleImport">导入明细</a-button> -->
  145. </template>
  146. <!-- 已选产品 -->
  147. <div>
  148. <!-- 总计 -->
  149. <a-alert type="info" showIcon style="margin-bottom:15px">
  150. <div slot="message">产品款数 <strong>{{ detail ? ((detail.totalCategory || detail.totalCategory==0) ? detail.totalCategory : '--') : '--' }}</strong> ,
  151. 采购数量合计 <strong>{{ detail ? ((detail.totalQty || detail.totalQty==0) ? detail.totalQty : '--') : '--' }}</strong> ,
  152. 采购金额合计¥<strong>{{ detail ? ((detail.discountedAmount || detail.discountedAmount==0) ? detail.discountedAmount : '--') : '--' }}</strong></div>
  153. </a-alert>
  154. <!-- 列表 -->
  155. <s-table
  156. class="sTable"
  157. ref="purchaseTable"
  158. size="small"
  159. :rowKey="(record) => record.id"
  160. :columns="chooseColumns"
  161. :data="chooseLoadData"
  162. :scroll="{ x: 1070, y: 300 }"
  163. bordered>
  164. <!-- 采购数量 -->
  165. <template slot="storageQuantity" slot-scope="text, record">
  166. <a-input-number
  167. id="purchaseOrderEdit-qty"
  168. v-model="record.qty"
  169. :precision="0"
  170. :min="1"
  171. :max="999999"
  172. @blur="e => qtyBlur(e.target.value, record)"
  173. placeholder="请输入" />
  174. </template>
  175. <!-- 操作 -->
  176. <template slot="action" slot-scope="text, record">
  177. <a-button
  178. size="small"
  179. type="primary"
  180. class="button-error"
  181. :loading="delLoading"
  182. @click="handleDel(record)"
  183. id="purchaseOrderEdit-del-btn">删除</a-button>
  184. </template>
  185. </s-table>
  186. </div>
  187. </a-collapse-panel>
  188. </a-collapse>
  189. </a-card>
  190. <a-affix :offset-bottom="0" v-if="detail">
  191. <div style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  192. <a-button
  193. type="primary"
  194. id="purchaseOrderEdit-submit-btn"
  195. size="large"
  196. class="button-primary"
  197. :loading="subLoading"
  198. @click="handleSubmit"
  199. style="padding: 0 60px;">提交</a-button>
  200. </div>
  201. </a-affix>
  202. </a-spin>
  203. <!-- 选择基本信息弹框 -->
  204. <basic-info-modal ref="baseInfo" :openModal="openModal" @ok="handleOk" @cancel="openModal=false" />
  205. <!-- 打印 -->
  206. <div id="print"></div>
  207. </div>
  208. </template>
  209. <script>
  210. import { STable, VSelect } from '@/components'
  211. import basicInfoModal from './basicInfoModal.vue'
  212. import ProductType from '../../common/productType.js'
  213. import ProductBrand from '../../common/productBrand.js'
  214. import { purchaseDetailBySn, purchaseWriteSubmit, purchaseDetailPrint } from '@/api/purchase'
  215. import { purchaseDetailList, purchaseDetailSave, purchaseDetailDel, purchaseDetailCount } from '@/api/purchaseDetail'
  216. import { productListPurchase } from '@/api/product'
  217. export default {
  218. components: { STable, VSelect, basicInfoModal, ProductType, ProductBrand },
  219. data () {
  220. return {
  221. spinning: false,
  222. openModal: false, // 选择基本信息弹框是否显示
  223. detail: null, // 详细信息
  224. subLoading: false,
  225. // 选择产品
  226. addLoading: false,
  227. productType: [],
  228. queryParam: {
  229. productBrandSn: undefined,
  230. queryWord: '',
  231. productTypeSn1: '', // 产品一级分类
  232. productTypeSn2: '', // 产品二级分类
  233. productTypeSn3: '' // 产品三级分类
  234. },
  235. typeData: [], // 下拉数据
  236. advanced: false, // 高级搜索 展开/关闭
  237. disabled: false, // 查询、重置按钮是否可操作
  238. // 表头
  239. columns: [
  240. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  241. { title: '产品编码', dataIndex: 'code', width: 220, align: 'center', sorter: true },
  242. { title: '产品名称', dataIndex: 'name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  243. { title: '原厂编码', dataIndex: 'origCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  244. { title: '箱/单位', dataIndex: 'unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  245. { title: '采购单价', dataIndex: 'purchasePrice', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) }, fixed: 'right' },
  246. { title: '采购数量', dataIndex: 'qty', scopedSlots: { customRender: 'storageQuantity' }, width: 150, align: 'center', fixed: 'right' },
  247. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  248. ],
  249. // 加载数据方法 必须为 Promise 对象
  250. loadData: parameter => {
  251. this.disabled = true
  252. return productListPurchase(Object.assign(parameter, this.queryParam, { purchaseBillSn: this.$route.params.sn })).then(res => {
  253. const data = res.data
  254. const no = (data.pageNo - 1) * data.pageSize
  255. for (var i = 0; i < data.list.length; i++) {
  256. data.list[i].no = no + i + 1
  257. data.list[i].qty = 1
  258. }
  259. this.disabled = false
  260. return data
  261. })
  262. },
  263. // -------已选产品-------------
  264. orderCountData: null,
  265. delLoading: false,
  266. // 表头
  267. chooseColumns: [
  268. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  269. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: 220, align: 'center', sorter: true },
  270. { title: '产品名称', dataIndex: 'dealerProductEntity.name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  271. { title: '采购单价', dataIndex: 'discountedPrice', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  272. { title: '采购数量', scopedSlots: { customRender: 'storageQuantity' }, width: 150, align: 'center' },
  273. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  274. { title: '采购金额', dataIndex: 'discountedAmount', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  275. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  276. ],
  277. // 加载数据方法 必须为 Promise 对象
  278. chooseLoadData: parameter => {
  279. this.disabled = true
  280. // 查询总计
  281. const params = Object.assign(parameter, { purchaseBillSn: this.$route.params.sn })
  282. // this.getCountQuery(params)
  283. return purchaseDetailList(params).then(res => {
  284. const data = res.data
  285. const no = (data.pageNo - 1) * data.pageSize
  286. for (var i = 0; i < data.list.length; i++) {
  287. data.list[i].no = no + i + 1
  288. data.list[i].qtyBackups = data.list[i].qty
  289. }
  290. this.localDataSource = data.list
  291. this.disabled = false
  292. return data
  293. })
  294. },
  295. localDataSource: [],
  296. printerType: 'NEEDLE' // 打印机类型
  297. }
  298. },
  299. methods: {
  300. // 获取采购单明细统计
  301. getCountQuery (params) {
  302. purchaseDetailCount(params).then(res => {
  303. this.orderCountData = res.data || null
  304. })
  305. },
  306. // 获取采购单基本信息
  307. getOrderDetail () {
  308. purchaseDetailBySn({ sn: this.$route.params.sn }).then(res => {
  309. if (res.status == 200) {
  310. this.detail = res.data
  311. }
  312. })
  313. },
  314. // 基本信息编辑成功
  315. handleOk (data) {
  316. this.openModal = false
  317. this.getOrderDetail()
  318. },
  319. // 编辑基本信息
  320. handleEditInfo () {
  321. this.openModal = true
  322. this.$refs.baseInfo.setData(this.detail)
  323. },
  324. // ---已选产品-----
  325. // 删除产品
  326. handleDel (row) {
  327. const _this = this
  328. this.$confirm({
  329. title: '提示',
  330. content: '确认要删除吗?',
  331. centered: true,
  332. closable: true,
  333. onOk () {
  334. _this.delLoading = true
  335. _this.spinning = true
  336. purchaseDetailDel({ id: row.id }).then(res => {
  337. if (res.status == 200) {
  338. _this.resetPurchaseDetail(true)
  339. _this.$message.success(res.message)
  340. _this.delLoading = false
  341. _this.spinning = false
  342. } else {
  343. _this.delLoading = false
  344. _this.spinning = false
  345. }
  346. })
  347. }
  348. })
  349. },
  350. // 重新查询已选产品
  351. resetPurchaseDetail (flag) {
  352. this.$refs.purchaseTable.refresh(!!flag)
  353. this.getOrderDetail()
  354. },
  355. // 修改数量后
  356. qtyBlur (val, record) {
  357. // this.handleAdd(record, 1)
  358. // 光标移出,值发生改变再调用编辑接口
  359. if (val != record.qtyBackups) {
  360. // this.handleAdd(record, 'edit')
  361. this.handleAdd(record, 1)
  362. }
  363. },
  364. // 导入明细
  365. handleImport () {
  366. console.log(333)
  367. },
  368. // ---------产品库--------
  369. filterOption (input, option) {
  370. return (
  371. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  372. )
  373. },
  374. // 产品分类 change
  375. changeProductType (val, opt) {
  376. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  377. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  378. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  379. },
  380. // 重置产品库
  381. resetSearchForm () {
  382. this.queryParam = {
  383. productBrandSn: undefined,
  384. productTypeSn1: '', // 产品一级分类
  385. productTypeSn2: '', // 产品二级分类
  386. productTypeSn3: '', // 产品三级分类
  387. queryWord: ''
  388. }
  389. this.productType = []
  390. this.$refs.table.refresh(true)
  391. },
  392. // 添加或修改
  393. handleAdd (row, type) {
  394. let params = {}
  395. // 添加
  396. if (type == 0) {
  397. params.productSn = row.productSn
  398. params.purchaseBillSn = this.detail.purchaseBillSn
  399. params.purchaseBillNo = this.detail.purchaseBillNo
  400. params.price = row.purchasePrice
  401. params.qty = row.qty
  402. } else { // 编辑
  403. // 清空成本价或数量时,值应保持未清空前的值,因成本价和数量都不可为空
  404. if (!row.qty) {
  405. row.qty = row.qtyBackups
  406. return
  407. }
  408. params = row
  409. }
  410. this.addLoading = true
  411. this.spinning = true
  412. purchaseDetailSave(params).then(res => {
  413. if (res.status == 200) {
  414. this.resetPurchaseDetail()
  415. this.$message.success(res.message)
  416. this.spinning = false
  417. } else {
  418. this.spinning = false
  419. }
  420. this.addLoading = false
  421. })
  422. },
  423. // ------------产品库 end --------
  424. // 提交
  425. handleSubmit () {
  426. const _this = this
  427. this.subLoading = true
  428. this.spinning = true
  429. purchaseWriteSubmit({ id: this.detail.id }).then(res => {
  430. if (res.status == 200) {
  431. this.$message.success(res.message)
  432. setTimeout(() => {
  433. _this.handleBack()
  434. _this.spinning = false
  435. }, 1000)
  436. } else {
  437. _this.spinning = false
  438. }
  439. _this.subLoading = false
  440. })
  441. },
  442. // 打印预览/快捷打印
  443. handlePrint (type) {
  444. const _this = this
  445. _this.spinning = true
  446. purchaseDetailPrint({ sn: this.$route.params.sn, type: this.printerType }).then(res => {
  447. _this.spinning = false
  448. if (res.type == 'application/json') {
  449. var reader = new FileReader()
  450. reader.addEventListener('loadend', function () {
  451. const obj = JSON.parse(reader.result)
  452. _this.$notification.error({
  453. message: '提示',
  454. description: obj.message
  455. })
  456. })
  457. reader.readAsText(res)
  458. } else {
  459. this.print(res, type)
  460. }
  461. })
  462. },
  463. print (data, type) {
  464. if (!data) {
  465. return
  466. }
  467. const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
  468. document.getElementById('print').innerHTML = '<iframe id="printf" name="printf" src="' + url + '" hidden></iframe>'
  469. if (type == 'preview') { // 预览
  470. window.open(url)
  471. } else if (type == 'print') { // 打印
  472. window.frames['printf'].focus()
  473. window.frames['printf'].print()
  474. }
  475. },
  476. // 返回列表
  477. handleBack () {
  478. this.$router.push({ name: 'purchaseOrderList' })
  479. }
  480. },
  481. beforeRouteEnter (to, from, next) {
  482. next(vm => {
  483. vm.openModal = false
  484. vm.getOrderDetail()
  485. })
  486. }
  487. }
  488. </script>
  489. <style lang="less">
  490. .purchaseOrderEdit-wrap{
  491. .billno{
  492. margin: 0 0 0 30px;
  493. font-size: 18px;
  494. font-weight: 600;
  495. display: inline-block;
  496. vertical-align: top;
  497. color: #666;
  498. }
  499. .purchaseOrderEdit-cont{
  500. margin-bottom: 15px;
  501. .sub-title{
  502. font-size: 12px;
  503. color: #808695;
  504. margin-left: 10px;
  505. }
  506. .tag-txt{
  507. font-size: 12px;
  508. color: #ed1c24;
  509. }
  510. .edit-circle-btn{
  511. margin-left: 15px;
  512. i{
  513. vertical-align: text-bottom;
  514. }
  515. }
  516. .import-btn{
  517. margin-left: 15px;
  518. }
  519. }
  520. }
  521. </style>