index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import Dialog from "../../miniprogram_npm/@vant/weapp/dialog/dialog";
  2. Page({
  3. data: {
  4. uploadImg: "../../assets/accessory/upload.png",
  5. value: [
  6. {
  7. name: "身份证",
  8. maxlen: 2,
  9. key: 1,
  10. value: [
  11. // { value: "https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg" }
  12. ],
  13. },
  14. {
  15. name: "驾驶证",
  16. maxlen: 2,
  17. key: 2,
  18. value: [],
  19. },
  20. {
  21. name: "收入类",
  22. key: 3,
  23. value: [],
  24. },
  25. {
  26. name: "半年流水",
  27. key: 3,
  28. value: [],
  29. },
  30. {
  31. name: "营业执照",
  32. key: 4,
  33. value: [],
  34. },
  35. {
  36. name: "挂靠协议",
  37. key: 5,
  38. value: [],
  39. },
  40. ]
  41. },
  42. // 查看
  43. seeFunc (e) { wx.previewImage({ current: e.currentTarget.dataset.url, urls: [e.currentTarget.dataset.url] }) },
  44. // 刪除
  45. async deleteFunc (e) {
  46. try {
  47. await wx.$request({ url: `/order/${this.id}/deleteImage/`, method: 'post', data: { id: e.currentTarget.dataset } });
  48. let { value } = this.data;
  49. value[e.currentTarget.dataset.index]['value'].splice(e.currentTarget.dataset.ind, 1);
  50. } catch (err) { wx.$err(er) };
  51. },
  52. //修改
  53. // updateFunc (e) {
  54. // this.photoAblum(e.currentTarget.dataset.index);
  55. // },
  56. // 添加
  57. addFunc (e) {
  58. this.photoAblum(e.currentTarget.dataset.index);
  59. },
  60. /**
  61. * 证件照来源
  62. * @param {number}
  63. */
  64. photoAblum (data) {
  65. let { value } = this.data;
  66. let count = value[data].hasOwnProperty('maxlen') ? value[data]['maxlen'] - value[data]['value'].length : 9;
  67. wx.chooseImage({
  68. count,
  69. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  70. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  71. success: res => this.request(res.tempFiles, value[data]['key'], data)
  72. })
  73. },
  74. /**
  75. * 上传图片
  76. * @param {array} data 图片本地路径 res.tempFiles
  77. * @param {string} key 订单id
  78. * @param {string} _index value[_index]
  79. */
  80. request (data, key, _index) {
  81. let { value } = this.data, brr = [], { id } = this.data;
  82. data.forEach((item, index) => {
  83. wx.$uploadFile({ url: `/order/${id}/upload_image/`, filePath: item.path, name: 'file', formData: { type: key } }).then(res => {
  84. value[_index]['value'].push({ value: JSON.parse(res).data.path, key: JSON.parse(res).data.id });
  85. index == data.length - 1 && end.bind(this)();
  86. }).catch(err => {
  87. brr.push(`第${index}张图片上传失败!`);
  88. index == data.length - 1 && end.bind(this)();
  89. });
  90. })
  91. function end () {
  92. let obj = { value };
  93. if (brr.length > 0) {
  94. obj['errorShow'] = true;
  95. obj['megs'] = brr;
  96. };
  97. this.setData({ ...obj });
  98. }
  99. },
  100. onLoad: function (options) {
  101. this.setData({ id: options.data })
  102. },
  103. onReady: function () {
  104. },
  105. onShow: function () {
  106. },
  107. onHide: function () {
  108. },
  109. onUnload: function () {
  110. },
  111. onPullDownRefresh: function () {
  112. },
  113. onReachBottom: function () {
  114. }
  115. })