list.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <a-card size="small" :bordered="false" class="priceInquiryList-wrap">
  3. <!-- 搜索条件 -->
  4. <div ref="tableSearch" class="table-page-search-wrapper">
  5. <a-form-model
  6. ref="ruleForm"
  7. class="form-model-con"
  8. layout="inline"
  9. :rules="rules"
  10. :model="queryParam"
  11. @keyup.enter.native="$refs.table.refresh(true)" >
  12. <a-row :gutter="15">
  13. <a-col :md="6" :sm="24">
  14. <a-form-model-item label="车架号(VIN)" prop="vinCode">
  15. <a-input id="priceInquiryList-vinCode" v-model.trim="queryParam.vinCode" allowClear placeholder="请输入车架号(VIN)">
  16. <a-icon @click="uploadFun" :type="vinLoading?'loading':'camera'" slot="addonAfter" :style="{ fontSize: '18px', verticalAlign: 'bottom' }" />
  17. </a-input>
  18. <input type="file" id="filed" accept="image/jpeg,image/png" hidden="" @change="filePreview">
  19. </a-form-model-item>
  20. </a-col>
  21. <a-col :md="6" :sm="24">
  22. <a-form-model-item label="产品编码">
  23. <a-input id="priceInquiryList-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  24. </a-form-model-item>
  25. </a-col>
  26. <a-col :md="6" :sm="24">
  27. <a-form-model-item label="产品名称">
  28. <a-input id="priceInquiryList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  29. </a-form-model-item>
  30. </a-col>
  31. <template v-if="advanced">
  32. <a-col :md="6" :sm="24">
  33. <a-form-model-item label="产品分类">
  34. <a-cascader
  35. @change="changeProductType"
  36. change-on-select
  37. v-model="productType"
  38. expand-trigger="hover"
  39. :options="productTypeList"
  40. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  41. id="priceInquiryList-productType"
  42. placeholder="请选择产品分类"
  43. allowClear />
  44. </a-form-model-item>
  45. </a-col>
  46. <a-col :md="6" :sm="24">
  47. <a-form-model-item label="产品品牌">
  48. <ProductBrand id="priceInquiryList-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
  49. </a-form-model-item>
  50. </a-col>
  51. <a-col :md="6" :sm="24">
  52. <a-form-model-item label="产品状态">
  53. <v-select code="PRODUCT_ONOFFLINE_STATUS" id="priceInquiryList-state" v-model="queryParam.state" allowClear placeholder="请选择状态"></v-select>
  54. </a-form-model-item>
  55. </a-col>
  56. </template>
  57. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  58. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="priceInquiryList-refresh">查询</a-button>
  59. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="priceInquiryList-reset">重置</a-button>
  60. <a @click="advanced=!advanced" style="margin-left: 5px">
  61. {{ advanced ? '收起' : '展开' }}
  62. <a-icon :type="advanced ? 'up' : 'down'"/>
  63. </a>
  64. </a-col>
  65. </a-row>
  66. </a-form-model>
  67. </div>
  68. <a-alert type="error" style="margin-bottom: 10px;" v-if="vinInfoData&&!vinInfoData.vinInfo">
  69. <template slot="message"><a-icon type="exclamation-circle" theme="filled" :style="{ color: '#E70012', fontSize: '15px', verticalAlign: 'sub', marginRight: '3px' }" />抱歉!暂未找到匹配VIN码的车型!</template>
  70. </a-alert>
  71. <a-alert type="warning" style="margin-bottom: 10px;cursor: pointer;" v-if="vinInfoData&&vinInfoData.vinInfo" @click="openCarInfoModal=true">
  72. <template slot="message">
  73. <div style="display: flex;justify-content: space-between;align-items: center;" @click="openCarInfoModal=true">
  74. <div>
  75. <img :src="vinInfoData.vinInfo && vinInfoData.vinInfo.icon?(vinInfoData.vinInfo.icon+'?x-oss-process=image/resize,h_30,m_lfit'):defImg" width="30" height="30" class="imageUrl" style="border-radius: 50%;vertical-align: middle;margin-right: 3px;" />
  76. <span style="vertical-align: middle;">{{ vinInfoData.vinInfo.text }}</span>
  77. </div>
  78. <div style="color: #f90;">
  79. <span>查看更多</span> >
  80. </div>
  81. </div>
  82. </template>
  83. </a-alert>
  84. <!-- 列表 -->
  85. <s-table
  86. class="sTable fixPagination"
  87. ref="table"
  88. :style="{ height: tableHeight+84.5+'px' }"
  89. size="small"
  90. :rowKey="(record) => record.id"
  91. :columns="columns"
  92. :data="loadData"
  93. :scroll="{ y: tableHeight }"
  94. :defaultLoadData="false"
  95. bordered>
  96. <!-- 产品图片 -->
  97. <template slot="imageUrl" slot-scope="text, record">
  98. <div v-if="record.productPicList && record.productPicList.length>0">
  99. <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)" />
  100. </div>
  101. <span v-else>--</span>
  102. </template>
  103. <!-- 产品分类 -->
  104. <template slot="productType" slot-scope="text, record">
  105. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  106. <span v-else>--</span>
  107. </template>
  108. <!-- 产品编码 可点击查看详情 -->
  109. <template slot="detail" slot-scope="text, record">
  110. <span style="color: #00aaff;cursor: pointer;" @click="handleDetail(record)">{{ record.code }}</span>
  111. </template>
  112. </s-table>
  113. <!-- 查看车辆信息 -->
  114. <car-info-modal ref="carInfoModal" :openModal="openCarInfoModal" :infoData="vinInfoData&&vinInfoData.vinInfo" @close="openCarInfoModal=false" />
  115. </a-card>
  116. </template>
  117. <script>
  118. import { STable, VSelect } from '@/components'
  119. import carInfoModal from './carInfoModal.vue'
  120. import { productBrandQuery } from '@/api/productBrand'
  121. import { productTypeQuery } from '@/api/productType'
  122. import { productPriceList } from '@/api/product'
  123. import { supperCodeByVin, vinCodeParse } from '@/api/sales'
  124. import ProductBrand from '@/views/common/productBrand.js'
  125. export default {
  126. components: { STable, VSelect, ProductBrand, carInfoModal },
  127. data () {
  128. return {
  129. advanced: true, // 高级搜索 展开/关闭
  130. vinLoading: false,
  131. tableHeight: 0,
  132. productType: [],
  133. queryParam: { // 查询条件
  134. code: '', // 产品编码
  135. name: '', // 产品名称
  136. vinCode: '',
  137. codeList: undefined, // 车架号
  138. productBrandSn: undefined, // 产品品牌
  139. productTypeSn1: '', // 产品一级分类
  140. productTypeSn2: '', // 产品二级分类
  141. productTypeSn3: '', // 产品三级分类
  142. state: 'ONLINE' // 产品状态
  143. },
  144. rules: {
  145. vinCode: [ { len: 17, message: '请输入正确的车架号(VIN)', trigger: 'change' } ]
  146. },
  147. disabled: false, // 查询、重置按钮是否可操作
  148. // 加载数据方法 必须为 Promise 对象
  149. loadData: parameter => {
  150. const _this = this
  151. const params = Object.assign(parameter, _this.queryParam)
  152. if (_this.queryParam.vinCode && _this.queryParam.vinCode.length == 17 && !this.onlyList) { // 输入vin,查出vin码信息后请求列表数据
  153. _this.disabled = true
  154. return supperCodeByVin({ vin: _this.queryParam.vinCode }).then(res => {
  155. if (res.status == 200) {
  156. _this.vinInfoData = res.data
  157. params.codeList = res.data.partCodeList || []
  158. return _this.getList(params)
  159. } else {
  160. _this.vinInfoData = null
  161. _this.$refs.table.localLoading = false
  162. _this.$refs.table.clearTable()
  163. }
  164. })
  165. } else if (_this.queryParam.vinCode && _this.queryParam.vinCode.length < 17 && !this.onlyList) { // 输入vin,但vin码不符合标准,不查vin码信息,不请求列表数据
  166. _this.$refs.table.localLoading = false
  167. _this.$refs.table.clearTable()
  168. } else if (this.onlyList) {
  169. _this.disabled = true
  170. if (_this.queryParam.vinCode && _this.vinInfoData) {
  171. return _this.getList(Object.assign(params, { codeList: _this.vinInfoData.partCodeList }))
  172. } else {
  173. return _this.getList(params)
  174. }
  175. } else { // 未输入vin码信息,只查列表数据
  176. _this.disabled = true
  177. return _this.getList(params)
  178. }
  179. },
  180. vinInfoData: null,
  181. productBrandList: [], // 品牌下拉数据
  182. productTypeList: [], // 分类下拉数据
  183. openCarInfoModal: false,
  184. onlyList: false
  185. }
  186. },
  187. computed: {
  188. columns () {
  189. const arr = [
  190. { title: '产品编码', dataIndex: 'code', scopedSlots: { customRender: 'detail' }, width: '15%', align: 'center' },
  191. { title: '产品名称', dataIndex: 'name', width: '15%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  192. { title: '原厂编码', dataIndex: 'origCode', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  193. { title: '产品状态', dataIndex: 'stateDictValue', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  194. // { title: '省级价', dataIndex: 'provincePrice', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  195. // { title: '市级价', dataIndex: 'cityPrice', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  196. // { title: '特约价', dataIndex: 'specialPrice', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  197. // { title: '终端价', dataIndex: 'terminalPrice', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  198. // { title: '车主价', dataIndex: 'carOwnersPrice', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  199. { title: '产品图片', scopedSlots: { customRender: 'imageUrl' }, width: '8%', align: 'center' }
  200. ]
  201. if (this.$hasPermissions('B_isShowPrice')) { // 售价权限
  202. arr.splice(4, 0, { title: '省级价', dataIndex: 'provincePrice', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  203. arr.splice(5, 0, { title: '市级价', dataIndex: 'cityPrice', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  204. arr.splice(6, 0, { title: '特约价', dataIndex: 'specialPrice', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  205. arr.splice(7, 0, { title: '终端价', dataIndex: 'terminalPrice', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  206. arr.splice(8, 0, { title: '车主价', dataIndex: 'carOwnersPrice', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  207. }
  208. return arr
  209. }
  210. },
  211. methods: {
  212. // 详情
  213. handleDetail (row) {
  214. this.itemId = row.productSn
  215. this.$router.push({ name: 'viewProduct', params: { sn: row.productSn } })
  216. },
  217. getList (params) {
  218. const _this = this
  219. return productPriceList(params).then(res => {
  220. let data
  221. this.onlyList = false
  222. if (res.status == 200) {
  223. data = res.data
  224. data.list = data.list.filter(item => item != null)
  225. const no = (data.pageNo - 1) * data.pageSize
  226. for (var i = 0; i < data.list.length; i++) {
  227. data.list[i].no = no + i + 1
  228. }
  229. if (!params.vinCode) {
  230. _this.vinInfoData = null
  231. }
  232. } else {
  233. data = {
  234. list: [],
  235. pageNo: 1,
  236. pageSize: 10
  237. }
  238. }
  239. _this.disabled = false
  240. return data
  241. })
  242. },
  243. inited (viewer) {
  244. if (viewer) {
  245. const imageUrl = []
  246. viewer.map(item => {
  247. imageUrl.push(item.imageUrl)
  248. })
  249. this.$viewerApi({
  250. images: imageUrl
  251. })
  252. }
  253. },
  254. // 重置
  255. resetSearchForm () {
  256. this.queryParam.code = ''
  257. this.queryParam.name = ''
  258. this.queryParam.productBrandSn = undefined
  259. this.queryParam.productTypeSn1 = ''
  260. this.queryParam.productTypeSn2 = ''
  261. this.queryParam.productTypeSn3 = ''
  262. this.queryParam.state = 'ONLINE'
  263. this.queryParam.codeList = undefined
  264. this.productType = []
  265. this.$refs.ruleForm.resetFields()
  266. this.$refs.table.refresh(true)
  267. this.vinInfoData = null
  268. },
  269. uploadFun () {
  270. document.getElementById('filed').click()
  271. },
  272. filePreview (e) {
  273. const _this = this
  274. var files = e.target.files[0]
  275. const formData = new FormData()
  276. formData.append('savePathType', 'local')
  277. formData.append('file', files)
  278. this.vinLoading = true
  279. vinCodeParse(formData).then(res => {
  280. if (res.type == 'application/json') {
  281. var reader = new FileReader()
  282. reader.addEventListener('loadend', function () {
  283. const obj = JSON.parse(reader.result)
  284. if (obj.status == 200) {
  285. _this.queryParam.vinCode = obj.data || ''
  286. // 移除表单项的校验结果
  287. _this.$refs.ruleForm.clearValidate('vinCode')
  288. } else {
  289. _this.$notification.error({
  290. message: '提示',
  291. description: obj.message
  292. })
  293. }
  294. _this.vinLoading = false
  295. document.getElementById('filed').value = ''
  296. })
  297. reader.readAsText(res)
  298. } else {
  299. _this.vinLoading = false
  300. }
  301. })
  302. },
  303. // 产品分类 change
  304. changeProductType (val, opt) {
  305. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  306. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  307. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  308. },
  309. // 产品品牌 列表
  310. getProductBrand () {
  311. productBrandQuery({}).then(res => {
  312. if (res.status == 200) {
  313. this.productBrandList = res.data
  314. } else {
  315. this.productBrandList = []
  316. }
  317. })
  318. },
  319. // 产品分类 列表
  320. getProductType () {
  321. productTypeQuery({}).then(res => {
  322. if (res.status == 200) {
  323. this.productTypeList = res.data
  324. } else {
  325. this.productTypeList = []
  326. }
  327. })
  328. },
  329. pageInit () {
  330. const _this = this
  331. this.$nextTick(() => { // 页面渲染完成后的回调
  332. _this.setTableH()
  333. })
  334. this.getProductBrand()
  335. this.getProductType()
  336. },
  337. setTableH () {
  338. const tableSearchH = this.$refs.tableSearch.offsetHeight
  339. this.tableHeight = window.innerHeight - tableSearchH - 243
  340. }
  341. },
  342. watch: {
  343. advanced (newValue, oldValue) {
  344. const _this = this
  345. this.$nextTick(() => { // 页面渲染完成后的回调
  346. _this.setTableH()
  347. })
  348. },
  349. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  350. this.setTableH()
  351. }
  352. },
  353. mounted () {
  354. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  355. this.pageInit()
  356. this.resetSearchForm()
  357. }
  358. },
  359. activated () {
  360. // 如果是新页签打开,则重置当前页面
  361. if (this.$store.state.app.isNewTab) {
  362. this.pageInit()
  363. this.resetSearchForm()
  364. }
  365. // 仅刷新列表,不重置页面
  366. if (this.$store.state.app.updateList) {
  367. this.pageInit()
  368. this.$refs.table.refresh()
  369. }
  370. },
  371. beforeRouteEnter (to, from, next) {
  372. next(vm => {})
  373. }
  374. }
  375. </script>