list.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <template>
  2. <a-card size="small" :bordered="false" class="productInfoList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="产品名称">
  10. <a-input id="productInfoList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="产品编码/原厂编码">
  15. <a-input id="productInfoList-queryWord" v-model.trim="queryParam.queryWord" allowClear placeholder="请输入产品编码/原厂编码"/>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="24">
  19. <a-form-item label="品牌">
  20. <a-select
  21. placeholder="请选择"
  22. id="productInfoList-productBrandSn"
  23. allowClear
  24. v-model="queryParam.productBrandSn"
  25. :showSearch="true"
  26. option-filter-prop="children"
  27. :filter-option="filterOption">
  28. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  29. </a-select>
  30. </a-form-item>
  31. </a-col>
  32. <template v-if="advanced">
  33. <a-col :md="6" :sm="24">
  34. <a-form-item label="产品分类">
  35. <a-cascader
  36. @change="changeProductType"
  37. expand-trigger="hover"
  38. change-on-select
  39. :options="productTypeList"
  40. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  41. id="productInfoList-productType"
  42. placeholder="请选择产品分类"
  43. allowClear
  44. v-model="productType" />
  45. </a-form-item>
  46. </a-col>
  47. <a-col :md="6" :sm="24">
  48. <a-form-item label="产品状态">
  49. <v-select code="PRODUCT_STATUS" id="productInfoList-state" v-model="queryParam.state" allowClear placeholder="请选择产品状态"></v-select>
  50. </a-form-item>
  51. </a-col>
  52. <a-col :md="6" :sm="24">
  53. <a-form-item label="定价状态">
  54. <v-select code="PRICING_STATUS" id="productInfoList-pricingState" v-model="queryParam.pricingState" allowClear placeholder="请选择定价状态"></v-select>
  55. </a-form-item>
  56. </a-col>
  57. </template>
  58. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  59. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
  60. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="productInfoList-reset">重置</a-button>
  61. <a-button
  62. v-if="$hasPermissions('B_productInfo_export')"
  63. style="margin-left: 5px"
  64. type="primary"
  65. class="button-warning"
  66. @click="handleExport"
  67. :disabled="disabled"
  68. :loading="exportLoading"
  69. id="productInfoList-export">导出</a-button>
  70. <a @click="advanced=!advanced" style="margin-left: 5px">
  71. {{ advanced ? '收起' : '展开' }}
  72. <a-icon :type="advanced ? 'up' : 'down'"/>
  73. </a>
  74. </a-col>
  75. </a-row>
  76. </a-form>
  77. </div>
  78. <!-- 操作按钮 -->
  79. <div class="table-operator">
  80. <a-button id="productInfoList-add" type="primary" v-if="$hasPermissions('B_productInfo_add')" class="button-error" @click="handleEdit()">新增</a-button>
  81. <a-button
  82. id="productInfoList-batchAudit"
  83. type="primary"
  84. v-if="$hasPermissions('B_productInfo_batchAudit')"
  85. class="button-warning"
  86. :loading="loadingAudit"
  87. @click="handleBatchAudit"
  88. style="margin: 0 15px;">批量审核</a-button>
  89. <a-button
  90. id="productInfoList-batchLaunch"
  91. type="primary"
  92. v-if="$hasPermissions('B_productInfo_batchLaunch')"
  93. class="button-primary"
  94. :loading="loadingLaunch"
  95. @click="handleBatchLaunch"
  96. style="margin: 0 15px;">批量上线</a-button>
  97. <a-button
  98. id="productInfoList-batchDownline"
  99. type="primary"
  100. v-if="$hasPermissions('B_productInfo_batchDownline')"
  101. class="button-grey"
  102. :loading="loadingDownline"
  103. @click="handleBatchDownline"
  104. style="margin: 0 15px;">批量下线</a-button>
  105. <span style="margin-left: 8px" v-if="$hasPermissions('B_productInfo_batchAudit') || $hasPermissions('B_productInfo_batchLaunch') || $hasPermissions('B_productInfo_batchDownline')">
  106. <template v-if="hasSelected">{{ `已选 ${selectedRowKeys.length} 项` }}</template>
  107. </span>
  108. </div>
  109. <s-table
  110. class="sTable"
  111. ref="table"
  112. size="small"
  113. :row-selection=" showSelect ?{ selectedRowKeys: selectedRowKeys, onChange: onChange, onSelect: onSelectChange, onSelectAll: onSelectAllChange }:null"
  114. :rowKey="(record) => record.id"
  115. :columns="columns"
  116. :data="loadData"
  117. :scroll="{ x: 2150, y: tableHeight }"
  118. bordered>
  119. <!-- 自定义表头 -->
  120. <template slot="arrowFalgTitle">
  121. <a-tooltip placement="top">
  122. <template slot="title">
  123. <span>自有即箭冠产品,非自有即非箭冠产品</span>
  124. </template>
  125. 自有<a-icon type="question-circle" :style="{ marginLeft: '10px' }" />
  126. </a-tooltip>
  127. </template>
  128. <template slot="arrowFalg" slot-scope="text, record">
  129. <span v-if="record.arrowFalg">{{ record.arrowFalg == 1 ? '是' : '否' }}</span>
  130. <span v-else>--</span>
  131. </template>
  132. <!-- 产品分类 -->
  133. <template slot="productType" slot-scope="text, record">
  134. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  135. <span v-else>--</span>
  136. </template>
  137. <!-- 操作 -->
  138. <template slot="action" slot-scope="text, record">
  139. <a-button
  140. size="small"
  141. type="link"
  142. v-if="record.state=='WAIT' && $hasPermissions('B_productInfo_audit')"
  143. class="button-warning"
  144. @click="handleAudit(record)"
  145. id="productInfoList-audit-btn">审核</a-button>
  146. <a-button
  147. size="small"
  148. type="link"
  149. v-if="(record.state=='WAIT_ONLINE'||record.state=='OFFLINE') && $hasPermissions('B_productInfo_launch')"
  150. class="button-primary"
  151. @click="handleLaunch(record)"
  152. id="productInfoList-launch-btn">上线</a-button>
  153. <a-button
  154. size="small"
  155. type="link"
  156. v-if="record.state=='ONLINE' && $hasPermissions('B_productInfo_downline')"
  157. class="button-grey"
  158. @click="handleDownline(record)"
  159. id="productInfoList-downline-btn">下线</a-button>
  160. <a-button
  161. size="small"
  162. type="link"
  163. v-if="$hasPermissions('B_productInfo_edit')"
  164. class="button-info"
  165. @click="handleEdit(record)"
  166. id="productInfoList-edit-btn">编辑</a-button>
  167. <a-button
  168. size="small"
  169. type="link"
  170. v-if="$hasPermissions('B_productInfo_detail')"
  171. class="button-success"
  172. @click="handleDetail(record)"
  173. id="productInfoList-detail-btn">详情</a-button>
  174. <a-button
  175. size="small"
  176. type="link"
  177. v-if="record.state=='WAIT' && $hasPermissions('B_productInfo_del')"
  178. class="button-error"
  179. @click="handleDel(record)"
  180. id="productInfoList-del-btn">删除</a-button>
  181. <span v-if="!(record.state=='WAIT' && $hasPermissions('B_productInfo_audit')) && !((record.state=='WAIT_ONLINE'||record.state=='OFFLINE') && $hasPermissions('B_productInfo_launch')) && !(record.state=='ONLINE' && $hasPermissions('B_productInfo_downline')) && !$hasPermissions('B_productInfo_edit') && !$hasPermissions('B_productInfo_detail') && !(record.state=='WAIT' && $hasPermissions('B_productInfo_del'))">--</span>
  182. </template>
  183. </s-table>
  184. </a-spin>
  185. <!-- 产品详情 -->
  186. <product-info-detail-modal :openModal="openModal" :itemSn="itemSn" @close="closeModal" />
  187. <!-- 产品下线 -->
  188. <product-info-offline-modal :openModal="openOfflineModal" :offlineProductList="offlineProductList" @close="closeOfflineModal" @ok="$refs.table.refresh()" />
  189. </a-card>
  190. </template>
  191. <script>
  192. import moment from 'moment'
  193. import { STable, VSelect } from '@/components'
  194. import productInfoDetailModal from './detailModal.vue'
  195. import productInfoOfflineModal from './offlineModal.vue'
  196. import { productBrandQuery } from '@/api/productBrand'
  197. import { productTypeQueryAll } from '@/api/productType'
  198. import { productList, productAudit, productBatchAudit, productDel, productOnline, productBatchOnline, productExport } from '@/api/product'
  199. export default {
  200. components: { STable, VSelect, productInfoDetailModal, productInfoOfflineModal },
  201. data () {
  202. return {
  203. spinning: false,
  204. advanced: true, // 高级搜索 展开/关闭
  205. queryParam: { // 查询条件
  206. name: '', // 产品名称
  207. queryWord: '', // 产品编码/原厂编码
  208. productBrandSn: undefined, // 产品品牌
  209. productTypeSn1: '', // 产品一级分类
  210. productTypeSn2: '', // 产品二级分类
  211. productTypeSn3: '', // 产品三级分类
  212. state: undefined, // 产品状态
  213. pricingState: undefined // 定价状态
  214. },
  215. productType: [],
  216. disabled: false, // 查询、重置按钮是否可操作
  217. exportLoading: false,
  218. columns: [
  219. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  220. { title: '创建时间', dataIndex: 'createDate', width: 160, align: 'center', customRender: function (text) { return text || '--' } },
  221. { title: '产品名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  222. { title: '产品编码', dataIndex: 'code', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  223. { title: '原厂编码', dataIndex: 'origCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  224. { title: '品牌', dataIndex: 'productBrandName', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
  225. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 200, align: 'center' },
  226. { slots: { title: 'arrowFalgTitle' }, scopedSlots: { customRender: 'arrowFalg' }, width: 100, align: 'center' },
  227. { title: '最近修改时间', dataIndex: 'updateDate', width: 160, align: 'center', customRender: function (text) { return text || '--' } },
  228. { title: '产品状态', dataIndex: 'stateDictValue', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  229. { title: '定价状态', dataIndex: 'pricingStateDictValue', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  230. { title: '操作', scopedSlots: { customRender: 'action' }, width: 250, align: 'center', fixed: 'right' }
  231. ],
  232. selectedRowKeys: [], // Check here to configure the default column
  233. selectedRows: [],
  234. loadingAudit: false,
  235. loadingLaunch: false,
  236. loadingDownline: false,
  237. // 加载数据方法 必须为 Promise 对象
  238. loadData: parameter => {
  239. this.disabled = true
  240. return productList(Object.assign(parameter, this.queryParam)).then(res => {
  241. const data = res.data
  242. const no = (data.pageNo - 1) * data.pageSize
  243. for (var i = 0; i < data.list.length; i++) {
  244. data.list[i].no = no + i + 1
  245. }
  246. this.disabled = false
  247. return data
  248. })
  249. },
  250. openModal: false, // 查看详情 弹框
  251. itemSn: '', // 当前sn
  252. openOfflineModal: false, // 下线 弹框
  253. offlineProductList: [], // 下线 当前所选数据
  254. productBrandList: [], // 品牌下拉数据
  255. productTypeList: [] // 分类下拉数据
  256. }
  257. },
  258. computed: {
  259. tableHeight () {
  260. return window.innerHeight - (this.advanced ? 330 : 290)
  261. },
  262. hasSelected () {
  263. return this.selectedRowKeys.length > 0
  264. },
  265. // 是否显示table选择框
  266. showSelect () {
  267. return this.$hasPermissions('B_productInfo_batchAudit') || this.$hasPermissions('B_productInfo_batchLaunch') || this.$hasPermissions('B_productInfo_batchDownline')
  268. }
  269. },
  270. methods: {
  271. onChange (selectedRowKeys, selectedRows) {
  272. this.selectedRowKeys = selectedRowKeys
  273. },
  274. onSelectChange (record, selected, selectedRows, nativeEvent) {
  275. const _this = this
  276. if (selected) { // 选择
  277. this.selectedRows.push(record)
  278. } else { // 取消
  279. this.selectedRows.map((item, index) => {
  280. if (item.id == record.id) {
  281. _this.selectedRows.splice(index, 1)
  282. }
  283. })
  284. }
  285. },
  286. // 本页全选/取消全选
  287. onSelectAllChange (selected, selectedRows, changeRows) {
  288. const _this = this
  289. if (selected) { // 选择
  290. this.selectedRows = [...this.selectedRows, ...changeRows]
  291. } else { // 取消
  292. this.selectedRows.map((item, index) => {
  293. this.selectedRows.map((subItem, ind) => {
  294. if (item.id == subItem.id) {
  295. _this.selectedRows.splice(index, 1)
  296. }
  297. })
  298. })
  299. }
  300. },
  301. // 审核
  302. handleAudit (row) {
  303. const _this = this
  304. this.$confirm({
  305. title: '提示',
  306. content: '确认要审核吗?',
  307. centered: true,
  308. onOk () {
  309. _this.spinning = true
  310. productAudit({ sn: row.productSn }).then(res => {
  311. if (res.status == 200) {
  312. _this.$message.success(res.message)
  313. _this.$refs.table.refresh()
  314. _this.spinning = false
  315. } else {
  316. _this.spinning = false
  317. }
  318. })
  319. }
  320. })
  321. },
  322. // 批量审核
  323. handleBatchAudit () {
  324. const _this = this
  325. if (_this.selectedRowKeys.length < 1) {
  326. _this.$message.warning('请在列表勾选后再进行批量操作!')
  327. return
  328. }
  329. let num = 0
  330. const obj = []
  331. _this.selectedRows.map(item => {
  332. if (item.state == 'WAIT') {
  333. num++
  334. obj.push(item.productSn)
  335. }
  336. })
  337. if (num < 1) {
  338. _this.$message.warning('当前数据不可操作!')
  339. return
  340. }
  341. this.$confirm({
  342. title: '提示',
  343. content: '已选有效数据' + num + '条,确认要批量审核吗?',
  344. centered: true,
  345. onOk () {
  346. _this.loadingAudit = true
  347. _this.spinning = true
  348. productBatchAudit(obj).then(res => {
  349. _this.loadingAudit = false
  350. if (res.status == 200) {
  351. _this.selectedRowKeys = []
  352. _this.selectedRows = []
  353. _this.$message.success(res.message)
  354. _this.$refs.table.refresh()
  355. _this.spinning = false
  356. } else {
  357. _this.spinning = false
  358. }
  359. })
  360. }
  361. })
  362. },
  363. // 批量上线
  364. handleBatchLaunch () {
  365. const _this = this
  366. if (_this.selectedRowKeys.length < 1) {
  367. _this.$message.warning('请在列表勾选后再进行批量操作!')
  368. return
  369. }
  370. let num = 0
  371. const obj = []
  372. _this.selectedRows.map(item => {
  373. if (item.state == 'WAIT_ONLINE' || item.state == 'OFFLINE') {
  374. num++
  375. obj.push(item.productSn)
  376. }
  377. })
  378. if (num < 1) {
  379. _this.$message.warning('当前数据不可操作!')
  380. return
  381. }
  382. this.$confirm({
  383. title: '提示',
  384. content: '已选有效数据' + num + '条,确认要批量上线吗?',
  385. centered: true,
  386. onOk () {
  387. _this.loadingLaunch = true
  388. _this.spinning = true
  389. productBatchOnline(obj).then(res => {
  390. _this.loadingLaunch = false
  391. if (res.status == 200) {
  392. _this.selectedRowKeys = []
  393. _this.selectedRows = []
  394. _this.$message.success(res.message)
  395. _this.$refs.table.refresh()
  396. _this.spinning = false
  397. } else {
  398. _this.spinning = false
  399. }
  400. })
  401. }
  402. })
  403. },
  404. // 批量下线
  405. handleBatchDownline () {
  406. const _this = this
  407. if (_this.selectedRowKeys.length < 1) {
  408. _this.$message.warning('请在列表勾选后再进行批量操作!')
  409. return
  410. }
  411. let num = 0
  412. _this.offlineProductList = []
  413. _this.selectedRows.map(item => {
  414. if (item.state == 'ONLINE') {
  415. num++
  416. _this.offlineProductList.push({ productSn: item.productSn, code: item.code, commonProductList: [] })
  417. }
  418. })
  419. if (num < 1) {
  420. _this.$message.warning('当前数据不可操作!')
  421. return
  422. }
  423. this.openOfflineModal = true
  424. },
  425. // 重置
  426. resetSearchForm () {
  427. this.queryParam.name = ''
  428. this.queryParam.queryWord = ''
  429. this.queryParam.productBrandSn = undefined
  430. this.queryParam.productTypeSn1 = ''
  431. this.queryParam.productTypeSn2 = ''
  432. this.queryParam.productTypeSn3 = ''
  433. this.queryParam.state = undefined
  434. this.queryParam.pricingState = undefined
  435. this.productType = []
  436. this.$refs.table.refresh(true)
  437. },
  438. // 新增/编辑
  439. handleEdit (row) {
  440. if (row) { // 编辑
  441. this.$router.push({ path: `/productManagement/productInfo/edit/${row.id}/${row.productSn}` })
  442. } else { // 新增
  443. this.$router.push({ path: '/productManagement/productInfo/add' })
  444. }
  445. },
  446. // 上线
  447. handleLaunch (row) {
  448. const _this = this
  449. this.$confirm({
  450. title: '提示',
  451. content: '确认要上线吗?',
  452. centered: true,
  453. onOk () {
  454. _this.spinning = true
  455. productOnline({ sn: row.productSn }).then(res => {
  456. if (res.status == 200) {
  457. _this.$message.success(res.message)
  458. _this.$refs.table.refresh()
  459. _this.spinning = false
  460. } else {
  461. _this.spinning = false
  462. }
  463. })
  464. }
  465. })
  466. },
  467. // 下线
  468. handleDownline (row) {
  469. this.offlineProductList.push({ productSn: row.productSn, code: row.code, commonProductList: [] })
  470. this.openOfflineModal = true
  471. },
  472. // 删除
  473. handleDel (row) {
  474. const _this = this
  475. this.$confirm({
  476. title: '提示',
  477. content: '确认要删除吗?',
  478. centered: true,
  479. onOk () {
  480. _this.spinning = true
  481. productDel({ sn: row.productSn }).then(res => {
  482. if (res.status == 200) {
  483. _this.$message.success(res.message)
  484. _this.$refs.table.refresh()
  485. _this.spinning = false
  486. } else {
  487. _this.spinning = false
  488. }
  489. })
  490. }
  491. })
  492. },
  493. filterOption (input, option) {
  494. return (
  495. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  496. )
  497. },
  498. // 详情
  499. handleDetail (row) {
  500. this.itemSn = row.productSn
  501. this.openModal = true
  502. },
  503. // 关闭弹框
  504. closeModal () {
  505. this.itemSn = ''
  506. this.openModal = false
  507. },
  508. // 关闭下线弹框
  509. closeOfflineModal () {
  510. this.selectedRowKeys = []
  511. this.selectedRows = []
  512. this.offlineProductList = []
  513. this.openOfflineModal = false
  514. },
  515. // 导出
  516. handleExport () {
  517. const _this = this
  518. const params = this.queryParam
  519. this.exportLoading = true
  520. _this.spinning = true
  521. productExport(params).then(res => {
  522. this.exportLoading = false
  523. _this.spinning = false
  524. if (res.type == 'application/json') {
  525. var reader = new FileReader()
  526. reader.addEventListener('loadend', function () {
  527. const obj = JSON.parse(reader.result)
  528. _this.$notification.error({
  529. message: '提示',
  530. description: obj.message
  531. })
  532. })
  533. reader.readAsText(res)
  534. } else {
  535. this.download(res)
  536. }
  537. })
  538. },
  539. download (data) {
  540. if (!data) { return }
  541. const url = window.URL.createObjectURL(new Blob([data]))
  542. const link = document.createElement('a')
  543. link.style.display = 'none'
  544. link.href = url
  545. const a = moment().format('YYYYMMDDHHmmss')
  546. const fname = '产品列表' + a
  547. link.setAttribute('download', fname + '.xlsx')
  548. document.body.appendChild(link)
  549. link.click()
  550. },
  551. // 产品分类 change
  552. changeProductType (val, opt) {
  553. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  554. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  555. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  556. },
  557. // 产品品牌 列表
  558. getProductBrand () {
  559. productBrandQuery({}).then(res => {
  560. if (res.status == 200) {
  561. this.productBrandList = res.data
  562. } else {
  563. this.productBrandList = []
  564. }
  565. })
  566. },
  567. // 产品分类 列表
  568. getProductType () {
  569. productTypeQueryAll({}).then(res => {
  570. if (res.status == 200) {
  571. this.productTypeList = res.data
  572. } else {
  573. this.productTypeList = []
  574. }
  575. })
  576. }
  577. },
  578. beforeRouteEnter (to, from, next) {
  579. next(vm => {
  580. vm.getProductBrand()
  581. vm.getProductType()
  582. })
  583. }
  584. }
  585. </script>