edit.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <div class="bulkReturnGoodsEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="bulkReturnGoodsEdit-cont">
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="bulkReturnGoodsEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. </template>
  9. </a-page-header>
  10. <!-- 选择产品 -->
  11. <a-card size="small" :bordered="false" class="bulkReturnGoodsEdit-cont">
  12. <!-- 搜索条件 -->
  13. <div class="table-page-search-wrapper">
  14. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  15. <a-row :gutter="15">
  16. <a-col :md="6" :sm="24">
  17. <a-form-item label="产品编码" prop="productCode">
  18. <a-input id="bulkReturnGoodsEdit-productCode" v-model="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  19. </a-form-item>
  20. </a-col>
  21. <a-col :md="6" :sm="24">
  22. <a-form-item label="产品名称" prop="productName">
  23. <a-input id="bulkReturnGoodsEdit-productName" v-model="queryParam.productName" placeholder="请输入产品名称" allowClear />
  24. </a-form-item>
  25. </a-col>
  26. <a-col :md="6" :sm="24">
  27. <a-form-model-item label="仓库">
  28. <a-select
  29. placeholder="请选择仓库"
  30. id="bulkReturnGoodsEdit-warehouseSn"
  31. allowClear
  32. v-model="queryParam.warehouseSn"
  33. :showSearch="true"
  34. option-filter-prop="children"
  35. :filter-option="filterOption">
  36. <a-select-option v-for="item in warehouseList" :key="item.warehouseSn" :value="item.warehouseSn">{{ item.name }}</a-select-option>
  37. </a-select>
  38. </a-form-model-item>
  39. </a-col>
  40. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  41. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="bulkReturnGoodsEdit-refresh">查询</a-button>
  42. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="bulkReturnGoodsEdit-reset">重置</a-button>
  43. </a-col>
  44. </a-row>
  45. </a-form>
  46. </div>
  47. <!-- 列表 -->
  48. <s-table
  49. class="sTable"
  50. ref="table"
  51. size="small"
  52. :rowKey="(record) => record.id"
  53. :columns="columns"
  54. :customRow="handleClickRow"
  55. :data="loadData"
  56. :defaultLoadData="false"
  57. :scroll="{ x: 980, y:300 }"
  58. bordered>
  59. <!-- 退货单价 -->
  60. <template slot="purchaseCost" slot-scope="text, record">
  61. <a-input-number
  62. size="small"
  63. id="bulkReturnGoodsEdit-purchaseCost"
  64. v-model="record.purchaseCost"
  65. :precision="2"
  66. :min="0"
  67. :max="999999"
  68. placeholder="请输入"
  69. style="width: 100%;" />
  70. </template>
  71. <!-- 退货数量 -->
  72. <template slot="purchaseQty" slot-scope="text, record">
  73. <a-input-number
  74. size="small"
  75. id="bulkReturnGoodsEdit-purchaseQty"
  76. v-model="record.purchaseQty"
  77. :precision="0"
  78. :min="1"
  79. :max="record.currentQty"
  80. placeholder="请输入"
  81. style="width: 100%;" />
  82. </template>
  83. <!-- 操作 -->
  84. <template slot="action" slot-scope="text, record">
  85. <a-button size="small" type="primary" class="button-primary" @click="handleAdd(record)" id="bulkReturnGoodsEdit-add-btn">添加</a-button>
  86. </template>
  87. </s-table>
  88. </a-card>
  89. <!-- 已选产品 -->
  90. <a-card size="small" :bordered="false" class="bulkReturnGoodsEdit-cont">
  91. <!-- 总计 -->
  92. <a-alert type="info" style="margin-bottom:10px">
  93. <div slot="message">
  94. 总款数<strong>{{ (productTotal&&(productTotal.purchaseSize || productTotal.purchaseSize==0)) ? productTotal.purchaseSize : '--' }}</strong> ,
  95. 总数量<strong>{{ (productTotal&&(productTotal.purchaseQty || productTotal.purchaseQty==0)) ? productTotal.purchaseQty : '--' }}</strong> ,
  96. 总金额<strong>{{ (productTotal&&(productTotal.purchaseCost || productTotal.purchaseCost==0)) ? '¥'+productTotal.purchaseCost : '--' }}</strong>
  97. </div>
  98. </a-alert>
  99. <!-- 筛选条件 -->
  100. <a-row :gutter="15" justify="space-between">
  101. <a-col :span="17">
  102. <div class="table-page-search-wrapper">
  103. <a-form layout="inline" @keyup.enter.native="$refs.chooseTable.refresh(true)">
  104. <a-row :gutter="15">
  105. <a-col :md="9" :sm="24">
  106. <a-form-item label="产品编码" prop="productCode">
  107. <a-input id="bulkReturnGoodsEdit-productCode" v-model="chooseQueryParam.productCode" placeholder="请输入产品编码" allowClear />
  108. </a-form-item>
  109. </a-col>
  110. <a-col :md="9" :sm="24">
  111. <a-form-item label="产品名称" prop="productName">
  112. <a-input id="bulkReturnGoodsEdit-productName" v-model="chooseQueryParam.productName" placeholder="请输入产品名称" allowClear />
  113. </a-form-item>
  114. </a-col>
  115. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  116. <a-button type="primary" @click="$refs.chooseTable.refresh(true)" :disabled="chooseDisabled" id="bulkReturnGoodsEdit-refresh">查询</a-button>
  117. <a-button style="margin-left: 8px" @click="chooseResetSearchForm" :disabled="chooseDisabled" id="bulkReturnGoodsEdit-reset">重置</a-button>
  118. </a-col>
  119. </a-row>
  120. </a-form>
  121. </div>
  122. </a-col>
  123. <a-col :span="7" style="text-align: right;"></a-col>
  124. </a-row>
  125. <!-- 列表 -->
  126. <s-table
  127. class="sTable"
  128. ref="chooseTable"
  129. size="small"
  130. :rowKey="(record) => record.id"
  131. :columns="chooseColumns"
  132. :data="chooseLoadData"
  133. :defaultLoadData="false"
  134. :scroll="{ x: 980, y:300 }"
  135. bordered>
  136. <!-- 退货单价 -->
  137. <template slot="purchaseCost" slot-scope="text, record">
  138. <a-input-number
  139. size="small"
  140. id="bulkReturnGoodsEdit-purchaseCost"
  141. v-model="record.purchaseCost"
  142. :precision="2"
  143. :min="0"
  144. :max="999999"
  145. placeholder="请输入"
  146. @blur="e => purchaseCostBlur(e.target.value, record)"
  147. style="width: 100%;" />
  148. </template>
  149. <!-- 退货数量 -->
  150. <template slot="purchaseQty" slot-scope="text, record">
  151. <a-input-number
  152. size="small"
  153. id="bulkReturnGoodsEdit-purchaseQty"
  154. v-model="record.purchaseQty"
  155. :precision="0"
  156. :min="1"
  157. :max="999999"
  158. placeholder="请输入"
  159. @blur="e => purchaseQtyBlur(e.target.value, record)"
  160. style="width: 100%;" />
  161. </template>
  162. <!-- 操作 -->
  163. <template slot="action" slot-scope="text, record">
  164. <a-button size="small" type="primary" class="button-error" @click="handleDel(record)" id="bulkReturnGoodsEdit-del-btn">删除</a-button>
  165. </template>
  166. </s-table>
  167. </a-card>
  168. </a-spin>
  169. <div class="affix-cont">
  170. <a-button
  171. type="primary"
  172. id="bulkReturnGoodsEdit-submit-btn"
  173. size="large"
  174. :disabled="spinning"
  175. class="button-primary"
  176. @click="handleSubmit"
  177. style="padding: 0 60px;">提交</a-button>
  178. </div>
  179. </div>
  180. </template>
  181. <script>
  182. import { STable, VSelect } from '@/components'
  183. import { warehouseAllList } from '@/api/warehouse'
  184. import { sparePartsRetDetailList, stockDetailProductList, sparePartsRetDetailSave, sparePartsRetDetailCount, sparePartsRetDetailDel, sparePartsRetSubmit } from '@/api/sparePartsRet'
  185. export default {
  186. components: { STable, VSelect },
  187. data () {
  188. return {
  189. spinning: false,
  190. queryParam: {
  191. productCode: '',
  192. productName: '',
  193. warehouseSn: undefined
  194. },
  195. disabled: false, // 查询、重置按钮是否可操作
  196. // 表头
  197. columns: [
  198. { title: '产品编码', dataIndex: 'productCode', width: 180, align: 'center', customRender: function (text) { return text || '--' } },
  199. { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' } },
  200. { title: '仓库', dataIndex: 'warehouseName', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  201. { title: '仓位', dataIndex: 'warehouseLocationName', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  202. { title: '库存数量', dataIndex: 'currentQty', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  203. { title: '单位', dataIndex: 'unit', width: 60, align: 'center', customRender: function (text) { return text || '--' } },
  204. { title: '退货单价', scopedSlots: { customRender: 'purchaseCost' }, width: 100, align: 'center' },
  205. { title: '退货数量', scopedSlots: { customRender: 'purchaseQty' }, width: 100, align: 'center' },
  206. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center', fixed: 'right' }
  207. ],
  208. // 加载数据方法 必须为 Promise 对象
  209. loadData: parameter => {
  210. this.disabled = true
  211. return stockDetailProductList(Object.assign(parameter, this.queryParam)).then(res => {
  212. const data = res.data
  213. const no = (data.pageNo - 1) * data.pageSize
  214. for (var i = 0; i < data.list.length; i++) {
  215. data.list[i].no = no + i + 1
  216. }
  217. this.disabled = false
  218. return data
  219. })
  220. },
  221. chooseDisabled: false,
  222. chooseQueryParam: {
  223. productCode: '',
  224. productName: ''
  225. },
  226. // 表头
  227. chooseColumns: [
  228. { title: '产品编码', dataIndex: 'productCode', width: 180, align: 'center', customRender: function (text) { return text || '--' } },
  229. { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' } },
  230. { title: '仓库', dataIndex: 'warehouseName', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  231. { title: '仓位', dataIndex: 'warehouseLocationName', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  232. { title: '单位', dataIndex: 'productUnit', width: 60, align: 'center', customRender: function (text) { return text || '--' } },
  233. { title: '退货单价', scopedSlots: { customRender: 'purchaseCost' }, width: 100, align: 'center' },
  234. { title: '退货数量', scopedSlots: { customRender: 'purchaseQty' }, width: 100, align: 'center' },
  235. { title: '退货金额', dataIndex: 'purchaseAmount', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  236. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center', fixed: 'right' }
  237. ],
  238. // 加载数据方法 必须为 Promise 对象
  239. chooseLoadData: parameter => {
  240. this.chooseDisabled = true
  241. const params = Object.assign(parameter, this.chooseQueryParam, { sparePartsReturnSn: this.$route.params.sn })
  242. return sparePartsRetDetailList(params).then(res => {
  243. const data = res.data
  244. const no = (data.pageNo - 1) * data.pageSize
  245. for (var i = 0; i < data.list.length; i++) {
  246. data.list[i].no = no + i + 1
  247. data.list[i].purchaseCostBackups = data.list[i].purchaseCost
  248. data.list[i].purchaseQtyBackups = data.list[i].purchaseQty
  249. }
  250. this.localDataSource = data.list || []
  251. this.chooseDisabled = false
  252. this.getDetailCount(params)
  253. return data
  254. })
  255. },
  256. localDataSource: [],
  257. productTotal: null, // 合计
  258. warehouseList: [] // 仓库列表
  259. }
  260. },
  261. methods: {
  262. // 合计
  263. getDetailCount (params) {
  264. sparePartsRetDetailCount(params).then(res => {
  265. if (res.status == 200) {
  266. this.productTotal = res.data
  267. } else {
  268. this.productTotal = null
  269. }
  270. })
  271. },
  272. // 重置
  273. resetSearchForm () {
  274. this.queryParam.productCode = ''
  275. this.queryParam.productName = ''
  276. this.queryParam.warehouseSn = undefined
  277. this.$refs.table.refresh(true)
  278. },
  279. // 已选产品 重置
  280. chooseResetSearchForm () {
  281. this.chooseQueryParam.productCode = ''
  282. this.chooseQueryParam.productName = ''
  283. this.$refs.chooseTable.refresh(true)
  284. },
  285. // 添加/编辑
  286. handleAdd (row, isEdit) {
  287. if (!isEdit && !row.purchaseCost && row.purchaseCost != 0) {
  288. this.$message.warning('请输入退货单价后再添加!')
  289. return
  290. }
  291. if (!isEdit && !row.purchaseQty) {
  292. this.$message.warning('请输入退货数量后再添加!')
  293. return
  294. }
  295. const params = {
  296. id: isEdit ? row.id : undefined,
  297. sparePartsReturnSn: this.$route.params.sn,
  298. purchaseCost: row.purchaseCost,
  299. purchaseQty: row.purchaseQty,
  300. productSn: row.productSn,
  301. productCode: row.productCode,
  302. productOrigCode: row.productOrigCode,
  303. productTypeSn1: row.productTypeSn1,
  304. productTypeSn2: row.productTypeSn2,
  305. productTypeSn3: row.productTypeSn3,
  306. brandSn: row.brandSn,
  307. warehouseLocationSn: row.warehouseLocationSn,
  308. warehouseSn: row.warehouseSn,
  309. productExpiryDate: row.productExpiryDate
  310. }
  311. if (isEdit) { // 编辑
  312. // 清空成本价或数量时,值应保持未清空前的值,因成本价和数量都不可为空
  313. if (!row.purchaseCost) {
  314. row.purchaseCost = row.purchaseCostBackups
  315. return
  316. }
  317. if (!row.purchaseQty) {
  318. row.purchaseQty = row.purchaseQtyBackups
  319. return
  320. }
  321. }
  322. this.spinning = true
  323. sparePartsRetDetailSave(params).then(res => {
  324. if (res.status == 200) {
  325. this.$message.success(res.message)
  326. this.$refs.table.refresh()
  327. this.$refs.chooseTable.refresh()
  328. this.spinning = false
  329. } else {
  330. this.spinning = false
  331. this.$refs.chooseTable.refresh()
  332. }
  333. })
  334. },
  335. // 删除
  336. handleDel (row) {
  337. const _this = this
  338. this.$confirm({
  339. title: '提示',
  340. content: '删除后不可恢复,确定要进行删除吗?',
  341. centered: true,
  342. onOk () {
  343. _this.spinning = true
  344. sparePartsRetDetailDel({ id: row.id }).then(res => {
  345. if (res.status == 200) {
  346. _this.$message.success(res.message)
  347. _this.$refs.table.refresh()
  348. _this.$refs.chooseTable.refresh()
  349. _this.spinning = false
  350. } else {
  351. _this.spinning = false
  352. }
  353. })
  354. }
  355. })
  356. },
  357. // 提交
  358. handleSubmit () {
  359. const _this = this
  360. if (this.localDataSource.length < 1) {
  361. this.$message.info('退货单中不存在任何产品,无法提交')
  362. return
  363. }
  364. _this.spinning = true
  365. sparePartsRetSubmit({ id: this.$route.params.id }).then(res => {
  366. if (res.status == 200) {
  367. this.$message.success(res.message)
  368. setTimeout(() => {
  369. _this.handleBack()
  370. _this.spinning = false
  371. }, 1000)
  372. } else {
  373. _this.spinning = false
  374. }
  375. })
  376. },
  377. // 已选产品 单价 blur
  378. purchaseCostBlur (val, record) {
  379. // 光标移出,值发生改变再调用编辑接口
  380. if (val != record.purchaseCostBackups) {
  381. this.handleAdd(record, 'edit')
  382. }
  383. },
  384. // 已选产品 数量 blur
  385. purchaseQtyBlur (val, record) {
  386. if (val != record.purchaseQtyBackups) {
  387. this.handleAdd(record, 'edit')
  388. }
  389. },
  390. // 返回列表
  391. handleBack () {
  392. this.$router.push({ path: '/bulkManagement/bulkReturnGoods/list', query: { closeLastOldTab: true } })
  393. },
  394. // 双击快速添加
  395. handleClickRow (record) {
  396. return {
  397. on: {
  398. dblclick: (event) => {
  399. this.handleAdd(record)
  400. }
  401. }
  402. }
  403. },
  404. // 仓库
  405. getWarehouse () {
  406. warehouseAllList({}).then(res => {
  407. if (res.status == 200) {
  408. this.warehouseList = res.data
  409. } else {
  410. this.warehouseList = []
  411. }
  412. })
  413. },
  414. filterOption (input, option) {
  415. return (
  416. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  417. )
  418. },
  419. initPage () {
  420. this.getWarehouse()
  421. this.resetSearchForm()
  422. this.chooseResetSearchForm()
  423. }
  424. },
  425. mounted () {
  426. this.initPage()
  427. },
  428. beforeRouteEnter (to, from, next) {
  429. next(vm => {
  430. if (!vm.disabled) {
  431. vm.initPage()
  432. }
  433. })
  434. }
  435. }
  436. </script>
  437. <style lang="less">
  438. .bulkReturnGoodsEdit-wrap{
  439. position: relative;
  440. height: 100%;
  441. padding-bottom: 51px;
  442. box-sizing: border-box;
  443. >.ant-spin-nested-loading{
  444. overflow-y: scroll;
  445. height: 100%;
  446. }
  447. .bulkReturnGoodsEdit-cont{
  448. margin-bottom: 10px;
  449. }
  450. }
  451. </style>