productSearch.vue 9.9 KB

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