setPriceModal.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <a-modal
  3. centered
  4. class="setPrice-detail-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. v-model="isShow"
  8. :title="modalTit"
  9. :bodyStyle="{padding: modalTit?'25px 32px 20px':'50px 32px 15px'}"
  10. @cancel="isShow=false"
  11. width="80%">
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <div class="common-main">
  14. <div class="form-row">
  15. <div>
  16. 退货单价:
  17. <a-radio-group v-model="form.grabFlag" @change="grabChange">
  18. <a-radio :value="0">
  19. 不抓单
  20. </a-radio>
  21. <a-radio :value="1">
  22. 抓单
  23. </a-radio>
  24. </a-radio-group>
  25. </div>
  26. <div v-if="form.grabFlag==0">
  27. 是否打折:
  28. <a-radio-group v-model="form.discountFlag">
  29. <a-radio :value="0">
  30. 不打折
  31. </a-radio>
  32. <a-radio :value="1">
  33. 打折
  34. </a-radio>
  35. </a-radio-group>
  36. <div v-if="form.discountFlag==1">
  37. <a-input-number placeholder="请输入折扣" v-model="form.discount" :min="0" :max="10" :precision="2" />
  38. <span class="mleft">示例:7折表示使用当前售价×0.7作为退货单价(保留两位小数)</span>
  39. <a-button type="primary" :disabled="disabled" @click="handleSave" class="button-error">设置完成</a-button>
  40. </div>
  41. <div v-else>
  42. <a-button type="primary" :disabled="disabled" @click="handleSave" class="button-error">设置完成</a-button>
  43. </div>
  44. </div>
  45. <div v-else>
  46. 销售单号:
  47. <a-input placeholder="请输入销售单号" v-model.trim="form.salesBillNo" :maxLength="50" @change="fetchUser" @blur="handleBlur"/>
  48. <span class="mleft">{{ buyerName }}</span>
  49. <a-button type="primary" @click="handleSave('salesBillNo')" class="button-error">设置完成</a-button>
  50. </div>
  51. </div>
  52. <a-divider>请给以下产品设置新的退货单价</a-divider>
  53. <!-- 搜索条件 -->
  54. <div style="overflow: hidden;">
  55. <a-form layout="inline" style="margin-bottom:10px;float:left;" @keyup.enter.native="searchProduct">
  56. <a-form-item label="产品编码">
  57. <a-input id="setPrice-productCode" v-model.trim="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  58. </a-form-item>
  59. <a-form-item label="产品名称">
  60. <a-input id="setPrice-productName" v-model.trim="queryParam.productName" placeholder="请输入产品名称" allowClear />
  61. </a-form-item>
  62. <a-form-item>
  63. <a-button type="primary" class="button-info" @click="searchProduct" :disabled="disabled" id="setPrice-refresh">查询</a-button>
  64. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="setPrice-reset">重置</a-button>
  65. </a-form-item>
  66. </a-form>
  67. <div style="float:right;color:#999;margin-top:10px;">说明:红色行表示收货时新增的产品;黄色行表示客服确认时新增的产品;退货原因文字显示红色表示退货原因和退货类别不一致;</div>
  68. </div>
  69. <!-- 表格数据 -->
  70. <s-table
  71. class="sTable"
  72. ref="table"
  73. size="small"
  74. :rowKey="(record) => record.id"
  75. :rowClassName="(record, index) => record.addFlag == '1' ? (record.addType == 'WAREHOUSE_RECEIVE'?'redBg-row':'orgBg-row'):''"
  76. :columns="columns"
  77. :data="loadData"
  78. :scroll="{ y: 400 }"
  79. :showPagination="false"
  80. bordered>
  81. <!-- 退货原因 -->
  82. <template slot="returnReason" slot-scope="text, record">
  83. <span title="退货原因和退货类别不一致" :style="{color:record.needHandleFlag==1?'red':''}">{{ record.returnReason||'--' }}</span>
  84. </template>
  85. </s-table>
  86. </div>
  87. <grabOrderModal ref="grabOrder" :infoData="listInfo" :openModal="openGrabOrderModal" @ok="handleGrabOrderOk" @close="closeGrabOrder"></grabOrderModal>
  88. </a-spin>
  89. </a-modal>
  90. </template>
  91. <script>
  92. import { commonMixin } from '@/utils/mixin'
  93. import debounce from 'lodash/debounce'
  94. import { STable, VSelect } from '@/components'
  95. import { salesDetailByNo } from '@/api/sales'
  96. import { setReturnPrice } from '@/api/salesReturnDetail'
  97. import { grabSalesBill } from '@/api/salesReturn'
  98. import grabOrderModal from './grabOrderModal.vue'
  99. export default {
  100. name: 'SetPriceModal',
  101. mixins: [commonMixin],
  102. components: { STable, VSelect, grabOrderModal },
  103. props: {
  104. openModal: { // 弹框显示状态
  105. type: Boolean,
  106. default: false
  107. },
  108. modalTit: { // 弹框标题
  109. type: String,
  110. default: null
  111. },
  112. chooseData: {
  113. type: Array,
  114. default: function () {
  115. return []
  116. }
  117. }
  118. },
  119. data () {
  120. this.fetchUser = debounce(this.fetchUser, 800)
  121. return {
  122. isShow: this.openModal, // 是否打开弹框
  123. disabled: false,
  124. spinning: false,
  125. queryParam: {
  126. productName: '',
  127. productCode: ''
  128. },
  129. form: {
  130. grabFlag: 0, // 是否抓单
  131. discountFlag: 0, // 是否打折
  132. discount: '', // 折扣
  133. salesBillNo: '' // 销售单号
  134. },
  135. columns: [
  136. { title: '序号', dataIndex: 'no', width: '6%', align: 'center' },
  137. { title: '产品编码', dataIndex: 'productEntity.code', align: 'center', width: '13%', customRender: function (text) { return text || '--' } },
  138. { title: '产品名称', dataIndex: 'productEntity.name', width: '25%', align: 'left', customRender: function (text) { return text || '--' } },
  139. { title: '单位', dataIndex: 'productEntity.unit', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  140. { title: '申请退货数量', dataIndex: 'qty', align: 'center', width: '10%', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  141. { title: '仓库实收数量', dataIndex: 'receiveQty', align: 'center', width: '10%', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  142. { title: '坏件数量', dataIndex: 'badQty', align: 'center', width: '10%', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  143. { title: '良品数量', dataIndex: 'goodQty', align: 'center', width: '10%', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  144. { title: '返库数量', dataIndex: 'backStockQty', align: 'center', width: '10%', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  145. { title: '退货单价', dataIndex: 'price', align: 'right', width: '10%', customRender: text => ((text || text == 0) ? this.toThousands(text) : '--') },
  146. { title: '退货单价说明', dataIndex: 'priceRemark', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  147. { title: '退货原因', dataIndex: 'returnReason', width: '15%', align: 'center', scopedSlots: { customRender: 'returnReason' } }
  148. ],
  149. // 加载数据方法 必须为 Promise 对象
  150. loadData: parameter => {
  151. return new Promise((res, rej) => {
  152. const ret = this.chooseData.filter(item => {
  153. return item.productEntity.code.indexOf(this.queryParam.productCode) >= 0 &&
  154. item.productEntity.name.indexOf(this.queryParam.productName) >= 0
  155. })
  156. res({
  157. list: ret,
  158. count: ret.length
  159. })
  160. })
  161. },
  162. buyerName: '',
  163. openGrabOrderModal: false,
  164. listInfo: null,
  165. noShowBillSnList: null,
  166. salesBillSnList: []
  167. }
  168. },
  169. methods: {
  170. fetchUser () {
  171. this.form.salesBillNo = this.form.salesBillNo.replace(/\s+/g, '')
  172. if (!this.form.salesBillNo) {
  173. this.form.salesBillNo = ''
  174. this.buyerName = ''
  175. return
  176. }
  177. this.spinning = true
  178. salesDetailByNo({ salesBillNo: this.form.salesBillNo }).then(res => {
  179. this.spinning = false
  180. this.buyerName = res.data ? res.data.buyerName : ''
  181. })
  182. },
  183. // 打开抓单设置单价弹窗
  184. handleBlur () {
  185. if (!this.buyerName) {
  186. this.$message.warning('请输入正确的销售单号!')
  187. return
  188. }
  189. const productArr = this.chooseData.map(item => { return { productSn: item.productSn, code: item.productEntity.code, salesReturnDetailSn: item.salesReturnDetailSn } })
  190. const objInfo = {
  191. salesReturnBillSn: this.$route.params.sn,
  192. salesBillNo: this.form.salesBillNo,
  193. productList: productArr
  194. }
  195. grabSalesBill(objInfo).then(res => {
  196. const newList = res.data
  197. const _this = this
  198. if (newList && newList.length > 0) {
  199. const flag = newList.some(item => Object.keys(item).length > 2)
  200. if (flag) {
  201. this.listInfo = newList.filter(con => Object.keys(con).length > 2)
  202. this.openGrabOrderModal = true
  203. const noShowList = newList.filter(con => Object.keys(con).length <= 2)
  204. this.noShowBillSnList = _this.getNewSalesBillList(noShowList)
  205. } else {
  206. const resultVal = _this.getNewSalesBillList(newList)
  207. this.salesBillSnList = resultVal
  208. }
  209. }
  210. })
  211. },
  212. getNewSalesBillList (list) {
  213. const resultVal = list.map(item => {
  214. const nameArr = Object.getOwnPropertyNames(item)
  215. let newName = ''
  216. nameArr.forEach(con => {
  217. if (con != 'product') {
  218. newName = con
  219. }
  220. })
  221. const newobj = {
  222. salesReturnDetailSn: item.product.salesReturnDetailSn, salesBillDetailSn: item[newName].salesBillDetailSn
  223. }
  224. return newobj
  225. })
  226. return resultVal
  227. },
  228. handleGrabOrderOk (con) {
  229. if (this.noShowBillSnList && this.noShowBillSnList.length > 0) {
  230. this.salesBillSnList = this.salesBillSnList.concat(con)
  231. } else {
  232. this.salesBillSnList = con
  233. }
  234. },
  235. closeGrabOrder () {
  236. this.listInfo = null
  237. this.openGrabOrderModal = false
  238. },
  239. // 设置价格
  240. handleSave (type) {
  241. if (type && type === 'salesBillNo') {
  242. if (!this.buyerName) {
  243. this.$message.warning('请输入正确的销售单号!')
  244. return
  245. }
  246. }
  247. // 不抓单且打折
  248. if (this.form.grabFlag == 0 && this.form.discountFlag == 1) {
  249. if (!this.form.discount) {
  250. this.$message.info('请输入折扣')
  251. return
  252. }
  253. }
  254. // 抓单
  255. if (this.form.grabFlag == 1) {
  256. if (!this.form.salesBillNo) {
  257. this.$message.info('请输入销售单号')
  258. return
  259. }
  260. this.form.discountFlag = undefined
  261. this.form.discount = undefined
  262. this.form.salesReturnBillDetailList = this.salesBillSnList
  263. } else {
  264. const snList = []
  265. this.form.salesBillNo = ''
  266. this.chooseData.map(item => {
  267. snList.push({ salesReturnDetailSn: item.salesReturnDetailSn })
  268. })
  269. this.form.salesReturnBillDetailList = snList
  270. }
  271. const params = Object.assign(this.form)
  272. this.disabled = true
  273. this.spinning = true
  274. setReturnPrice(params).then(res => {
  275. if (res.status == 200) {
  276. this.salesBillSnList = null
  277. this.$emit('setOk')
  278. this.$message.info(res.message)
  279. }
  280. this.disabled = false
  281. this.spinning = false
  282. })
  283. },
  284. grabChange (e) {
  285. this.buyerName = ''
  286. if (e.target.value == 1) {
  287. this.form.salesBillNo = ''
  288. } else {
  289. this.form.discountFlag = 0
  290. this.form.discount = ''
  291. }
  292. },
  293. // 取消
  294. handleCommonCancel () {
  295. this.$emit('cancel')
  296. },
  297. // 查询
  298. searchProduct () {
  299. this.$refs.table.refresh(true)
  300. },
  301. // 重置
  302. resetSearchForm () {
  303. this.form = {
  304. grabFlag: 0, // 是否抓单
  305. discountFlag: 0, // 是否打折
  306. discount: '', // 折扣
  307. salesBillNo: '' // 销售单号
  308. }
  309. this.queryParam = {
  310. productName: '',
  311. productCode: ''
  312. }
  313. this.buyerName = ''
  314. if (this.$refs.table) {
  315. this.$refs.table.refresh(true)
  316. }
  317. }
  318. },
  319. watch: {
  320. // 父页面传过来的弹框状态
  321. openModal (newValue, oldValue) {
  322. this.isShow = newValue
  323. },
  324. // 重定义的弹框状态
  325. isShow (newValue, oldValue) {
  326. if (!newValue) {
  327. this.salesBillSnList = null
  328. this.handleCommonCancel()
  329. } else {
  330. this.resetSearchForm()
  331. }
  332. }
  333. }
  334. }
  335. </script>
  336. <style lang="less">
  337. .setPrice-detail-modal{
  338. .form-row{
  339. > div{
  340. display: flex;
  341. align-items:center;
  342. padding: 10px 0;
  343. input[type='text']{
  344. width:250px;
  345. }
  346. .mleft{
  347. margin-left:10px;
  348. }
  349. }
  350. }
  351. .redBg-row{
  352. background-color: #f5beb4;
  353. }
  354. .orgBg-row{
  355. background-color: #fffca2;
  356. }
  357. }
  358. </style>