list.vue 13 KB

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