queryPart.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <template>
  2. <div class="productInfoList-wrap">
  3. <!-- 搜索条件 -->
  4. <div 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="5">
  13. <a-col :md="4" :sm="24">
  14. <a-form-model-item label="产品编码">
  15. <a-input id="productInfoList-code" ref="searchProductCode" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  16. </a-form-model-item>
  17. </a-col>
  18. <a-col :md="4" :sm="24">
  19. <a-form-model-item label="产品名称">
  20. <a-input id="productInfoList-name" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  21. </a-form-model-item>
  22. </a-col>
  23. <a-col :md="4" :sm="24">
  24. <a-form-model-item label="原厂编码">
  25. <a-input id="productInfoList-origCode" v-model.trim="queryParam.productOrigCode" allowClear placeholder="请输入原厂编码"/>
  26. </a-form-model-item>
  27. </a-col>
  28. <a-col :md="4" :sm="24">
  29. <a-form-model-item label="产品分类">
  30. <a-cascader
  31. @change="changeProductType"
  32. change-on-select
  33. v-model="productType"
  34. expand-trigger="hover"
  35. :options="productTypeList"
  36. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  37. id="productInfoList-productType"
  38. placeholder="请选择产品分类"
  39. allowClear />
  40. </a-form-model-item>
  41. </a-col>
  42. <template v-if="advanced">
  43. <a-col :md="4" :sm="24">
  44. <a-form-model-item label="产品品牌">
  45. <a-select
  46. placeholder="请选择产品品牌"
  47. id="productInfoList-productBrandSn"
  48. allowClear
  49. v-model="queryParam.brandSn"
  50. :showSearch="true"
  51. option-filter-prop="children"
  52. :filter-option="filterOption">
  53. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  54. </a-select>
  55. </a-form-model-item>
  56. </a-col>
  57. <a-col :md="4" :sm="24">
  58. <a-form-model-item label="仓库">
  59. <a-select
  60. placeholder="请选择仓库"
  61. id="productInfoList-warehouseSn"
  62. allowClear
  63. v-model="queryParam.warehouseSn"
  64. :showSearch="true"
  65. option-filter-prop="children"
  66. :filter-option="filterOption">
  67. <a-select-option v-for="item in warehouseList" :key="item.warehouseSn" :value="item.warehouseSn">{{ item.name }}</a-select-option>
  68. </a-select>
  69. </a-form-model-item>
  70. </a-col>
  71. <a-col :md="8" :sm="24" v-if="$hasPermissions('B_salerVinFindProduct')">
  72. <a-form-model-item label="车架号(VIN)" prop="vinCode">
  73. <a-input id="productInfoList-vinCode" v-model.trim="queryParam.vinCode" allowClear placeholder="请输入车架号(VIN)">
  74. <a-icon @click="uploadFun" :type="vinLoading?'loading':'camera'" slot="addonAfter" :style="{ fontSize: '18px', verticalAlign: 'bottom' }" />
  75. </a-input>
  76. <input type="file" id="filed" accept="image/jpeg,image/png" hidden="" @change="filePreview">
  77. </a-form-model-item>
  78. </a-col>
  79. </template>
  80. <a-col :md="8" :sm="24" style="margin-bottom: 10px;">
  81. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
  82. <a-button style="margin-left: 5px" @click="resetSearchForm" id="productInfoList-reset">重置</a-button>
  83. <a @click="advanced=!advanced" style="margin:0 30px 0 10px">
  84. {{ advanced ? '收起' : '展开' }}
  85. <a-icon :type="advanced ? 'up' : 'down'"/>
  86. </a>
  87. <a-checkbox v-model="cost" id="salesQuery-cost">成本价</a-checkbox>
  88. <a-checkbox v-model="cityPrice" id="salesQuery-cityPrice">市级价</a-checkbox>
  89. </a-col>
  90. </a-row>
  91. </a-form-model>
  92. </div>
  93. <a-alert type="error" style="margin-bottom: 10px;" v-if="vinInfoData&&!vinInfoData.vinInfo">
  94. <template slot="message"><a-icon type="exclamation-circle" theme="filled" :style="{ color: '#E70012', fontSize: '15px', verticalAlign: 'sub', marginRight: '3px' }" />抱歉!暂未找到匹配VIN码的车型!</template>
  95. </a-alert>
  96. <a-alert type="warning" style="margin-bottom: 10px;cursor: pointer;" v-if="vinInfoData&&vinInfoData.vinInfo" @click="openCarInfoModal=true">
  97. <template slot="message">
  98. <div style="display: flex;justify-content: space-between;align-items: center;" @click="openCarInfoModal=true">
  99. <div>
  100. <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;" />
  101. <span style="vertical-align: middle;">{{ vinInfoData.vinInfo.text }}</span>
  102. </div>
  103. <div style="color: #f90;">
  104. <span>查看更多</span> >
  105. </div>
  106. </div>
  107. </template>
  108. </a-alert>
  109. <!-- 列表 -->
  110. <s-table
  111. class="sTable"
  112. ref="table"
  113. size="small"
  114. :rowKey="(record) => record.productSn+record.currentQty+record.warehouseSn+record.warehouseLocationSn"
  115. :columns="columns"
  116. :data="loadData"
  117. :customRow="handleClickRow"
  118. :defaultLoadData="false"
  119. :pageSize="10"
  120. :scroll="{ y: 149 }"
  121. bordered>
  122. <!-- 售价 -->
  123. <template slot="salePrice" slot-scope="text, record">
  124. <div style="display: flex;align-items: center;" @dblclick.stop>
  125. <a-input-number
  126. size="small"
  127. v-model="record.price"
  128. :precision="2"
  129. :min="0"
  130. :max="999999"
  131. style="width: 100%;"
  132. placeholder="请输入" />
  133. <span style="color: red;margin: 0 2px;font-size: 14px;" v-if="record.origSalePriceFlag == 1">原</span>
  134. <span v-else>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
  135. </div>
  136. </template>
  137. <!-- 销售数量 -->
  138. <template slot="nums" slot-scope="text, record">
  139. <div @dblclick.stop>
  140. <a-input-number
  141. size="small"
  142. v-model="record.salesNums"
  143. :precision="0"
  144. :min="0"
  145. :max="999999"
  146. style="width: 100%;"
  147. placeholder="请输入" />
  148. </div>
  149. </template>
  150. <!-- 操作 -->
  151. <template slot="action" slot-scope="text, record">
  152. <a-button
  153. size="small"
  154. type="link"
  155. class="button-primary"
  156. @click="handleAdd(record)"
  157. id="productInfoList-edit-btn">添加</a-button>
  158. <a-button
  159. size="small"
  160. type="link"
  161. class="button-primary"
  162. @click="handleDetail(record)"
  163. id="productInfoList-detail-btn"
  164. style="margin-left: 5px;">销售记录</a-button>
  165. </template>
  166. </s-table>
  167. <!-- 销售记录 -->
  168. <product-salesRecord-modal ref="salseRecord" :openModal="openModal" @close="closeModal" />
  169. <!-- 查看车辆信息 -->
  170. <car-info-modal ref="carInfoModal" :openModal="openCarInfoModal" :infoData="vinInfoData&&vinInfoData.vinInfo" @close="openCarInfoModal=false" />
  171. </div>
  172. </template>
  173. <script>
  174. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  175. import { dealerProductTypeList } from '@/api/dealerProductType'
  176. import { querySumByProductLocation } from '@/api/stock'
  177. import { warehouseAllList } from '@/api/warehouse'
  178. import productSalesRecordModal from './productSalesRecordModal.vue'
  179. import carInfoModal from './carInfoModal.vue'
  180. import { STable, VSelect, Upload } from '@/components'
  181. import { supperCodeByVin, vinCodeParse } from '@/api/sales'
  182. import defImg from '@/assets/def_img@2x.png'
  183. export default {
  184. name: 'QueryPart',
  185. components: { STable, VSelect, Upload, productSalesRecordModal, carInfoModal },
  186. props: {
  187. // buyerSn: {
  188. // type: [Number, String],
  189. // default: ''
  190. // },
  191. // priceType: {
  192. // type: [Number, String],
  193. // default: ''
  194. // },
  195. newLoading: Boolean
  196. },
  197. data () {
  198. return {
  199. advanced: false, // 高级搜索 展开/关闭
  200. vinLoading: false,
  201. productType: [],
  202. defImg,
  203. queryParam: { // 查询条件
  204. customerSn: '',
  205. salePriceType: '',
  206. productCode: '', // 产品编码
  207. productName: '', // 产品名称
  208. productOrigCode: '', // 原厂编码
  209. vinCode: '',
  210. productCodeList: undefined, // 车架号
  211. brandSn: undefined, // 产品品牌
  212. productTypeSn1: '', // 产品一级分类
  213. productTypeSn2: '', // 产品二级分类
  214. productTypeSn3: '', // 产品三级分类
  215. warehouseSn: undefined // 仓库、
  216. },
  217. priceType: '',
  218. buyerSn: '',
  219. rules: {
  220. vinCode: [ { len: 17, message: '请输入正确的车架号(VIN)', trigger: 'change' } ]
  221. },
  222. disabled: false, // 查询、重置按钮是否可操作
  223. productBrandList: [], // 下拉数据
  224. productTypeList: [], // 产品分类 下拉数据
  225. warehouseList: [], // 仓库列表
  226. vinInfoData: null,
  227. // 加载数据方法 必须为 Promise 对象
  228. loadData: parameter => {
  229. const _this = this
  230. _this.queryParam.salePriceType = _this.priceType
  231. _this.queryParam.customerSn = _this.buyerSn
  232. // 排序
  233. if (parameter.sortField == 'productCode') {
  234. parameter.sortField = 'code'
  235. parameter.sortAlias = 'product '
  236. }
  237. if (parameter.sortField == 'brandName') {
  238. parameter.sortField = 'firstChar'
  239. parameter.sortAlias = 'brand'
  240. }
  241. if (parameter.sortField == 'warehouseName') {
  242. parameter.sortField = 'warehouseSn'
  243. parameter.sortAlias = 'sd'
  244. }
  245. const params = Object.assign(parameter, _this.queryParam)
  246. if (_this.queryParam.vinCode && _this.queryParam.vinCode.length == 17 && !this.onlyList) { // 输入vin,查出vin码信息后请求列表数据
  247. _this.disabled = true
  248. return supperCodeByVin({ vin: _this.queryParam.vinCode }).then(res => {
  249. if (res.status == 200) {
  250. _this.vinInfoData = res.data
  251. params.productCodeList = res.data.partCodeList || []
  252. return _this.getList(params)
  253. } else {
  254. _this.vinInfoData = null
  255. _this.$refs.table.localLoading = false
  256. _this.$refs.table.clearTable()
  257. }
  258. })
  259. } else if (_this.queryParam.vinCode && _this.queryParam.vinCode.length < 17 && !this.onlyList) { // 输入vin,但vin码不符合标准,不查vin码信息,不请求列表数据
  260. _this.$refs.table.localLoading = false
  261. _this.$refs.table.clearTable()
  262. } else if (this.onlyList) {
  263. _this.disabled = true
  264. if (_this.queryParam.vinCode && _this.vinInfoData) {
  265. return _this.getList(Object.assign(params, { productCodeList: _this.vinInfoData.partCodeList }))
  266. } else {
  267. return _this.getList(params)
  268. }
  269. } else { // 未输入vin码信息,只查列表数据
  270. _this.disabled = true
  271. return _this.getList(params)
  272. }
  273. },
  274. openModal: false, // 查看客户详情 弹框
  275. cost: false,
  276. cityPrice: false,
  277. openCarInfoModal: false,
  278. onlyList: false
  279. }
  280. },
  281. computed: {
  282. columns () {
  283. const arr = [
  284. { title: '产品编码', dataIndex: 'productCode', width: '15%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  285. { title: '产品名称', dataIndex: 'productName', width: '18%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  286. { title: '原厂编码', dataIndex: 'productOrigCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  287. { title: '品牌', dataIndex: 'brandName', width: '11%', align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
  288. { title: '仓库', dataIndex: 'warehouseName', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  289. { title: '仓位', dataIndex: 'warehouseLocationName', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  290. { title: '库存数量', dataIndex: 'currentQty', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  291. { title: '单位', dataIndex: 'unit', width: '4%', align: 'center', customRender: function (text) { return text || '--' } },
  292. { title: '售价', dataIndex: 'salePrice', scopedSlots: { customRender: 'salePrice' }, width: '7%', align: 'center' },
  293. { title: '销售数量', dataIndex: 'salesNums', scopedSlots: { customRender: 'nums' }, width: '6%', align: 'center' },
  294. { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' }, width: '13%', align: 'center' }
  295. ]
  296. if (this.cost) {
  297. arr.splice(6, 0, { title: '成本价', dataIndex: 'putCost', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  298. }
  299. if (this.cityPrice) {
  300. arr.splice(this.cost ? 7 : 6, 0, { title: '市级价', dataIndex: 'dealerProduct.cityPrice', width: '5%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  301. }
  302. return arr
  303. }
  304. },
  305. created () {
  306. // 产品品牌
  307. if (this.productBrandList.length == 0) {
  308. this.getProductBrand()
  309. }
  310. // 产品分类
  311. if (this.productTypeList.length == 0) {
  312. this.getProductType()
  313. }
  314. // 仓库
  315. if (this.warehouseList.length == 0) {
  316. this.getWarehouse()
  317. }
  318. },
  319. methods: {
  320. getList (params) {
  321. const _this = this
  322. return querySumByProductLocation(params).then(res => {
  323. let data
  324. this.onlyList = false
  325. if (res.status == 200) {
  326. data = res.data
  327. data.list = data.list.filter(item => item != null)
  328. const no = (data.pageNo - 1) * data.pageSize
  329. for (var i = 0; i < data.list.length; i++) {
  330. data.list[i].no = no + i + 1
  331. data.list[i].salesNums = 1
  332. data.list[i].currentQty = data.list[i].currentQty || 0
  333. data.list[i].price = data.list[i].lastSalePrice ? data.list[i].lastSalePrice : data.list[i].salePrice
  334. }
  335. if (!params.vinCode) {
  336. _this.vinInfoData = null
  337. }
  338. } else {
  339. data = {
  340. list: [],
  341. pageNo: 1,
  342. pageSize: 10
  343. }
  344. }
  345. _this.disabled = false
  346. return data
  347. })
  348. },
  349. // vin change
  350. vinCodeChange (e) {
  351. if (e.target.value.length == 17) {
  352. supperCodeByVin({ vin: e.target.value }).then(res => {
  353. if (res.status == 200) {
  354. this.queryParam.productCodeList = res.data
  355. } else {
  356. this.queryParam.productCodeList = undefined
  357. }
  358. })
  359. } else {
  360. this.queryParam.productCodeList = undefined
  361. }
  362. },
  363. // 双击列表
  364. handleClickRow (record) {
  365. const _this = this
  366. return {
  367. on: {
  368. dblclick: (event) => {
  369. event.stopPropagation()
  370. _this.$emit('add', record)
  371. }
  372. }
  373. }
  374. },
  375. // 重置
  376. resetSearchForm () {
  377. this.queryParam.productCode = ''
  378. this.queryParam.productName = ''
  379. this.queryParam.productOrigCode = ''
  380. this.queryParam.brandSn = undefined
  381. this.queryParam.productTypeSn1 = ''
  382. this.queryParam.productTypeSn2 = ''
  383. this.queryParam.productTypeSn3 = ''
  384. this.queryParam.warehouseSn = undefined
  385. this.queryParam.productCodeList = undefined
  386. this.queryParam.vinCode = ''
  387. this.productType = []
  388. this.$refs.ruleForm.resetFields()
  389. this.$refs.table.refresh(true)
  390. this.vinInfoData = null
  391. },
  392. pageInit (buyerSn, priceType) {
  393. this.priceType = priceType || ''
  394. this.buyerSn = buyerSn || ''
  395. if (this.onlyList) { // 不清空查询条件
  396. this.$refs.table.refresh()
  397. } else {
  398. this.resetSearchForm()
  399. }
  400. this.$refs.searchProductCode.focus()
  401. },
  402. // 刷新当前页面
  403. resetCurForm () {
  404. this.$refs.table.refresh()
  405. },
  406. // 清空数据
  407. clearTable () {
  408. this.vinInfoData = null
  409. this.$refs.ruleForm.resetFields()
  410. this.$refs.table.clearTable()
  411. },
  412. filterOption (input, option) {
  413. return (
  414. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  415. )
  416. },
  417. // 选择配件
  418. handleAdd (row) {
  419. const _this = this
  420. console.log(row.price, row.lastSalePrice, row.salePrice, row.lastSalePrice < row.salePrice)
  421. if (row.lastSalePrice && (row.price < row.salePrice)) {
  422. _this.$confirm({
  423. title: '提示',
  424. content: '售价低于定价,是否仍继续添加?',
  425. centered: true,
  426. closable: true,
  427. onOk () {
  428. _this.$emit('add', row)
  429. }
  430. })
  431. } else {
  432. _this.$emit('add', row)
  433. }
  434. },
  435. // 销售记录
  436. handleDetail (row) {
  437. this.openModal = true
  438. this.$refs.salseRecord.getDetail(this.buyerSn, row.productSn)
  439. },
  440. // 关闭弹框
  441. closeModal () {
  442. this.openModal = false
  443. },
  444. uploadFun () {
  445. document.getElementById('filed').click()
  446. },
  447. filePreview (e) {
  448. const _this = this
  449. var files = e.target.files[0]
  450. const formData = new FormData()
  451. formData.append('savePathType', 'local')
  452. formData.append('file', files)
  453. this.vinLoading = true
  454. vinCodeParse(formData).then(res => {
  455. if (res.type == 'application/json') {
  456. var reader = new FileReader()
  457. reader.addEventListener('loadend', function () {
  458. const obj = JSON.parse(reader.result)
  459. if (obj.status == 200) {
  460. _this.queryParam.vinCode = obj.data || ''
  461. // 移除表单项的校验结果
  462. _this.$refs.ruleForm.clearValidate('vinCode')
  463. } else {
  464. _this.$notification.error({
  465. message: '提示',
  466. description: obj.message
  467. })
  468. }
  469. _this.vinLoading = false
  470. document.getElementById('filed').value = ''
  471. })
  472. reader.readAsText(res)
  473. } else {
  474. _this.vinLoading = false
  475. }
  476. })
  477. },
  478. // 仓库
  479. getWarehouse () {
  480. warehouseAllList({}).then(res => {
  481. if (res.status == 200) {
  482. this.warehouseList = res.data
  483. } else {
  484. this.warehouseList = []
  485. }
  486. })
  487. },
  488. // 产品品牌 列表
  489. getProductBrand () {
  490. dealerProductBrandQuery({}).then(res => {
  491. if (res.status == 200) {
  492. this.productBrandList = res.data
  493. } else {
  494. this.productBrandList = []
  495. }
  496. })
  497. },
  498. // 产品分类 列表
  499. getProductType () {
  500. dealerProductTypeList({}).then(res => {
  501. if (res.status == 200) {
  502. this.productTypeList = res.data
  503. } else {
  504. this.productTypeList = []
  505. }
  506. })
  507. },
  508. // 产品分类 change
  509. changeProductType (val, opt) {
  510. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  511. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  512. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  513. }
  514. },
  515. watch: {
  516. cost (newValue, oldValue) {
  517. this.$emit('isCost', newValue)
  518. }
  519. }
  520. }
  521. </script>