edit.vue 18 KB

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