uploadImage.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const services_ams = require("../../services/ams.js");
  4. if (!Array) {
  5. const _easycom_wd_upload2 = common_vendor.resolveComponent("wd-upload");
  6. _easycom_wd_upload2();
  7. }
  8. const _easycom_wd_upload = () => "../../node-modules/wot-design-uni/components/wd-upload/wd-upload.js";
  9. if (!Math) {
  10. _easycom_wd_upload();
  11. }
  12. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  13. __name: "uploadImage",
  14. setup(__props) {
  15. const fileList = common_vendor.ref([]);
  16. const imgList = common_vendor.ref([]);
  17. const aData = JSON.parse(common_vendor.index.getStorageSync("activityData"));
  18. const openid = common_vendor.index.getStorageSync("openid");
  19. const phone = common_vendor.index.getStorageSync("phone");
  20. const routerInfo = common_vendor.reactive({ discountId: "", discountLevel: "" });
  21. const action = "https://test-coupon.qiuyutech.com.cn/stage-api/miniApp/oss/upload/" + aData.brandId;
  22. const customUpload = (file, formData, options) => {
  23. common_vendor.index.uploadFile({
  24. url: action,
  25. header: options.header,
  26. name: options.name,
  27. fileName: options.name,
  28. fileType: options.fileType,
  29. formData,
  30. filePath: file.url,
  31. success(res) {
  32. if (res.statusCode === options.statusCode) {
  33. options.onSuccess(res, file, formData);
  34. const data = JSON.parse(res.data);
  35. imgList.value.push(data.url);
  36. } else {
  37. options.onError({ ...res, errMsg: res.errMsg || "" }, file, formData);
  38. }
  39. },
  40. fail(err) {
  41. options.onError(err, file, formData);
  42. }
  43. });
  44. };
  45. const handleRemove = (file) => {
  46. const data = JSON.parse(file.file.response);
  47. imgList.value = imgList.value.filter((item) => item !== data.url);
  48. };
  49. const onAdd = () => {
  50. const location = JSON.parse(common_vendor.index.getStorageSync("location"));
  51. if (imgList.value.length === 0)
  52. return common_vendor.index.showToast({ title: "请上传图片", icon: "none" });
  53. const params = {
  54. openid,
  55. mobile: phone,
  56. latitude: location.latitude || "",
  57. longitude: location.longitude || "",
  58. discountId: routerInfo.discountId,
  59. discountLevel: routerInfo.discountLevel,
  60. receiptImages: imgList.value.join(","),
  61. marketingActivityId: aData.id
  62. };
  63. services_ams.addCustomer(params).then((res) => {
  64. if (res.code === 200) {
  65. common_vendor.wx$1.requestSubscribeMessage({
  66. tmplIds: ["ZZhiUAFnGXkIIIId6W9mBbf16DGC-OtX1sT_d5TWNUU"],
  67. success(response) {
  68. services_ams.subscribeToMessage(openid).then((res2) => {
  69. if (res2.code === 200) {
  70. common_vendor.index.showToast({ title: "订阅成功", icon: "success" });
  71. common_vendor.index.navigateBack();
  72. } else {
  73. common_vendor.index.showToast({ title: "订阅失败", icon: "error" });
  74. common_vendor.index.navigateBack();
  75. }
  76. });
  77. },
  78. fail(err) {
  79. common_vendor.index.showToast({ title: "订阅失败", icon: "error" });
  80. common_vendor.index.navigateBack();
  81. }
  82. });
  83. } else {
  84. common_vendor.index.showToast({ title: "上传图片失败", icon: "error" });
  85. }
  86. });
  87. };
  88. common_vendor.onLoad((options) => {
  89. routerInfo.discountId = options.discountId;
  90. routerInfo.discountLevel = options.discountLevel;
  91. });
  92. return (_ctx, _cache) => {
  93. return {
  94. a: common_vendor.o(handleRemove),
  95. b: common_vendor.p({
  96. ["file-list"]: fileList.value,
  97. multiple: true,
  98. limit: 5,
  99. ["upload-method"]: customUpload
  100. }),
  101. c: common_vendor.o(onAdd)
  102. };
  103. };
  104. }
  105. });
  106. wx.createPage(_sfc_main);