list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <a-card size="small" :bordered="false" class="inventoryQueryList-wrap">
  3. <!-- 搜索条件 -->
  4. <div class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="15">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="产品编码">
  9. <a-input id="inventoryQueryList-productCode" v-model="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="原厂编码">
  14. <a-input id="inventoryQueryList-productOrigCode" v-model.trim="queryParam.productOrigCode" allowClear placeholder="请输入原厂编码"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="5" :sm="24">
  18. <a-form-item label="产品名称">
  19. <a-input id="inventoryQueryList-productName" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  20. </a-form-item>
  21. </a-col>
  22. <template v-if="advanced">
  23. <a-col :md="6" :sm="24">
  24. <a-form-item label="产品品牌">
  25. <a-select
  26. placeholder="请选择产品品牌"
  27. id="inventoryQueryList-brandSn"
  28. allowClear
  29. v-model="queryParam.brandSn"
  30. :showSearch="true"
  31. option-filter-prop="children"
  32. :filter-option="filterOption">
  33. <a-select-option v-for="item in brandData" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  34. </a-select>
  35. </a-form-item>
  36. </a-col>
  37. <a-col :md="6" :sm="24">
  38. <a-form-item label="产品分类">
  39. <a-cascader
  40. :options="typeData"
  41. expand-trigger="hover"
  42. :field-names="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  43. placeholder="请选择产品分类"
  44. allowClear
  45. v-model="productTypeSn"
  46. @change="changeType" />
  47. </a-form-item>
  48. </a-col>
  49. <a-col :md="6" :sm="24">
  50. <a-form-item label="库存情况">
  51. <a-select placeholder="请选择库存情况" id="inventoryQueryList-zeroQtyFlag" allowClear v-model="queryParam.zeroQtyFlag">
  52. <a-select-option v-for="item in zeroQtyData" :key="item.id" :value="item.id">{{ item.name }}</a-select-option>
  53. </a-select>
  54. </a-form-item>
  55. </a-col>
  56. </template>
  57. <a-col :md="7" :sm="24">
  58. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="inventoryQueryList-refresh">查询</a-button>
  59. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="inventoryQueryList-reset">重置</a-button>
  60. <a-button
  61. type="primary"
  62. class="button-warning"
  63. @click="handleExport"
  64. :disabled="disabled"
  65. :loading="exportLoading"
  66. id="inventoryQueryList-export">导出</a-button>
  67. <a @click="advanced=!advanced" style="margin-left: 5px">
  68. {{ advanced ? '收起' : '展开' }}
  69. <a-icon :type="advanced ? 'up' : 'down'"/>
  70. </a>
  71. </a-col>
  72. </a-row>
  73. </a-form>
  74. </div>
  75. <!-- 合计 -->
  76. <a-alert type="info" showIcon style="margin-bottom:15px">
  77. <div class="ftext" slot="message">现有库存总数量(个):<strong>{{ currentStock.currentStockQty || 0 }}</strong>;现有库存总成本(¥):<strong>{{ currentStock.currentStockCost || 0 }}</strong>。</div>
  78. </a-alert>
  79. <!-- 列表 -->
  80. <s-table
  81. class="sTable"
  82. ref="table"
  83. size="default"
  84. :rowKey="(record) => record.id"
  85. :columns="columns"
  86. :data="loadData"
  87. :scroll="{ x: 1630, y: tableHeight }"
  88. bordered>
  89. <!-- 产品分类 -->
  90. <template slot="productTypeName" slot-scope="text, record">
  91. <span v-if="record.productTypeName2">{{ record.productTypeName2 || '' }} ></span>
  92. <span v-if="record.productTypeName3">{{ record.productTypeName3 || '' }}</span>
  93. </template>
  94. <!-- 现有库存数量 -->
  95. <template slot="currentStockQty" slot-scope="text, record">
  96. {{ (record.currentStockQty + record.freezeQty) || 0 }}
  97. <span v-if="record.freezeQty">(冻结{{ record.freezeQty }})</span>
  98. </template>
  99. <!-- 操作 -->
  100. <template slot="action" slot-scope="text, record">
  101. <a-button size="small" type="link" class="button-success" @click="goDetail(record)" id="inventoryQueryList-detail-btn">库存详情</a-button>
  102. <a-button size="small" type="link" class="button-warning" @click="goWarehouseDetail(record)" id="inventoryQueryList-warehouseDetail-btn">出入库明细</a-button>
  103. </template>
  104. </s-table>
  105. <!-- 库存详情 -->
  106. <inventory-query-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
  107. </a-card>
  108. </template>
  109. <script>
  110. import moment from 'moment'
  111. import { stockList, stockCount, stockExport } from '@/api/stock'
  112. import { dealerProductTypeList } from '@/api/dealerProductType'
  113. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  114. import { STable, VSelect } from '@/components'
  115. import inventoryQueryDetailModal from './detailModal.vue'
  116. export default {
  117. components: { STable, VSelect, inventoryQueryDetailModal },
  118. data () {
  119. return {
  120. advanced: false, // 高级搜索 展开/关闭
  121. tableHeight: 0,
  122. queryParam: { // 查询条件
  123. productCode: '', // 产品编码
  124. productName: '', // 产品名称
  125. productOrigCode: '', // 原厂编码
  126. brandSn: undefined, // 产品品牌
  127. productTypeSn1: '', // 产品分类1
  128. productTypeSn2: '', // 产品分类2
  129. productTypeSn3: '', // 产品分类3
  130. zeroQtyFlag: undefined // 库存数量是否为0
  131. },
  132. productTypeSn: [],
  133. exportLoading: false, // 导出loading
  134. disabled: false, // 查询、重置按钮是否可操作
  135. brandData: [], // 产品品牌下拉数据
  136. typeData: [], // 产品分类下拉数据
  137. zeroQtyData: [ // 库存情况
  138. { name: '库存数量为0', id: '1' },
  139. { name: '库存数量不为0', id: '0' }
  140. ],
  141. columns: [
  142. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  143. { title: '产品编码', dataIndex: 'productCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  144. { title: '产品名称', dataIndex: 'productName', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  145. { title: '原厂编码', dataIndex: 'productOrigCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  146. { title: '产品品牌', dataIndex: 'brandName', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  147. { title: '产品分类', scopedSlots: { customRender: 'productTypeName' }, width: 240, align: 'center' },
  148. { title: '现有库存数量(个)', dataIndex: 'currentStockQty', scopedSlots: { customRender: 'currentStockQty' }, width: 165, align: 'center', sorter: true },
  149. { title: '现有库存成本(¥)', dataIndex: 'currentStockCost', width: 165, align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  150. { title: '操作', scopedSlots: { customRender: 'action' }, width: 200, align: 'center', fixed: 'right' }
  151. ],
  152. // 加载数据方法 必须为 Promise 对象
  153. loadData: parameter => {
  154. this.disabled = true
  155. if (this.tableHeight == 0) {
  156. this.tableHeight = window.innerHeight - 370
  157. }
  158. // 排序
  159. if (parameter.sortField == 'currentStockQty') {
  160. parameter.sortField = 'qty'
  161. parameter.sortAlias = ''
  162. }
  163. if (parameter.sortField == 'currentStockCost') {
  164. parameter.sortField = 'currentStockCost'
  165. parameter.sortAlias = 'stock'
  166. }
  167. return stockList(Object.assign(parameter, this.queryParam)).then(res => {
  168. const data = res.data
  169. const no = (data.pageNo - 1) * data.pageSize
  170. for (var i = 0; i < data.list.length; i++) {
  171. data.list[i].no = no + i + 1
  172. }
  173. this.disabled = false
  174. // 总计
  175. this.getTotal(Object.assign(parameter, this.queryParam))
  176. // 产品分类
  177. if (this.typeData.length == 0) {
  178. this.getProductType()
  179. }
  180. // 产品品牌
  181. if (this.brandData.length == 0) {
  182. this.getProductBrand()
  183. }
  184. return data
  185. })
  186. },
  187. openModal: false, // 查看库存详情 弹框
  188. itemId: '', // 当前库存记录id
  189. currentStock: { // 合计信息
  190. currentStockQty: '',
  191. currentStockCost: ''
  192. }
  193. }
  194. },
  195. methods: {
  196. // 重置
  197. resetSearchForm () {
  198. this.queryParam.brandSn = undefined
  199. this.queryParam.productTypeSn1 = ''
  200. this.queryParam.productTypeSn2 = ''
  201. this.queryParam.productTypeSn3 = ''
  202. this.queryParam.productCode = ''
  203. this.queryParam.productOrigCode = ''
  204. this.queryParam.productName = ''
  205. this.queryParam.brandName = undefined
  206. this.queryParam.productTypeName = undefined
  207. this.queryParam.zeroQtyFlag = undefined
  208. this.productTypeSn = []
  209. this.$refs.table.refresh(true)
  210. },
  211. // 合计
  212. getTotal (param) {
  213. stockCount(param).then(res => {
  214. if (res.status == 200 && res.data) {
  215. this.currentStock = res.data
  216. } else {
  217. this.currentStock = { // 合计信息
  218. currentStockQty: '',
  219. currentStockCost: ''
  220. }
  221. }
  222. })
  223. },
  224. // 库存详情
  225. goDetail (row) {
  226. this.itemId = row.stockSn
  227. this.openModal = true
  228. },
  229. // 关闭弹框
  230. closeModal () {
  231. this.itemId = ''
  232. this.openModal = false
  233. },
  234. // 出入库明细
  235. goWarehouseDetail (row) {
  236. this.$router.push({ path: `/inventoryManagement/inventoryQuery/warehouseDetail/${row.productSn}` })
  237. },
  238. // 导出
  239. handleExport () {
  240. const params = this.queryParam
  241. this.exportLoading = true
  242. stockExport(params).then(res => {
  243. this.exportLoading = false
  244. this.download(res)
  245. })
  246. },
  247. download (data) {
  248. if (!data) { return }
  249. const url = window.URL.createObjectURL(new Blob([data]))
  250. const link = document.createElement('a')
  251. link.style.display = 'none'
  252. link.href = url
  253. const a = moment().format('YYYYMMDDHHmmss')
  254. const fname = '库存查询' + a
  255. link.setAttribute('download', fname + '.xlsx')
  256. document.body.appendChild(link)
  257. link.click()
  258. },
  259. getProductType () {
  260. dealerProductTypeList({}).then(res => {
  261. this.recursionFun(res.data)
  262. this.typeData = res.data
  263. })
  264. },
  265. // 递归函数
  266. recursionFun (data) {
  267. if (data) {
  268. data.map((item, index) => {
  269. if (item.children && item.children.length == 0) {
  270. delete item.children
  271. } else {
  272. this.recursionFun(item.children)
  273. }
  274. })
  275. }
  276. },
  277. // 分类 changeType
  278. changeType (val, selectedOptions) {
  279. console.log(val, selectedOptions)
  280. for (let i = 0; i < val.length; i++) {
  281. this.queryParam['productTypeSn' + (i + 1)] = val[i]
  282. }
  283. },
  284. // 产品品牌 列表
  285. getProductBrand () {
  286. dealerProductBrandQuery({}).then(res => {
  287. if (res.status == 200) {
  288. this.brandData = res.data
  289. } else {
  290. this.brandData = []
  291. }
  292. })
  293. },
  294. filterOption (input, option) {
  295. return (
  296. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  297. )
  298. }
  299. }
  300. }
  301. </script>