checking.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div class="salesReturnCheck-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="salesReturnCheck-back" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="salesReturnCheck-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. <span style="margin: 0 15px;color: #666;">客户名称:{{ ordeDetail&&ordeDetail.buyerName || '--' }}</span>
  9. </template>
  10. </a-page-header>
  11. <a-card size="small" :bordered="false" class="salesReturnCheck-cont">
  12. <a-form layout="inline" style="margin-bottom:10px;" @keyup.enter.native="searchForm">
  13. <a-form-item label="产品编码" prop="productCode">
  14. <a-input id="salesReturnCheck-productCode" v-model.trim="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  15. </a-form-item>
  16. <a-form-item label="产品名称" prop="productName">
  17. <a-input id="salesReturnCheck-productName" v-model.trim="queryParam.productName" placeholder="请输入产品名称" allowClear />
  18. </a-form-item>
  19. <a-form-item>
  20. <a-button type="primary" class="button-info" @click="searchForm" :disabled="disabled" id="salesReturnCheck-refresh">查询</a-button>
  21. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="salesReturnCheck-reset">重置</a-button>
  22. </a-form-item>
  23. </a-form>
  24. <div style="border-top:1px solid #eee;padding-top:10px;">
  25. <a-button type="primary" :loading="loading" class="button-info" @click="plSetQty(1)">批量设置良品数量</a-button>
  26. <a-button type="primary" :loading="loading" class="button-error" @click="plSetQty(2)">批量设置返库数量</a-button>
  27. <div style="float:right;color:#999;margin-top:8px;">说明:红色行表示收货时新增的产品</div>
  28. </div>
  29. <!-- 已选配件列表 -->
  30. <s-table
  31. class="sTable"
  32. ref="table"
  33. :style="{ height: tableHeight+84.5+'px' }"
  34. :rowClassName="(record, index) => record.addFlag == '1' ? (record.addType == 'WAREHOUSE_RECEIVE'?'redBg-row':'orgBg-row'):''"
  35. size="small"
  36. :rowKey="(record) => record.id"
  37. :row-selection="{ columnWidth: 40 }"
  38. @rowSelection="rowSelectionFun"
  39. :columns="columns"
  40. :data="loadData"
  41. :scroll="{ y: tableHeight }"
  42. :defaultLoadData="false"
  43. bordered>
  44. <!-- 良品数量 -->
  45. <template slot="goodQty" slot-scope="text, record">
  46. <a-input-number
  47. id="salesReturn-goodQty"
  48. size="small"
  49. v-model="record.goodQty"
  50. :precision="0"
  51. :min="0"
  52. :max="record.receiveQty"
  53. placeholder="请输入"
  54. @blur="e => updateGoodQty(e.target.value, record)"
  55. style="width: 100%;" />
  56. </template>
  57. <!-- 返库数量 -->
  58. <template slot="backStockQty" slot-scope="text, record">
  59. <a-input-number
  60. id="salesReturn-backStockQty"
  61. size="small"
  62. v-model="record.backStockQty"
  63. :precision="0"
  64. :min="0"
  65. placeholder="请输入"
  66. @blur="e => updateBackStockQty(e.target.value, record)"
  67. style="width: 100%;" />
  68. </template>
  69. </s-table>
  70. <div class="footer-btn">
  71. <a-button
  72. size="large"
  73. style="padding: 0 60px;"
  74. :disabled="spinning"
  75. type="primary"
  76. class="button-primary"
  77. @click="handleSubmit()"
  78. id="salesReturn-handleSubmit">提交</a-button>
  79. </div>
  80. </a-card>
  81. </a-spin>
  82. <!-- 选中批量操作 -->
  83. <chooseTypeModal :openModal="openTypeModal" :type="actionType" @close="openTypeModal=false" @confirm="plconfirm"></chooseTypeModal>
  84. </div>
  85. </template>
  86. <script>
  87. import { commonMixin } from '@/utils/mixin'
  88. import { STable, VSelect } from '@/components'
  89. import { salesReturnDetail, salesReturnCheck } from '@/api/salesReturn'
  90. import { salesReturnDetailList, updateBatchBackStockQty, updateBatchGoodQty } from '@/api/salesReturnDetail'
  91. import chooseTypeModal from './chooseTypeModal.vue'
  92. export default {
  93. name: 'SalesReturnCheck',
  94. mixins: [commonMixin],
  95. components: {
  96. STable,
  97. VSelect,
  98. chooseTypeModal
  99. },
  100. data () {
  101. return {
  102. spinning: false,
  103. tableHeight: 0, // 表格高度
  104. orderSn: null,
  105. openTypeModal: false,
  106. actionType: '',
  107. disabled: false,
  108. isInster: false, // 是否正在添加产品
  109. ordeDetail: { discountAmount: 0 },
  110. loading: false,
  111. // 已选产品
  112. dataSource: [],
  113. productForm: {
  114. salesReturnBillSn: ''
  115. },
  116. queryParam: {
  117. productCode: '',
  118. productName: ''
  119. },
  120. chooseLoadData: [],
  121. // 加载数据方法 必须为 Promise 对象
  122. loadData: parameter => {
  123. this.disabled = true
  124. // 查询总计
  125. this.productForm.salesReturnBillSn = this.$route.params.sn
  126. return salesReturnDetailList(Object.assign(parameter, this.productForm, this.queryParam)).then(res => {
  127. let data
  128. if (res.status == 200) {
  129. data = res.data
  130. const no = (data.pageNo - 1) * data.pageSize
  131. for (var i = 0; i < data.list.length; i++) {
  132. data.list[i].no = no + i + 1
  133. data.list[i].goodQty = data.list[i].goodQty || 0
  134. data.list[i].backStockQty = data.list[i].backStockQty || 0
  135. data.list[i].goodQtyBackups = data.list[i].goodQty
  136. data.list[i].backStockQtyBackups = data.list[i].backStockQty
  137. }
  138. this.disabled = false
  139. this.chooseLoadData = data.list
  140. }
  141. return data
  142. })
  143. },
  144. rowSelectionInfo: null
  145. }
  146. },
  147. computed: {
  148. columns () {
  149. const arr = [
  150. { title: '序号', dataIndex: 'no', width: '6%', align: 'center' },
  151. { title: '产品编码', dataIndex: 'productEntity.code', align: 'center', width: '20%', customRender: function (text) { return text || '--' } },
  152. { title: '产品名称', dataIndex: 'productEntity.name', width: '28%', align: 'left', customRender: function (text) { return text || '--' } },
  153. { title: '单位', dataIndex: 'productEntity.unit', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  154. { title: '申请退货数量', dataIndex: 'qty', align: 'center', width: '10%', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  155. { title: '仓库实收数量', dataIndex: 'receiveQty', align: 'center', width: '10%', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  156. { title: '坏件数量', dataIndex: 'badQty', align: 'center', width: '10%', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  157. { title: '良品数量', dataIndex: 'goodQty', width: '10%', align: 'center', scopedSlots: { customRender: 'goodQty' } },
  158. { title: '返库数量', dataIndex: 'backStockQty', width: '10%', align: 'center', scopedSlots: { customRender: 'backStockQty' } },
  159. { title: '退货原因', dataIndex: 'returnReasonDictValue', width: '20%', align: 'center', customRender: function (text) { return text || '--' } }
  160. ]
  161. return arr
  162. }
  163. },
  164. methods: {
  165. // 表格选中项
  166. rowSelectionFun (obj) {
  167. this.rowSelectionInfo = obj || null
  168. },
  169. // 返回
  170. handleBack () {
  171. this.$router.push({ name: 'receiveCheckList' })
  172. },
  173. // 批量设置
  174. plSetQty (type) {
  175. const _this = this
  176. if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  177. _this.$message.warning('请先选择产品!')
  178. return
  179. }
  180. this.actionType = type
  181. this.openTypeModal = true
  182. },
  183. // 批量修改数量
  184. plconfirm (val) {
  185. const _this = this
  186. const obj = []
  187. const hasError = _this.rowSelectionInfo.selectedRows.filter(item => item.backStockQty > 0)
  188. _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRows.map(item => {
  189. // 批量设置良品
  190. if (this.actionType == 1) {
  191. const pa = {
  192. salesReturnDetailSn: item.salesReturnDetailSn,
  193. goodQty: val == 1 ? item.receiveQty : 0
  194. }
  195. // 如果批量修改良品数量为0,且返库数量又不是0的情况
  196. if (hasError.length && val == 0) {
  197. pa.backStockQty = 0
  198. }
  199. obj.push(pa)
  200. } else {
  201. // 批量设置返库
  202. obj.push({
  203. salesReturnDetailSn: item.salesReturnDetailSn,
  204. backStockQty: val == 1 ? item.goodQty : 0
  205. })
  206. }
  207. })
  208. console.log(obj)
  209. // 如果批量修改良品数量为0
  210. if (val == 0 && this.actionType == 1 && hasError.length) {
  211. this.$confirm({
  212. title: '提示',
  213. content: '是否将返库数量同样设置为0?',
  214. centered: true,
  215. closable: true,
  216. onOk () {
  217. _this.plSave(obj)
  218. }
  219. })
  220. } else {
  221. _this.plSave(obj)
  222. }
  223. },
  224. plSave (obj) {
  225. const fun = this.actionType == 1 ? updateBatchGoodQty : updateBatchBackStockQty
  226. this.spinning = true
  227. fun(obj).then(res => {
  228. if (res.status == 200) {
  229. this.$refs.table.clearSelected()
  230. this.$refs.table.refresh()
  231. this.$message.success(res.message)
  232. }
  233. this.spinning = false
  234. this.openTypeModal = false
  235. })
  236. },
  237. // 修改良品数量
  238. updateGoodQty (val, record) {
  239. if (record.backStockQty > record.goodQty) {
  240. this.$message.info('返库数量不能大于良品数量')
  241. record.goodQty = record.goodQtyBackups
  242. return
  243. }
  244. // 光标移出,值发生改变再调用编辑接口
  245. if (val && val != record.goodQtyBackups) {
  246. this.spinning = true
  247. updateBatchGoodQty([{
  248. salesReturnDetailSn: record.salesReturnDetailSn,
  249. goodQty: record.goodQty
  250. }]).then(res => {
  251. if (res.status == 200) {
  252. this.resetSearchForm(false)
  253. this.$message.success(res.message)
  254. record.goodQtyBackups = record.goodQty
  255. } else {
  256. record.goodQty = record.goodQtyBackups
  257. }
  258. this.spinning = false
  259. })
  260. } else {
  261. record.goodQty = record.goodQtyBackups
  262. }
  263. },
  264. // 修改返库数量
  265. updateBackStockQty (val, record) {
  266. if (record.backStockQty > record.goodQty) {
  267. this.$message.info('返库数量不能大于良品数量')
  268. record.backStockQtyBackups = record.backStockQty
  269. return
  270. }
  271. // 光标移出,值发生改变再调用编辑接口
  272. if (val && val != record.backStockQtyBackups) {
  273. this.spinning = true
  274. updateBatchBackStockQty([{
  275. salesReturnDetailSn: record.salesReturnDetailSn,
  276. backStockQty: record.backStockQty
  277. }]).then(res => {
  278. if (res.status == 200) {
  279. this.resetSearchForm(false)
  280. this.$message.success(res.message)
  281. record.backStockQtyBackups = record.backStockQty
  282. } else {
  283. record.backStockQty = record.backStockQtyBackups
  284. }
  285. this.spinning = false
  286. })
  287. } else {
  288. record.backStockQty = record.backStockQtyBackups
  289. }
  290. },
  291. // 获取单据详细
  292. getOrderDetail () {
  293. salesReturnDetail({ sn: this.orderSn }).then(res => {
  294. this.ordeDetail = res.data || null
  295. })
  296. },
  297. // 重置
  298. resetSearchForm (flag) {
  299. if (flag) {
  300. this.rowSelectionInfo = null
  301. this.$refs.table.clearSelected()
  302. this.queryParam = {
  303. productCode: '',
  304. productName: ''
  305. }
  306. }
  307. this.$refs.table.refresh(!!flag)
  308. },
  309. searchForm () {
  310. this.$refs.table.refresh(true)
  311. this.$refs.table.clearSelected()
  312. },
  313. // 提交品检
  314. handleSubmit () {
  315. const _this = this
  316. this.$confirm({
  317. title: '提示',
  318. content: '提交后将无法修改,确认提交吗?',
  319. centered: true,
  320. closable: true,
  321. onOk () {
  322. _this.spinning = true
  323. salesReturnCheck({ salesReturnBillSn: _this.orderSn }).then(res => {
  324. if (res.status == 200) {
  325. _this.handleBack()
  326. _this.$message.success(res.message)
  327. _this.spinning = false
  328. } else {
  329. _this.spinning = false
  330. }
  331. })
  332. }
  333. })
  334. },
  335. pageInit () {
  336. const _this = this
  337. this.$nextTick(() => { // 页面渲染完成后的回调
  338. _this.setTableH()
  339. })
  340. this.orderSn = this.$route.params.sn
  341. this.getOrderDetail()
  342. },
  343. setTableH () {
  344. this.tableHeight = window.innerHeight - 390
  345. }
  346. },
  347. mounted () {
  348. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  349. this.$refs.table.refresh(true)
  350. this.pageInit()
  351. }
  352. },
  353. activated () {
  354. this.$refs.table.refresh()
  355. this.pageInit()
  356. },
  357. beforeRouteEnter (to, from, next) {
  358. next(vm => {})
  359. }
  360. }
  361. </script>
  362. <style lang="less">
  363. .salesReturnCheck-wrap{
  364. position: relative;
  365. height: 100%;
  366. padding-bottom: 51px;
  367. box-sizing: border-box;
  368. >.ant-spin-nested-loading{
  369. height: 100%;
  370. }
  371. .footer-btn{
  372. text-align: center;
  373. }
  374. .salesReturnCheck-cont{
  375. margin-top: 10px;
  376. .sTable{
  377. margin-top: 10px;
  378. }
  379. .total-bar{
  380. display: flex;
  381. align-items: center;
  382. justify-content: space-between;
  383. > div{
  384. &:last-child{
  385. display: flex;
  386. align-items: center;
  387. justify-content: space-between;
  388. > div{
  389. padding: 0 10px;
  390. }
  391. }
  392. }
  393. }
  394. }
  395. .redBg-row{
  396. background-color: #f5beb4;
  397. }
  398. .orgBg-row{
  399. background-color: #fffca2;
  400. }
  401. }
  402. </style>