edit.vue 17 KB

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