list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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-info"
  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 { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  135. import { dealerProductTypeList } from '@/api/dealerProductType'
  136. import { dealerProductList, dealerProductUpdate, dealerProductExport } from '@/api/dealerProduct'
  137. import { STable, VSelect } from '@/components'
  138. import productInfoDetailModal from './detailModal.vue'
  139. import { downloadExcel } from '@/libs/JGPrint.js'
  140. export default {
  141. name: 'ProductList',
  142. components: { STable, VSelect, productInfoDetailModal },
  143. data () {
  144. return {
  145. spinning: false,
  146. advanced: true, // 高级搜索 展开/关闭
  147. tableHeight: 0,
  148. productType: [],
  149. queryParam: { // 查询条件
  150. code: '', // 产品编码
  151. name: '', // 产品名称
  152. origCode: '', // 原厂编码
  153. sysFlag: '0',
  154. productBrandSn: undefined, // 产品品牌
  155. productTypeSn1: '', // 产品一级分类
  156. productTypeSn2: '', // 产品二级分类
  157. productTypeSn3: '', // 产品三级分类
  158. enabledFlag: undefined // 状态
  159. },
  160. disabled: false, // 查询、重置按钮是否可操作
  161. exportLoading: false, // 导出loading
  162. columns: [
  163. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  164. { title: '产品编码', dataIndex: 'code', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  165. { title: '产品名称', dataIndex: 'name', width: '13%', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  166. { title: '原厂编码', dataIndex: 'origCode', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  167. { title: '产品品牌', dataIndex: 'productBrandName', width: '9%', align: 'center', customRender: function (text) { return text || '--' } },
  168. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '9%', align: 'center' },
  169. { title: '经销批发价', dataIndex: 'specialPrice', width: '7%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  170. { title: '终端价', dataIndex: 'terminalPrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  171. { title: '车主价', dataIndex: 'carOwnersPrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  172. { title: '创建时间', dataIndex: 'createDate', width: '7%', align: 'center', customRender: function (text) { return text || '--' } },
  173. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: '7%', align: 'center' },
  174. { title: '操作', scopedSlots: { customRender: 'action' }, width: '9%', align: 'center' }
  175. ],
  176. // 加载数据方法 必须为 Promise 对象
  177. loadData: parameter => {
  178. this.disabled = true
  179. this.spinning = true
  180. return dealerProductList(Object.assign(parameter, this.queryParam)).then(res => {
  181. let data
  182. if (res.status == 200) {
  183. data = res.data
  184. const no = (data.pageNo - 1) * data.pageSize
  185. for (var i = 0; i < data.list.length; i++) {
  186. data.list[i].no = no + i + 1
  187. const productTypeName1 = data.list[i].productTypeName1 ? data.list[i].productTypeName1 : ''
  188. const productTypeName2 = data.list[i].productTypeName2 ? ' > ' + data.list[i].productTypeName2 : ''
  189. const productTypeName3 = data.list[i].productTypeName3 ? ' > ' + data.list[i].productTypeName3 : ''
  190. data.list[i].productTypeName = productTypeName1 + productTypeName2 + productTypeName3
  191. }
  192. this.disabled = false
  193. }
  194. this.spinning = false
  195. return data
  196. })
  197. },
  198. openModal: false, // 查看客户详情 弹框
  199. itemId: '', // 当前产品id
  200. productBrandList: [], // 品牌下拉数据
  201. productTypeList: [] // 分类下拉数据
  202. }
  203. },
  204. methods: {
  205. // 重置
  206. resetSearchForm () {
  207. this.queryParam.code = ''
  208. this.queryParam.name = ''
  209. this.queryParam.origCode = ''
  210. this.queryParam.productBrandSn = undefined
  211. this.queryParam.productTypeSn1 = ''
  212. this.queryParam.productTypeSn2 = ''
  213. this.queryParam.productTypeSn3 = ''
  214. this.queryParam.enabledFlag = undefined
  215. this.productType = []
  216. this.$refs.table.refresh(true)
  217. },
  218. // 新增/编辑
  219. handleEdit (row) {
  220. if (row) { // 编辑
  221. this.$router.push({ path: `/productManagement/productInfo/edit/${row.id}` })
  222. } else { // 新增
  223. this.$router.push({ path: '/productManagement/productInfo/add' })
  224. }
  225. },
  226. // 批量导入
  227. handleImport () {
  228. },
  229. filterOption (input, option) {
  230. return (
  231. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  232. )
  233. },
  234. // 详情
  235. handleDetail (row) {
  236. this.itemId = row.id
  237. this.openModal = true
  238. },
  239. // 关闭弹框
  240. closeModal () {
  241. this.itemId = ''
  242. this.openModal = false
  243. },
  244. // 产品分类 change
  245. changeProductType (val, opt) {
  246. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  247. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  248. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  249. },
  250. // 启用 禁用
  251. changeStatus (record) {
  252. if (record.enabledFlag == '1') {
  253. this.$confirm({
  254. title: '提示',
  255. content: '产品被禁用后,不能再销售,确定禁用吗?',
  256. centered: true,
  257. onOk: () => {
  258. this.setEnable(record)
  259. }
  260. })
  261. } else {
  262. this.setEnable(record)
  263. }
  264. },
  265. // 启用 禁用
  266. setEnable (record) {
  267. const params = {
  268. id: record.id,
  269. enabledFlag: record.enabledFlag == 1 ? '0' : '1'
  270. }
  271. this.spinning = true
  272. dealerProductUpdate(params).then(res => {
  273. if (res.status == 200) {
  274. this.$message.success(res.message)
  275. this.$refs.table.refresh()
  276. this.spinning = false
  277. } else {
  278. this.$refs.table.refresh()
  279. this.spinning = false
  280. }
  281. })
  282. },
  283. // 导出
  284. handleExport () {
  285. this.exportLoading = true
  286. this.spinning = true
  287. dealerProductExport(this.queryParam).then(res => {
  288. this.exportLoading = false
  289. this.spinning = false
  290. downloadExcel(res, '自建产品列表')
  291. })
  292. },
  293. // 产品品牌 列表
  294. getProductBrand () {
  295. dealerProductBrandQuery({}).then(res => {
  296. if (res.status == 200) {
  297. this.productBrandList = res.data
  298. } else {
  299. this.productBrandList = []
  300. }
  301. })
  302. },
  303. // 产品分类 列表
  304. getProductType () {
  305. dealerProductTypeList({}).then(res => {
  306. if (res.status == 200) {
  307. this.productTypeList = res.data
  308. } else {
  309. this.productTypeList = []
  310. }
  311. })
  312. },
  313. pageInit () {
  314. const _this = this
  315. this.$nextTick(() => { // 页面渲染完成后的回调
  316. _this.setTableH()
  317. })
  318. this.getProductBrand()
  319. this.getProductType()
  320. },
  321. setTableH () {
  322. const tableSearchH = this.$refs.tableSearch.offsetHeight
  323. this.tableHeight = window.innerHeight - tableSearchH - 235
  324. }
  325. },
  326. watch: {
  327. advanced (newValue, oldValue) {
  328. const _this = this
  329. this.$nextTick(() => { // 页面渲染完成后的回调
  330. _this.setTableH()
  331. })
  332. },
  333. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  334. this.setTableH()
  335. }
  336. },
  337. mounted () {
  338. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  339. this.pageInit()
  340. this.resetSearchForm()
  341. }
  342. },
  343. activated () {
  344. // 如果是新页签打开,则重置当前页面
  345. if (this.$store.state.app.isNewTab) {
  346. this.pageInit()
  347. this.resetSearchForm()
  348. }
  349. // 仅刷新列表,不重置页面
  350. if (this.$store.state.app.updateList) {
  351. this.pageInit()
  352. this.$refs.table.refresh()
  353. }
  354. },
  355. beforeRouteEnter (to, from, next) {
  356. next(vm => {})
  357. }
  358. }
  359. </script>