salesReturnGrabEdit.vue 13 KB

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