list.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. rowKeyName="productSn"
  119. :columns="columns"
  120. :data="loadData"
  121. :defaultLoadData="false"
  122. bordered>
  123. <!-- 直销天数 -->
  124. <template slot="unsalableDays" slot-scope="text, record" >
  125. <span v-if="record.unsalableDays>=180&&record.unsalableDays<=360" style="color:#FF9900">{{ num(record.unsalableDays) }}</span>
  126. <span v-else-if="record.unsalableDays>360" style="color:#FF0000">{{ num(record.unsalableDays) }}</span>
  127. <span v-else >{{ num(record.unsalableDays) }}</span>
  128. </template>
  129. <!-- 操作 -->
  130. <template slot="action" slot-scope="text, record">
  131. <a-button size="small" type="link" class="button-success" @click="goDetail(record)" id="chainStockReportList-detail-btn">详情</a-button>
  132. </template>
  133. </s-table>
  134. </a-spin>
  135. <!-- 详情 -->
  136. <chain-stock-report-detail-modal :openModal="openModal" :productSn="productSn" :stockSn="stockSn" @close="closeModal" />
  137. </a-card>
  138. </template>
  139. <script>
  140. import { commonMixin } from '@/utils/mixin'
  141. import { STable, VSelect } from '@/components'
  142. import chainStockReportDetailModal from './detailModal.vue'
  143. import { linkageGroupList } from '@/api/reportData'
  144. import ProductType from '../../common/productType.js'
  145. import ProductBrand from '../../common/productBrand.js'
  146. import { reportStockList, reportStockCount } from '@/api/reportStock'
  147. import { downloadExcel } from '@/libs/JGPrint.js'
  148. import { stockExport } from '@/api/stock'
  149. export default {
  150. components: { STable, VSelect, chainStockReportDetailModal, ProductType, ProductBrand },
  151. mixins: [commonMixin],
  152. data () {
  153. const _this = this
  154. return {
  155. spinning: false,
  156. advanced: true, // 高级搜索 展开/关闭
  157. tableHeight: 0,
  158. queryParam: { // 查询条件
  159. tenantId: undefined,
  160. productCode: '', // 产品编码
  161. productName: '', // 产品名称
  162. productOrigCode: '', // 原厂编码
  163. productBrandSn: undefined, // 产品品牌
  164. productTypeSn1: '', // 产品分类1
  165. productTypeSn2: '', // 产品分类2
  166. productTypeSn3: '', // 产品分类3
  167. minUnsalableDays: undefined, // 滞销天数最小值
  168. maxUnsalableDays: undefined // 滞销天数最大值
  169. },
  170. labelCol: { span: 8 },
  171. wrapperCol: { span: 16 },
  172. rules: {
  173. 'tenantId': [{ required: true, message: '请选择连锁店', trigger: 'change' }]
  174. },
  175. disabled: false, // 查询、重置按钮是否可操作
  176. exportLoading: false,
  177. columns: [
  178. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  179. { title: '产品编码', dataIndex: 'productCode', width: '20%', align: 'center', customRender: function (text) { return text || '--' }, sorter: true },
  180. { title: '产品名称', dataIndex: 'productName', width: '20%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  181. { title: '原厂编码', dataIndex: 'productOrigCode', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  182. { title: '可用库存数量(个)', dataIndex: 'currentStockQty', width: '14%', align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  183. { title: '可用库存成本(¥)', dataIndex: 'currentStockCost', width: '14%', align: 'right', sorter: true, customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
  184. { 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 },
  185. { title: '操作', scopedSlots: { customRender: 'action' }, width: '5%', align: 'center' }
  186. ],
  187. // 加载数据方法 必须为 Promise 对象
  188. loadData: parameter => {
  189. this.disabled = true
  190. const params = Object.assign(parameter, this.queryParam)
  191. this.spinning = true
  192. if (params.tenantId) {
  193. if (this.checkValueRange()) {
  194. return reportStockList(params).then(res => {
  195. let data
  196. if (res.status == 200) {
  197. data = res.data
  198. // 总计
  199. this.getCount(params)
  200. const no = (data.pageNo - 1) * data.pageSize
  201. for (var i = 0; i < data.list.length; i++) {
  202. data.list[i].no = no + i + 1
  203. }
  204. this.disabled = false
  205. }
  206. this.spinning = false
  207. return data
  208. })
  209. } else {
  210. console.log('=======未登录')
  211. const _this = this
  212. return new Promise(function (resolve, reject) {
  213. const data = {
  214. pageNo: 1,
  215. pageSize: 10,
  216. list: [],
  217. count: 0
  218. }
  219. _this.disabled = false
  220. _this.spinning = false
  221. resolve(data)
  222. })
  223. }
  224. } else {
  225. const _this = this
  226. return new Promise(function (resolve, reject) {
  227. const data = {
  228. pageNo: 1,
  229. pageSize: 10,
  230. list: [],
  231. count: 0
  232. }
  233. _this.disabled = false
  234. _this.spinning = false
  235. _this.$message.info('请选择连锁店')
  236. resolve(data)
  237. })
  238. }
  239. },
  240. productType: [],
  241. linkageGroupData: [],
  242. productBrandList: [], // 品牌下拉数据
  243. productTypeList: [], // 分类下拉数据
  244. allocateTypeList: [], // 调拨类型
  245. totalData: null, // 合计
  246. productSn: '',
  247. stockSn: '',
  248. openModal: false // 弹框
  249. }
  250. },
  251. methods: {
  252. // 校验滞销天数数值范围
  253. checkValueRange () {
  254. const isONull = this.queryParam.minUnsalableDays === null || this.queryParam.minUnsalableDays === undefined
  255. const isOEmpty = this.queryParam.minUnsalableDays === ''
  256. const isOZero = this.queryParam.minUnsalableDays === 0
  257. const isTNull = this.queryParam.maxUnsalableDays === null || this.queryParam.maxUnsalableDays === undefined
  258. const isTEmpty = this.queryParam.maxUnsalableDays === ''
  259. const isTZero = this.queryParam.maxUnsalableDays === 0
  260. // 第一个为空(可为null可为空字符)第二个不为空
  261. // 第一个不为空第二个为空(可为null可为空字符)
  262. // 第一个大于第二个
  263. if ((isONull || isOEmpty) && (this.queryParam.maxUnsalableDays || isTZero)) {
  264. this.$message.info('请输入正确的滞销天数查询范围!')
  265. return false
  266. }
  267. if ((this.queryParam.minUnsalableDays || isOZero) && (isTNull || isTEmpty)) {
  268. this.$message.info('请输入正确的滞销天数查询范围!')
  269. return false
  270. }
  271. if (this.queryParam.minUnsalableDays > this.queryParam.maxUnsalableDays) {
  272. this.$message.info('请输入正确的滞销天数查询范围!')
  273. return false
  274. }
  275. this.queryParam.minUnsalableDays = this.queryParam.minUnsalableDays > 999999999 ? 999999999 : this.queryParam.minUnsalableDays
  276. this.queryParam.maxUnsalableDays = this.queryParam.maxUnsalableDays > 999999999 ? 999999999 : this.queryParam.maxUnsalableDays
  277. return true
  278. },
  279. num (val) {
  280. let days
  281. if (val) {
  282. if (val >= 30) {
  283. const a = Math.floor(val / 30)
  284. const b = val - a * 30
  285. if (b > 0) {
  286. days = a + '个月' + b + '天'
  287. } else {
  288. days = a + '个月'
  289. }
  290. } else {
  291. days = val + '天'
  292. }
  293. } else {
  294. days = '--'
  295. }
  296. return days
  297. },
  298. // 合计
  299. getCount (params) {
  300. reportStockCount(params).then(res => {
  301. if (res.status == 200) {
  302. this.totalData = res.data
  303. } else {
  304. this.totalData = null
  305. }
  306. })
  307. },
  308. // 查询
  309. handleSearch () {
  310. const _this = this
  311. this.$refs.ruleForm.validate(valid => {
  312. if (valid) {
  313. _this.$refs.table.refresh(true)
  314. } else {
  315. console.log('error submit!!')
  316. return false
  317. }
  318. })
  319. },
  320. // 重置
  321. resetSearchForm () {
  322. this.queryParam.tenantId = undefined
  323. this.queryParam.productCode = ''
  324. this.queryParam.productName = ''
  325. this.queryParam.productOrigCode = ''
  326. this.queryParam.productBrandSn = undefined
  327. this.queryParam.productTypeSn1 = ''
  328. this.queryParam.productTypeSn2 = ''
  329. this.queryParam.productTypeSn3 = ''
  330. this.queryParam.minUnsalableDays = undefined // 滞销天数最小值
  331. this.queryParam.maxUnsalableDays = undefined // 滞销天数最大值
  332. this.productType = []
  333. this.$refs.ruleForm.resetFields()
  334. this.totalData = null
  335. this.$refs.table.clearTable()
  336. },
  337. // 导出
  338. handleExport () {
  339. const _this = this
  340. const params = JSON.parse(JSON.stringify(this.queryParam))
  341. params.showCost = this.$hasPermissions('M_ShowAllCost') ? '1' : '0'
  342. if (params.tenantId) {
  343. this.exportLoading = true
  344. _this.spinning = true
  345. stockExport(params).then(res => {
  346. this.exportLoading = false
  347. _this.spinning = false
  348. if (res.type == 'application/json') {
  349. var reader = new FileReader()
  350. reader.addEventListener('loadend', function () {
  351. const obj = JSON.parse(reader.result)
  352. _this.$notification.error({
  353. message: '提示',
  354. description: obj.message
  355. })
  356. })
  357. reader.readAsText(res)
  358. } else {
  359. downloadExcel(res, '连锁库存总表')
  360. }
  361. })
  362. } else {
  363. this.exportLoading = false
  364. _this.spinning = false
  365. this.$message.info('请选择连锁店')
  366. return false
  367. }
  368. },
  369. // 详情
  370. goDetail (row) {
  371. this.productSn = row.productSn
  372. this.stockSn = row.stockSn
  373. this.openModal = true
  374. },
  375. // 关闭弹框
  376. closeModal () {
  377. this.productSn = ''
  378. this.stockSn = ''
  379. this.openModal = false
  380. },
  381. // 产品分类 change
  382. changeProductType (val, opt) {
  383. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  384. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  385. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  386. },
  387. filterOption (input, option) {
  388. return (
  389. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  390. )
  391. },
  392. // 连锁店
  393. getLinkageGroup () {
  394. linkageGroupList({}).then(res => {
  395. if (res.status == 200) {
  396. const data = res.data || []
  397. if (data.length > 0) {
  398. this.linkageGroupData = data
  399. } else {
  400. this.linkageGroupData = []
  401. }
  402. } else {
  403. this.linkageGroupData = []
  404. }
  405. })
  406. },
  407. pageInit () {
  408. this.getLinkageGroup()
  409. }
  410. },
  411. mounted () {
  412. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  413. this.pageInit()
  414. this.resetSearchForm()
  415. }
  416. },
  417. activated () {
  418. // 如果是新页签打开,则重置当前页面
  419. if (this.$store.state.app.isNewTab) {
  420. this.pageInit()
  421. this.resetSearchForm()
  422. }
  423. },
  424. beforeRouteEnter (to, from, next) {
  425. next(vm => {})
  426. }
  427. }
  428. </script>