123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- import Dialog from "../../miniprogram_npm/@vant/weapp/dialog/dialog";
- Page({
- data: {
- uploadImg: "../../assets/accessory/upload.png",
- value: [
- {
- name: "身份证",
- detail: '需要身份证清晰的正反面',
- require: true,
- maxlen: 2,
- key: 1,
- value: [
- // { value: "https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg" }
- ],
- },
- {
- name: "驾驶证",
- detail: '需要驾驶证清晰的正反面',
- require: true,
- maxlen: 2,
- key: 2,
- value: [],
- },
- {
- name: "收入类",
- key: 3,
- value: [],
- },
- {
- name: "半年流水",
- key: 3,
- value: [],
- },
- {
- name: "营业执照",
- key: 4,
- value: [],
- },
- {
- name: "挂靠协议",
- key: 5,
- value: [],
- },
- ]
- },
- // 查看
- seeFunc (e) { wx.previewImage({ current: e.currentTarget.dataset.url, urls: [e.currentTarget.dataset.url] }) },
- // 刪除
- deleteFunc (e) {
- Dialog.confirm({ message: '确认删除吗?' }).then(() => this._delete(e)).catch(() => { });
- },
- async _delete (e) {
- try {
- await wx.$request({ url: `/order/${this.data.id}/deleteImage/`, method: 'post', data: { id: e.currentTarget.dataset.id } });
- let { value } = this.data;
- value[e.currentTarget.dataset.index]['value'].splice(e.currentTarget.dataset.ind, 1);
- this.setData({ value })
- } catch (err) { wx.$err(err) };
- },
- // 添加
- addFunc (e) {
- this.photoAblum(e.currentTarget.dataset.index);
- },
- /**
- * 证件照来源
- * @param {number}
- */
- photoAblum (data) {
- let { value } = this.data;
- let count = value[data].hasOwnProperty('maxlen') ? value[data]['maxlen'] - value[data]['value'].length : 9;
- wx.chooseImage({
- count,
- sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
- success: res => this.request(res.tempFiles, value[data]['key'], data)
- })
- },
- /**
- * 上传图片
- * @param {array} data 图片本地路径 res.tempFiles
- * @param {string} key 订单id
- * @param {string} _index value[_index]
- */
- request (data, key, _index) {
- let { value } = this.data, brr = [], { id } = this.data;
- data.forEach((item, index) => {
- wx.$uploadFile({ url: `/order/${id}/upload_image/`, filePath: item.path, name: 'file', formData: { type: key } }).then(res => {
- value[_index]['value'].push({ value: JSON.parse(res).data.path, key: JSON.parse(res).data.id });
- index == data.length - 1 && end.bind(this)();
- }).catch(err => {
- brr.push(`第${index + 1}张图片上传失败!`);
- index == data.length - 1 && end.bind(this)();
- });
- })
- function end () {
- let obj = { value };
- if (brr.length > 0) {
- obj['errorShow'] = true;
- obj['megs'] = brr;
- };
- this.setData({ ...obj });
- }
- },
- onLoad: function (options) {
- let { value } = this.data;
- if (options.imgs || options.images) {
- options.imgs = JSON.parse(options.imgs);
- options.images = JSON.parse(options.images);
- value = value.map(itemA => {
- if (itemA.hasOwnProperty('maxlen') && options.imgs.length > 0) itemA['disabled'] = true;
- options.imgs.forEach(itemB => {
- if (itemA.key == itemB.name && itemA.hasOwnProperty('maxlen')) {
- itemA["disabled"] = false;
- itemA['errMsg'] = itemB.reason;
- };
- })
- options.images.forEach(itemC => {
- itemC.type == itemA.key && itemA.value.push({ ...itemA, key: itemC.upload_id, value: itemC.url })
- })
- return itemA
- })
- }
- this.setData({ id: options.data, value })
- },
- onReady: function () {
- },
- onShow: function () {
- },
- onHide: function () {
- },
- onUnload: function () {
- },
- onPullDownRefresh: function () {
- },
- onReachBottom: function () {
- }
- })
|