list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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="$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-code" v-model.trim="queryParam.code" 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-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="24">
  19. <a-form-item label="原厂编码">
  20. <a-input id="productInfoList-origCode" v-model.trim="queryParam.origCode" allowClear placeholder="请输入原厂编码"/>
  21. </a-form-item>
  22. </a-col>
  23. <template v-if="advanced">
  24. <a-col :md="6" :sm="24">
  25. <a-form-item label="产品品牌">
  26. <a-select
  27. placeholder="请选择产品品牌"
  28. id="productInfoList-productBrandSn"
  29. allowClear
  30. v-model="queryParam.productBrandSn"
  31. :showSearch="true"
  32. option-filter-prop="children"
  33. :filter-option="filterOption">
  34. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  35. </a-select>
  36. </a-form-item>
  37. </a-col>
  38. <a-col :md="6" :sm="24">
  39. <a-form-item label="产品分类">
  40. <a-cascader
  41. @change="changeProductType"
  42. change-on-select
  43. v-model="productType"
  44. expand-trigger="hover"
  45. :options="productTypeList"
  46. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  47. id="productInfoList-productType"
  48. placeholder="请选择产品分类"
  49. allowClear />
  50. </a-form-item>
  51. </a-col>
  52. <a-col :md="6" :sm="24">
  53. <a-form-item label="状态">
  54. <v-select code="ENABLE_FLAG" id="productInfoList-enabledFlag" v-model="queryParam.enabledFlag" 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. style="margin: 0 0 18px 8px"
  63. type="danger"
  64. @click="handleExport"
  65. :disabled="disabled"
  66. :loading="exportLoading"
  67. id="inventoryQueryList-export">导出</a-button> -->
  68. <a @click="advanced=!advanced" style="margin-left: 5px">
  69. {{ advanced ? '收起' : '展开' }}
  70. <a-icon :type="advanced ? 'up' : 'down'"/>
  71. </a>
  72. </a-col>
  73. </a-row>
  74. </a-form>
  75. </div>
  76. <!-- 操作按钮 -->
  77. <div class="table-operator">
  78. <a-button v-if="$hasPermissions('B_product_dealerProduct_add')" id="productInfoList-add" type="primary" class="button-error" @click="handleEdit()">新增</a-button>
  79. <!-- <a-button id="productInfoList-import" @click="handleImport" style="margin: 0 15px;">批量导入产品</a-button> -->
  80. </div>
  81. <!-- 列表 -->
  82. <s-table
  83. class="sTable fixPagination"
  84. ref="table"
  85. :style="{ height: tableHeight+84.5+'px' }"
  86. size="small"
  87. :rowKey="(record) => record.id"
  88. :columns="columns"
  89. :data="loadData"
  90. :scroll="{ y: tableHeight }"
  91. :defaultLoadData="false"
  92. bordered>
  93. <!-- 产品分类 -->
  94. <template slot="productType" slot-scope="text, record">
  95. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</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')"
  105. @change="changeStatus(record)"
  106. :checked="record.enabledFlag == 1 ? true : false" />
  107. <span v-else :style="{color:(record.enabledFlag==1?'#00aa00':'#999')}"> {{ record.enabledFlag==1? '已启用': '已禁用' }} </span>
  108. </template>
  109. <!-- 操作 -->
  110. <template slot="action" slot-scope="text, record">
  111. <a-button
  112. size="small"
  113. v-if="$hasPermissions('B_product_dealerProduct_edit')"
  114. type="link"
  115. class="button-primary"
  116. @click="handleEdit(record)"
  117. id="productInfoList-edit-btn">编辑</a-button>
  118. <a-button
  119. v-if="$hasPermissions('B_product_dealerProduct_detail')"
  120. size="small"
  121. type="link"
  122. class="button-success"
  123. @click="handleDetail(record)"
  124. id="productInfoList-detail-btn">详情</a-button>
  125. <span v-if="!$hasPermissions('B_product_dealerProduct_edit') && !$hasPermissions('B_product_dealerProduct_detail')">--</span>
  126. </template>
  127. </s-table>
  128. </a-spin>
  129. <!-- 产品详情 -->
  130. <product-info-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
  131. </a-card>
  132. </template>
  133. <script>
  134. import { commonMixin } from '@/utils/mixin'
  135. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  136. import { dealerProductTypeList } from '@/api/dealerProductType'
  137. import { dealerProductList, dealerProductUpdate, dealerProductExport } from '@/api/dealerProduct'
  138. import { STable, VSelect } from '@/components'
  139. import productInfoDetailModal from './detailModal.vue'
  140. import { downloadExcel } from '@/libs/JGPrint.js'
  141. export default {
  142. name: 'ProductList',
  143. components: { STable, VSelect, productInfoDetailModal },
  144. mixins: [commonMixin],
  145. data () {
  146. return {
  147. spinning: false,
  148. advanced: true, // 高级搜索 展开/关闭
  149. tableHeight: 0,
  150. productType: [],
  151. queryParam: { // 查询条件
  152. code: '', // 产品编码
  153. name: '', // 产品名称
  154. origCode: '', // 原厂编码
  155. sysFlag: '0',
  156. productBrandSn: undefined, // 产品品牌
  157. productTypeSn1: '', // 产品一级分类
  158. productTypeSn2: '', // 产品二级分类
  159. productTypeSn3: '', // 产品三级分类
  160. enabledFlag: undefined // 状态
  161. },
  162. disabled: false, // 查询、重置按钮是否可操作
  163. exportLoading: false, // 导出loading
  164. columns: [
  165. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  166. { title: '产品编码', dataIndex: 'code', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  167. { title: '产品名称', dataIndex: 'name', width: '13%', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  168. { title: '原厂编码', dataIndex: 'origCode', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  169. { title: '产品品牌', dataIndex: 'productBrandName', width: '9%', align: 'center', customRender: function (text) { return text || '--' } },
  170. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '9%', align: 'center' },
  171. { title: '经销批发价', dataIndex: 'specialPrice', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  172. { title: '终端价', dataIndex: 'terminalPrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  173. { title: '车主价', dataIndex: 'carOwnersPrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  174. { title: '创建时间', dataIndex: 'createDate', width: '7%', align: 'center', customRender: function (text) { return text || '--' } },
  175. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: '7%', align: 'center' },
  176. { title: '操作', scopedSlots: { customRender: 'action' }, width: '9%', align: 'center' }
  177. ],
  178. // 加载数据方法 必须为 Promise 对象
  179. loadData: parameter => {
  180. this.disabled = true
  181. this.spinning = true
  182. return dealerProductList(Object.assign(parameter, this.queryParam)).then(res => {
  183. let data
  184. if (res.status == 200) {
  185. data = res.data
  186. const no = (data.pageNo - 1) * data.pageSize
  187. for (var i = 0; i < data.list.length; i++) {
  188. data.list[i].no = no + i + 1
  189. const productTypeName1 = data.list[i].productTypeName1 ? data.list[i].productTypeName1 : ''
  190. const productTypeName2 = data.list[i].productTypeName2 ? ' > ' + data.list[i].productTypeName2 : ''
  191. const productTypeName3 = data.list[i].productTypeName3 ? ' > ' + data.list[i].productTypeName3 : ''
  192. data.list[i].productTypeName = productTypeName1 + productTypeName2 + productTypeName3
  193. }
  194. this.disabled = false
  195. }
  196. this.spinning = false
  197. return data
  198. })
  199. },
  200. openModal: false, // 查看客户详情 弹框
  201. itemId: '', // 当前产品id
  202. productBrandList: [], // 品牌下拉数据
  203. productTypeList: [] // 分类下拉数据
  204. }
  205. },
  206. methods: {
  207. // 重置
  208. resetSearchForm () {
  209. this.queryParam.code = ''
  210. this.queryParam.name = ''
  211. this.queryParam.origCode = ''
  212. this.queryParam.productBrandSn = undefined
  213. this.queryParam.productTypeSn1 = ''
  214. this.queryParam.productTypeSn2 = ''
  215. this.queryParam.productTypeSn3 = ''
  216. this.queryParam.enabledFlag = undefined
  217. this.productType = []
  218. this.$refs.table.refresh(true)
  219. },
  220. // 新增/编辑
  221. handleEdit (row) {
  222. if (row) { // 编辑
  223. this.$router.push({ path: `/productManagement/productInfo/edit/${row.id}` })
  224. } else { // 新增
  225. this.$router.push({ path: '/productManagement/productInfo/add' })
  226. }
  227. },
  228. // 批量导入
  229. handleImport () {
  230. },
  231. filterOption (input, option) {
  232. return (
  233. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  234. )
  235. },
  236. // 详情
  237. handleDetail (row) {
  238. this.itemId = row.id
  239. this.openModal = true
  240. },
  241. // 关闭弹框
  242. closeModal () {
  243. this.itemId = ''
  244. this.openModal = false
  245. },
  246. // 产品分类 change
  247. changeProductType (val, opt) {
  248. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  249. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  250. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  251. },
  252. // 启用 禁用
  253. changeStatus (record) {
  254. if (record.enabledFlag == '1') {
  255. this.$confirm({
  256. title: '提示',
  257. content: '产品被禁用后,不能再销售,确定禁用吗?',
  258. centered: true,
  259. onOk: () => {
  260. this.setEnable(record)
  261. }
  262. })
  263. } else {
  264. this.setEnable(record)
  265. }
  266. },
  267. // 启用 禁用
  268. setEnable (record) {
  269. const params = {
  270. id: record.id,
  271. enabledFlag: record.enabledFlag == 1 ? '0' : '1'
  272. }
  273. this.spinning = true
  274. dealerProductUpdate(params).then(res => {
  275. if (res.status == 200) {
  276. this.$message.success(res.message)
  277. this.$refs.table.refresh()
  278. this.spinning = false
  279. } else {
  280. this.$refs.table.refresh()
  281. this.spinning = false
  282. }
  283. })
  284. },
  285. // 导出
  286. handleExport () {
  287. this.exportLoading = true
  288. this.spinning = true
  289. dealerProductExport(this.queryParam).then(res => {
  290. this.exportLoading = false
  291. this.spinning = false
  292. downloadExcel(res, '自建产品列表')
  293. })
  294. },
  295. // 产品品牌 列表
  296. getProductBrand () {
  297. dealerProductBrandQuery({}).then(res => {
  298. if (res.status == 200) {
  299. this.productBrandList = res.data
  300. } else {
  301. this.productBrandList = []
  302. }
  303. })
  304. },
  305. // 产品分类 列表
  306. getProductType () {
  307. dealerProductTypeList({}).then(res => {
  308. if (res.status == 200) {
  309. this.productTypeList = res.data
  310. } else {
  311. this.productTypeList = []
  312. }
  313. })
  314. },
  315. pageInit () {
  316. const _this = this
  317. this.$nextTick(() => { // 页面渲染完成后的回调
  318. _this.setTableH()
  319. })
  320. this.getProductBrand()
  321. this.getProductType()
  322. },
  323. setTableH () {
  324. const tableSearchH = this.$refs.tableSearch.offsetHeight
  325. this.tableHeight = window.innerHeight - tableSearchH - 235
  326. }
  327. },
  328. watch: {
  329. advanced (newValue, oldValue) {
  330. const _this = this
  331. this.$nextTick(() => { // 页面渲染完成后的回调
  332. _this.setTableH()
  333. })
  334. },
  335. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  336. this.setTableH()
  337. }
  338. },
  339. mounted () {
  340. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  341. this.pageInit()
  342. this.resetSearchForm()
  343. }
  344. },
  345. activated () {
  346. // 如果是新页签打开,则重置当前页面
  347. if (this.$store.state.app.isNewTab) {
  348. this.pageInit()
  349. this.resetSearchForm()
  350. }
  351. // 仅刷新列表,不重置页面
  352. if (this.$store.state.app.updateList) {
  353. this.pageInit()
  354. this.$refs.table.refresh()
  355. }
  356. },
  357. beforeRouteEnter (to, from, next) {
  358. next(vm => {})
  359. }
  360. }
  361. </script>