edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <div class="purchaseReturnEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="purchaseReturnEdit-back" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="purchaseReturnEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <span style="margin: 0 15px;color: #666;">供应商名称:{{ $route.params.name || '--' }}</span>
  9. </template>
  10. <!-- 操作区,位于 title 行的行尾 -->
  11. <template slot="extra" v-if="$hasPermissions('B_purchaseReturnPrint')">
  12. <Print :disabled="dataSource.length==0" @handlePrint="handlePrint"></Print>
  13. </template>
  14. </a-page-header>
  15. <!-- 选择产品 -->
  16. <a-card size="small" :bordered="false" class="purchaseReturnEdit-cont">
  17. <a-collapse :activeKey="['1']">
  18. <a-collapse-panel key="1" header="选择产品">
  19. <!-- 筛选条件 -->
  20. <div class="table-page-search-wrapper">
  21. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  22. <a-row :gutter="15">
  23. <a-col :md="6" :sm="24">
  24. <a-form-item label="采购单号" prop="purchaseBillNo">
  25. <a-input id="purchaseReturnEdit-purchaseBillNo" v-model.trim="queryParam.purchaseBillNo" placeholder="请输入采购单号" allowClear />
  26. </a-form-item>
  27. </a-col>
  28. <a-col :md="6" :sm="24">
  29. <a-form-item label="产品编码" prop="productCode">
  30. <a-input id="purchaseReturnEdit-productCode" v-model.trim="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  31. </a-form-item>
  32. </a-col>
  33. <a-col :md="6" :sm="24">
  34. <a-form-item label="产品名称" prop="productName">
  35. <a-input id="purchaseReturnEdit-productName" v-model.trim="queryParam.productName" placeholder="请输入产品名称" allowClear />
  36. </a-form-item>
  37. </a-col>
  38. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  39. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="purchaseReturnList-refresh">查询</a-button>
  40. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="purchaseReturnList-reset">重置</a-button>
  41. </a-col>
  42. </a-row>
  43. </a-form>
  44. </div>
  45. <!-- 列表 -->
  46. <s-table
  47. class="sTable"
  48. ref="table"
  49. size="small"
  50. :rowKey="(record) => record.id"
  51. :columns="columns"
  52. :data="loadData"
  53. :defaultLoadData="false"
  54. :pageSize="10"
  55. :scroll="{ y: 149 }"
  56. bordered>
  57. <!-- 自定义表头 -->
  58. <template slot="refundableQtyTitle">
  59. <a-tooltip placement="top">
  60. <template slot="title">
  61. <span>同一个采购单,可多次退货,所以可退数量=采购数量-已退货数量</span>
  62. </template>
  63. 可退数量<a-icon type="question-circle" :style="{ marginLeft: '3px' }" />
  64. </a-tooltip>
  65. </template>
  66. <!-- 数量 -->
  67. <template slot="returnQty" slot-scope="text, record">
  68. <a-input-number
  69. size="small"
  70. id="purchaseReturnEdit-returnQty"
  71. v-model="record.returnQty"
  72. :precision="0"
  73. :min="1"
  74. :max="record.refundableQty"
  75. placeholder="请输入"
  76. style="width: 100%;" />
  77. </template>
  78. <!-- 操作 -->
  79. <template slot="action" slot-scope="text, record">
  80. <a-button
  81. size="small"
  82. type="primary"
  83. class="button-primary"
  84. :disabled="record.refundableQty==0"
  85. @click="handleAdd(record)"
  86. id="purchaseReturnEdit-add-btn">添加</a-button>
  87. </template>
  88. </s-table>
  89. </a-collapse-panel>
  90. </a-collapse>
  91. </a-card>
  92. <!-- 已选产品 -->
  93. <a-card size="small" :bordered="false" class="purchaseReturnEdit-cont">
  94. <a-collapse :activeKey="['1']">
  95. <a-collapse-panel key="1">
  96. <template slot="header">
  97. 已选产品
  98. <a-button
  99. size="small"
  100. type="primary"
  101. class="import-btn"
  102. id="purchaseReturnEdit-delAll-btn"
  103. @click.stop="handleDel('', 'all')"
  104. style="margin-left: 10px;">整单删除</a-button>
  105. </template>
  106. <!-- 列表 -->
  107. <s-table
  108. class="sTable"
  109. ref="chooseTable"
  110. size="small"
  111. :rowKey="(record) => record.id"
  112. :columns="chooseColumns"
  113. :data="chooseLoadData"
  114. :defaultLoadData="false"
  115. :pageSize="10"
  116. :scroll="{ y: 149 }"
  117. bordered>
  118. <!-- 退货数量 -->
  119. <template slot="qty" slot-scope="text, record">
  120. <a-input-number
  121. size="small"
  122. id="purchaseReturnEdit-qty"
  123. v-model="record.qty"
  124. :precision="0"
  125. :min="1"
  126. :max="record.refundableQty"
  127. placeholder="请输入"
  128. @blur="e => qtyBlur(e.target.value, record)"
  129. style="width: 100%;" />
  130. </template>
  131. <!-- 退货原因 -->
  132. <template slot="remarks" slot-scope="text, record">
  133. <a-input
  134. size="small"
  135. id="purchaseReturnEdit-remarks"
  136. v-model="record.remarks"
  137. :maxLength="30"
  138. placeholder="退货原因(最多30个字符)"
  139. @blur="e => remarksBlur(e.target.value, record)"
  140. style="width: 100%;" />
  141. </template>
  142. <!-- 操作 -->
  143. <template slot="action" slot-scope="text, record">
  144. <a-button size="small" type="primary" class="button-error" @click="handleDel(record)" id="purchaseReturnEdit-del-btn">删除</a-button>
  145. </template>
  146. </s-table>
  147. </a-collapse-panel>
  148. </a-collapse>
  149. </a-card>
  150. </a-spin>
  151. <div class="affix-cont">
  152. <a-button
  153. type="primary"
  154. id="purchaseReturnEdit-submit"
  155. size="large"
  156. :disabled="spinning"
  157. class="button-primary"
  158. @click="handleSubmit"
  159. style="padding: 0 60px;">提交</a-button>
  160. </div>
  161. </div>
  162. </template>
  163. <script>
  164. import { STable, VSelect } from '@/components'
  165. import Print from '@/views/common/print.vue'
  166. import { hdPrint } from '@/libs/JGPrint'
  167. import {
  168. purchaseReturnPurchaseBillDetailList,
  169. purchaseReturnDetailList,
  170. purchaseReturnDetailSave,
  171. purchaseReturnDetailDel,
  172. purchaseReturnSubmit,
  173. purchaseReturnDelAll,
  174. purchaseReturnDetailPrint,
  175. purchaseReturnDetailExport } from '@/api/purchaseReturn'
  176. export default {
  177. components: { STable, VSelect, Print },
  178. data () {
  179. return {
  180. spinning: false,
  181. queryParam: {
  182. purchaseBillNo: '',
  183. productCode: '',
  184. productName: ''
  185. },
  186. dataSource: [],
  187. disabled: false, // 查询、重置按钮是否可操作
  188. advanced: false, // 高级搜索 展开/关闭
  189. // 表头
  190. columns: [
  191. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  192. { title: '采购单号', dataIndex: 'purchaseBillNo', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  193. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  194. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '13%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  195. { title: '采购总数', dataIndex: 'qty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  196. { slots: { title: 'refundableQtyTitle' }, dataIndex: 'refundableQty', width: '9%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  197. { title: '库存数量', dataIndex: 'stock.currentStockQty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  198. { title: '缺货数量', dataIndex: 'cancelQty', width: '7%', align: 'center' },
  199. { title: '退货数量', scopedSlots: { customRender: 'returnQty' }, width: '8%', align: 'center' },
  200. { title: '采购价', dataIndex: 'price', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  201. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '5%', align: 'center', customRender: function (text) { return text || '--' } },
  202. { title: '操作', scopedSlots: { customRender: 'action' }, width: '7%', align: 'center' }
  203. ],
  204. // 加载数据方法 必须为 Promise 对象
  205. loadData: parameter => {
  206. this.disabled = true
  207. return purchaseReturnPurchaseBillDetailList(Object.assign(parameter, this.queryParam)).then(res => {
  208. const data = res.data
  209. const no = (data.pageNo - 1) * data.pageSize
  210. for (var i = 0; i < data.list.length; i++) {
  211. data.list[i].no = no + i + 1
  212. }
  213. this.disabled = false
  214. return data
  215. })
  216. },
  217. // 表头
  218. chooseColumns: [
  219. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  220. { title: '采购单号', dataIndex: 'purchaseBillNo', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  221. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  222. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  223. { title: '采购总数', dataIndex: 'purchaseBillQty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  224. { title: '退货数量', scopedSlots: { customRender: 'qty' }, width: '10%', align: 'center' },
  225. { title: '采购价', dataIndex: 'cost', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  226. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  227. { title: '退货原因', scopedSlots: { customRender: 'remarks' }, width: '15%', align: 'center' },
  228. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  229. ],
  230. // 加载数据方法 必须为 Promise 对象
  231. chooseLoadData: parameter => {
  232. return purchaseReturnDetailList(Object.assign(parameter, { purchaseReturnSn: this.$route.params.sn, orderBy: 'qpls_purchase_return_bill_detail.CREATE_DATE desc' })).then(res => {
  233. const data = res.data
  234. const no = (data.pageNo - 1) * data.pageSize
  235. for (var i = 0; i < data.list.length; i++) {
  236. data.list[i].no = no + i + 1
  237. data.list[i].qtyBackups = data.list[i].qty
  238. data.list[i].remarksBackups = data.list[i].remarks
  239. data.list[i].refundableQty = data.list[i].purchaseBillRefundableQty + data.list[i].qty
  240. }
  241. this.dataSource = data.list
  242. return data
  243. })
  244. }
  245. }
  246. },
  247. methods: {
  248. // 打印预览/快捷打印
  249. handlePrint (type, printerType) {
  250. const _this = this
  251. _this.spinning = true
  252. let url = purchaseReturnDetailPrint
  253. const params = { sn: this.$route.params.sn }
  254. if (type == 'export') { // 导出
  255. url = purchaseReturnDetailExport
  256. }
  257. // 打印或导出
  258. hdPrint(printerType, type, url, params, '采购退货单', function () {
  259. _this.spinning = false
  260. })
  261. },
  262. // 重置
  263. resetSearchForm () {
  264. this.queryParam.purchaseBillNo = ''
  265. this.queryParam.productCode = ''
  266. this.queryParam.productName = ''
  267. this.$refs.table.refresh(true)
  268. },
  269. // 添加/编辑
  270. handleAdd (row, isEdit) {
  271. // 添加时退货数量字段名为returnQty,编辑时退货数量字段名为qty
  272. if (!isEdit && !row.returnQty) {
  273. this.$message.warning('请输入退货数量')
  274. return
  275. }
  276. const params = {
  277. id: isEdit ? row.id : undefined,
  278. purchaseReturnSn: this.$route.params.sn,
  279. purchaseBillSn: row.purchaseBillSn,
  280. purchaseBillNo: row.purchaseBillNo,
  281. purchaseBillDetailSn: row.purchaseBillDetailSn,
  282. qty: isEdit ? row.qty : row.returnQty, // 退货数量
  283. productSn: row.productSn,
  284. cost: row.price,
  285. remarks: row.remarks,
  286. promotionFlag: row.promotionFlag
  287. }
  288. if (isEdit) { // 编辑
  289. // 清空退货数量时,值应保持未清空前的值,因退货数量都不可为空
  290. if (!row.qty) {
  291. row.qty = row.qtyBackups
  292. return
  293. }
  294. }
  295. this.spinning = true
  296. purchaseReturnDetailSave(params).then(res => {
  297. if (res.status == 200) {
  298. this.$message.success(res.message)
  299. this.$refs.table.refresh()
  300. this.$refs.chooseTable.refresh()
  301. this.spinning = false
  302. } else {
  303. this.spinning = false
  304. }
  305. })
  306. },
  307. // 双击快速添加
  308. handleClickRow (record) {
  309. return {
  310. on: {
  311. dblclick: (event) => {
  312. this.handleAdd(record)
  313. }
  314. }
  315. }
  316. },
  317. // 导入明细
  318. handleImport () {},
  319. // 删除
  320. handleDel (row, isAll) {
  321. const _this = this
  322. const content = isAll ? '删除后不可恢复,确定要进行整单删除吗?' : '删除后不可恢复,确定要进行删除吗?'
  323. this.$confirm({
  324. title: '提示',
  325. content: content,
  326. centered: true,
  327. onOk () {
  328. if (isAll) { // 整单删除
  329. _this.spinning = true
  330. purchaseReturnDelAll({ purchaseReturnSn: _this.$route.params.sn }).then(res => {
  331. if (res.status == 200) {
  332. _this.$message.success(res.message)
  333. _this.$refs.table.refresh()
  334. _this.$refs.chooseTable.refresh()
  335. _this.spinning = false
  336. } else {
  337. _this.spinning = false
  338. }
  339. })
  340. } else { // 单个删除
  341. _this.spinning = true
  342. purchaseReturnDetailDel({ id: row.id }).then(res => {
  343. if (res.status == 200) {
  344. _this.$message.success(res.message)
  345. _this.$refs.table.refresh()
  346. _this.$refs.chooseTable.refresh()
  347. _this.spinning = false
  348. } else {
  349. _this.spinning = false
  350. }
  351. })
  352. }
  353. }
  354. })
  355. },
  356. // 提交
  357. handleSubmit () {
  358. const _this = this
  359. _this.spinning = true
  360. purchaseReturnSubmit({ id: this.$route.params.id }).then(res => {
  361. if (res.status == 200) {
  362. this.$message.success(res.message)
  363. setTimeout(() => {
  364. _this.handleBack()
  365. _this.spinning = false
  366. }, 1000)
  367. } else {
  368. _this.spinning = false
  369. }
  370. })
  371. },
  372. // 返回列表
  373. handleBack () {
  374. this.$router.push({ path: '/purchasingManagement/purchaseReturn/list' })
  375. },
  376. // 已选产品 退货数量 blur
  377. qtyBlur (val, record) {
  378. // 光标移出,值发生改变再调用编辑接口
  379. if (val != record.qtyBackups) {
  380. this.handleAdd(record, 'edit')
  381. }
  382. },
  383. // 已选产品 退货原因 blur
  384. remarksBlur (val, record) {
  385. if (val && (val != record.remarksBackups)) {
  386. this.handleAdd(record, 'edit')
  387. }
  388. },
  389. filterOption (input, option) {
  390. return (
  391. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  392. )
  393. }
  394. },
  395. mounted () {
  396. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  397. this.$refs.chooseTable.refresh(true)
  398. this.resetSearchForm()
  399. }
  400. },
  401. activated () {
  402. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  403. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  404. this.$refs.chooseTable.refresh(true)
  405. this.resetSearchForm()
  406. }
  407. },
  408. beforeRouteEnter (to, from, next) {
  409. next(vm => {})
  410. }
  411. }
  412. </script>
  413. <style lang="less">
  414. .purchaseReturnEdit-wrap{
  415. position: relative;
  416. height: 100%;
  417. padding-bottom: 51px;
  418. box-sizing: border-box;
  419. >.ant-spin-nested-loading{
  420. overflow-y: scroll;
  421. height: 100%;
  422. }
  423. .purchaseReturnEdit-back, .purchaseReturnEdit-cont{
  424. margin-bottom: 10px;
  425. }
  426. }
  427. </style>