list.vue 13 KB

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