list.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <a-card size="small" :bordered="false" class="productInfoList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="searchForm">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="产品编码"><a-input id="productInfoList-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码" /></a-form-item>
  10. </a-col>
  11. <a-col :md="6" :sm="24">
  12. <a-form-item label="产品名称"><a-input id="productInfoList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称" /></a-form-item>
  13. </a-col>
  14. <a-col :md="6" :sm="24">
  15. <a-form-item label="原厂编码"><a-input id="productInfoList-origCode" v-model.trim="queryParam.origCode" allowClear placeholder="请输入原厂编码" /></a-form-item>
  16. </a-col>
  17. <template v-if="advanced">
  18. <a-col :md="6" :sm="24">
  19. <a-form-item label="产品品牌">
  20. <ProductBrand id="productInfoList-productBrandSn" placeholder="请选择产品品牌" v-model="queryParam.productBrandSn"></ProductBrand>
  21. </a-form-item>
  22. </a-col>
  23. <a-col :md="6" :sm="24">
  24. <a-form-item label="产品分类">
  25. <ProductType id="productInfoList-productType" placeholder="请选择产品分类" :isDealer="true" @change="changeProductType" v-model="productType"></ProductType>
  26. </a-form-item>
  27. </a-col>
  28. <a-col :md="6" :sm="24">
  29. <a-form-item label="启用状态">
  30. <v-select code="ENABLE_FLAG" id="productInfoList-enabledFlag" v-model="queryParam.enabledFlag" allowClear placeholder="请选择启用状态"></v-select>
  31. </a-form-item>
  32. </a-col>
  33. <a-col :md="6" :sm="24">
  34. <a-form-item label="是否有库存">
  35. <a-select id="productInfoList-stockEmptyFlag" allowClear v-model="queryParam.stockEmptyFlag" placeholder="请选择查看是否有库存">
  36. <a-select-option value="0" id="productInfoList-stockEmptyFlag0">
  37. </a-select-option>
  38. <a-select-option value="1" id="productInfoList-stockEmptyFlag1">
  39. </a-select-option>
  40. </a-select>
  41. </a-form-item>
  42. </a-col>
  43. </template>
  44. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  45. <a-button type="primary" @click="searchForm()" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
  46. <a-button style="margin-left: 5px" @click="resetSearchForm()" :disabled="disabled" id="productInfoList-reset">重置</a-button>
  47. <a-button
  48. style="margin-left: 5px"
  49. type="primary"
  50. class="button-warning"
  51. @click="handleExport"
  52. :disabled="disabled"
  53. :loading="exportLoading"
  54. v-if="$hasPermissions('B_product_dealerProduct_export')"
  55. id="productInfoList-export">导出</a-button>
  56. <a @click="advanced = !advanced" style="margin-left: 5px" id="productInfoList-advanced">
  57. {{ advanced ? '收起' : '展开' }}
  58. <a-icon :type="advanced ? 'up' : 'down'" />
  59. </a>
  60. </a-col>
  61. </a-row>
  62. </a-form>
  63. </div>
  64. <!-- 操作按钮 -->
  65. <div class="table-operator">
  66. <a-button v-if="$hasPermissions('B_product_dealerProduct_add')" id="productInfoList-add" type="primary" class="button-error" @click="handleEdit()">新增</a-button>
  67. <a-button class="button-primary" id="productInfoList-import" type="primary" v-if="$hasPermissions('B_product_dealerProduct_import')" @click="importProduct">导入</a-button>
  68. <a-button class="button-primary" v-if="$hasPermissions('B_product_dealerProduct_importPrice')" id="productInfoList-importPrice" type="primary" @click="importProductPrice">批量导入价格</a-button>
  69. <a-dropdown v-if="$hasPermissions('B_product_dealerProduct_enable')">
  70. <a-menu slot="overlay" @click="handleMenuClick" id="productInfoList-menus">
  71. <a-menu-item key="1" id="productInfoList-menus-1"> 批量启用</a-menu-item>
  72. <a-menu-item key="2" id="productInfoList-menus-2"> 批量禁用</a-menu-item>
  73. </a-menu>
  74. <a-button id="productInfoList-menus-action" type="danger" ghost style="margin:0 15px 0 5px;">批量操作 <a-icon type="down" /> </a-button>
  75. </a-dropdown>
  76. <span v-if="rowSelectionInfo&&rowSelectionInfo.selectedRowKeys">已选 {{ rowSelectionInfo.selectedRowKeys.length }} 项</span>
  77. </div>
  78. <!-- 列表 -->
  79. <s-table
  80. class="sTable fixPagination"
  81. ref="table"
  82. :style="{ height: tableHeight + 84.5 + 'px' }"
  83. size="small"
  84. :row-selection="$hasPermissions('B_product_dealerProduct_enable')?rowSelection:null"
  85. @rowSelection="rowSelectionFun"
  86. rowKeyName="productSn"
  87. :rowKey="(record) => record.productSn"
  88. :columns="columns"
  89. :data="loadData"
  90. :scroll="{ y: tableHeight }"
  91. :defaultLoadData="false"
  92. bordered
  93. >
  94. <!-- 产品分类 -->
  95. <template slot="productType" slot-scope="text, record">
  96. <span v-if="record.productTypeName2 || record.productTypeName3">
  97. {{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}
  98. </span>
  99. <span v-else>--</span>
  100. </template>
  101. <!-- 状态 -->
  102. <template slot="enabledFlag" slot-scope="text, record">
  103. <a-switch
  104. :id="'productInfoList-enable-'+record.productSn"
  105. checkedChildren="启用"
  106. unCheckedChildren="禁用"
  107. v-if="$hasPermissions('B_product_dealerProduct_enable')&&record.enabledFlag!=undefined"
  108. @change="changeStatus(record)"
  109. :checked="record.enabledFlag == 1 ? true : false"
  110. />
  111. <span v-else :style="{ color: record.enabledFlag == 1 ? '#00aa00' : '#999' }">
  112. {{ record.enabledFlag == 1 ? '已启用' : (record.enabledFlag!=undefined?'已禁用':'--') }}
  113. </span>
  114. </template>
  115. <!-- 操作 -->
  116. <template slot="action" slot-scope="text, record">
  117. <a-button
  118. size="small"
  119. v-if="$hasPermissions('B_product_dealerProduct_edit')"
  120. type="link"
  121. class="button-primary"
  122. @click="handleEdit(record)"
  123. :id="'productInfoList-edit-'+record.productSn"
  124. >
  125. 编辑
  126. </a-button>
  127. <a-button
  128. v-if="$hasPermissions('B_product_dealerProduct_detail')"
  129. size="small"
  130. type="link"
  131. class="button-success"
  132. @click="handleDetail(record)"
  133. :id="'productInfoList-detail-'+record.productSn"
  134. >
  135. 详情
  136. </a-button>
  137. <span v-if="!$hasPermissions('B_product_dealerProduct_edit') && !$hasPermissions('B_product_dealerProduct_detail')">--</span>
  138. </template>
  139. </s-table>
  140. </a-spin>
  141. <!-- 产品详情 -->
  142. <product-info-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
  143. <!-- 导入产品 -->
  144. <importGuideModal :openModal="openGuideModal" @close="openGuideModal=false" @ok="resetSearchForm" />
  145. <!-- 批量导入价格 -->
  146. <importPriceModal :openModal="openEditPriceModal" @close="openEditPriceModal=false" @ok="resetSearchForm" />
  147. </a-card>
  148. </template>
  149. <script>
  150. import { commonMixin } from '@/utils/mixin'
  151. import ProductType from '../../common/productType.js'
  152. import ProductBrand from '../../common/productBrand.js'
  153. import { dealerProductList, dealerProductUpdate, dealerProductExport } from '@/api/dealerProduct'
  154. import { STable, VSelect } from '@/components'
  155. import productInfoDetailModal from './detailModal.vue'
  156. import importGuideModal from './importGuideModal.vue'
  157. import importPriceModal from './importPriceModal.vue'
  158. import { downloadExcel } from '@/libs/JGPrint.js'
  159. export default {
  160. name: 'ProductList',
  161. components: { STable, VSelect, productInfoDetailModal, ProductType, ProductBrand, importGuideModal, importPriceModal },
  162. mixins: [commonMixin],
  163. data () {
  164. const _this = this
  165. return {
  166. spinning: false,
  167. advanced: true, // 高级搜索 展开/关闭
  168. tableHeight: 0,
  169. productType: [],
  170. queryParam: {
  171. // 查询条件
  172. code: '', // 产品编码
  173. name: '', // 产品名称
  174. origCode: '', // 原厂编码
  175. sysFlag: '0',
  176. productBrandSn: undefined, // 产品品牌
  177. productTypeSn1: '', // 产品一级分类
  178. productTypeSn2: '', // 产品二级分类
  179. productTypeSn3: '', // 产品三级分类
  180. enabledFlag: undefined, // 状态
  181. stockEmptyFlag: undefined
  182. },
  183. disabled: false, // 查询、重置按钮是否可操作
  184. exportLoading: false, // 导出loading
  185. openGuideModal: false, // 打开导入弹窗
  186. openEditPriceModal: false, // 打开修改价格弹窗
  187. columns: [
  188. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  189. {
  190. title: '产品编码',
  191. dataIndex: 'code',
  192. width: '12%',
  193. align: 'center',
  194. customRender: function (text) {
  195. return text || '--'
  196. }
  197. },
  198. {
  199. title: '产品名称',
  200. dataIndex: 'name',
  201. width: '13%',
  202. align: 'left',
  203. ellipsis: true,
  204. customRender: function (text) {
  205. return text || '--'
  206. }
  207. },
  208. {
  209. title: '原厂编码',
  210. dataIndex: 'origCode',
  211. width: '11%',
  212. align: 'center',
  213. customRender: function (text) {
  214. return text || '--'
  215. }
  216. },
  217. {
  218. title: '产品品牌',
  219. dataIndex: 'productBrandName',
  220. width: '9%',
  221. align: 'center',
  222. customRender: function (text) {
  223. return text || '--'
  224. }
  225. },
  226. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '9%', align: 'center' },
  227. {
  228. title: '经销批发价',
  229. dataIndex: 'specialPrice',
  230. width: '7%',
  231. align: 'right',
  232. customRender: function (text) {
  233. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  234. }
  235. },
  236. {
  237. title: '终端价',
  238. dataIndex: 'terminalPrice',
  239. width: '6%',
  240. align: 'right',
  241. customRender: function (text) {
  242. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  243. }
  244. },
  245. {
  246. title: '车主价',
  247. dataIndex: 'carOwnersPrice',
  248. width: '6%',
  249. align: 'right',
  250. customRender: function (text) {
  251. return text || text == 0 ? _this.toThousands(text, 2) : '--'
  252. }
  253. },
  254. {
  255. title: '创建时间',
  256. dataIndex: 'createDate',
  257. width: '7%',
  258. align: 'center',
  259. customRender: function (text) {
  260. return text || '--'
  261. }
  262. },
  263. {
  264. title: '可用库存',
  265. dataIndex: 'currentStockQty',
  266. width: '7%',
  267. align: 'center',
  268. customRender: function (text) {
  269. return text || text == 0 ? text : '--'
  270. }
  271. },
  272. { title: <div><a-tooltip placement='top' title='注意:产品被禁用后,不能再销售。'><a-icon type="question-circle" /></a-tooltip>&nbsp;启用状态</div>, scopedSlots: { customRender: 'enabledFlag' }, width: '7%', align: 'center' },
  273. { title: '操作', scopedSlots: { customRender: 'action' }, width: '9%', align: 'center' }
  274. ],
  275. // 加载数据方法 必须为 Promise 对象
  276. loadData: parameter => {
  277. this.disabled = true
  278. this.spinning = true
  279. return dealerProductList(Object.assign(parameter, this.queryParam)).then(res => {
  280. let data
  281. if (res.status == 200) {
  282. data = res.data
  283. const no = (data.pageNo - 1) * data.pageSize
  284. for (var i = 0; i < data.list.length; i++) {
  285. data.list[i].no = no + i + 1
  286. const productTypeName1 = data.list[i].productTypeName1 ? data.list[i].productTypeName1 : ''
  287. const productTypeName2 = data.list[i].productTypeName2 ? ' > ' + data.list[i].productTypeName2 : ''
  288. const productTypeName3 = data.list[i].productTypeName3 ? ' > ' + data.list[i].productTypeName3 : ''
  289. data.list[i].productTypeName = productTypeName1 + productTypeName2 + productTypeName3
  290. }
  291. this.disabled = false
  292. }
  293. this.spinning = false
  294. return data
  295. })
  296. },
  297. openModal: false, // 查看客户详情 弹框
  298. itemId: '', // 当前产品id
  299. productBrandList: [], // 品牌下拉数据
  300. productTypeList: [], // 分类下拉数据
  301. rowSelectionInfo: null
  302. }
  303. },
  304. computed: {
  305. rowSelection () {
  306. return {
  307. getCheckboxProps: record => ({
  308. props: {
  309. disabled: record.enabledFlag == undefined // Column configuration not to be checked
  310. }
  311. })
  312. }
  313. }
  314. },
  315. methods: {
  316. // 查询
  317. searchForm () {
  318. this.$refs.table.clearSelected() // 清空表格选中项
  319. this.rowSelectionInfo = null
  320. this.$refs.table.refresh(true)
  321. },
  322. // 重置
  323. resetSearchForm () {
  324. this.queryParam.code = ''
  325. this.queryParam.name = ''
  326. this.queryParam.origCode = ''
  327. this.queryParam.productBrandSn = undefined
  328. this.queryParam.productTypeSn1 = ''
  329. this.queryParam.productTypeSn2 = ''
  330. this.queryParam.productTypeSn3 = ''
  331. this.queryParam.enabledFlag = undefined
  332. this.queryParam.stockEmptyFlag = undefined
  333. this.productType = []
  334. // this.$refs.table.clearSelected()
  335. // this.rowSelectionInfo = null
  336. this.$refs.table.refresh(true)
  337. },
  338. // 新增/编辑
  339. handleEdit (row) {
  340. if (row) {
  341. // 编辑
  342. this.$router.push({ path: `/productManagement/productInfo/edit/${row.id}` })
  343. } else {
  344. // 新增
  345. this.$router.push({ path: '/productManagement/productInfo/add' })
  346. }
  347. },
  348. // 详情
  349. handleDetail (row) {
  350. this.itemId = row.id
  351. this.openModal = true
  352. },
  353. // 关闭弹框
  354. closeModal () {
  355. this.itemId = ''
  356. this.openModal = false
  357. },
  358. // 产品分类 change
  359. changeProductType (val, opt) {
  360. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  361. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  362. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  363. },
  364. // 启用 禁用
  365. changeStatus (record) {
  366. if (record.currentStockQty != 0) {
  367. this.$confirm({
  368. title: '提示',
  369. content: record.enabledFlag == '1' ? '当前产品存在可用库存,产品被禁用后,不能再销售,确定禁用吗?' : '确定启用吗?',
  370. centered: true,
  371. onOk: () => {
  372. this.setEnable(record.enabledFlag == 1 ? '0' : '1', [record.productSn])
  373. }
  374. })
  375. } else {
  376. if (record.enabledFlag == 1) {
  377. this.setEnable('0', [record.productSn])
  378. } else {
  379. this.$confirm({
  380. title: '提示',
  381. content: '确定启用吗?',
  382. centered: true,
  383. onOk: () => {
  384. this.setEnable('1', [record.productSn])
  385. }
  386. })
  387. }
  388. }
  389. },
  390. // 启用 禁用
  391. setEnable (enabledFlag, snList) {
  392. const params = {
  393. productSnList: snList,
  394. enabledFlag: enabledFlag
  395. }
  396. this.spinning = true
  397. dealerProductUpdate(params).then(res => {
  398. if (res.status == 200) {
  399. this.$message.success(res.message)
  400. this.$refs.table.clearSelected()
  401. this.rowSelectionInfo = null
  402. this.$refs.table.refresh()
  403. this.spinning = false
  404. } else {
  405. this.$refs.table.refresh()
  406. this.spinning = false
  407. }
  408. })
  409. },
  410. // 导入产品
  411. importProduct () {
  412. this.openGuideModal = true
  413. },
  414. // 导入产品 修改价格
  415. importProductPrice () {
  416. this.openEditPriceModal = true
  417. },
  418. // 表格选中项
  419. rowSelectionFun (obj) {
  420. this.rowSelectionInfo = obj || null
  421. },
  422. // 批量操作
  423. handleOutbounds (type) {
  424. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length <= 0)) {
  425. this.$message.warning('请在列表勾选后再进行批量操作!')
  426. return
  427. }
  428. // 判断所选产品是否都是库存为0的产品
  429. const isZero = this.rowSelectionInfo.selectedRows.every(item => { return item.currentStockQty == 0 })
  430. this.$confirm({
  431. title: '提示',
  432. content: type == '2' ? (isZero ? '产品被禁用后,不能再销售,确定批量禁用吗?' : '当前产品存在可用库存,产品被禁用后,不能再销售,确定禁用吗?') : '确定批量启用吗?',
  433. centered: true,
  434. onOk: () => {
  435. this.setEnable(type == '2' ? '0' : '1', this.rowSelectionInfo.selectedRowKeys)
  436. }
  437. })
  438. },
  439. // 更多操作
  440. handleMenuClick (e) {
  441. this.handleOutbounds(e.key)
  442. },
  443. // 导出
  444. handleExport () {
  445. this.exportLoading = true
  446. this.spinning = true
  447. dealerProductExport(this.queryParam).then(res => {
  448. this.exportLoading = false
  449. this.spinning = false
  450. downloadExcel(res, '自建产品列表')
  451. })
  452. },
  453. pageInit () {
  454. const _this = this
  455. this.$nextTick(() => {
  456. // 页面渲染完成后的回调
  457. _this.setTableH()
  458. })
  459. },
  460. setTableH () {
  461. const tableSearchH = this.$refs.tableSearch.offsetHeight
  462. this.tableHeight = window.innerHeight - tableSearchH - 235
  463. }
  464. },
  465. watch: {
  466. advanced (newValue, oldValue) {
  467. const _this = this
  468. this.$nextTick(() => {
  469. // 页面渲染完成后的回调
  470. _this.setTableH()
  471. })
  472. },
  473. '$store.state.app.winHeight' (newValue, oldValue) {
  474. // 窗口变更时,需同时更改表格高度
  475. this.setTableH()
  476. }
  477. },
  478. mounted () {
  479. if (!this.$store.state.app.isNewTab) {
  480. // 页签刷新时调用
  481. this.pageInit()
  482. this.resetSearchForm()
  483. }
  484. },
  485. activated () {
  486. // 如果是新页签打开,则重置当前页面
  487. if (this.$store.state.app.isNewTab) {
  488. this.pageInit()
  489. this.resetSearchForm()
  490. }
  491. // 仅刷新列表,不重置页面
  492. if (this.$store.state.app.updateList) {
  493. this.pageInit()
  494. this.$refs.table.refresh()
  495. }
  496. },
  497. beforeRouteEnter (to, from, next) {
  498. next(vm => {})
  499. }
  500. }
  501. </script>