edit.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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. <div 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. <span v-if="record.refundableQty==0">--</span>
  81. <a-button
  82. v-else
  83. size="small"
  84. type="link"
  85. class="button-primary"
  86. @click="handleAdd(record)"
  87. id="purchaseReturnEdit-add-btn">添加</a-button>
  88. </template>
  89. </s-table>
  90. </a-collapse-panel>
  91. </a-collapse>
  92. </div>
  93. <!-- 已选产品 -->
  94. <a-card size="small" :bordered="false" class="purchaseReturnEdit-cont">
  95. <a-collapse :activeKey="['1']">
  96. <a-collapse-panel key="1">
  97. <template slot="header">
  98. 已选产品
  99. <a-button
  100. size="small"
  101. type="primary"
  102. class="button-error"
  103. id="purchaseReturnEdit-delAll-btn"
  104. @click.stop="handleDel('', 'all')"
  105. style="margin-right: 10px;float: right;">清空列表</a-button>
  106. </template>
  107. <!-- 列表 -->
  108. <s-table
  109. class="sTable"
  110. ref="chooseTable"
  111. size="small"
  112. :rowKey="(record) => record.id"
  113. :columns="chooseColumns"
  114. :data="chooseLoadData"
  115. :defaultLoadData="false"
  116. :pageSize="10"
  117. :scroll="{ y: 149 }"
  118. bordered>
  119. <!-- 退货数量 -->
  120. <template slot="qty" slot-scope="text, record">
  121. <a-input-number
  122. size="small"
  123. id="purchaseReturnEdit-qty"
  124. v-model="record.qty"
  125. :precision="0"
  126. :min="1"
  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.trim="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="link" 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. <a-card size="small" :bordered="false" 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. </a-card>
  161. </div>
  162. </template>
  163. <script>
  164. import { commonMixin } from '@/utils/mixin'
  165. import { STable, VSelect } from '@/components'
  166. import Print from '@/views/common/print.vue'
  167. import { hdPrint } from '@/libs/JGPrint'
  168. import {
  169. purchaseReturnPurchaseBillDetailList,
  170. purchaseReturnDetailList,
  171. purchaseReturnDetailSave,
  172. purchaseReturnDetailDel,
  173. purchaseReturnSubmit,
  174. purchaseReturnDelAll,
  175. purchaseReturnDetailPrint,
  176. purchaseReturnDetailExport } from '@/api/purchaseReturn'
  177. export default {
  178. name: 'PurchaseReturnEdit',
  179. components: { STable, VSelect, Print },
  180. mixins: [commonMixin],
  181. data () {
  182. return {
  183. spinning: false,
  184. queryParam: {
  185. purchaseBillNo: '',
  186. productCode: '',
  187. productName: ''
  188. },
  189. dataSource: [],
  190. disabled: false, // 查询、重置按钮是否可操作
  191. advanced: false, // 高级搜索 展开/关闭
  192. // 加载数据方法 必须为 Promise 对象
  193. loadData: parameter => {
  194. this.disabled = true
  195. return purchaseReturnPurchaseBillDetailList(Object.assign(parameter, this.queryParam)).then(res => {
  196. const data = res.data
  197. const no = (data.pageNo - 1) * data.pageSize
  198. for (var i = 0; i < data.list.length; i++) {
  199. data.list[i].no = no + i + 1
  200. }
  201. this.disabled = false
  202. return data
  203. })
  204. },
  205. // 加载数据方法 必须为 Promise 对象
  206. chooseLoadData: parameter => {
  207. return purchaseReturnDetailList(Object.assign(parameter, { purchaseReturnSn: this.$route.params.sn, orderBy: 'qpls_purchase_return_bill_detail.CREATE_DATE desc' })).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. data.list[i].qtyBackups = data.list[i].qty
  213. data.list[i].remarksBackups = data.list[i].remarks
  214. data.list[i].refundableQty = data.list[i].purchaseBillRefundableQty + data.list[i].qty
  215. }
  216. this.dataSource = data.list
  217. return data
  218. })
  219. }
  220. }
  221. },
  222. computed: {
  223. columns () {
  224. const _this = this
  225. const arr = [
  226. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  227. { title: '采购单号', dataIndex: 'purchaseBillNo', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  228. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  229. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '13%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  230. { title: '采购总数', dataIndex: 'qty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  231. { slots: { title: 'refundableQtyTitle' }, dataIndex: 'refundableQty', width: '9%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  232. { title: '库存数量', dataIndex: 'stock.currentStockQty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  233. { title: '缺货数量', dataIndex: 'cancelQty', width: '7%', align: 'center' },
  234. { title: '退货数量', scopedSlots: { customRender: 'returnQty' }, width: '8%', align: 'center' },
  235. // { title: '采购价', dataIndex: 'price', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  236. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '5%', align: 'center', customRender: function (text) { return text || '--' } },
  237. { title: '操作', scopedSlots: { customRender: 'action' }, width: '7%', align: 'center' }
  238. ]
  239. if (this.$hasPermissions('M_ShowAllCost')) {
  240. arr.splice(9, 0, { title: '采购价', dataIndex: 'price', width: '6%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } })
  241. }
  242. return arr
  243. },
  244. chooseColumns () {
  245. const _this = this
  246. const arr = [
  247. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  248. { title: '采购单号', dataIndex: 'purchaseBillNo', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  249. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  250. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '15%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  251. { title: '采购总数', dataIndex: 'purchaseBillQty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  252. { title: '退货数量', scopedSlots: { customRender: 'qty' }, width: '10%', align: 'center' },
  253. // { title: '采购价', dataIndex: 'cost', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  254. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  255. { title: '退货原因', scopedSlots: { customRender: 'remarks' }, width: '15%', align: 'center' },
  256. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  257. ]
  258. if (this.$hasPermissions('M_ShowAllCost')) {
  259. arr.splice(6, 0, { title: '采购价', dataIndex: 'cost', width: '7%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } })
  260. }
  261. return arr
  262. }
  263. },
  264. methods: {
  265. // 打印预览/快捷打印
  266. handlePrint (type, printerType) {
  267. const _this = this
  268. _this.spinning = true
  269. let url = purchaseReturnDetailPrint
  270. const params = { sn: this.$route.params.sn }
  271. params.showFlag = this.$hasPermissions('M_ShowAllCost') ? 1 : 0
  272. if (type == 'export') { // 导出
  273. url = purchaseReturnDetailExport
  274. }
  275. // 打印或导出
  276. hdPrint(printerType, type, url, params, '采购退货单', function () {
  277. _this.spinning = false
  278. })
  279. },
  280. // 重置
  281. resetSearchForm () {
  282. this.queryParam.purchaseBillNo = ''
  283. this.queryParam.productCode = ''
  284. this.queryParam.productName = ''
  285. this.$refs.table.refresh(true)
  286. },
  287. // 添加/编辑
  288. handleAdd (row, isEdit) {
  289. // 添加时退货数量字段名为returnQty,编辑时退货数量字段名为qty
  290. if (!isEdit && !row.returnQty) {
  291. this.$message.warning('请输入退货数量')
  292. return
  293. }
  294. const params = {
  295. id: isEdit ? row.id : undefined,
  296. purchaseReturnSn: this.$route.params.sn,
  297. purchaseBillSn: row.purchaseBillSn,
  298. purchaseBillNo: row.purchaseBillNo,
  299. purchaseBillDetailSn: row.purchaseBillDetailSn,
  300. qty: isEdit ? row.qty : row.returnQty, // 退货数量
  301. productSn: row.productSn,
  302. cost: row.price,
  303. remarks: row.remarks,
  304. promotionFlag: row.promotionFlag
  305. }
  306. if (isEdit) { // 编辑
  307. // 清空退货数量时,值应保持未清空前的值,因退货数量都不可为空
  308. if (!row.qty) {
  309. row.qty = row.qtyBackups
  310. return
  311. }
  312. }
  313. this.spinning = true
  314. purchaseReturnDetailSave(params).then(res => {
  315. if (res.status == 200) {
  316. this.$message.success(res.message)
  317. if (isEdit) {
  318. this.$refs.table.refresh()
  319. }
  320. this.$refs.chooseTable.refresh()
  321. this.spinning = false
  322. } else {
  323. this.spinning = false
  324. }
  325. })
  326. },
  327. // 导入明细
  328. handleImport () {},
  329. // 删除
  330. handleDel (row, isAll) {
  331. const _this = this
  332. const content = isAll ? '删除后不可恢复,确定要清空列表吗?' : '删除后不可恢复,确定要进行删除吗?'
  333. this.$confirm({
  334. title: '提示',
  335. content: content,
  336. centered: true,
  337. onOk () {
  338. if (isAll) { // 清空列表
  339. _this.spinning = true
  340. purchaseReturnDelAll({ purchaseReturnSn: _this.$route.params.sn }).then(res => {
  341. if (res.status == 200) {
  342. _this.$message.success(res.message)
  343. _this.$refs.table.refresh()
  344. _this.$refs.chooseTable.refresh()
  345. _this.spinning = false
  346. } else {
  347. _this.spinning = false
  348. }
  349. })
  350. } else { // 单个删除
  351. _this.spinning = true
  352. purchaseReturnDetailDel({ id: row.id }).then(res => {
  353. if (res.status == 200) {
  354. _this.$message.success(res.message)
  355. _this.$refs.table.refresh()
  356. _this.$refs.chooseTable.refresh()
  357. _this.spinning = false
  358. } else {
  359. _this.spinning = false
  360. }
  361. })
  362. }
  363. }
  364. })
  365. },
  366. // 提交
  367. handleSubmit () {
  368. const _this = this
  369. _this.spinning = true
  370. purchaseReturnSubmit({ id: this.$route.params.id }).then(res => {
  371. if (res.status == 200) {
  372. this.$message.success(res.message)
  373. setTimeout(() => {
  374. _this.handleBack()
  375. _this.spinning = false
  376. }, 1000)
  377. } else {
  378. _this.spinning = false
  379. }
  380. })
  381. },
  382. // 返回列表
  383. handleBack () {
  384. this.$router.push({ path: '/purchasingManagement/purchaseReturn/list' })
  385. },
  386. // 已选产品 退货数量 blur
  387. qtyBlur (val, record) {
  388. // 光标移出,值发生改变再调用编辑接口
  389. if (val != record.qtyBackups) {
  390. this.handleAdd(record, 'edit')
  391. }
  392. },
  393. // 已选产品 退货原因 blur
  394. remarksBlur (val, record) {
  395. if (val && (val != record.remarksBackups)) {
  396. this.handleAdd(record, 'edit')
  397. }
  398. },
  399. filterOption (input, option) {
  400. return (
  401. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  402. )
  403. }
  404. },
  405. mounted () {
  406. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  407. this.$refs.chooseTable.refresh(true)
  408. this.resetSearchForm()
  409. }
  410. },
  411. activated () {
  412. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  413. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  414. this.$refs.chooseTable.refresh(true)
  415. this.resetSearchForm()
  416. }
  417. },
  418. beforeRouteEnter (to, from, next) {
  419. next(vm => {})
  420. }
  421. }
  422. </script>
  423. <style lang="less">
  424. .purchaseReturnEdit-wrap{
  425. position: relative;
  426. height: 100%;
  427. padding-bottom: 51px;
  428. box-sizing: border-box;
  429. >.ant-spin-nested-loading{
  430. overflow-y: auto;
  431. height: 100%;
  432. }
  433. .purchaseReturnEdit-back, .purchaseReturnEdit-cont{
  434. margin-bottom: 10px;
  435. }
  436. }
  437. </style>