edit.vue 16 KB

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