outStockModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <a-drawer
  3. :zIndex="zIndex"
  4. :title="title"
  5. placement="right"
  6. :visible="isShow"
  7. :width="width"
  8. :get-container="false"
  9. :wrap-style="{ position: 'absolute' }"
  10. @close="onCancel"
  11. wrapClassName="outStock-modal"
  12. >
  13. <a-spin :spinning="spinning" tip="Loading...">
  14. <div class="outStock-con jg-drawer-wrap">
  15. <div>
  16. <div ref="searchBox" class="table-page-search-wrapper">
  17. <a-form layout="inline" @keyup.enter.native="searchForm">
  18. <a-row type="flex" :gutter="12" justify="start">
  19. <a-col flex="auto">
  20. <a-form-item label="产品编码">
  21. <a-input id="productInfoList-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  22. </a-form-item>
  23. </a-col>
  24. <a-col flex="auto">
  25. <a-form-item label="产品名称">
  26. <a-input id="productInfoList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  27. </a-form-item>
  28. </a-col>
  29. <a-col flex="250px">
  30. <a-form-item label="产品分类">
  31. <ProductType id="productInfoList-productType" placeholder="请选择产品分类" :isDealer="true" @change="changeProductType" v-model="productType"></ProductType>
  32. </a-form-item>
  33. </a-col>
  34. <a-col flex="250px">
  35. <a-form-item label="产品品牌">
  36. <ProductBrand id="productInfoList-productBrandSn" placeholder="请选择产品品牌" v-model="queryParam.productBrandSn"></ProductBrand>
  37. </a-form-item>
  38. </a-col>
  39. <a-col flex="auto">
  40. <a-button type="primary" @click="searchForm" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
  41. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="productInfoList-reset">重置</a-button>
  42. </a-col>
  43. </a-row>
  44. </a-form>
  45. </div>
  46. <div class="actions-buttons">
  47. <a-button
  48. type="primary"
  49. ghost
  50. id="outStock-save"
  51. @click="handleSave"
  52. style="padding: 0 20px;">批量添加</a-button>
  53. <span style="font-weight: bold;margin-left:15px;" v-if="rowSelectionInfo&&rowSelectionInfo.selectedRowKeys.length">已选:{{ rowSelectionInfo&&rowSelectionInfo.selectedRowKeys.length }}个</span>
  54. </div>
  55. <!-- 列表 -->
  56. <s-table
  57. class="sTable"
  58. ref="table"
  59. size="small"
  60. :rowKey="(record) => record.productSn"
  61. rowKeyName="productSn"
  62. :row-selection="{ columnWidth: 40 }"
  63. :scroll="{ y:tableHeight, x: 1000 }"
  64. @rowSelection="rowSelectionFun"
  65. :data="loadData"
  66. :defaultLoadData="false"
  67. :columns="columns"
  68. :pageSize="30"
  69. bordered>
  70. </s-table>
  71. </div>
  72. </div>
  73. </a-spin>
  74. </a-drawer>
  75. </template>
  76. <script>
  77. import { commonMixin } from '@/utils/mixin'
  78. import { STable } from '@/components'
  79. import { purchaseDetailCancelList, purchaseDetailCancelSave } from '@/api/purchaseDetail'
  80. import ProductType from '../../common/productType.js'
  81. import ProductBrand from '../../common/productBrand.js'
  82. export default {
  83. name: 'OutStockModal',
  84. components: { STable, ProductType, ProductBrand },
  85. mixins: [commonMixin],
  86. props: {
  87. openModal: { // 弹框显示状态
  88. type: Boolean,
  89. default: false
  90. },
  91. chooseData: {
  92. type: Array,
  93. default: () => {
  94. return []
  95. }
  96. },
  97. paramsData: {
  98. type: Object,
  99. default: () => {
  100. return {}
  101. }
  102. },
  103. width: {
  104. type: [String, Number],
  105. default: '70%'
  106. },
  107. zIndex: {
  108. type: Number,
  109. default: 100
  110. }
  111. },
  112. data () {
  113. return {
  114. isShow: this.openModal, // 是否打开弹框
  115. tableHeight: 0,
  116. formItemLayout: {
  117. labelCol: { span: 4 },
  118. wrapperCol: { span: 20 }
  119. },
  120. disabled: false, // 查询、重置按钮是否可操作
  121. columns: [
  122. { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: '240px', align: 'center', customRender: function (text) { return text || '--' }, fixed: 'left' },
  123. { title: '产品名称', dataIndex: 'dealerProductEntity.name', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  124. { title: '上次采购数量', dataIndex: 'qty', width: '180px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  125. { title: '上次缺货数量', dataIndex: 'cancelQty', width: '180px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  126. { title: '单位', dataIndex: 'dealerProductEntity.unit', width: '80px', align: 'center', customRender: function (text) { return text || '--' } }
  127. ],
  128. title: '',
  129. // 加载数据方法 必须为 Promise 对象
  130. loadData: parameter => {
  131. this.disabled = true
  132. this.spinning = true
  133. return purchaseDetailCancelList(Object.assign(parameter, { dealerProductEntity: this.queryParam })).then(res => {
  134. let data
  135. if (res.status == 200) {
  136. data = res.data
  137. this.disabled = false
  138. }
  139. this.spinning = false
  140. return data
  141. })
  142. },
  143. spinning: false,
  144. rowSelectionInfo: null,
  145. productType: [],
  146. queryParam: { // 查询条件
  147. code: '', // 产品编码
  148. name: '', // 产品名称
  149. productBrandSn: undefined, // 产品品牌
  150. productTypeSn1: '', // 产品一级分类
  151. productTypeSn2: '', // 产品二级分类
  152. productTypeSn3: '' // 产品三级分类
  153. }
  154. }
  155. },
  156. methods: {
  157. setTableH () {
  158. this.$nextTick(() => {
  159. const searchBoxH = this.$refs.searchBox.offsetHeight
  160. this.tableHeight = window.innerHeight - searchBoxH - 340
  161. })
  162. },
  163. // 产品分类 change
  164. changeProductType (val, opt) {
  165. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  166. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  167. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  168. },
  169. // 表格选中项
  170. rowSelectionFun (obj) {
  171. this.rowSelectionInfo = obj || null
  172. },
  173. // 保存
  174. handleSave () {
  175. const _this = this
  176. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  177. this.$message.warning('请在列表勾选后再进行操作!')
  178. return
  179. }
  180. const rows = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows || []
  181. const list = []
  182. rows.map(item => {
  183. list.push({
  184. cancelQty: item.cancelQty,
  185. qty: item.qty,
  186. productSn: item.productSn,
  187. price: item.price
  188. })
  189. })
  190. const params = {
  191. confirm: false,
  192. purchaseBillSn: this.paramsData.purchaseBillSn,
  193. purchaseBillNo: this.paramsData.purchaseBillNo,
  194. purchaseBillDetailEntityList: list
  195. }
  196. purchaseDetailCancelSave(params).then(res => {
  197. if (res.status == 200 && res.data) {
  198. let content = ''
  199. if ((res.data.productSizeRepeat != res.data.productSize) && (res.data.productSizeRepeat != 0)) {
  200. content = `您已经选择 ${res.data.productSize} 个产品,其中 ${res.data.productSizeRepeat} 个产品已经存在于采购单中。本次只会加入不重复的产品,上次缺货数量将作为本次采购数量。确认加入本次采购吗?`
  201. this.confirmFun(content, params)
  202. } else if (res.data.productSizeRepeat == res.data.productSize) {
  203. content = `抱歉,您选择的 ${res.data.productSize} 个产品,采购单中已经全部存在,无需加入!`
  204. this.$info({
  205. title: '提示',
  206. content: content,
  207. okText: '好的',
  208. centered: true,
  209. zIndex: 1100,
  210. onOk () {
  211. _this.$refs.table.clearSelected() // 清空表格选中项
  212. }
  213. })
  214. } else {
  215. content = `您已经选择 ${res.data.productSize} 个产品,上次缺货数量将作为本次采购数量。确认加入本次采购吗?`
  216. this.confirmFun(content, params)
  217. }
  218. }
  219. })
  220. },
  221. confirmFun (content, params) {
  222. const _this = this
  223. this.$confirm({
  224. title: '提示',
  225. content: content,
  226. okText: '确认加入',
  227. cancelText: '重新选择',
  228. centered: true,
  229. closable: true,
  230. zIndex: 1100,
  231. onOk () {
  232. _this.spinning = true
  233. params.confirm = true
  234. purchaseDetailCancelSave(params).then(res => {
  235. if (res.status == 200) {
  236. _this.$emit('ok')
  237. _this.isShow = false
  238. _this.spinning = false
  239. } else {
  240. _this.spinning = false
  241. }
  242. })
  243. },
  244. onCancel () {
  245. _this.$refs.table.clearSelected() // 清空表格选中项
  246. }
  247. })
  248. },
  249. onCancel () {
  250. this.$emit('close')
  251. this.$refs.table.clearSelected() // 清空表格选中项
  252. },
  253. searchForm () {
  254. this.$refs.table.refresh(true)
  255. },
  256. resetSearchForm () {
  257. this.queryParam = {
  258. productBrandSn: undefined,
  259. code: '', // 产品编码
  260. name: '', // 产品名称
  261. productTypeSn1: '', // 产品一级分类
  262. productTypeSn2: '', // 产品二级分类
  263. productTypeSn3: '' // 产品三级分类
  264. }
  265. this.productType = []
  266. this.$refs.table.refresh(true)
  267. }
  268. },
  269. watch: {
  270. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  271. this.setTableH()
  272. },
  273. // 父页面传过来的弹框状态
  274. openModal (newValue, oldValue) {
  275. this.isShow = newValue
  276. },
  277. // 重定义的弹框状态
  278. isShow (newValue, oldValue) {
  279. if (!newValue) {
  280. this.onCancel()
  281. } else {
  282. setTimeout(() => {
  283. this.setTableH()
  284. }, 200)
  285. this.resetSearchForm()
  286. this.title = '上次采购缺货产品明细(采购单号:' + this.paramsData.purchaseBillNo + ')'
  287. }
  288. }
  289. }
  290. }
  291. </script>
  292. <style lang="less">
  293. .outStock-modal{
  294. .ant-drawer-header{
  295. padding: 13px 20px;
  296. }
  297. .ant-drawer-body{
  298. padding: 15px 20px;
  299. height: calc(100% - 50px);
  300. }
  301. .outStock-con{
  302. .actions-buttons{
  303. padding: 10px 0;
  304. }
  305. }
  306. }
  307. </style>