list.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <template>
  2. <a-card size="small" :bordered="false" class="chainStockReportList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper">
  6. <a-form-model
  7. id="chainStockReportList-form"
  8. ref="ruleForm"
  9. class="form-model-con"
  10. layout="inline"
  11. :model="queryParam"
  12. :rules="rules"
  13. :labelCol="labelCol"
  14. :wrapperCol="wrapperCol"
  15. @keyup.enter.native="handleSearch" >
  16. <a-row :gutter="15">
  17. <a-col :md="6" :sm="24">
  18. <a-form-model-item label="连锁店" prop="tenantId">
  19. <a-select
  20. placeholder="请选择连锁店"
  21. id="chainStockReportList-tenantId"
  22. allowClear
  23. v-model="queryParam.tenantId"
  24. :showSearch="true"
  25. option-filter-prop="children"
  26. :filter-option="filterOption">
  27. <a-select-option v-for="item in linkageGroupData" :key="item.dealerSn" :value="item.dealerSn">{{ item.dealerName }}</a-select-option>
  28. </a-select>
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :md="6" :sm="24">
  32. <a-form-model-item label="产品编码">
  33. <a-input id="chainStockReportList-code" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  34. </a-form-model-item>
  35. </a-col>
  36. <a-col :md="6" :sm="24">
  37. <a-form-model-item label="产品名称">
  38. <a-input id="chainStockReportList-name" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  39. </a-form-model-item>
  40. </a-col>
  41. <template v-if="advanced">
  42. <a-col :md="6" :sm="24">
  43. <a-form-model-item label="原厂编码">
  44. <a-input id="chainStockReportList-origCode" v-model.trim="queryParam.productOrigCode" allowClear placeholder="请输入原厂编码"/>
  45. </a-form-model-item>
  46. </a-col>
  47. <a-col :md="6" :sm="24">
  48. <a-form-model-item label="产品品牌">
  49. <ProductBrand id="chainStockReportList-productBrandSn" placeholder="请选择产品品牌" v-model="queryParam.productBrandSn"></ProductBrand>
  50. </a-form-model-item>
  51. </a-col>
  52. <a-col :md="6" :sm="24">
  53. <a-form-model-item label="产品分类">
  54. <ProductType id="chainStockReportList-productType" placeholder="请选择产品分类" :isDealer="true" @change="changeProductType" v-model="productType"></ProductType>
  55. </a-form-model-item>
  56. </a-col>
  57. <a-col :md="6" :sm="24">
  58. <a-form-model-item label="滞销天数">
  59. <a-input-group>
  60. <a-row>
  61. <a-col :span="11">
  62. <a-input-number
  63. id="shelfMonitoringList-minUnsalableDays"
  64. v-model="queryParam.minUnsalableDays"
  65. :precision="0"
  66. :min="0"
  67. :max="999999"
  68. placeholder="起始天数"
  69. style="width: 100%;display: inline-block;" />
  70. </a-col>
  71. <a-col :span="2"><span style="display: block;text-align: center;line-height: 32px;">至</span></a-col>
  72. <a-col :span="11">
  73. <a-input-number
  74. id="shelfMonitoringList-maxUnsalableDays"
  75. v-model="queryParam.maxUnsalableDays"
  76. :precision="0"
  77. :min="0"
  78. :max="999999"
  79. placeholder="截止天数"
  80. style="width: 100%;display: inline-block;" />
  81. </a-col>
  82. </a-row>
  83. </a-input-group>
  84. </a-form-model-item>
  85. </a-col>
  86. </template>
  87. <a-col :md="6" :sm="24">
  88. <a-button type="primary" @click="handleSearch" :disabled="disabled" id="chainStockReportList-refresh">查询</a-button>
  89. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="chainStockReportList-reset">重置</a-button>
  90. <a-button
  91. type="primary"
  92. class="button-warning"
  93. @click="handleExport"
  94. :disabled="disabled"
  95. :loading="exportLoading"
  96. id="inventoryQueryList-export">导出</a-button>
  97. <a @click="advanced=!advanced" style="margin-left: 8px">
  98. {{ advanced ? '收起' : '展开' }}
  99. <a-icon :type="advanced ? 'up' : 'down'"/>
  100. </a>
  101. </a-col>
  102. </a-row>
  103. </a-form-model>
  104. </div>
  105. <!-- 合计 -->
  106. <a-alert type="info" style="margin-bottom:10px">
  107. <div class="ftext" slot="message">
  108. 可用库存总数量:<strong> {{ (totalData && (totalData.currentStockQty || totalData.currentStockQty==0)) ? totalData.currentStockQty : '--' }} </strong>;
  109. 可用库存总成本:<strong> {{ (totalData && (totalData.currentStockCost || totalData.currentStockCost==0)) ? toThousands(totalData.currentStockCost) : '--' }} </strong>。
  110. </div>
  111. </a-alert>
  112. <!-- 列表 -->
  113. <s-table
  114. class="sTable"
  115. ref="table"
  116. size="small"
  117. :rowKey="(record) => record.productSn + record.stockSn"
  118. :columns="columns"
  119. :data="loadData"
  120. :defaultLoadData="false"
  121. bordered>
  122. <!-- 直销天数 -->
  123. <template slot="unsalableDays" slot-scope="text, record" >
  124. <span v-if="record.unsalableDays>=180&&record.unsalableDays<=360" style="color:#FF9900">{{ num(record.unsalableDays) }}</span>
  125. <span v-else-if="record.unsalableDays>360" style="color:#FF0000">{{ num(record.unsalableDays) }}</span>
  126. <span v-else >{{ num(record.unsalableDays) }}</span>
  127. </template>
  128. <!-- 操作 -->
  129. <template slot="action" slot-scope="text, record">
  130. <a-button size="small" type="link" class="button-success" @click="goDetail(record)" id="chainStockReportList-detail-btn">详情</a-button>
  131. </template>
  132. </s-table>
  133. </a-spin>
  134. <!-- 详情 -->
  135. <chain-stock-report-detail-modal :openModal="openModal" :productSn="productSn" :stockSn="stockSn" @close="closeModal" />
  136. </a-card>
  137. </template>
  138. <script>
  139. import { commonMixin } from '@/utils/mixin'
  140. import { STable, VSelect } from '@/components'
  141. import chainStockReportDetailModal from './detailModal.vue'
  142. import { linkageGroupList } from '@/api/reportData'
  143. import ProductType from '../../common/productType.js'
  144. import ProductBrand from '../../common/productBrand.js'
  145. import { reportStockList, reportStockCount } from '@/api/reportStock'
  146. import { downloadExcel } from '@/libs/JGPrint.js'
  147. import { stockExport } from '@/api/stock'
  148. export default {
  149. components: { STable, VSelect, chainStockReportDetailModal, ProductType, ProductBrand },
  150. mixins: [commonMixin],
  151. data () {
  152. const _this = this
  153. return {
  154. spinning: false,
  155. advanced: true, // 高级搜索 展开/关闭
  156. tableHeight: 0,
  157. queryParam: { // 查询条件
  158. tenantId: undefined,
  159. productCode: '', // 产品编码
  160. productName: '', // 产品名称
  161. productOrigCode: '', // 原厂编码
  162. productBrandSn: undefined, // 产品品牌
  163. productTypeSn1: '', // 产品分类1
  164. productTypeSn2: '', // 产品分类2
  165. productTypeSn3: '', // 产品分类3
  166. minUnsalableDays: undefined, // 滞销天数最小值
  167. maxUnsalableDays: undefined // 滞销天数最大值
  168. },
  169. labelCol: { span: 8 },
  170. wrapperCol: { span: 16 },
  171. rules: {
  172. 'tenantId': [{ required: true, message: '请选择连锁店', trigger: 'change' }]
  173. },
  174. disabled: false, // 查询、重置按钮是否可操作
  175. exportLoading: false,
  176. columns: [
  177. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  178. { title: '产品编码', dataIndex: 'productCode', width: '20%', align: 'center', customRender: function (text) { return text || '--' }, sorter: true },
  179. { title: '产品名称', dataIndex: 'productName', width: '20%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  180. { title: '原厂编码', dataIndex: 'productOrigCode', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  181. { title: '可用库存数量(个)', dataIndex: 'currentStockQty', width: '14%', align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  182. { title: '可用库存成本(¥)', dataIndex: 'currentStockCost', width: '14%', align: 'right', sorter: true, customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  183. { title: <div><a-tooltip placement='top' title='1:产品距离最近一次销售的时间,30天算一个月 2:采购退货,调拨等不算销售,不用来计算滞销天数'><a-icon type="question-circle" /></a-tooltip>&nbsp;滞销天数</div>, width: '10%', align: 'center', scopedSlots: { customRender: 'unsalableDays' }, sorter: true },
  184. { title: '操作', scopedSlots: { customRender: 'action' }, width: '5%', align: 'center' }
  185. ],
  186. // 加载数据方法 必须为 Promise 对象
  187. loadData: parameter => {
  188. this.disabled = true
  189. const params = Object.assign(parameter, this.queryParam)
  190. this.spinning = true
  191. if (params.tenantId) {
  192. if (this.checkValueRange()) {
  193. return reportStockList(params).then(res => {
  194. let data
  195. if (res.status == 200) {
  196. data = res.data
  197. // 总计
  198. this.getCount(params)
  199. const no = (data.pageNo - 1) * data.pageSize
  200. for (var i = 0; i < data.list.length; i++) {
  201. data.list[i].no = no + i + 1
  202. }
  203. this.disabled = false
  204. }
  205. this.spinning = false
  206. return data
  207. })
  208. } else {
  209. console.log('=======未登录')
  210. const _this = this
  211. return new Promise(function (resolve, reject) {
  212. const data = {
  213. pageNo: 1,
  214. pageSize: 10,
  215. list: [],
  216. count: 0
  217. }
  218. _this.disabled = false
  219. _this.spinning = false
  220. resolve(data)
  221. })
  222. }
  223. } else {
  224. const _this = this
  225. return new Promise(function (resolve, reject) {
  226. const data = {
  227. pageNo: 1,
  228. pageSize: 10,
  229. list: [],
  230. count: 0
  231. }
  232. _this.disabled = false
  233. _this.spinning = false
  234. _this.$message.info('请选择连锁店')
  235. resolve(data)
  236. })
  237. }
  238. },
  239. productType: [],
  240. linkageGroupData: [],
  241. productBrandList: [], // 品牌下拉数据
  242. productTypeList: [], // 分类下拉数据
  243. allocateTypeList: [], // 调拨类型
  244. totalData: null, // 合计
  245. productSn: '',
  246. stockSn: '',
  247. openModal: false // 弹框
  248. }
  249. },
  250. methods: {
  251. // 校验滞销天数数值范围
  252. checkValueRange () {
  253. const isONull = this.queryParam.minUnsalableDays === null || this.queryParam.minUnsalableDays === undefined
  254. const isOEmpty = this.queryParam.minUnsalableDays === ''
  255. const isOZero = this.queryParam.minUnsalableDays === 0
  256. const isTNull = this.queryParam.maxUnsalableDays === null || this.queryParam.maxUnsalableDays === undefined
  257. const isTEmpty = this.queryParam.maxUnsalableDays === ''
  258. const isTZero = this.queryParam.maxUnsalableDays === 0
  259. // 第一个为空(可为null可为空字符)第二个不为空
  260. // 第一个不为空第二个为空(可为null可为空字符)
  261. // 第一个大于第二个
  262. if ((isONull || isOEmpty) && (this.queryParam.maxUnsalableDays || isTZero)) {
  263. this.$message.info('请输入正确的滞销天数查询范围!')
  264. return false
  265. }
  266. if ((this.queryParam.minUnsalableDays || isOZero) && (isTNull || isTEmpty)) {
  267. this.$message.info('请输入正确的滞销天数查询范围!')
  268. return false
  269. }
  270. if (this.queryParam.minUnsalableDays > this.queryParam.maxUnsalableDays) {
  271. this.$message.info('请输入正确的滞销天数查询范围!')
  272. return false
  273. }
  274. this.queryParam.minUnsalableDays = this.queryParam.minUnsalableDays > 999999999 ? 999999999 : this.queryParam.minUnsalableDays
  275. this.queryParam.maxUnsalableDays = this.queryParam.maxUnsalableDays > 999999999 ? 999999999 : this.queryParam.maxUnsalableDays
  276. return true
  277. },
  278. num (val) {
  279. let days
  280. if (val) {
  281. if (val >= 30) {
  282. const a = Math.floor(val / 30)
  283. const b = val - a * 30
  284. if (b > 0) {
  285. days = a + '个月' + b + '天'
  286. } else {
  287. days = a + '个月'
  288. }
  289. } else {
  290. days = val + '天'
  291. }
  292. } else {
  293. days = '--'
  294. }
  295. return days
  296. },
  297. // 合计
  298. getCount (params) {
  299. reportStockCount(params).then(res => {
  300. if (res.status == 200) {
  301. this.totalData = res.data
  302. } else {
  303. this.totalData = null
  304. }
  305. })
  306. },
  307. // 查询
  308. handleSearch () {
  309. const _this = this
  310. this.$refs.ruleForm.validate(valid => {
  311. if (valid) {
  312. _this.$refs.table.refresh(true)
  313. } else {
  314. console.log('error submit!!')
  315. return false
  316. }
  317. })
  318. },
  319. // 重置
  320. resetSearchForm () {
  321. this.queryParam.tenantId = undefined
  322. this.queryParam.productCode = ''
  323. this.queryParam.productName = ''
  324. this.queryParam.productOrigCode = ''
  325. this.queryParam.productBrandSn = undefined
  326. this.queryParam.productTypeSn1 = ''
  327. this.queryParam.productTypeSn2 = ''
  328. this.queryParam.productTypeSn3 = ''
  329. this.queryParam.minUnsalableDays = undefined // 滞销天数最小值
  330. this.queryParam.maxUnsalableDays = undefined // 滞销天数最大值
  331. this.productType = []
  332. this.$refs.ruleForm.resetFields()
  333. this.totalData = null
  334. this.$refs.table.clearTable()
  335. },
  336. // 导出
  337. handleExport () {
  338. const _this = this
  339. const params = JSON.parse(JSON.stringify(this.queryParam))
  340. if (params.tenantId) {
  341. this.exportLoading = true
  342. _this.spinning = true
  343. stockExport(params).then(res => {
  344. this.exportLoading = false
  345. _this.spinning = false
  346. if (res.type == 'application/json') {
  347. var reader = new FileReader()
  348. reader.addEventListener('loadend', function () {
  349. const obj = JSON.parse(reader.result)
  350. _this.$notification.error({
  351. message: '提示',
  352. description: obj.message
  353. })
  354. })
  355. reader.readAsText(res)
  356. } else {
  357. downloadExcel(res, '连锁库存总表')
  358. }
  359. })
  360. } else {
  361. this.exportLoading = false
  362. _this.spinning = false
  363. this.$message.info('请选择连锁店')
  364. return false
  365. }
  366. },
  367. // 详情
  368. goDetail (row) {
  369. this.productSn = row.productSn
  370. this.stockSn = row.stockSn
  371. this.openModal = true
  372. },
  373. // 关闭弹框
  374. closeModal () {
  375. this.productSn = ''
  376. this.stockSn = ''
  377. this.openModal = false
  378. },
  379. // 产品分类 change
  380. changeProductType (val, opt) {
  381. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  382. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  383. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  384. },
  385. filterOption (input, option) {
  386. return (
  387. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  388. )
  389. },
  390. // 连锁店
  391. getLinkageGroup () {
  392. linkageGroupList({}).then(res => {
  393. if (res.status == 200) {
  394. const data = res.data || []
  395. if (data.length > 0) {
  396. this.linkageGroupData = data
  397. } else {
  398. this.linkageGroupData = []
  399. }
  400. } else {
  401. this.linkageGroupData = []
  402. }
  403. })
  404. },
  405. pageInit () {
  406. this.getLinkageGroup()
  407. }
  408. },
  409. mounted () {
  410. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  411. this.pageInit()
  412. this.resetSearchForm()
  413. }
  414. },
  415. activated () {
  416. // 如果是新页签打开,则重置当前页面
  417. if (this.$store.state.app.isNewTab) {
  418. this.pageInit()
  419. this.resetSearchForm()
  420. }
  421. },
  422. beforeRouteEnter (to, from, next) {
  423. next(vm => {})
  424. }
  425. }
  426. </script>