grapEdit.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. // 表头
  193. columns: [
  194. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  195. { title: '采购单号', dataIndex: 'purchaseBillNo', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  196. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  197. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '13%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  198. { title: '采购总数', dataIndex: 'qty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  199. { slots: { title: 'refundableQtyTitle' }, dataIndex: 'refundableQty', width: '9%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  200. { title: '库存数量', dataIndex: 'stock.currentStockQty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  201. { title: '缺货数量', dataIndex: 'cancelQty', width: '7%', align: 'center' },
  202. { title: '退货数量', scopedSlots: { customRender: 'returnQty' }, width: '8%', align: 'center' },
  203. { title: '采购价', dataIndex: 'price', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  204. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '5%', align: 'center', customRender: function (text) { return text || '--' } },
  205. { title: '操作', scopedSlots: { customRender: 'action' }, width: '7%', align: 'center' }
  206. ],
  207. // 加载数据方法 必须为 Promise 对象
  208. loadData: parameter => {
  209. this.disabled = true
  210. return purchaseReturnPurchaseBillDetailList(Object.assign(parameter, this.queryParam)).then(res => {
  211. const data = res.data
  212. const no = (data.pageNo - 1) * data.pageSize
  213. for (var i = 0; i < data.list.length; i++) {
  214. data.list[i].no = no + i + 1
  215. }
  216. this.disabled = false
  217. return data
  218. })
  219. },
  220. // 表头
  221. chooseColumns: [
  222. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  223. { title: '采购单号', dataIndex: 'purchaseBillNo', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  224. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  225. { title: '产品名称', dataIndex: 'dealerProductEntity.name', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  226. { title: '采购总数', dataIndex: 'purchaseBillQty', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  227. { title: '退货数量', scopedSlots: { customRender: 'qty' }, width: '10%', align: 'center' },
  228. { title: '采购价', dataIndex: 'cost', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  229. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  230. { title: '退货原因', scopedSlots: { customRender: 'remarks' }, width: '15%', align: 'center' },
  231. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  232. ],
  233. // 加载数据方法 必须为 Promise 对象
  234. chooseLoadData: parameter => {
  235. return purchaseReturnDetailList(Object.assign(parameter, { purchaseReturnSn: this.$route.params.sn, orderBy: 'qpls_purchase_return_bill_detail.CREATE_DATE desc' })).then(res => {
  236. const data = res.data
  237. const no = (data.pageNo - 1) * data.pageSize
  238. for (var i = 0; i < data.list.length; i++) {
  239. data.list[i].no = no + i + 1
  240. data.list[i].qtyBackups = data.list[i].qty
  241. data.list[i].remarksBackups = data.list[i].remarks
  242. data.list[i].refundableQty = data.list[i].purchaseBillRefundableQty + data.list[i].qty
  243. }
  244. this.dataSource = data.list
  245. return data
  246. })
  247. }
  248. }
  249. },
  250. methods: {
  251. // 打印预览/快捷打印
  252. handlePrint (type, printerType) {
  253. const _this = this
  254. _this.spinning = true
  255. let url = purchaseReturnDetailPrint
  256. const params = { sn: this.$route.params.sn }
  257. if (type == 'export') { // 导出
  258. url = purchaseReturnDetailExport
  259. }
  260. // 打印或导出
  261. hdPrint(printerType, type, url, params, '采购退货单', function () {
  262. _this.spinning = false
  263. })
  264. },
  265. // 重置
  266. resetSearchForm () {
  267. this.queryParam.purchaseBillNo = ''
  268. this.queryParam.productCode = ''
  269. this.queryParam.productName = ''
  270. this.$refs.table.refresh(true)
  271. },
  272. // 添加/编辑
  273. handleAdd (row, isEdit) {
  274. // 添加时退货数量字段名为returnQty,编辑时退货数量字段名为qty
  275. if (!isEdit && !row.returnQty) {
  276. this.$message.warning('请输入退货数量')
  277. return
  278. }
  279. const params = {
  280. id: isEdit ? row.id : undefined,
  281. purchaseReturnSn: this.$route.params.sn,
  282. purchaseBillSn: row.purchaseBillSn,
  283. purchaseBillNo: row.purchaseBillNo,
  284. purchaseBillDetailSn: row.purchaseBillDetailSn,
  285. qty: isEdit ? row.qty : row.returnQty, // 退货数量
  286. productSn: row.productSn,
  287. cost: row.price,
  288. remarks: row.remarks,
  289. promotionFlag: row.promotionFlag
  290. }
  291. if (isEdit) { // 编辑
  292. // 清空退货数量时,值应保持未清空前的值,因退货数量都不可为空
  293. if (!row.qty) {
  294. row.qty = row.qtyBackups
  295. return
  296. }
  297. }
  298. this.spinning = true
  299. purchaseReturnDetailSave(params).then(res => {
  300. if (res.status == 200) {
  301. this.$message.success(res.message)
  302. // this.$refs.table.refresh()
  303. this.$refs.chooseTable.refresh()
  304. this.spinning = false
  305. } else {
  306. this.spinning = false
  307. }
  308. })
  309. },
  310. // 双击快速添加
  311. handleClickRow (record) {
  312. return {
  313. on: {
  314. dblclick: (event) => {
  315. this.handleAdd(record)
  316. }
  317. }
  318. }
  319. },
  320. // 导入明细
  321. handleImport () {},
  322. // 删除
  323. handleDel (row, isAll) {
  324. const _this = this
  325. const content = isAll ? '删除后不可恢复,确定要进行整单删除吗?' : '删除后不可恢复,确定要进行删除吗?'
  326. this.$confirm({
  327. title: '提示',
  328. content: content,
  329. centered: true,
  330. onOk () {
  331. if (isAll) { // 整单删除
  332. _this.spinning = true
  333. purchaseReturnDelAll({ purchaseReturnSn: _this.$route.params.sn }).then(res => {
  334. if (res.status == 200) {
  335. _this.$message.success(res.message)
  336. // _this.$refs.table.refresh()
  337. _this.$refs.chooseTable.refresh()
  338. _this.spinning = false
  339. } else {
  340. _this.spinning = false
  341. }
  342. })
  343. } else { // 单个删除
  344. _this.spinning = true
  345. purchaseReturnDetailDel({ id: row.id }).then(res => {
  346. if (res.status == 200) {
  347. _this.$message.success(res.message)
  348. // _this.$refs.table.refresh()
  349. _this.$refs.chooseTable.refresh()
  350. _this.spinning = false
  351. } else {
  352. _this.spinning = false
  353. }
  354. })
  355. }
  356. }
  357. })
  358. },
  359. // 提交
  360. handleSubmit () {
  361. const _this = this
  362. _this.spinning = true
  363. purchaseReturnSubmit({ id: this.$route.params.id }).then(res => {
  364. if (res.status == 200) {
  365. this.$message.success(res.message)
  366. setTimeout(() => {
  367. _this.handleBack()
  368. _this.spinning = false
  369. }, 1000)
  370. } else {
  371. _this.spinning = false
  372. }
  373. })
  374. },
  375. // 返回列表
  376. handleBack () {
  377. this.$router.push({ path: '/purchasingManagement/purchaseReturn/list' })
  378. },
  379. // 已选产品 退货数量 blur
  380. qtyBlur (val, record) {
  381. // 光标移出,值发生改变再调用编辑接口
  382. if (val != record.qtyBackups) {
  383. this.handleAdd(record, 'edit')
  384. }
  385. },
  386. // 已选产品 退货原因 blur
  387. remarksBlur (val, record) {
  388. if (val && (val != record.remarksBackups)) {
  389. this.handleAdd(record, 'edit')
  390. }
  391. },
  392. filterOption (input, option) {
  393. return (
  394. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  395. )
  396. }
  397. },
  398. mounted () {
  399. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  400. this.$refs.chooseTable.refresh(true)
  401. this.resetSearchForm()
  402. }
  403. },
  404. activated () {
  405. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  406. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  407. this.$refs.chooseTable.refresh(true)
  408. this.resetSearchForm()
  409. }
  410. },
  411. beforeRouteEnter (to, from, next) {
  412. next(vm => {})
  413. }
  414. }
  415. </script>
  416. <style lang="less">
  417. .purchaseReturnEdit-wrap{
  418. position: relative;
  419. height: 100%;
  420. padding-bottom: 51px;
  421. box-sizing: border-box;
  422. >.ant-spin-nested-loading{
  423. overflow-y: scroll;
  424. height: 100%;
  425. }
  426. .purchaseReturnEdit-back, .purchaseReturnEdit-cont{
  427. margin-bottom: 10px;
  428. }
  429. }
  430. </style>