salesReturnGrabEdit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div class="salesReturnEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="salesReturnEdit-back" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="salesReturnEdit-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="salesReturnEdit-cont" v-show="ordeDetail&&ordeDetail.salesReturnBillSource=='SALES'">
  12. <!-- 查询配件列表 -->
  13. <queryPart ref="queryPart" :newLoading="isInster" @add="saveProduct"></queryPart>
  14. </a-card>
  15. <a-card size="small" :bordered="false" class="salesReturnEdit-cont">
  16. <!-- alert -->
  17. <a-alert style="margin-bottom: 10px;" type="info">
  18. <div slot="message" class="total-bar">
  19. <div style="position: relative;width: 100%;">
  20. <div>
  21. <span>退货总金额:<strong>{{ ordeDetail&&(ordeDetail.totalAmount || ordeDetail.totalAmount==0) ? ordeDetail.totalAmount : '--' }}</strong>元;</span>
  22. <span>退货总数量:<strong>{{ ordeDetail&&(ordeDetail.totalQty || ordeDetail.totalQty==0) ? ordeDetail.totalQty : '--' }}</strong>;</span>
  23. </div>
  24. <div style="position: absolute;right: 0;top: -3px;">
  25. <a-button size="small" type="primary" class="button-info" id="salesReturnEdit-import-btn" @click="openGuideModal=true">导入产品</a-button>
  26. </div>
  27. </div>
  28. </div>
  29. </a-alert>
  30. <!-- 已选配件列表 -->
  31. <s-table
  32. class="sTable"
  33. ref="table"
  34. size="small"
  35. :rowKey="(record) => record.id"
  36. :columns="columns"
  37. :data="loadData"
  38. :defaultLoadData="false"
  39. :scroll="{ x: 1270, y: 300 }"
  40. bordered>
  41. <!-- 本次退货数量 -->
  42. <template slot="qty" slot-scope="text, record">
  43. <a-input-number
  44. id="salesReturn-qty"
  45. size="small"
  46. v-model="record.qty"
  47. :precision="0"
  48. :min="0"
  49. :max="999999"
  50. placeholder="请输入"
  51. @blur="e => onCellBlur(e.target.value, record, 'qty')"
  52. style="width: 100%;" />
  53. </template>
  54. <!-- 退货单价 -->
  55. <template slot="price" slot-scope="text, record">
  56. <a-input-number
  57. id="salesReturn-price"
  58. size="small"
  59. v-model="record.price"
  60. :precision="2"
  61. :min="0"
  62. :max="999999"
  63. placeholder="请输入"
  64. @blur="e => onCellBlur(e.target.value, record, 'price')"
  65. style="width: 100%;" />
  66. </template>
  67. <!-- 退货原因 -->
  68. <template slot="remark" slot-scope="text, record">
  69. <a-input size="small" placeholder="30个字符内" :maxLength="30" v-model="record.remark" @blur="updateRemark(record)"></a-input>
  70. </template>
  71. <!-- 操作 -->
  72. <template slot="action" slot-scope="text, record">
  73. <a-button
  74. size="small"
  75. type="primary"
  76. :loading="delLoading"
  77. class="button-error"
  78. @click="handleDel(record)"
  79. id="salesReturn-Del">删除</a-button>
  80. </template>
  81. </s-table>
  82. </a-card>
  83. </a-spin>
  84. <div class="affix-cont">
  85. <a-button
  86. size="large"
  87. style="padding: 0 60px;"
  88. :disabled="spinning"
  89. type="primary"
  90. class="button-primary"
  91. @click="handleSubmit()"
  92. id="salesReturn-handleSubmit">提交</a-button>
  93. </div>
  94. <!-- 导入产品 -->
  95. <importGuideModal :openModal="openGuideModal" :params="{salesReturnBillSn: $route.params.sn, grabFlag: ordeDetail&&ordeDetail.grabFlag || ''}" @close="openGuideModal=false" @ok="hanldeOk" />
  96. </div>
  97. </template>
  98. <script>
  99. import { STable, VSelect } from '@/components'
  100. import ImportGuideModal from './importGuideModal.vue'
  101. import queryPart from './queryPart.vue'
  102. import EditableCell from '@/views/common/editInput.js'
  103. import { salesReturnDetail, salesReturnSubmit, salesReturnBatchInsert } from '@/api/salesReturn'
  104. import { salesReturnDetailList, salesReturnDetailDel, salesReturnDetailInsert, salesReturnDetailUpdateQty, salesReturnDetailUpdateReason } from '@/api/salesReturnDetail'
  105. export default {
  106. name: 'SalesReturnGrabEdit',
  107. components: { STable, VSelect, queryPart, EditableCell, ImportGuideModal },
  108. data () {
  109. return {
  110. spinning: false,
  111. orderId: null,
  112. orderSn: null,
  113. buyerSn: null,
  114. disabled: false,
  115. isInster: false, // 是否正在添加产品
  116. ordeDetail: null,
  117. delLoading: false,
  118. // 已选产品
  119. dataSource: [],
  120. productForm: {
  121. salesReturnBillSn: ''
  122. },
  123. // 表头
  124. columns: [
  125. { title: '序号', dataIndex: 'no', align: 'center', width: 70 },
  126. { title: '采购单号', dataIndex: 'purchaseBillNo', align: 'center', width: 180, customRender: function (text) { return text || '--' } },
  127. { title: '产品编码', dataIndex: 'productEntity.code', align: 'center', customRender: function (text) { return text || '--' } },
  128. { title: '产品名称', dataIndex: 'productEntity.name', align: 'center', customRender: function (text) { return text || '--' } },
  129. { title: '剩余可退数量', dataIndex: 'refundableQty', align: 'center', width: 100, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  130. { title: '本次退货数量', dataIndex: 'qty', align: 'center', width: 100, scopedSlots: { customRender: 'qty' } },
  131. { title: '退货单价', dataIndex: 'price', align: 'center', width: 100, scopedSlots: { customRender: 'price' } },
  132. { title: '单位', dataIndex: 'productEntity.unit', align: 'center', width: 60, customRender: function (text) { return text || '--' } },
  133. { title: '退货小计', align: 'center', width: 80, dataIndex: 'totalAmount', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  134. { title: '退货原因', dataIndex: 'remark', align: 'center', width: 200, scopedSlots: { customRender: 'remark' } },
  135. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center', fixed: 'right' }
  136. ],
  137. chooseLoadData: [],
  138. // 加载数据方法 必须为 Promise 对象
  139. loadData: parameter => {
  140. this.disabled = true
  141. // 查询总计
  142. this.productForm.salesReturnBillSn = this.$route.params.sn
  143. return salesReturnDetailList(Object.assign(parameter, this.productForm)).then(res => {
  144. const data = res.data
  145. const no = (data.pageNo - 1) * data.pageSize
  146. for (var i = 0; i < data.list.length; i++) {
  147. data.list[i].no = no + i + 1
  148. data.list[i].qtyBackups = data.list[i].qty
  149. data.list[i].priceBackups = data.list[i].price
  150. }
  151. this.disabled = false
  152. this.chooseLoadData = data.list
  153. return data
  154. })
  155. },
  156. openGuideModal: false // 导入产品引导
  157. }
  158. },
  159. methods: {
  160. // 返回
  161. handleBack () {
  162. this.$router.push({ path: '/salesManagement/salesReturn/list', query: { closeLastOldTab: true } })
  163. },
  164. // 已选产品 blur
  165. onCellBlur (val, record, type) {
  166. let valBackups
  167. if (type) {
  168. if (type == 'qty') {
  169. valBackups = record.qtyBackups
  170. } else if (type == 'price') {
  171. valBackups = record.priceBackups
  172. }
  173. }
  174. // 光标移出,值发生改变再调用编辑接口
  175. if (val && val != valBackups) {
  176. if (Number(record.qty) > Number(record.refundableQty)) {
  177. this.$message.info('本次退货数量不可大于剩余可退数量')
  178. record.qty = record.qtyBackups
  179. record.price = record.priceBackups
  180. } else {
  181. this.spinning = true
  182. const params = {
  183. salesReturnDetailSn: record.salesReturnDetailSn,
  184. qty: record.qty,
  185. price: record.price
  186. }
  187. this.setFun(params)
  188. }
  189. } else {
  190. if (type == 'qty') {
  191. record.qty = valBackups
  192. } else if (type == 'price') {
  193. record.price = valBackups
  194. }
  195. }
  196. },
  197. setFun (params) {
  198. salesReturnDetailUpdateQty(params).then(res => {
  199. if (res.status == 200) {
  200. this.resetSearchForm(true)
  201. this.$message.success(res.message)
  202. }
  203. this.spinning = false
  204. })
  205. },
  206. // 修改退货原因
  207. updateRemark (row) {
  208. this.spinning = true
  209. salesReturnDetailUpdateReason({
  210. salesReturnDetailSn: row.salesReturnDetailSn,
  211. remark: row.remark
  212. }).then(res => {
  213. if (res.status == 200) {
  214. this.resetSearchForm(true)
  215. this.$message.success(res.message)
  216. }
  217. this.spinning = false
  218. })
  219. },
  220. // 获取单据详细
  221. getOrderDetail () {
  222. salesReturnDetail({ sn: this.$route.params.sn }).then(res => {
  223. this.ordeDetail = res.data || null
  224. })
  225. },
  226. // 删除产品
  227. handleDel (row) {
  228. const _this = this
  229. this.$confirm({
  230. title: '提示',
  231. content: '确认要删除吗?',
  232. centered: true,
  233. closable: true,
  234. onOk () {
  235. _this.delLoading = true
  236. _this.spinning = true
  237. salesReturnDetailDel({ salesReturnDetailSn: row.salesReturnDetailSn }).then(res => {
  238. if (res.status == 200) {
  239. _this.resetSearchForm(true)
  240. }
  241. _this.$message.info(res.message)
  242. _this.delLoading = false
  243. _this.spinning = false
  244. })
  245. }
  246. })
  247. },
  248. // 重置
  249. resetSearchForm (flag) {
  250. this.$refs.table.refresh(!!flag)
  251. this.getOrderDetail()
  252. },
  253. // 添加或修改产品
  254. saveProduct (row) {
  255. // 防止多次添加产品
  256. if (this.isInster) {
  257. return
  258. }
  259. this.isInster = true
  260. const params = {
  261. 'salesReturnBillSn': this.orderSn,
  262. 'salesReturnBillNo': this.ordeDetail.salesReturnBillNo,
  263. 'salesBillSn': row.salesBillSn,
  264. 'salesBillNo': row.salesBillNo,
  265. 'refundableQty': row.refundableQty,
  266. 'salesBillDetailSn': row.salesBillDetailSn,
  267. 'price': row.price,
  268. 'cost': row.showCost,
  269. 'productSn': row.productSn,
  270. 'qty': row.qty
  271. }
  272. this.spinning = true
  273. salesReturnDetailInsert(params).then(res => {
  274. if (res.status == 200) {
  275. this.resetSearchForm(true)
  276. this.$message.success(res.message)
  277. this.$refs.queryPart.refreshData()
  278. }
  279. this.isInster = false
  280. this.spinning = false
  281. })
  282. },
  283. // 提交销售单
  284. handleSubmit () {
  285. this.spinning = true
  286. salesReturnSubmit({ salesReturnBillSn: this.orderSn }).then(res => {
  287. if (res.status == 200) {
  288. this.handleBack()
  289. this.$message.success(res.message)
  290. }
  291. this.spinning = false
  292. })
  293. },
  294. // 导入产品
  295. hanldeOk (obj) {
  296. salesReturnBatchInsert(obj).then(res => {
  297. if (res.status == 200) {
  298. this.$refs.table.refresh(true)
  299. this.getOrderDetail()
  300. }
  301. })
  302. },
  303. pageInit () {
  304. this.orderSn = this.$route.params.sn
  305. this.buyerSn = this.$route.params.buyerSn
  306. this.getOrderDetail()
  307. this.$refs.table.refresh(true)
  308. this.$refs.queryPart.pageInit(this.buyerSn, 1)
  309. }
  310. },
  311. mounted () {
  312. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  313. this.pageInit()
  314. }
  315. },
  316. activated () {
  317. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  318. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  319. this.pageInit()
  320. }
  321. },
  322. beforeRouteEnter (to, from, next) {
  323. next(vm => {})
  324. }
  325. }
  326. </script>
  327. <style lang="less">
  328. .salesReturnEdit-wrap{
  329. position: relative;
  330. height: 100%;
  331. padding-bottom: 51px;
  332. box-sizing: border-box;
  333. >.ant-spin-nested-loading{
  334. overflow-y: scroll;
  335. height: 100%;
  336. }
  337. .salesReturnEdit-cont{
  338. margin-top: 10px;
  339. .total-bar{
  340. display: flex;
  341. align-items: center;
  342. justify-content: space-between;
  343. > div{
  344. &:last-child{
  345. display: flex;
  346. align-items: center;
  347. justify-content: space-between;
  348. > div{
  349. padding: 0 10px;
  350. }
  351. }
  352. }
  353. }
  354. }
  355. }
  356. </style>