Commit 0f071587 authored by xiangzj's avatar xiangzj

选择终端

parent 405f6f47
{
"javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": true
}
\ No newline at end of file
# image-tools
图像转换工具,可用于如下环境:uni-app、微信小程序、5+APP、浏览器(需允许跨域)
## 使用方式
### NPM
```
npm i image-tools --save
```
```js
import { pathToBase64, base64ToPath } from 'image-tools'
```
### 直接下载
```js
// 以下路径需根据项目实际情况填写
import { pathToBase64, base64ToPath } from '../../js/image-tools/index.js'
```
## API
### pathToBase64
从图像路径转换为base64,uni-app、微信小程序和5+APP使用的路径不支持网络路径,如果是网络路径需要先使用下载API下载下来。
```js
pathToBase64(path)
.then(base64 => {
console.log(base64)
})
.catch(error => {
console.error(error)
})
```
### base64ToPath
将图像base64保存为文件,返回文件路径。
```js
base64ToPath(base64)
.then(path => {
console.log(path)
})
.catch(error => {
console.error(error)
})
```
## 提示
可以利用promise来串行和并行的执行多个任务
```js
// 并行
Promise.all(paths.map(path => pathToBase64(path)))
.then(res => {
console.log(res)
// [base64, base64...]
})
.catch(error => {
console.error(error)
})
// 串行
paths.reduce((promise, path) => promise.then(res => pathToBase64(path).then(base64 => (res.push(base64), res))), Promise.resolve([]))
.then(res => {
console.log(res)
// [base64, base64...]
})
.catch(error => {
console.error(error)
})
```
\ No newline at end of file
function getLocalFilePath(path) {
if (path.indexOf('_www') === 0 || path.indexOf('_doc') === 0 || path.indexOf('_documents') === 0 || path.indexOf('_downloads') === 0) {
return path
}
if (path.indexOf('file://') === 0) {
return path
}
if (path.indexOf('/storage/emulated/0/') === 0) {
return path
}
if (path.indexOf('/') === 0) {
var localFilePath = plus.io.convertAbsoluteFileSystem(path)
if (localFilePath !== path) {
return localFilePath
} else {
path = path.substr(1)
}
}
return '_www/' + path
}
function dataUrlToBase64(str) {
var array = str.split(',')
return array[array.length - 1]
}
var index = 0
function getNewFileId() {
return Date.now() + String(index++)
}
function biggerThan(v1, v2) {
var v1Array = v1.split('.')
var v2Array = v2.split('.')
var update = false
for (var index = 0; index < v2Array.length; index++) {
var diff = v1Array[index] - v2Array[index]
if (diff !== 0) {
update = diff > 0
break
}
}
return update
}
export function pathToBase64(path) {
return new Promise(function(resolve, reject) {
if (typeof window === 'object' && 'document' in window) {
if (typeof FileReader === 'function') {
var xhr = new XMLHttpRequest()
xhr.open('GET', path, true)
xhr.responseType = 'blob'
xhr.onload = function() {
if (this.status === 200) {
let fileReader = new FileReader()
fileReader.onload = function(e) {
resolve(e.target.result)
}
fileReader.onerror = reject
fileReader.readAsDataURL(this.response)
}
}
xhr.onerror = reject
xhr.send()
return
}
var canvas = document.createElement('canvas')
var c2x = canvas.getContext('2d')
var img = new Image
img.onload = function() {
canvas.width = img.width
canvas.height = img.height
c2x.drawImage(img, 0, 0)
resolve(canvas.toDataURL())
canvas.height = canvas.width = 0
}
img.onerror = reject
img.src = path
return
}
if (typeof plus === 'object') {
plus.io.resolveLocalFileSystemURL(getLocalFilePath(path), function(entry) {
entry.file(function(file) {
var fileReader = new plus.io.FileReader()
fileReader.onload = function(data) {
resolve(data.target.result)
}
fileReader.onerror = function(error) {
reject(error)
}
fileReader.readAsDataURL(file)
}, function(error) {
reject(error)
})
}, function(error) {
reject(error)
})
return
}
if (typeof wx === 'object' && wx.canIUse('getFileSystemManager')) {
wx.getFileSystemManager().readFile({
filePath: path,
encoding: 'base64',
success: function(res) {
resolve('data:image/png;base64,' + res.data)
},
fail: function(error) {
reject(error)
}
})
return
}
reject(new Error('not support'))
})
}
export function base64ToPath(base64) {
return new Promise(function(resolve, reject) {
if (typeof window === 'object' && 'document' in window) {
base64 = base64.split(',')
var type = base64[0].match(/:(.*?);/)[1]
var str = atob(base64[1])
var n = str.length
var array = new Uint8Array(n)
while (n--) {
array[n] = str.charCodeAt(n)
}
return resolve((window.URL || window.webkitURL).createObjectURL(new Blob([array], { type: type })))
}
var extName = base64.split(',')[0].match(/data\:\S+\/(\S+);/)
if (extName) {
extName = extName[1]
} else {
reject(new Error('base64 error'))
}
var fileName = getNewFileId() + '.' + extName
if (typeof plus === 'object') {
var basePath = '_doc'
var dirPath = 'uniapp_temp'
var filePath = basePath + '/' + dirPath + '/' + fileName
if (!biggerThan(plus.os.name === 'Android' ? '1.9.9.80627' : '1.9.9.80472', plus.runtime.innerVersion)) {
plus.io.resolveLocalFileSystemURL(basePath, function(entry) {
entry.getDirectory(dirPath, {
create: true,
exclusive: false,
}, function(entry) {
entry.getFile(fileName, {
create: true,
exclusive: false,
}, function(entry) {
entry.createWriter(function(writer) {
writer.onwrite = function() {
resolve(filePath)
}
writer.onerror = reject
writer.seek(0)
writer.writeAsBinary(dataUrlToBase64(base64))
}, reject)
}, reject)
}, reject)
}, reject)
return
}
var bitmap = new plus.nativeObj.Bitmap(fileName)
bitmap.loadBase64Data(base64, function() {
bitmap.save(filePath, {}, function() {
bitmap.clear()
resolve(filePath)
}, function(error) {
bitmap.clear()
reject(error)
})
}, function(error) {
bitmap.clear()
reject(error)
})
return
}
if (typeof wx === 'object' && wx.canIUse('getFileSystemManager')) {
var filePath = wx.env.USER_DATA_PATH + '/' + fileName
wx.getFileSystemManager().writeFile({
filePath: filePath,
data: dataUrlToBase64(base64),
encoding: 'base64',
success: function() {
resolve(filePath)
},
fail: function(error) {
reject(error)
}
})
return
}
reject(new Error('not support'))
})
}
\ No newline at end of file
{
"_from": "image-tools",
"_id": "image-tools@1.4.0",
"_inBundle": false,
"_integrity": "sha512-TKtvJ6iUwM0mfaD4keMnk1ENHFC470QEjBfA3IlvKdEOufzvWbjbaoNcoyYq6HlViF8+d5tOS1ooE6j7CHf1lQ==",
"_location": "/image-tools",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "image-tools",
"name": "image-tools",
"escapedName": "image-tools",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmmirror.com/image-tools/-/image-tools-1.4.0.tgz",
"_shasum": "66aacbafad677af7f3fd7f32f8fa1e0881b83783",
"_spec": "image-tools",
"_where": "C:\\Users\\86183\\Desktop\\wly-app",
"author": {
"name": "Shengqiang Guo"
},
"bugs": {
"url": "https://github.com/zhetengbiji/image-tools/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "图像转换工具,可用于如下环境:uni-app、微信小程序、5+APP、浏览器",
"devDependencies": {
"@types/html5plus": "^1.0.0"
},
"homepage": "https://github.com/zhetengbiji/image-tools#readme",
"keywords": [
"base64"
],
"license": "ISC",
"main": "index.js",
"name": "image-tools",
"repository": {
"type": "git",
"url": "git+https://github.com/zhetengbiji/image-tools.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.4.0"
}
......@@ -106,9 +106,19 @@
<!-- <image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode=""></image> -->
</view>
</view>
<view class="text-block" v-if="orderItem.demandType=='ZDZG'">
<view class="text-block" @click="goTerminal" v-if="orderItem.demandType=='ZDZG'">
<text class="middle-date">收货终端</text>
<view class="middle-date-address uni-list picker-year">
<view class="middle-date-des uni-list picker-year" >
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<text class="uni-input">{{orderItem.terminalName}}</text>
</view>
</view>
<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode=""></image>
</view>
<!-- <view class="middle-date-address uni-list picker-year">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker class="picker-block" @change="bindPickerChange($event,'terminalRobot')" :value="orderItem.terminalId"
......@@ -118,7 +128,7 @@
</view>
</view>
<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode=""></image>
</view>
</view> -->
</view>
</view>
......@@ -259,12 +269,21 @@
_this.orderItem.kaStoreShortname = data.selectSalePlaceAccountInfo.shortName
_this.orderItem.kaStoreArea = data.selectSalePlaceAccountInfo.area
})
// 选择终端
uni.$on('selectTerminal', function(data) {
console.log('监听到事件来自 selectTerminal ,携带参数 msg 为:', data);
_this.orderItem.terminalName = data.selectTerminal.storeName
_this.orderItem.terminalId = data.selectTerminal.storeId
_this.orderItem.receiveUnitName = data.selectTerminal.storeName
})
},
onUnload() {
uni.$off('selectSalePlaceAccountInfo')
uni.$off('selectTerminal')
},
beforeDestroy() {
uni.$off('selectSalePlaceAccountInfo')
uni.$off('selectTerminal')
},
created() {
// 发货计划类型:A0002
......@@ -285,6 +304,15 @@
// }
},
methods: {
goTerminal() {
const params= {
dealerId: this.orderItem.customerCode,
inventoryCode: this.orderItem.brand
}
uni.navigateTo({
url: `/pages/select-terminal/select-terminal??params=${JSON.stringify(params)}`
})
},
getDate() {
const date = new Date();
let year = date.getFullYear();
......
......@@ -711,9 +711,9 @@
return
}
}
if(!this.orderItem.receiveAddress){
if(!this.orderItem.contacPerson){
uni.showToast({
title: '请先选择收货地址',
title: '请先选择联系人',
duration: 2000,
icon: 'none'
});
......@@ -727,9 +727,9 @@
});
return
}
if(!this.orderItem.contacPerson){
if(!this.orderItem.receiveAddress){
uni.showToast({
title: '请先选择联系人',
title: '请先选择收货地址',
duration: 2000,
icon: 'none'
});
......@@ -1174,5 +1174,6 @@
.edit-add{
text-align: right;
padding-top: 10px;
font-size: 28rpx;
}
</style>
......@@ -2,7 +2,7 @@
<view class="apply-history view" :style="winHeight">
<view class="status_bar" :style="navHeight"></view>
<view class="apply-history-wrapper view">
<component :style="componentHeight" :sourceType='sourceType' :orderItem='detail' :channelTypeArr='channelTypeArr' :terminalRobotArrs=terminalRobotArrs :is="currentTabComponent" @click="changeComponent" @submit="submit" ></component>
<component :style="componentHeight" :sourceType='sourceType' :orderItem='detail' :channelTypeArr='channelTypeArr' :is="currentTabComponent" @click="changeComponent" @submit="submit" ></component>
</view>
</view>
</template>
......@@ -159,7 +159,7 @@
demandTypeTextView: res.data.demandType == 'ZDZG' ? '终端直配' : '',
}
this.getChannelType()
res.data.demandType == 'ZDZG' && this.getTerminalRobot()
// res.data.demandType == 'ZDZG' && this.getTerminalRobot()
},
async getChannelType(){
const res = await getChannelType({'salePlan': this.detail.planType})
......@@ -200,12 +200,13 @@
demandType: this.demandType ==1 ? '' : 'ZDZG',
demandTypeTextView: this.demandType ==1 ? '' : '终端直配',
terminalId: '',
terminalName: '',
terminalIdTextView: '',
receiveUnitName: res.data.demandType == 'ZDZG' ? '' : res.data.receiveUnitName,
}
this.getChannelType()
this.sourceType === 'purchase' && this.generateUUID()
this.demandType == 2 && this.getTerminalRobot()
// this.demandType == 2 && this.getTerminalRobot()
},
// 绑定终端
getTerminalRobot(){
......
<template>
<view class="lists">
<view class="status_bar" :style="navHeight"></view>
<view class="header-bg">
<image class="header-bg-img" src="@/static/image/nav_bg@3x.png" mode="scaleToFill"></image>
</view>
<view class="main">
<view class="middle view">
<view class="text-block ">
<text class="middle-date">终端名称</text>
<input class="middle-date-des" type="text" v-model="condition.storeName" placeholder="" />
</view>
</view>
<view class="planout-block">
<button class="btn" type="default" @tap="search">
<text class="btn-text">查询</text>
</button>
</view>
<scroll-view class="scroll-area" :style='scrollHeight' scroll-y="true" lower-threshold='150'
@scrolltolower='scrolltolower'>
<view class="middle view planout-block-item" v-for="(item,index) in lists" :key='index'
@click="handleClick($event,item, index)">
<view class="text-block">
<text class="middle-date middle-date-select">终端名称</text>
<text class="middle-date-des middle-date-des-select">{{item.storeName}}</text>
</view>
<view class="text-block">
<text class="middle-date middle-date-select">终端ID</text>
<text class="middle-date-pro middle-date-des-select">{{item.storeId}}</text>
</view>
</view>
<view class="loading-more" v-if='lists.length>2'>
<text class="loading-more-text">{{loadingText}}</text>
</view>
</scroll-view>
</view>
</view>
</template>
<script>
import {
mapState
} from 'vuex'
import { queryDirectStore } from '@/servers/purchaseList.js'
export default {
data() {
return {
isOpened: 'none',
loadingText: '加载中...',
condition: {
storeName: '',
},
lists: [],
pageOption: {
current: 1,
size: 50
},
totalCount: 0,
totalPage: 0,
terminalQureyParams: {}
}
},
computed: {
...mapState(['sysinfo']),
navHeight() {
return {
'height': `${this.sysinfo.safeArea.top + 44}px`
}
},
scrollHeight() {
return {
'height': `${this.sysinfo.safeArea.height - 237- 44 - 20}px`
}
},
pagination(){
return{
page: this.pageOption.current,
pagesize: this.pageOption.size,
totalCount: this.totalCount,
}
}
},
onPullDownRefresh() {
this.reset()
this.getProduct(true)
setTimeout(function() {
uni.stopPullDownRefresh();
}, 600);
},
onLoad(option) {
this.terminalQureyParams = {
...JSON.parse(option.params)
}
},
created() {
this.reset()
this.getProduct(true);
},
methods: {
async getProduct(isRefresh) {
const params = { page:this.pageOption, ...this.terminalQureyParams, ...this.condition }
uni.showLoading({
title: '加载中'
});
setTimeout(function() {
uni.hideLoading();
}, 2000);
const res = await queryDirectStore(params)
uni.hideLoading();
const {
records,
total
} = res.data.data
this.totalCount = total
this.totalPage = Math.ceil(total * 1 / this.pageOption.size * 1)
if (isRefresh) {
this.lists = records
} else {
this.lists = this.lists.concat(records)
}
},
scrolltolower() {
console.log('onReachBottom');
if (this.pageOption.current < this.totalPage) {
this.pageOption.current++
this.getProduct()
} else {
this.loadingText = '-- 到底了 --'
}
},
reset() {
this.condition = {
storeName: '',
},
this.pageOption = {
current: 1,
size: 50
},
this.lists = []
this.loadingText = '加载中'
},
search() {
this.pageOption = {
current: 1,
size: 50
},
this.lists = []
this.getProduct(true)
},
handleClick(e, content, index) {
console.log(e, content, index)
uni.$emit('selectTerminal', {
selectTerminal: content
})
uni.navigateBack()
}
}
}
</script>
<style lang="scss" scoped>
.view {
flex-direction: column;
}
.header-bg {
height: 284rpx;
margin-top: -88rpx;
}
.header-bg-img {
width: 750rpx;
}
.lists {
position: relative;
flex-direction: column;
overflow-y: scroll;
background: #f0f4f5;
overflow-x: hidden;
height: 100vh;
}
.main {
position: relative;
flex-direction: column;
margin-top: -164rpx;
padding: 0 16rpx;
}
.middle {
background-color: #fff;
border-radius: 16rpx;
padding: 32rpx;
}
.text-block {
display: flex;
overflow: hidden;
height: 96rpx;
margin-bottom: 14rpx;
border-bottom: 1px solid #f4f5f6;
}
.text-block-last {
margin-bottom: 0;
border-bottom: 0;
}
.middle-date {
flex: 2;
font-size: 28rpx;
line-height: 96rpx;
color: #333;
margin-bottom: 8rpx;
}
.middle-date-des {
flex: 3;
font-size: 28rpx;
line-height: 96rpx;
height: 96rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #888;
}
.middle-date-pro {
flex: 3;
font-size: 28rpx;
height: 96rpx;
color: #888;
word-break: break-all;
padding-right: 4px;
}
.middle-date-select {
color: #888;
}
.middle-date-des-select {
color: #333;
}
.picker-year {
position: relative;
border-radius: 4px;
align-items: center;
}
.uni-list-cell {
flex: 1;
}
.uni-list-cell-db {
flex: 1;
}
.picker-block {
flex: 1;
}
.icon-arrow {
position: absolute;
right: 0;
top: 16px;
width: 12rpx;
height: 20rpx;
z-index: 10;
}
.scroll-area {
overflow-y: scroll;
}
.planout-block-lists {
display: flex;
flex-direction: column;
}
.uni-swipe {
flex: 1;
margin-bottom: 26rpx;
}
/deep/ .uni-swipe_box {
flex: 1;
}
.swipe-right-block {
display: flex;
width: 100rpx;
justify-content: center;
align-items: center;
}
.swipe-right-block__text {
display: inline-block;
width: 52rpx;
height: 52rpx;
border-radius: 50%;
background-color: #fff;
}
.swipe-right-block__active {
width: 52rpx;
height: 52rpx;
border-radius: 50%;
background-color: $wly-primary-color;
}
.planout-block {
display: flex;
justify-content: space-between;
height: 84rpx;
margin-top: 64rpx;
margin-bottom: 48rpx;
padding: 0 24rpx;
}
.planout-block-item {
flex: 1;
width: 750rpx;
margin-bottom: 26rpx;
}
.btn {
flex: 1;
height: 92rpx;
background: $wly-primary-color;
border-radius: 46rpx;
}
.btn-text {
color: #fff;
font-size: 34rpx;
}
.loading-more {
flex: 1;
align-items: center;
justify-content: center;
padding-top: 14px;
padding-bottom: 14px;
text-align: center;
}
.loading-more-text {
font-size: 12px;
color: #999;
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment