list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <a-card size="small" :bordered="false" class="productInfoList-wrap">
  3. <!-- 搜索条件 -->
  4. <div ref="tableSearch" class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="searchForm">
  6. <a-row :gutter="15">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="产品编码">
  9. <a-input id="productInfoList-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="产品名称">
  14. <a-input id="productInfoList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="6" :sm="24">
  18. <a-form-item label="原厂编码">
  19. <a-input id="productInfoList-origCode" v-model.trim="queryParam.origCode" allowClear placeholder="请输入原厂编码"/>
  20. </a-form-item>
  21. </a-col>
  22. <template v-if="advanced">
  23. <a-col :md="6" :sm="24">
  24. <a-form-item label="产品品牌">
  25. <ProductBrand id="productInfoList-productBrandSn" placeholder="请选择产品品牌" v-model="queryParam.productBrandSn"></ProductBrand>
  26. </a-select>
  27. </a-form-item>
  28. </a-col>
  29. <!-- <a-col :md="6" :sm="24">
  30. <a-form-item label="产品分类">
  31. <ProductType id="productInfoList-productType" placeholder="请选择产品分类" :isDealer="true" @change="changeProductType" v-model="productType"></ProductType>
  32. </a-form-item>
  33. </a-col> -->
  34. <a-col :md="6" :sm="24">
  35. <a-form-item label="状态">
  36. <v-select code="ENABLE_FLAG" id="productInfoList-enabledFlag" v-model="queryParam.enabledFlag" allowClear placeholder="请选择状态"></v-select>
  37. </a-form-item>
  38. </a-col>
  39. </template>
  40. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  41. <a-button type="primary" @click="searchForm" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
  42. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="productInfoList-reset">重置</a-button>
  43. <a @click="advanced=!advanced" style="margin-left: 5px">
  44. {{ advanced ? '收起' : '展开' }}
  45. <a-icon :type="advanced ? 'up' : 'down'"/>
  46. </a>
  47. </a-col>
  48. </a-row>
  49. </a-form>
  50. </div>
  51. <!-- 操作按钮 -->
  52. <div class="table-operator" v-if="$hasPermissions('B_JgProduct_enable')">
  53. <a-dropdown>
  54. <a-menu slot="overlay" @click="handleMenuClick">
  55. <a-menu-item key="1"> 批量启用</a-menu-item>
  56. <a-menu-item key="2"> 批量禁用</a-menu-item>
  57. </a-menu>
  58. <a-button ghost type="danger"> 批量操作 <a-icon type="down" /> </a-button>
  59. </a-dropdown>
  60. <span v-if="rowSelectionInfo&&rowSelectionInfo.selectedRowKeys">已选 {{ rowSelectionInfo.selectedRowKeys.length }} 项</span>
  61. </div>
  62. <!-- 列表 -->
  63. <s-table
  64. class="sTable fixPagination"
  65. ref="table"
  66. :style="{ height: tableHeight+84.5+'px' }"
  67. size="small"
  68. :row-selection="$hasPermissions('B_JgProduct_enable')?rowSelection:null"
  69. @rowSelection="rowSelectionFun"
  70. rowKeyName="productSn"
  71. :rowKey="(record) => record.productSn"
  72. :columns="columns"
  73. :data="loadData"
  74. :scroll="{ y: tableHeight }"
  75. :defaultLoadData="false"
  76. bordered>
  77. <!-- 产品图片 -->
  78. <template slot="imageUrl" slot-scope="text, record">
  79. <div v-if="record.productPicList && record.productPicList.length>0">
  80. <img :src="record.productPicList[0].imageUrl+'?x-oss-process=image/resize,h_30,m_lfit' || ''" width="30" height="30" class="imageUrl" @click="inited(record.productPicList)" />
  81. </div>
  82. <span v-else>--</span>
  83. </template>
  84. <!-- 产品分类 -->
  85. <template slot="productType" slot-scope="text, record">
  86. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  87. <span v-else>--</span>
  88. </template>
  89. <!-- 状态 -->
  90. <template slot="enabledFlag" slot-scope="text, record">
  91. <a-switch
  92. checkedChildren="启用"
  93. unCheckedChildren="禁用"
  94. v-if="$hasPermissions('B_JgProduct_enable')&&record.enabledFlag!=undefined"
  95. @change="changeStatus(record)"
  96. :checked="record.enabledFlag == 1 ? true : false"
  97. />
  98. <span v-else :style="{ color: record.enabledFlag == 1 ? '#00aa00' : '#999' }">
  99. {{ record.enabledFlag == 1 ? '已启用' : (record.enabledFlag!=undefined?'已禁用':'--') }}
  100. </span>
  101. </template>
  102. <!-- 操作 -->
  103. <template slot="action" slot-scope="text, record">
  104. <a-button
  105. size="small"
  106. type="link"
  107. class="button-success"
  108. @click="handleDetail(record)"
  109. id="productInfoList-detail-btn">详情</a-button>
  110. </template>
  111. </s-table>
  112. </a-card>
  113. </template>
  114. <script>
  115. import { commonMixin } from '@/utils/mixin'
  116. import { productList, getCurrentDealer, productUpdate } from '@/api/product'
  117. import ProductType from '../../common/productType.js'
  118. import ProductBrand from '../../common/productBrand.js'
  119. import { STable, VSelect } from '@/components'
  120. // import { downloadExcel } from '@/libs/JGPrint.js'
  121. export default {
  122. name: 'ProductJgList',
  123. components: { STable, VSelect, ProductType, ProductBrand },
  124. mixins: [commonMixin],
  125. data () {
  126. return {
  127. advanced: true, // 高级搜索 展开/关闭
  128. tableHeight: 0,
  129. productType: [],
  130. queryParam: { // 查询条件
  131. code: '', // 产品编码
  132. name: '', // 产品名称
  133. origCode: '', // 原厂编码
  134. sysFlag: '1',
  135. productBrandSn: undefined, // 产品品牌
  136. productTypeSn1: '', // 产品一级分类
  137. productTypeSn2: '', // 产品二级分类
  138. productTypeSn3: '', // 产品三级分类
  139. onlineFalg: ''
  140. },
  141. disabled: false, // 查询、重置按钮是否可操作
  142. exportLoading: false, // 导出loading
  143. dateFormat: 'YYYY-MM-DD',
  144. columns: [],
  145. // 加载数据方法 必须为 Promise 对象
  146. loadData: parameter => {
  147. this.disabled = true
  148. this.spinning = true
  149. return productList(Object.assign(parameter, this.queryParam)).then(res => {
  150. let data
  151. if (res.status == 200) {
  152. data = res.data
  153. const no = (data.pageNo - 1) * data.pageSize
  154. for (var i = 0; i < data.list.length; i++) {
  155. data.list[i].no = no + i + 1
  156. }
  157. this.disabled = false
  158. }
  159. this.spinning = false
  160. return data
  161. })
  162. },
  163. openModal: false, // 查看客户详情 弹框
  164. itemId: '', // 当前产品id
  165. productTypeList: [], // 分类下拉数据
  166. rowSelectionInfo: null
  167. }
  168. },
  169. computed: {
  170. rowSelection () {
  171. return {
  172. getCheckboxProps: record => ({
  173. props: {
  174. disabled: record.enabledFlag == undefined // Column configuration not to be checked
  175. }
  176. })
  177. }
  178. }
  179. },
  180. methods: {
  181. inited (viewer) {
  182. if (viewer) {
  183. const imageUrl = []
  184. viewer.map(item => {
  185. imageUrl.push(item.imageUrl)
  186. })
  187. this.$viewerApi({
  188. images: imageUrl
  189. })
  190. }
  191. },
  192. // 详情
  193. handleDetail (row) {
  194. this.$router.push({ name: 'viewProduct', params: { sn: row.productSn } })
  195. },
  196. // 查询
  197. searchForm () {
  198. this.$refs.table.clearSelected() // 清空表格选中项
  199. this.$refs.table.refresh(true)
  200. },
  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.onlineFalg = ''
  211. this.productType = []
  212. this.$refs.table.refresh(true)
  213. this.rowSelectionInfo = null
  214. this.$refs.table.clearSelected()
  215. },
  216. // 设置表头
  217. getColumns () {
  218. this.columns = [
  219. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  220. { title: '产品编码', dataIndex: 'code', width: '18%', align: 'center', customRender: function (text) { return text || '--' } },
  221. { title: '产品名称', dataIndex: 'name', width: '18%', align: 'center', customRender: function (text) { return text || '--' } },
  222. { title: '原厂编码', dataIndex: 'origCode', width: '17%', align: 'center', customRender: function (text) { return (!text || text == ' ') ? '--' : text } }
  223. ]
  224. const cArr = [
  225. { title: '终端价', dataIndex: 'terminalPrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  226. { title: '车主价', dataIndex: 'carOwnersPrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  227. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: '7%', align: 'center' },
  228. { title: '产品图片', scopedSlots: { customRender: 'imageUrl' }, width: '6%', align: 'center' },
  229. { title: '操作', scopedSlots: { customRender: 'action' }, width: '7%', align: 'center' }
  230. ]
  231. getCurrentDealer().then(res => {
  232. if (res.status == 200) {
  233. if (res.data.dealerLevel && res.data.dealerLevel == 'PROVINCE') { // 省级
  234. this.columns.push(
  235. { title: '省级价', dataIndex: 'provincePrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  236. { title: '市级价', dataIndex: 'cityPrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
  237. )
  238. } else if (res.data.dealerLevel && res.data.dealerLevel == 'CITY') { // 市级
  239. this.columns.push(
  240. { title: '市级价', dataIndex: 'cityPrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
  241. )
  242. }
  243. if (res.data.isShowSpecialPrice && res.data.isShowSpecialPrice == '1') { // 是否展示特约价
  244. this.columns.push({ title: '特约价', dataIndex: 'specialPrice', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  245. }
  246. this.columns = [...this.columns, ...cArr]
  247. }
  248. })
  249. },
  250. filterOption (input, option) {
  251. return (
  252. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  253. )
  254. },
  255. // 产品分类 change
  256. changeProductType (val, opt) {
  257. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  258. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  259. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  260. },
  261. // 启用 禁用
  262. changeStatus (record) {
  263. this.$confirm({
  264. title: '提示',
  265. content: record.enabledFlag == '1' ? '产品被禁用后,不能再销售,确定禁用吗?' : '确定启用吗?',
  266. centered: true,
  267. onOk: () => {
  268. this.setEnable(record.enabledFlag == 1 ? '0' : '1', [record.productSn])
  269. }
  270. })
  271. },
  272. // 启用 禁用
  273. setEnable (enabledFlag, snList) {
  274. const params = {
  275. productSnList: snList,
  276. enabledFlag: enabledFlag
  277. }
  278. this.spinning = true
  279. productUpdate(params).then(res => {
  280. if (res.status == 200) {
  281. this.$message.success(res.message)
  282. this.$refs.table.clearSelected()
  283. this.rowSelectionInfo = null
  284. this.$refs.table.refresh()
  285. this.spinning = false
  286. } else {
  287. this.$refs.table.refresh()
  288. this.spinning = false
  289. }
  290. })
  291. },
  292. // 表格选中项
  293. rowSelectionFun (obj) {
  294. this.rowSelectionInfo = obj || null
  295. },
  296. // 批量操作
  297. handleOutbounds (type) {
  298. console.log(this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length)
  299. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length <= 0)) {
  300. this.$message.warning('请在列表勾选后再进行批量操作!')
  301. return
  302. }
  303. this.$confirm({
  304. title: '提示',
  305. content: type == '2' ? '产品被禁用后,不能再销售,确定批量禁用吗?' : '确定批量启用吗?',
  306. centered: true,
  307. onOk: () => {
  308. this.setEnable(type == '2' ? '0' : '1', this.rowSelectionInfo.selectedRowKeys)
  309. }
  310. })
  311. },
  312. handleMenuClick (e) {
  313. this.handleOutbounds(e.key)
  314. },
  315. pageInit () {
  316. const _this = this
  317. this.$nextTick(() => { // 页面渲染完成后的回调
  318. _this.setTableH()
  319. })
  320. this.getColumns()
  321. },
  322. setTableH () {
  323. const tableSearchH = this.$refs.tableSearch.offsetHeight
  324. this.tableHeight = window.innerHeight - tableSearchH - 235
  325. }
  326. },
  327. watch: {
  328. advanced (newValue, oldValue) {
  329. const _this = this
  330. this.$nextTick(() => { // 页面渲染完成后的回调
  331. _this.setTableH()
  332. })
  333. },
  334. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  335. this.setTableH()
  336. }
  337. },
  338. mounted () {
  339. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  340. this.pageInit()
  341. this.resetSearchForm()
  342. }
  343. },
  344. activated () {
  345. // 如果是新页签打开,则重置当前页面
  346. if (this.$store.state.app.isNewTab) {
  347. this.pageInit()
  348. this.resetSearchForm()
  349. }
  350. },
  351. beforeRouteEnter (to, from, next) {
  352. next(vm => {})
  353. }
  354. }
  355. </script>