queryPart.vue 18 KB

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