outStockModal.vue 11 KB

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