productSearch.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <view class="productSearch-wrap">
  3. <u-popup v-model="isShow" class="search-popup" mode="right" @close="isShow=false" length="85%">
  4. <u-form class="form-content" :model="form" ref="uForm" label-width="180">
  5. <u-form-item label="车架号(VIN)" prop="vinCode" class="form-item">
  6. <u-input v-model.trim="form.vinCode" :maxlength="17" placeholder="请输入车架号" input-align="right" />
  7. <u-upload :custom-btn="true" ref="uUpload" :show-upload-list="false" :action="action" :form-data="{savePathType: 'local'}" @on-success="uploadSuccess" :max-size="2 * 1024 * 1024">
  8. <view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
  9. <u-icon name="camera-fill" color="#c8c0cc" size="34" style="margin-left: 14upx;"></u-icon>
  10. </view>
  11. </u-upload>
  12. </u-form-item>
  13. <u-form-item label="产品编码" prop="productCode" class="form-item">
  14. <u-input v-model.trim="form.productCode" placeholder="请输入产品编码" input-align="right" />
  15. </u-form-item>
  16. <u-form-item label="原厂编码" prop="productOrigCode" class="form-item">
  17. <u-input v-model.trim="form.productOrigCode" placeholder="请输入原厂编码" input-align="right" />
  18. </u-form-item>
  19. <u-form-item label="产品名称" prop="productName" class="form-item">
  20. <u-input v-model.trim="form.productName" placeholder="请输入产品名称" input-align="right" />
  21. </u-form-item>
  22. <u-form-item label="产品品牌" prop="productBrandSn" class="form-item">
  23. <u-input v-model="brandName" @click="brandModal=true" @clear="brandClean" clearable type="select" placeholder="请选择产品品牌" input-align="right" />
  24. </u-form-item>
  25. <u-form-item label="产品分类" prop="productTypeSn" class="form-item">
  26. <u-input v-model="productTypeNameArr" @click="showTypeModal=true" @clear="typeClean" type="select" clearable placeholder="请选择产品分类" input-align="right" />
  27. </u-form-item>
  28. <u-form-item label="仓库" prop="warehouseSn" class="form-item">
  29. <u-input v-model="warehouseName" @click="warehouseModal=true" @clear="clearWarehouse" type="select" clearable placeholder="请选择仓库" class="form-item-inp" input-align="right" />
  30. </u-form-item>
  31. <u-form-item label="成本价">
  32. <u-switch slot="right" v-model="form.cost"></u-switch>
  33. </u-form-item>
  34. <u-form-item label="市级价">
  35. <u-switch slot="right" v-model="form.cityPrice"></u-switch>
  36. </u-form-item>
  37. </u-form>
  38. <view class="uni-list-btns">
  39. <u-button class="handle-btn" size="medium" hover-class="none" shape="circle" @click="resetForm">重置</u-button>
  40. <u-button class="handle-btn search-btn" size="medium" shape="circle" hover-class="none" :custom-style="customBtnStyle" @click="handleSearch">查询</u-button>
  41. </view>
  42. </u-popup>
  43. <!-- 产品品牌 -->
  44. <productBrand :openModal="brandModal" :itemSn="form.productBrandSn" @choose="brandChoose" @clean="brandClean" @close="brandModal=false" />
  45. <!-- 产品分类 -->
  46. <productType :openModal="showTypeModal" :nowData="nowData" @choose="typeChoose" @close="showTypeModal=false" />
  47. <!-- 选择收款方式 -->
  48. <u-picker v-model="warehouseModal" @confirm="warehouseChange" :range="warehouseList" range-key="name" mode="selector"></u-picker>
  49. </view>
  50. </template>
  51. <script>
  52. import productBrand from '@/pages/common/productBrand.vue'
  53. import productType from '@/pages/common/productType.vue'
  54. import { warehouseAllList, vinCodeParse } from '@/api/sales'
  55. const baseUrl = getApp({ allowDefault: true }).globalData.baseUrl
  56. export default{
  57. components: { productBrand, productType },
  58. props: {
  59. openModal: { // 弹框显示状态
  60. type: Boolean,
  61. default: false
  62. },
  63. defaultParams: { // 默认查询条件
  64. type: Object,
  65. default: () => {
  66. return null
  67. }
  68. }
  69. },
  70. data(){
  71. return{
  72. isShow: this.openModal,
  73. form: {
  74. vinCode: '',
  75. productCode: '', // 产品编码
  76. productName: '', // 产品名称
  77. productOrigCode: '', // 原厂编码
  78. productBrandSn: undefined, // 产品品牌
  79. productTypeSn1: undefined, // 产品分类1
  80. productTypeSn2: undefined, // 产品分类2
  81. productTypeSn3: undefined, // 产品分类3
  82. warehouseSn: undefined, // 仓库
  83. cost: false, // 成本价
  84. cityPrice: false, // 市级价
  85. },
  86. customBtnStyle: { // 自定义按钮样式
  87. borderColor: this.$config('primaryColor'),
  88. backgroundColor: this.$config('primaryColor'),
  89. color: '#fff'
  90. },
  91. warehouseName: '',
  92. warehouseModal: false,
  93. warehouseList: [],
  94. brandModal: false,
  95. brandName: '',
  96. showTypeModal: false,
  97. nowData: [],
  98. action: baseUrl + 'vinIdentify/ocr',
  99. }
  100. },
  101. computed: {
  102. productTypeNameArr: function() {
  103. let str = ''
  104. this.nowData.map(item => {
  105. str += item.productTypeName+' / '
  106. })
  107. return str ? str.substr(0, str.length-3) : ''
  108. }
  109. },
  110. mounted() {
  111. this.getWarehouse()
  112. },
  113. methods: {
  114. // 初始化数据
  115. init(){
  116. console.log(this.defaultParams)
  117. this.form.vinCode = this.defaultParams && this.defaultParams.vinCode || ''
  118. this.form.productCode = this.defaultParams && this.defaultParams.productCode || ''
  119. this.form.productName = this.defaultParams && this.defaultParams.productName || ''
  120. this.form.productOrigCode = this.defaultParams && this.defaultParams.productOrigCode || ''
  121. this.form.productBrandSn = this.defaultParams && this.defaultParams.productBrandSn || undefined
  122. this.form.productTypeSn1 = this.defaultParams && this.defaultParams.productTypeSn1 || undefined
  123. this.form.productTypeSn2 = this.defaultParams && this.defaultParams.productTypeSn2 || undefined
  124. this.form.productTypeSn3 = this.defaultParams && this.defaultParams.productTypeSn3 || undefined
  125. this.form.warehouseSn = this.defaultParams && this.defaultParams.warehouseSn || undefined
  126. this.form.cost = this.defaultParams && this.defaultParams.cost || false
  127. this.form.cityPrice = this.defaultParams && this.defaultParams.cityPrice || false
  128. this.brandName = this.defaultParams && this.defaultParams.brandName || ''
  129. this.nowData = this.defaultParams && this.defaultParams.nowData ? this.defaultParams.nowData : []
  130. this.warehouseName = this.defaultParams && this.defaultParams.warehouseName || ''
  131. },
  132. // 查询
  133. handleSearch() {
  134. let params = JSON.parse(JSON.stringify(this.form))
  135. let other = {
  136. brandName: this.brandName,
  137. nowData: this.nowData,
  138. warehouseName: this.warehouseName
  139. }
  140. this.$emit('refresh', Object.assign(params, other))
  141. this.isShow = false
  142. },
  143. // 重置
  144. resetForm() {
  145. this.warehouseName = ''
  146. this.nowData = []
  147. this.$refs.uForm.resetFields()
  148. this.$emit('refresh', {})
  149. this.isShow = false
  150. this.brandClean()
  151. this.typeClean()
  152. },
  153. uploadSuccess(res){
  154. if(res.status == 200){
  155. this.form.vinCode = res.data
  156. }else{
  157. this.toashMsg(res.message)
  158. }
  159. },
  160. // 选择品牌
  161. brandChoose(data){
  162. this.brandName = data.brandName
  163. this.form.productBrandSn = data.brandSn
  164. },
  165. // 清空品牌
  166. brandClean(){
  167. this.brandName = ''
  168. this.form.productBrandSn = undefined
  169. },
  170. // 选择分类
  171. typeChoose(obj){
  172. if(obj){
  173. this.nowData = obj
  174. this.form.productTypeSn1 = obj[0].productTypeSn
  175. this.form.productTypeSn2 = obj[1].productTypeSn
  176. this.form.productTypeSn3 = obj[2].productTypeSn
  177. }else{
  178. this.typeClean()
  179. }
  180. },
  181. // 清空分类
  182. typeClean(){
  183. this.nowData = []
  184. this.form.productTypeSn1 = undefined
  185. this.form.productTypeSn2 = undefined
  186. this.form.productTypeSn3 = undefined
  187. },
  188. // 清空仓库
  189. clearWarehouse(){
  190. this.warehouseName = ''
  191. this.form.warehouseSn = undefined
  192. },
  193. // 仓库 change
  194. warehouseChange(ind){
  195. this.form.warehouseSn = this.warehouseList[ind].warehouseSn || undefined
  196. this.warehouseName = this.warehouseList[ind].name || ''
  197. },
  198. // 仓库列表
  199. getWarehouse () {
  200. warehouseAllList().then(res => {
  201. if(res.status == 200 && res.data){
  202. this.warehouseList = res.data
  203. // 仓库有值时,匹配对应name
  204. if(this.defaultParams && (this.defaultParams.warehouseSn || this.defaultParams.warehouseSn==0)){
  205. this.warehouseList.map(item => {
  206. if(item.warehouseSn == this.defaultParams.warehouseSn){
  207. this.warehouseName = item.name
  208. }
  209. })
  210. }
  211. }else{
  212. this.warehouseList = []
  213. }
  214. })
  215. },
  216. },
  217. watch: {
  218. // 父页面传过来的弹框状态
  219. openModal (newValue, oldValue) {
  220. this.isShow = newValue
  221. },
  222. // 重定义的弹框状态
  223. isShow (newValue, oldValue) {
  224. if (!newValue) {
  225. this.$emit('close')
  226. }else{
  227. this.init()
  228. }
  229. }
  230. }
  231. }
  232. </script>
  233. <style lang="scss">
  234. .productSearch-wrap{
  235. .search-popup {
  236. .form-content {
  237. display: block;
  238. padding: 0 20upx;
  239. box-sizing: content-box;
  240. .form-item{
  241. .vin-box{
  242. margin-left: 14upx;
  243. position: relative;
  244. .vin-upload{
  245. position: absolute;
  246. right: 0;
  247. top: 0;
  248. }
  249. }
  250. }
  251. .form-item-inp{
  252. display: inline-block;
  253. width: 88%;
  254. vertical-align: top;
  255. }
  256. }
  257. .uni-list-btns {
  258. display: flex;
  259. padding: 20upx;
  260. margin-top: 100upx;
  261. .handle-btn {
  262. font-size: 28upx;
  263. margin: 0 30upx;
  264. width: 100%;
  265. flex: 1;
  266. }
  267. }
  268. }
  269. }
  270. </style>