list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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="{ x: 1300, y: tableHeight }"
  91. bordered>
  92. <!-- 产品分类 -->
  93. <template slot="productType" slot-scope="text, record">
  94. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  95. <span v-else>--</span>
  96. </template>
  97. <!-- 状态 -->
  98. <template slot="enabledFlag" slot-scope="text, record">
  99. <a-switch
  100. id="productInfoList-enable"
  101. checkedChildren="启用"
  102. unCheckedChildren="禁用"
  103. v-if="$hasPermissions('B_product_dealerProduct_enable')"
  104. @change="changeStatus(record)"
  105. :checked="record.enabledFlag == 1 ? true : false" />
  106. <span v-else :style="{color:(record.enabledFlag==1?'#00aa00':'#999')}"> {{ record.enabledFlag==1? '已启用': '已禁用' }} </span>
  107. </template>
  108. <!-- 操作 -->
  109. <template slot="action" slot-scope="text, record">
  110. <a-button
  111. size="small"
  112. v-if="$hasPermissions('B_product_dealerProduct_edit')"
  113. type="link"
  114. class="button-info"
  115. @click="handleEdit(record)"
  116. id="productInfoList-edit-btn">编辑</a-button>
  117. <a-button
  118. v-if="$hasPermissions('B_product_dealerProduct_detail')"
  119. size="small"
  120. type="link"
  121. class="button-success"
  122. @click="handleDetail(record)"
  123. id="productInfoList-detail-btn">详情</a-button>
  124. <span v-if="!$hasPermissions('B_product_dealerProduct_edit') && !$hasPermissions('B_product_dealerProduct_detail')">--</span>
  125. </template>
  126. </s-table>
  127. </a-spin>
  128. <!-- 产品详情 -->
  129. <product-info-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
  130. </a-card>
  131. </template>
  132. <script>
  133. import moment from 'moment'
  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. export default {
  140. name: 'ProductList',
  141. components: { STable, VSelect, productInfoDetailModal },
  142. data () {
  143. return {
  144. spinning: false,
  145. advanced: true, // 高级搜索 展开/关闭
  146. tableHeight: 0,
  147. productType: [],
  148. queryParam: { // 查询条件
  149. code: '', // 产品编码
  150. name: '', // 产品名称
  151. origCode: '', // 原厂编码
  152. sysFlag: '0',
  153. productBrandSn: undefined, // 产品品牌
  154. productTypeSn1: '', // 产品一级分类
  155. productTypeSn2: '', // 产品二级分类
  156. productTypeSn3: '', // 产品三级分类
  157. enabledFlag: undefined // 状态
  158. },
  159. disabled: false, // 查询、重置按钮是否可操作
  160. exportLoading: false, // 导出loading
  161. columns: [
  162. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  163. { title: '产品编码', dataIndex: 'code', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  164. { title: '产品名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  165. { title: '原厂编码', dataIndex: 'origCode', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  166. { title: '产品品牌', dataIndex: 'productBrandName', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  167. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 120, align: 'center' },
  168. { title: '经销批发价', dataIndex: 'specialPrice', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  169. { title: '终端价', dataIndex: 'terminalPrice', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  170. { title: '车主价', dataIndex: 'carOwnersPrice', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  171. { title: '创建时间', dataIndex: 'createDate', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  172. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: 90, align: 'center', fixed: 'right' },
  173. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  174. ],
  175. // 加载数据方法 必须为 Promise 对象
  176. loadData: parameter => {
  177. this.disabled = true
  178. this.spinning = true
  179. return dealerProductList(Object.assign(parameter, this.queryParam)).then(res => {
  180. const data = res.data
  181. const no = (data.pageNo - 1) * data.pageSize
  182. for (var i = 0; i < data.list.length; i++) {
  183. data.list[i].no = no + i + 1
  184. const productTypeName1 = data.list[i].productTypeName1 ? data.list[i].productTypeName1 : ''
  185. const productTypeName2 = data.list[i].productTypeName2 ? ' > ' + data.list[i].productTypeName2 : ''
  186. const productTypeName3 = data.list[i].productTypeName3 ? ' > ' + data.list[i].productTypeName3 : ''
  187. data.list[i].productTypeName = productTypeName1 + productTypeName2 + productTypeName3
  188. }
  189. this.disabled = false
  190. this.spinning = false
  191. return data
  192. })
  193. },
  194. openModal: false, // 查看客户详情 弹框
  195. itemId: '', // 当前产品id
  196. productBrandList: [], // 品牌下拉数据
  197. productTypeList: [] // 分类下拉数据
  198. }
  199. },
  200. methods: {
  201. // 重置
  202. resetSearchForm () {
  203. this.queryParam.code = ''
  204. this.queryParam.name = ''
  205. this.queryParam.origCode = ''
  206. this.queryParam.productBrandSn = undefined
  207. this.queryParam.productTypeSn1 = ''
  208. this.queryParam.productTypeSn2 = ''
  209. this.queryParam.productTypeSn3 = ''
  210. this.queryParam.enabledFlag = undefined
  211. this.productType = []
  212. this.$refs.table.refresh(true)
  213. },
  214. // 新增/编辑
  215. handleEdit (row) {
  216. if (row) { // 编辑
  217. this.$router.push({ path: `/productManagement/productInfo/edit/${row.id}` })
  218. } else { // 新增
  219. this.$router.push({ path: '/productManagement/productInfo/add' })
  220. }
  221. },
  222. // 批量导入
  223. handleImport () {
  224. },
  225. filterOption (input, option) {
  226. return (
  227. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  228. )
  229. },
  230. // 详情
  231. handleDetail (row) {
  232. this.itemId = row.id
  233. this.openModal = true
  234. },
  235. // 关闭弹框
  236. closeModal () {
  237. this.itemId = ''
  238. this.openModal = false
  239. },
  240. // 产品分类 change
  241. changeProductType (val, opt) {
  242. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  243. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  244. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  245. },
  246. // 启用 禁用
  247. changeStatus (record) {
  248. if (record.enabledFlag == '1') {
  249. this.$confirm({
  250. title: '提示',
  251. content: '产品被禁用后,不能再销售,确定禁用吗?',
  252. centered: true,
  253. onOk: () => {
  254. this.setEnable(record)
  255. }
  256. })
  257. } else {
  258. this.setEnable(record)
  259. }
  260. },
  261. // 启用 禁用
  262. setEnable (record) {
  263. const params = {
  264. id: record.id,
  265. enabledFlag: record.enabledFlag == 1 ? '0' : '1'
  266. }
  267. this.spinning = true
  268. dealerProductUpdate(params).then(res => {
  269. if (res.status == 200) {
  270. this.$message.success(res.message)
  271. this.$refs.table.refresh()
  272. this.spinning = false
  273. } else {
  274. this.$refs.table.refresh()
  275. this.spinning = false
  276. }
  277. })
  278. },
  279. // 导出
  280. handleExport () {
  281. this.exportLoading = true
  282. this.spinning = true
  283. dealerProductExport(this.queryParam).then(res => {
  284. this.exportLoading = false
  285. this.download(res)
  286. this.spinning = false
  287. })
  288. },
  289. download (data) {
  290. if (!data) { return }
  291. const url = window.URL.createObjectURL(new Blob([data]))
  292. const link = document.createElement('a')
  293. link.style.display = 'none'
  294. link.href = url
  295. const a = moment().format('YYYYMMDDHHmmss')
  296. const fname = '自建产品列表' + a
  297. link.setAttribute('download', fname + '.xlsx')
  298. document.body.appendChild(link)
  299. link.click()
  300. },
  301. // 产品品牌 列表
  302. getProductBrand () {
  303. dealerProductBrandQuery({}).then(res => {
  304. if (res.status == 200) {
  305. this.productBrandList = res.data
  306. } else {
  307. this.productBrandList = []
  308. }
  309. })
  310. },
  311. // 产品分类 列表
  312. getProductType () {
  313. dealerProductTypeList({}).then(res => {
  314. if (res.status == 200) {
  315. this.productTypeList = res.data
  316. } else {
  317. this.productTypeList = []
  318. }
  319. })
  320. },
  321. setTableH () {
  322. const tableSearchH = this.$refs.tableSearch.offsetHeight
  323. this.tableHeight = window.innerHeight - tableSearchH - 235
  324. }
  325. },
  326. mounted () {
  327. const _this = this
  328. this.$nextTick(() => { // 页面渲染完成后的回调
  329. _this.setTableH()
  330. })
  331. },
  332. watch: {
  333. advanced (newValue, oldValue) {
  334. const _this = this
  335. setTimeout(() => {
  336. _this.setTableH()
  337. }, 400)
  338. }
  339. },
  340. beforeRouteEnter (to, from, next) {
  341. next(vm => {
  342. vm.getProductBrand()
  343. vm.getProductType()
  344. if (!vm.disabled) {
  345. vm.$refs.table.refresh()
  346. }
  347. })
  348. }
  349. }
  350. </script>