salesReturnEdit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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="partQuery" :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 v-if="$hasPermissions('B_isShowPrice')">退货总金额:{{ ordeDetail&&(ordeDetail.totalAmount || ordeDetail.totalAmount==0) ? ordeDetail.totalAmount : '--' }}元;</span>
  22. <span>退货总数量:{{ ordeDetail&&(ordeDetail.totalQty || ordeDetail.totalQty==0) ? ordeDetail.totalQty : '--' }};</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="{ 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.grabFlag}" @close="closeGuideModel" @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 {
  105. salesReturnDetailList,
  106. salesReturnDetailDel,
  107. salesReturnDetailInsert,
  108. salesReturnDetailUpdateQty,
  109. salesReturnDetailUpdateReason
  110. } from '@/api/salesReturnDetail'
  111. export default {
  112. name: 'SalesReturnEdit',
  113. components: {
  114. STable,
  115. VSelect,
  116. queryPart,
  117. EditableCell,
  118. ImportGuideModal
  119. },
  120. data () {
  121. return {
  122. spinning: false,
  123. orderId: null,
  124. orderSn: null,
  125. buyerSn: null,
  126. disabled: false,
  127. isInster: false, // 是否正在添加产品
  128. ordeDetail: { discountAmount: 0 },
  129. delLoading: false,
  130. // 已选产品
  131. dataSource: [],
  132. productForm: {
  133. salesReturnBillSn: ''
  134. },
  135. chooseLoadData: [],
  136. // 加载数据方法 必须为 Promise 对象
  137. loadData: parameter => {
  138. this.disabled = true
  139. // 查询总计
  140. this.productForm.salesReturnBillSn = this.$route.params.sn
  141. return salesReturnDetailList(Object.assign(parameter, this.productForm)).then(res => {
  142. let data
  143. if (res.status == 200) {
  144. 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. }
  154. return data
  155. })
  156. },
  157. openGuideModal: false // 导入产品引导
  158. }
  159. },
  160. computed: {
  161. columns () {
  162. const arr = [
  163. { title: '序号', dataIndex: 'no', align: 'center', width: '4%' },
  164. { title: '产品编码', dataIndex: 'productEntity.code', width: '18%', align: 'center', customRender: function (text) { return text || '--' } },
  165. { title: '产品名称', dataIndex: 'productEntity.name', width: '25%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  166. { title: '退货数量', dataIndex: 'qty', align: 'center', width: '8%', scopedSlots: { customRender: 'qty' } },
  167. // { title: '退货单价', dataIndex: 'price', align: 'center', width: '8%', scopedSlots: { customRender: 'price' } },
  168. { title: '单位', dataIndex: 'productEntity.unit', align: 'center', width: '6%', customRender: function (text) { return text || '--' } },
  169. // { title: '退货小计', align: 'center', dataIndex: 'totalAmount', width: '8%', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  170. { title: '退货原因', dataIndex: 'remark', align: 'center', width: '13%', scopedSlots: { customRender: 'remark' } },
  171. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  172. ]
  173. if (this.$hasPermissions('B_isShowPrice')) { // 售价权限
  174. arr.splice(4, 0, { title: '退货单价', dataIndex: 'price', align: 'center', width: '8%', scopedSlots: { customRender: 'price' } })
  175. arr.splice(6, 0, { title: '退货小计', align: 'center', dataIndex: 'totalAmount', width: '8%', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  176. }
  177. return arr
  178. }
  179. },
  180. methods: {
  181. // 返回
  182. handleBack () {
  183. this.$router.push({ path: '/salesManagement/salesReturn/list', query: { closeLastOldTab: true } })
  184. },
  185. // 已选产品 blur
  186. onCellBlur (val, record, type) {
  187. let valBackups
  188. if (type) {
  189. if (type == 'qty') {
  190. valBackups = record.qtyBackups
  191. } else if (type == 'price') {
  192. valBackups = record.priceBackups
  193. }
  194. }
  195. // 光标移出,值发生改变再调用编辑接口
  196. if (val && val != valBackups) {
  197. this.spinning = true
  198. salesReturnDetailUpdateQty({
  199. salesReturnDetailSn: record.salesReturnDetailSn,
  200. qty: record.qty,
  201. price: record.price
  202. }).then(res => {
  203. if (res.status == 200) {
  204. this.resetSearchForm(true)
  205. this.$message.success(res.message)
  206. this.spinning = false
  207. } else {
  208. this.spinning = false
  209. }
  210. })
  211. } else {
  212. if (type == 'qty') {
  213. record.qty = valBackups
  214. } else if (type == 'price') {
  215. record.price = valBackups
  216. }
  217. }
  218. },
  219. // 修改退货原因
  220. updateRemark (row) {
  221. this.spinning = true
  222. salesReturnDetailUpdateReason({
  223. salesReturnDetailSn: row.salesReturnDetailSn,
  224. remark: row.remark
  225. }).then(res => {
  226. if (res.status == 200) {
  227. this.resetSearchForm(true)
  228. this.$message.success(res.message)
  229. }
  230. this.spinning = false
  231. })
  232. },
  233. // 重置列表
  234. resetForm () {
  235. this.$refs.table.refresh(true)
  236. },
  237. // 获取单据详细
  238. getOrderDetail () {
  239. salesReturnDetail({ sn: this.orderSn }).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. console.log(row)
  273. // 防止多次添加产品
  274. if (this.isInster) {
  275. return
  276. }
  277. this.isInster = true
  278. const params = {
  279. 'salesReturnBillSn': this.orderSn,
  280. 'salesReturnBillNo': this.ordeDetail.salesReturnBillNo,
  281. 'price': row.productPrice,
  282. 'cost': row.lastStockCost,
  283. 'productSn': row.productSn,
  284. 'qty': row.qty
  285. }
  286. this.spinning = true
  287. salesReturnDetailInsert(params).then(res => {
  288. if (res.status == 200) {
  289. this.resetSearchForm(true)
  290. this.$message.success(res.message)
  291. }
  292. this.isInster = false
  293. this.spinning = false
  294. })
  295. },
  296. // 提交销售单
  297. handleSubmit () {
  298. this.spinning = true
  299. salesReturnSubmit({ salesReturnBillSn: this.orderSn }).then(res => {
  300. if (res.status == 200) {
  301. this.handleBack()
  302. this.$message.success(res.message)
  303. }
  304. this.spinning = false
  305. })
  306. },
  307. closeGuideModel () {
  308. this.openGuideModal = false
  309. },
  310. // 导入产品
  311. hanldeOk (obj) {
  312. salesReturnBatchInsert(obj).then(res => {
  313. if (res.status == 200) {
  314. this.$refs.table.refresh(true)
  315. this.getOrderDetail()
  316. }
  317. })
  318. },
  319. pageInit () {
  320. this.orderSn = this.$route.params.sn
  321. this.buyerSn = this.$route.params.buyerSn
  322. this.resetSearchForm(true)
  323. this.$refs.partQuery.pageInit(this.buyerSn, 0)
  324. }
  325. },
  326. mounted () {
  327. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  328. this.pageInit()
  329. }
  330. },
  331. activated () {
  332. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  333. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  334. this.pageInit()
  335. }
  336. },
  337. beforeRouteEnter (to, from, next) {
  338. next(vm => {})
  339. }
  340. }
  341. </script>
  342. <style lang="less">
  343. .salesReturnEdit-wrap{
  344. position: relative;
  345. height: 100%;
  346. padding-bottom: 51px;
  347. box-sizing: border-box;
  348. >.ant-spin-nested-loading{
  349. overflow-y: scroll;
  350. height: 100%;
  351. }
  352. .salesReturnEdit-cont{
  353. margin-top: 10px;
  354. .total-bar{
  355. display: flex;
  356. align-items: center;
  357. justify-content: space-between;
  358. > div{
  359. &:last-child{
  360. display: flex;
  361. align-items: center;
  362. justify-content: space-between;
  363. > div{
  364. padding: 0 10px;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. }
  371. </style>