list.vue 17 KB

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