|
|
@@ -11,10 +11,6 @@ Component({
|
|
|
fileList: {
|
|
|
type: Array
|
|
|
},
|
|
|
- /* 父页面传递图片 */
|
|
|
- attinfos: {
|
|
|
- type: Object
|
|
|
- },
|
|
|
/* 上传类型 Logo-品牌logo userImage-用户头像 productImage-产品图片 SupplyAndDemand-供需*/
|
|
|
upType: {
|
|
|
type: String
|
|
|
@@ -47,10 +43,6 @@ Component({
|
|
|
imageChange: {
|
|
|
type: Function
|
|
|
},
|
|
|
- /* 产品ID */
|
|
|
- tagents_productid: {
|
|
|
- type: String
|
|
|
- },
|
|
|
/* 图片尺寸 */
|
|
|
previewSize: {
|
|
|
type: String,
|
|
|
@@ -61,16 +53,47 @@ Component({
|
|
|
type: Boolean,
|
|
|
value: false
|
|
|
},
|
|
|
+ /* 供需产品id */
|
|
|
tsupplyanddemand: {
|
|
|
type: Number
|
|
|
}
|
|
|
},
|
|
|
+ /* 生命周期 */
|
|
|
+ lifetimes: {
|
|
|
+ attached: function () {
|
|
|
+ // 图片临时 id = 数字类型的 userid + 去掉前五位的时间戳
|
|
|
+ const forTheTimeId = parseInt(wx.getStorageSync('userData').userid + (Date.parse(new Date()).toString().slice(5)));
|
|
|
+ this.setData({
|
|
|
+ forTheTimeId
|
|
|
+ })
|
|
|
+ },
|
|
|
+ detached: function () {
|
|
|
+ // 在组件实例被从页面节点树移除时执行
|
|
|
+ if (this.data.ExitTheDelete) return;
|
|
|
+ const data = this.data.fileList.filter((value) => value.ownerid == 0);
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.system.docManage",
|
|
|
+ "method": "deleteDoc",
|
|
|
+ "content": {
|
|
|
+ "ownertable": data[i].ownertable,
|
|
|
+ "ownerid": data[i].ownerid,
|
|
|
+ "tattachmentid": data[i].tattachmentid
|
|
|
+ }
|
|
|
+ }).then((res) => {
|
|
|
+ if (res.msg != "成功") return;
|
|
|
+ console.log("附件删除成功")
|
|
|
+ })
|
|
|
+ };
|
|
|
+ },
|
|
|
+ },
|
|
|
|
|
|
/**
|
|
|
* 组件的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
-
|
|
|
+ ExitTheDelete: false,
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -79,7 +102,6 @@ Component({
|
|
|
methods: {
|
|
|
/* 文件校验 */
|
|
|
beforeRead(event) {
|
|
|
- console.log("文件校验")
|
|
|
const {
|
|
|
file,
|
|
|
callback
|
|
|
@@ -110,20 +132,81 @@ Component({
|
|
|
/* 上传图片 */
|
|
|
afterRead(event) {
|
|
|
// 初始化数据
|
|
|
- var that = this;
|
|
|
- const {
|
|
|
- file
|
|
|
- } = event.detail;
|
|
|
+ let that = this,
|
|
|
+ data = this.requestType(event.detail.file);
|
|
|
+ //发送请求
|
|
|
+ wx.getFileSystemManager().readFile({
|
|
|
+ filePath: event.detail.file.url,
|
|
|
+ success: result => {
|
|
|
+ //返回临时文件路径
|
|
|
+ const fileData = result.data
|
|
|
+ _Http.basic(data).then(res => {
|
|
|
+ that.uploadFile(res, fileData)
|
|
|
+ }).catch(err => {})
|
|
|
+ },
|
|
|
+ fail: console.error
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 上传成功反馈 */
|
|
|
+ uploadFile(res, data) {
|
|
|
+ var that = this
|
|
|
+ wx.request({
|
|
|
+ url: res.data.obsuploadurl,
|
|
|
+ method: "PUT",
|
|
|
+ data: data,
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/octet-stream' // 默认值
|
|
|
+ },
|
|
|
+ success() {
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.system.docManage",
|
|
|
+ "method": "uploadSuccess",
|
|
|
+ "content": {
|
|
|
+ "obsfilename": res.data.obsfilename
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ if (res.msg != "成功") return;
|
|
|
+ let fileList = that.data.fileList;
|
|
|
+ for (let i = 0; i < res.data.length; i++) {
|
|
|
+ let arr = {
|
|
|
+ url: res.data[i].fobsurl,
|
|
|
+ ownerid: res.data[i].ownerid,
|
|
|
+ tattachmentid: res.data[i].tattachmentid,
|
|
|
+ ownertable: res.data[i].ownertable,
|
|
|
+ fdocument: res.data[i].fdocument,
|
|
|
+ }
|
|
|
+ fileList.push(arr)
|
|
|
+ };
|
|
|
+ // 用户头像 先删除 在修改
|
|
|
+ if (that.data.upType == "userImage" && fileList.length >= 2) {
|
|
|
+ that.dleeteDealWith(0);
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ fileList
|
|
|
+ });
|
|
|
+ /* 返回数据 */
|
|
|
+ that.triggerEvent("imageChange", {
|
|
|
+ fileList
|
|
|
+ })
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 请求类型 */
|
|
|
+ requestType(file) {
|
|
|
//获取文件后缀
|
|
|
var index = file.url.lastIndexOf(".");
|
|
|
var ext = file.url.substr(index + 1);
|
|
|
//文件名称
|
|
|
const timestamp = Date.parse(new Date());;
|
|
|
- let data = {};
|
|
|
//不同类型图片数据
|
|
|
if (this.data.upType == 'Logo') {
|
|
|
//logo上传
|
|
|
- data = {
|
|
|
+ return {
|
|
|
"accesstoken": wx.getStorageSync('userData').token,
|
|
|
"classname": "system.system.docManage",
|
|
|
"method": "getFileName",
|
|
|
@@ -137,7 +220,7 @@ Component({
|
|
|
}
|
|
|
} else if (this.data.upType == 'userImage') {
|
|
|
//头像上传
|
|
|
- data = {
|
|
|
+ return {
|
|
|
"accesstoken": wx.getStorageSync('userData').token,
|
|
|
"classname": "system.system.docManage",
|
|
|
"method": "getFileName",
|
|
|
@@ -151,98 +234,33 @@ Component({
|
|
|
}
|
|
|
} else if (this.data.upType == 'productImage') {
|
|
|
//产品图片上传
|
|
|
- data = {
|
|
|
+ return {
|
|
|
"accesstoken": wx.getStorageSync('userData').token,
|
|
|
"classname": "system.system.docManage",
|
|
|
"method": "getFileName",
|
|
|
"content": {
|
|
|
"filename": timestamp,
|
|
|
"filetype": ext,
|
|
|
- "ownertable": "tagents_product",
|
|
|
- "ownerid": this.data.tagents_productid,
|
|
|
+ "ownertable": this.data.forTheTimeId,
|
|
|
+ "ownerid": 0,
|
|
|
"ftype": "default"
|
|
|
}
|
|
|
}
|
|
|
} else if (this.data.upType == "SupplyAndDemand") {
|
|
|
//供需附件上传
|
|
|
- data = {
|
|
|
+ return {
|
|
|
"accesstoken": wx.getStorageSync('userData').token,
|
|
|
"classname": "system.system.docManage",
|
|
|
"method": "getFileName",
|
|
|
"content": {
|
|
|
"filename": timestamp,
|
|
|
"filetype": ext,
|
|
|
- "ownertable": "tsupplyanddemand",
|
|
|
- "ownerid": this.data.tsupplyanddemand,
|
|
|
+ "ownertable": this.data.forTheTimeId,
|
|
|
+ "ownerid": 0,
|
|
|
"ftype": "default"
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //发送请求
|
|
|
- wx.getFileSystemManager().readFile({
|
|
|
- filePath: file.url,
|
|
|
- success: result => {
|
|
|
- //返回临时文件路径
|
|
|
- const fileData = result.data
|
|
|
- _Http.basic(data).then(res => {
|
|
|
- that.uploadFile(res, fileData)
|
|
|
- }).catch(err => {})
|
|
|
- },
|
|
|
- fail: console.error
|
|
|
- })
|
|
|
- },
|
|
|
- /* 上传成功反馈 */
|
|
|
- uploadFile(res, data) {
|
|
|
- var that = this
|
|
|
- wx.request({
|
|
|
- url: res.data.obsuploadurl,
|
|
|
- method: "PUT",
|
|
|
- data: data,
|
|
|
- header: {
|
|
|
- 'content-type': 'application/octet-stream' // 默认值
|
|
|
- },
|
|
|
- success() {
|
|
|
- _Http.basic({
|
|
|
- "accesstoken": wx.getStorageSync('userData').token,
|
|
|
- "classname": "system.system.docManage",
|
|
|
- "method": "uploadSuccess",
|
|
|
- "content": {
|
|
|
- "obsfilename": res.data.obsfilename
|
|
|
- }
|
|
|
- }).then(res => {
|
|
|
- console.log(res)
|
|
|
- if (res.msg != "成功") return;
|
|
|
- let fileList = that.data.fileList;
|
|
|
- for (let i = 0; i < res.data.length; i++) {
|
|
|
- let arr = {
|
|
|
- url: res.data[i].fobsurl,
|
|
|
- ownerid: res.data[i].ownerid,
|
|
|
- tattachmentid: res.data[i].tattachmentid
|
|
|
- }
|
|
|
- fileList.push(arr)
|
|
|
- };
|
|
|
- if (that.data.upType != "userImage") {
|
|
|
- //普通返回
|
|
|
- that.setData({
|
|
|
- fileList
|
|
|
- });
|
|
|
- that.triggerEvent("imageChange", {
|
|
|
- fileList
|
|
|
- })
|
|
|
- } else {
|
|
|
- // 需要返回到父组件中 userImage
|
|
|
- if (that.data.attinfos != null) {
|
|
|
- that.dleeteDealWith();
|
|
|
- }
|
|
|
- that.triggerEvent("imageChange", {
|
|
|
- fileList
|
|
|
- })
|
|
|
- }
|
|
|
- }).catch(err => {
|
|
|
- console.log(err)
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
},
|
|
|
/* 删除文件 */
|
|
|
imagesDelete(e) {
|
|
|
@@ -261,55 +279,54 @@ Component({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ /* 保存退出,修改附件位置 */
|
|
|
+ saveTheChanges(obj) {
|
|
|
+ const data = this.data.fileList.filter((value) => value.ownerid == 0);
|
|
|
+ this.setData({
|
|
|
+ ExitTheDelete: true
|
|
|
+ })
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ obj.tattachmentid = data[i].tattachmentid;
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.system.docManage",
|
|
|
+ "method": "changeFilesData",
|
|
|
+ "content": {
|
|
|
+ "files": [{
|
|
|
+ "tattachmentid": data[i].tattachmentid,
|
|
|
+ "fdocument": data[i].fdocument,
|
|
|
+ "ownertable": obj.ownertable,
|
|
|
+ "ownerid": obj.ownerid
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
/* 处理删除 */
|
|
|
dleeteDealWith(index) {
|
|
|
const that = this;
|
|
|
- let ownertable = '';
|
|
|
- if (that.data.upType == 'Logo') {
|
|
|
- //品牌logo
|
|
|
- ownertable = "tagents"
|
|
|
- } else if (that.data.upType == 'userImage') {
|
|
|
- //用户头像
|
|
|
- ownertable = "tenterprise_users"
|
|
|
- } else if (that.data.upType == "SupplyAndDemand") {
|
|
|
- ownertable = "tsupplyanddemand"
|
|
|
- };
|
|
|
- let content = {}
|
|
|
- if (that.data.upType != "userImage") {
|
|
|
- //图片在本页面
|
|
|
- content = {
|
|
|
- "ownertable": ownertable,
|
|
|
- "ownerid": that.data.fileList[index].ownerid,
|
|
|
- "tattachmentid": that.data.fileList[index].tattachmentid
|
|
|
- }
|
|
|
- } else {
|
|
|
- //图片在父组件
|
|
|
- content = {
|
|
|
- "ownertable": ownertable,
|
|
|
- "ownerid": that.data.attinfos.ownerid,
|
|
|
- "tattachmentid": that.data.attinfos.tattachmentid
|
|
|
- }
|
|
|
- }
|
|
|
+ const type = that.data.fileList[index];
|
|
|
_Http.basic({
|
|
|
"accesstoken": wx.getStorageSync('userData').token,
|
|
|
"classname": "system.system.docManage",
|
|
|
"method": "deleteDoc",
|
|
|
- "content": content
|
|
|
+ "content": {
|
|
|
+ "ownertable": type.ownertable,
|
|
|
+ "ownerid": type.ownerid,
|
|
|
+ "tattachmentid": type.tattachmentid
|
|
|
+ }
|
|
|
}).then(s => {
|
|
|
if (s.msg != '成功') return;
|
|
|
- if (that.data.upType != "userImage") {
|
|
|
- let fileList = that.data.fileList;
|
|
|
- fileList.splice(index - 1, 1);
|
|
|
- // 需要返回到父组件中 userImage
|
|
|
- that.triggerEvent("imageChange", {
|
|
|
- fileList
|
|
|
- })
|
|
|
- that.setData({
|
|
|
- fileList
|
|
|
- })
|
|
|
- } else {
|
|
|
- console.log("删除成功")
|
|
|
- }
|
|
|
+ let fileList = that.data.fileList;
|
|
|
+ fileList.splice(index, 1);
|
|
|
+ that.triggerEvent("imageChange", {
|
|
|
+ fileList
|
|
|
+ })
|
|
|
+ that.setData({
|
|
|
+ fileList
|
|
|
+ })
|
|
|
console.log("删除成功")
|
|
|
})
|
|
|
},
|