list.vue 18 KB

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