diff --git a/pages/myCar/carDetail.vue b/pages/myCar/carDetail.vue index 0efcdf2..7ba0cf9 100644 --- a/pages/myCar/carDetail.vue +++ b/pages/myCar/carDetail.vue @@ -16,6 +16,7 @@ - - {{ brandList && brandList[arrayIndex] ? brandList[arrayIndex].brandName : '' }} - + + + + { res.data.records.forEach(item => { - item.name = item.brandName, - item.value = item.id + item.text = item.brandName, + item.value = item.id }) this.brandList = res.data.records if (this.car) { for (let i = 0; i < this.brandList.length; i++) { if (this.car.carBrand == this.brandList[i].id) { - this.arrayIndex = i; + this.setCarBrand(this.brandList[i].id,this.brandList[i].brandName) } } } @@ -378,6 +392,9 @@ export default { message: '上传中' }) }) + uni.showLoading({ + title: '正在识别中...' + }); for (let i = 0; i < lists.length; i++) { const result = await this.uploadFilePromise(lists[i].url) let item = this[`fileList${event.name}`][fileListLen] @@ -411,8 +428,7 @@ export default { //车辆品牌自动定位 this.brandList.forEach((item, index) => { if (item.brandName == res.data.brand) { - this.arrayIndex = index; - this.brandId = this.brandList[index].id; + this.setCarBrand(item.brandName.id,item.brandName) } }) //车辆性质自动定位 @@ -422,10 +438,23 @@ export default { this.car.carNature = this.natureList[index].value; } }) + uni.hideLoading() }) }) }) }, + /** + * 设置选中的车辆品牌 + * @param id + * @param name + */ + setCarBrand(id,name){ + this.brandId = id + this.brandName = name + this.$nextTick(()=>{ + this.$refs.songpicker.inputSelected=[{text:name,value:id}] + }) + } } } diff --git a/uni_modules/song-data-picker/components/song-data-picker/song-data-picker.vue b/uni_modules/song-data-picker/components/song-data-picker/song-data-picker.vue new file mode 100644 index 0000000..a1c3dac --- /dev/null +++ b/uni_modules/song-data-picker/components/song-data-picker/song-data-picker.vue @@ -0,0 +1,524 @@ + + + + + diff --git a/uni_modules/song-data-picker/components/uni-badge/uni-badge.vue b/uni_modules/song-data-picker/components/uni-badge/uni-badge.vue new file mode 100644 index 0000000..4291fbc --- /dev/null +++ b/uni_modules/song-data-picker/components/uni-badge/uni-badge.vue @@ -0,0 +1,153 @@ + + + + + diff --git a/uni_modules/song-data-picker/components/uni-data-pickerview/uni-data-picker.js b/uni_modules/song-data-picker/components/uni-data-pickerview/uni-data-picker.js new file mode 100644 index 0000000..7bc0135 --- /dev/null +++ b/uni_modules/song-data-picker/components/uni-data-pickerview/uni-data-picker.js @@ -0,0 +1,468 @@ +export default { + props: { + localdata: { + type: [Array, Object], + default () { + return [] + } + }, + collection: { + type: String, + default: '' + }, + action: { + type: String, + default: '' + }, + field: { + type: String, + default: '' + }, + orderby: { + type: String, + default: '' + }, + where: { + type: [String, Object], + default: '' + }, + pageData: { + type: String, + default: 'add' + }, + pageCurrent: { + type: Number, + default: 1 + }, + pageSize: { + type: Number, + default: 20 + }, + getcount: { + type: [Boolean, String], + default: false + }, + getone: { + type: [Boolean, String], + default: false + }, + gettree: { + type: [Boolean, String], + default: false + }, + manual: { + type: Boolean, + default: false + }, + value: { + type: [Array, String, Number], + default () { + return [] + } + }, + preload: { + type: Boolean, + default: false + }, + stepSearh: { + type: Boolean, + default: true + }, + selfField: { + type: String, + default: '' + }, + parentField: { + type: String, + default: '' + }, + multiple: { + type: Boolean, + default: false + } + }, + data() { + return { + loading: false, + errorMessage: '', + loadMore: { + contentdown: '', + contentrefresh: '', + contentnomore: '' + }, + dataList: [], + selected: [], + selectedIndex: 0, + page: { + current: this.pageCurrent, + size: this.pageSize, + count: 0 + } + } + }, + computed: { + isLocaldata() { + return this.localdata.length > 0 + }, + postField() { + return `${this.field}, ${this.parentField} as parent_value` + }, + postWhere() { + let result = [] + let selected = this.selected + result.push(`${this.parentField} == null`) + if (selected.length) { + for (var i = 0; i < selected.length - 1; i++) { + result.push(`${this.parentField} == '${selected[i].value}'`) + } + } + + if (this.where) { + return `(${this.where}) && (${result.join(' || ')})` + } + + return result.join(' || ') + }, + nodeWhere() { + let result = [] + let selected = this.selected + if (selected.length) { + result.push(`${this.parentField} == '${selected[selected.length - 1].value}'`) + } + + if (this.where) { + return `(${this.where}) && (${result.join(' || ')})` + } + + return result.join(' || ') + } + }, + created() { + this.$watch(() => { + var al = []; + ['pageCurrent', + 'pageSize', + 'value', + 'localdata', + 'collection', + 'action', + 'field', + 'orderby', + 'where', + 'getont', + 'getcount', + 'gettree' + ].forEach(key => { + al.push(this[key]) + }); + return al + }, (newValue, oldValue) => { + let needReset = false + for (let i = 2; i < newValue.length; i++) { + if (newValue[i] != oldValue[i]) { + needReset = true + break + } + } + if (newValue[0] != oldValue[0]) { + this.page.current = this.pageCurrent + } + this.page.size = this.pageSize + + this.onPropsChange() + }) + this._treeData = [] + }, + methods: { + onPropsChange() { + this._treeData = [] + }, + getCommand(options = {}) { + /* eslint-disable no-undef */ + let db = uniCloud.database() + + const action = options.action || this.action + if (action) { + db = db.action(action) + } + + const collection = options.collection || this.collection + db = db.collection(collection) + + const where = options.where || this.where + if (!(!where || !Object.keys(where).length)) { + db = db.where(where) + } + + const field = options.field || this.field + if (field) { + db = db.field(field) + } + + const orderby = options.orderby || this.orderby + if (orderby) { + db = db.orderBy(orderby) + } + + const current = options.pageCurrent !== undefined ? options.pageCurrent : this.page.current + const size = options.pageSize !== undefined ? options.pageSize : this.page.size + const getCount = options.getcount !== undefined ? options.getcount : this.getcount + const getTree = options.gettree !== undefined ? options.gettree : this.gettree + + const getOptions = { + getCount, + getTree + } + if (options.getTreePath) { + getOptions.getTreePath = options.getTreePath + } + + db = db.skip(size * (current - 1)).limit(size).get(getOptions) + + return db + }, + getTreePath(callback) { + if (this.loading) { + return + } + this.loading = true + + this.getCommand({ + field: this.postField, + getTreePath: { + startWith: `${this.selfField}=='${this.value}'` + } + }).then((res) => { + this.loading = false + let treePath = [] + this._extractTreePath(res.result.data, treePath) + this.selected = treePath + callback && callback() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + loadData() { + if (this.isLocaldata) { + this._processLocalData() + return + } + + if (this.value.length) { + this._loadNodeData((data) => { + this._treeData = data + this._updateBindData() + this._updateSelected() + }) + return + } + + if (this.stepSearh) { + this._loadNodeData((data) => { + this._treeData = data + this._updateBindData() + }) + } else { + this._loadAllData((data) => { + this._treeData = [] + this._extractTree(data, this._treeData, null) + this._updateBindData() + }) + } + }, + _loadAllData(callback) { + if (this.loading) { + return + } + this.loading = true + + this.getCommand({ + field: this.postField, + gettree: true, + startwith: `${this.selfField}=='${this.value}'` + }).then((res) => { + this.loading = false + callback(res.result.data) + this.onDataChange() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + _loadNodeData(callback, pw) { + if (this.loading) { + return + } + this.loading = true + + this.getCommand({ + field: this.postField, + where: pw || this.postWhere, + pageSize: 500 + }).then((res) => { + this.loading = false + callback(res.result.data) + this.onDataChange() + }).catch((err) => { + this.loading = false + this.errorMessage = err + }) + }, + _updateSelected() { + var dl = this.dataList + var sl = this.selected + for (var i = 0; i < sl.length; i++) { + var value = sl[i].value + var dl2 = dl[i] + for (var j = 0; j < dl2.length; j++) { + var item2 = dl2[j] + if (item2.value === value) { + sl[i].text = item2.text + break + } + } + } + }, + _updateBindData(node) { + const { + dataList, + hasNodes + } = this._filterData(this._treeData, this.selected) + + let isleaf = this._stepSearh === false && !hasNodes + + if (node) { + node.isleaf = isleaf + } + + this.dataList = dataList + this.selectedIndex = dataList.length - 1 + + if (!isleaf && this.selected.length < dataList.length) { + this.selected.push({ + value: null, + text: "请选择" + }) + } + + return { + isleaf, + hasNodes + } + }, + _filterData(data, paths) { + let dataList = [] + + let hasNodes = true + + dataList.push(data.filter((item) => { + return item.parent_value === undefined + })) + for (let i = 0; i < paths.length; i++) { + var value = paths[i].value + var nodes = data.filter((item) => { + return item.parent_value === value + }) + + if (nodes.length) { + dataList.push(nodes) + } else { + hasNodes = false + } + } + + return { + dataList, + hasNodes + } + }, + _extractTree(nodes, result, parent_value) { + let list = result || [] + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i] + + let child = {} + for (let key in node) { + if (key !== 'children') { + child[key] = node[key] + } + } + if (parent_value !== null) { + child.parent_value = parent_value + } + result.push(child) + + let children = node.children + if (children) { + this._extractTree(children, result, node.value) + } + } + }, + _extractTreePath(nodes, result) { + let list = result || [] + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i] + + let child = {} + for (let key in node) { + if (key !== 'children') { + child[key] = node[key] + } + } + result.push(child) + + let children = node.children + if (children) { + this._extractTreePath(children, result) + } + } + }, + _findNodePath(key, nodes, path = []) { + for (let i = 0; i < nodes.length; i++) { + let { + value, + text, + children + } = nodes[i] + + path.push({ + value, + text + }) + + if (value === key) { + return path + } + + if (children) { + const p = this._findNodePath(key, children, path) + if (p.length) { + return p + } + } + + path.pop() + } + return [] + }, + _processLocalData() { + this._treeData = [] + this._extractTree(this.localdata, this._treeData) + + var inputValue = this.value + if (inputValue === undefined) { + return + } + + if (Array.isArray(inputValue)) { + inputValue = inputValue[inputValue.length - 1] + if (typeof inputValue === 'object' && inputValue.value) { + inputValue = inputValue.value + } + } + + this.selected = this._findNodePath(inputValue, this.localdata) + } + } +} diff --git a/uni_modules/song-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue b/uni_modules/song-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue new file mode 100644 index 0000000..91d1f3b --- /dev/null +++ b/uni_modules/song-data-picker/components/uni-data-pickerview/uni-data-pickerview.vue @@ -0,0 +1,271 @@ + + + + + diff --git a/uni_modules/song-data-picker/components/uni-easyinput/common.js b/uni_modules/song-data-picker/components/uni-easyinput/common.js new file mode 100644 index 0000000..df9abe1 --- /dev/null +++ b/uni_modules/song-data-picker/components/uni-easyinput/common.js @@ -0,0 +1,56 @@ +/** + * @desc 函数防抖 + * @param func 目标函数 + * @param wait 延迟执行毫秒数 + * @param immediate true - 立即执行, false - 延迟执行 + */ +export const debounce = function(func, wait = 1000, immediate = true) { + let timer; + console.log(1); + return function() { + console.log(123); + let context = this, + args = arguments; + if (timer) clearTimeout(timer); + if (immediate) { + let callNow = !timer; + timer = setTimeout(() => { + timer = null; + }, wait); + if (callNow) func.apply(context, args); + } else { + timer = setTimeout(() => { + func.apply(context, args); + }, wait) + } + } +} +/** + * @desc 函数节流 + * @param func 函数 + * @param wait 延迟执行毫秒数 + * @param type 1 使用表时间戳,在时间段开始的时候触发 2 使用表定时器,在时间段结束的时候触发 + */ +export const throttle = (func, wait = 1000, type = 1) => { + let previous = 0; + let timeout; + return function() { + let context = this; + let args = arguments; + if (type === 1) { + let now = Date.now(); + + if (now - previous > wait) { + func.apply(context, args); + previous = now; + } + } else if (type === 2) { + if (!timeout) { + timeout = setTimeout(() => { + timeout = null; + func.apply(context, args) + }, wait) + } + } + } +} diff --git a/uni_modules/song-data-picker/components/uni-easyinput/uni-easyinput.vue b/uni_modules/song-data-picker/components/uni-easyinput/uni-easyinput.vue new file mode 100644 index 0000000..e791d84 --- /dev/null +++ b/uni_modules/song-data-picker/components/uni-easyinput/uni-easyinput.vue @@ -0,0 +1,401 @@ + + + + + diff --git a/uni_modules/song-data-picker/components/uni-icons/icons.js b/uni_modules/song-data-picker/components/uni-icons/icons.js new file mode 100644 index 0000000..60b7332 --- /dev/null +++ b/uni_modules/song-data-picker/components/uni-icons/icons.js @@ -0,0 +1,132 @@ +export default { + "pulldown": "\ue588", + "refreshempty": "\ue461", + "back": "\ue471", + "forward": "\ue470", + "more": "\ue507", + "more-filled": "\ue537", + "scan": "\ue612", + "qq": "\ue264", + "weibo": "\ue260", + "weixin": "\ue261", + "pengyouquan": "\ue262", + "loop": "\ue565", + "refresh": "\ue407", + "refresh-filled": "\ue437", + "arrowthindown": "\ue585", + "arrowthinleft": "\ue586", + "arrowthinright": "\ue587", + "arrowthinup": "\ue584", + "undo-filled": "\ue7d6", + "undo": "\ue406", + "redo": "\ue405", + "redo-filled": "\ue7d9", + "bars": "\ue563", + "chatboxes": "\ue203", + "camera": "\ue301", + "chatboxes-filled": "\ue233", + "camera-filled": "\ue7ef", + "cart-filled": "\ue7f4", + "cart": "\ue7f5", + "checkbox-filled": "\ue442", + "checkbox": "\ue7fa", + "arrowleft": "\ue582", + "arrowdown": "\ue581", + "arrowright": "\ue583", + "smallcircle-filled": "\ue801", + "arrowup": "\ue580", + "circle": "\ue411", + "eye-filled": "\ue568", + "eye-slash-filled": "\ue822", + "eye-slash": "\ue823", + "eye": "\ue824", + "flag-filled": "\ue825", + "flag": "\ue508", + "gear-filled": "\ue532", + "reload": "\ue462", + "gear": "\ue502", + "hand-thumbsdown-filled": "\ue83b", + "hand-thumbsdown": "\ue83c", + "hand-thumbsup-filled": "\ue83d", + "heart-filled": "\ue83e", + "hand-thumbsup": "\ue83f", + "heart": "\ue840", + "home": "\ue500", + "info": "\ue504", + "home-filled": "\ue530", + "info-filled": "\ue534", + "circle-filled": "\ue441", + "chat-filled": "\ue847", + "chat": "\ue263", + "mail-open-filled": "\ue84d", + "email-filled": "\ue231", + "mail-open": "\ue84e", + "email": "\ue201", + "checkmarkempty": "\ue472", + "list": "\ue562", + "locked-filled": "\ue856", + "locked": "\ue506", + "map-filled": "\ue85c", + "map-pin": "\ue85e", + "map-pin-ellipse": "\ue864", + "map": "\ue364", + "minus-filled": "\ue440", + "mic-filled": "\ue332", + "minus": "\ue410", + "micoff": "\ue360", + "mic": "\ue302", + "clear": "\ue434", + "smallcircle": "\ue868", + "close": "\ue404", + "closeempty": "\ue460", + "paperclip": "\ue567", + "paperplane": "\ue503", + "paperplane-filled": "\ue86e", + "person-filled": "\ue131", + "contact-filled": "\ue130", + "person": "\ue101", + "contact": "\ue100", + "images-filled": "\ue87a", + "phone": "\ue200", + "images": "\ue87b", + "image": "\ue363", + "image-filled": "\ue877", + "location-filled": "\ue333", + "location": "\ue303", + "plus-filled": "\ue439", + "plus": "\ue409", + "plusempty": "\ue468", + "help-filled": "\ue535", + "help": "\ue505", + "navigate-filled": "\ue884", + "navigate": "\ue501", + "mic-slash-filled": "\ue892", + "search": "\ue466", + "settings": "\ue560", + "sound": "\ue590", + "sound-filled": "\ue8a1", + "spinner-cycle": "\ue465", + "download-filled": "\ue8a4", + "personadd-filled": "\ue132", + "videocam-filled": "\ue8af", + "personadd": "\ue102", + "upload": "\ue402", + "upload-filled": "\ue8b1", + "starhalf": "\ue463", + "star-filled": "\ue438", + "star": "\ue408", + "trash": "\ue401", + "phone-filled": "\ue230", + "compose": "\ue400", + "videocam": "\ue300", + "trash-filled": "\ue8dc", + "download": "\ue403", + "chatbubble-filled": "\ue232", + "chatbubble": "\ue202", + "cloud-download": "\ue8e4", + "cloud-upload-filled": "\ue8e5", + "cloud-upload": "\ue8e6", + "cloud-download-filled": "\ue8e9", + "headphones":"\ue8bf", + "shop":"\ue609" +} diff --git a/uni_modules/song-data-picker/components/uni-icons/uni-icons.vue b/uni_modules/song-data-picker/components/uni-icons/uni-icons.vue new file mode 100644 index 0000000..5f303e4 --- /dev/null +++ b/uni_modules/song-data-picker/components/uni-icons/uni-icons.vue @@ -0,0 +1,67 @@ + + + + + diff --git a/uni_modules/song-data-picker/components/uni-icons/uni.ttf b/uni_modules/song-data-picker/components/uni-icons/uni.ttf new file mode 100644 index 0000000..60a1968 Binary files /dev/null and b/uni_modules/song-data-picker/components/uni-icons/uni.ttf differ diff --git a/uni_modules/song-data-picker/components/uni-list-item/uni-list-item.vue b/uni_modules/song-data-picker/components/uni-list-item/uni-list-item.vue new file mode 100644 index 0000000..7688e64 --- /dev/null +++ b/uni_modules/song-data-picker/components/uni-list-item/uni-list-item.vue @@ -0,0 +1,440 @@ + + + + + diff --git a/uni_modules/song-data-picker/components/uni-load-more/config.json b/uni_modules/song-data-picker/components/uni-load-more/config.json new file mode 100644 index 0000000..12c5226 --- /dev/null +++ b/uni_modules/song-data-picker/components/uni-load-more/config.json @@ -0,0 +1,10 @@ +{ + "id": "29", + "name": "LoadMore", + "desc": "加载更多", + "url": "load-more", + "type": "功能组件", + "edition": "1.1.5", + "path": "https://ext.dcloud.net.cn/plugin?id=29", + "update_log": "- 新增 颜色大小等配置项" +} diff --git a/uni_modules/song-data-picker/components/uni-load-more/uni-load-more.vue b/uni_modules/song-data-picker/components/uni-load-more/uni-load-more.vue new file mode 100644 index 0000000..9430321 --- /dev/null +++ b/uni_modules/song-data-picker/components/uni-load-more/uni-load-more.vue @@ -0,0 +1,359 @@ + + + + + diff --git a/uni_modules/song-data-picker/manifest.json b/uni_modules/song-data-picker/manifest.json new file mode 100644 index 0000000..9f8baee --- /dev/null +++ b/uni_modules/song-data-picker/manifest.json @@ -0,0 +1,95 @@ +{ + "name" : "", + "appid" : "", + "description": "应用描述", + "versionName": "1.0.0", + "versionCode": "100", + "transformPx": false, + /* 5+App特有相关 */ + "app-plus": { + "usingComponents": true, + "splashscreen": { + "alwaysShowBeforeRender": true, + "waiting": true, + "autoclose": true, + "delay": 0 + }, + "modules": { + "OAuth": {}, + "Payment": {}, + "Push": {}, + "Share": {}, + "Speech": {}, + "VideoPlayer": {} + }, + /* 应用发布信息 */ + "distribute": { + /* android打包配置 */ + "android": { + "permissions": [ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" + ] + }, + /* ios打包配置 */ + "ios": { + "UIBackgroundModes": ["audio"] + }, + /* SDK配置 */ + "sdkConfigs": { + "speech": { + "ifly": {} + } + }, + "orientation": ["portrait-primary"] + } + }, + /* 快应用特有相关 */ + "quickapp": {}, + /* 小程序特有相关 */ + "mp-weixin": { + "appid": "", + "setting": { + "urlCheck": false + }, + "usingComponents": true + }, + "h5": { + "template": "template.h5.html", + "router": { + "mode": "history", + "base": "/h5/" + } + } +} diff --git a/uni_modules/song-data-picker/package.json b/uni_modules/song-data-picker/package.json new file mode 100644 index 0000000..94e4c88 --- /dev/null +++ b/uni_modules/song-data-picker/package.json @@ -0,0 +1,13 @@ +{ + "id": "song-data-picker", + "name": "基于DataPicker(uni-data-picker)的带有搜索功能的选择器", + "version": "0.1.2", + "description": "在uni官方的DataPicker(uni-data-picker)基础上添加搜索功能", + "keywords": [ + "picker", + "级联", + "省市区", + "地址", + "搜索" + ] +} \ No newline at end of file