productSearch.vue 10 KB

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