info.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div class="container">
  3. <el-form label-position="left">
  4. <template v-for="(item, index) in fromData">
  5. <template v-if="item.type === 'upload'">
  6. <el-form-item :label="item.title" label-width="200px">
  7. <FileUpload
  8. v-model:modelValue="item.content"
  9. v-model:loaderData="loaderData"
  10. />
  11. </el-form-item>
  12. </template>
  13. <template v-if="item.type === 'input'">
  14. <el-form-item
  15. :label="item.title"
  16. label-width="200px"
  17. :required="
  18. item.title == '手机号' ||
  19. item.title == '微信号' ||
  20. item.title == '需要设计的内容'
  21. "
  22. >
  23. <el-input
  24. v-model="item.content"
  25. :placeholder="'请输入' + item.title"
  26. />
  27. </el-form-item>
  28. </template>
  29. </template>
  30. <el-button type="primary" @click="saveData">确认</el-button>
  31. <el-button type="primary" @click="handleDownload(loaderData)"
  32. >下载全部文件</el-button
  33. >
  34. </el-form>
  35. <div style="text-align: center; margin-top: 50px">
  36. 闽ICP备2023014112号-1
  37. </div>
  38. </div>
  39. </template>
  40. <script setup>
  41. import { getFormData, saveFormData } from "../api/index";
  42. import { useRouter } from "vue-router";
  43. import { ElMessage } from "element-plus";
  44. import { handleBatchDownload } from "../utils/downFile";
  45. const baseUrl = "https://dfdiyfile.oss-cn-fuzhou.aliyuncs.com/";
  46. import { ref } from "vue";
  47. import FileUpload from "../components/FileUpload/index";
  48. const { currentRoute } = useRouter();
  49. const tid = currentRoute.value.query.tid;
  50. const userId = currentRoute.value.query.userId;
  51. const fromData = ref([]);
  52. const uploadList = ref([]);
  53. const CeErpOrderFormData = ref({});
  54. const loaderData = ref([]);
  55. async function saveData() {
  56. let mobile = false;
  57. let wx = false;
  58. let need_content = false;
  59. let mobile_number = "123";
  60. fromData.value?.map((item) => {
  61. if (item.title == "手机号" && !item?.content) {
  62. mobile = true;
  63. }
  64. if (item.title == "手机号" && item?.content) {
  65. mobile_number = item?.content;
  66. }
  67. if (item.title == "微信号" && !item?.content) {
  68. wx = true;
  69. }
  70. if (item.title == "需要设计的内容" && !item?.content) {
  71. need_content = true;
  72. }
  73. });
  74. if (need_content) {
  75. return ElMessage({
  76. message: "需要设计的内容不能为空",
  77. type: "error",
  78. });
  79. }
  80. if (mobile && wx) {
  81. return ElMessage({
  82. message: "手机号或者微信号不能都为空",
  83. type: "error",
  84. });
  85. }
  86. let regex =
  87. /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
  88. // if (mobile_number != "123" && !regex.test(mobile_number)) {
  89. // return ElMessage({
  90. // message: "请输入正确手机号",
  91. // type: "error",
  92. // });
  93. // }
  94. let data = await saveFormData({
  95. id: CeErpOrderFormData.value ? CeErpOrderFormData.value.id : 0,
  96. tid,
  97. userId,
  98. content: JSON.stringify(fromData.value),
  99. });
  100. if (data.type === "success") {
  101. ElMessage({
  102. message: "保存成功",
  103. type: "success",
  104. });
  105. }
  106. }
  107. async function getData() {
  108. if (!tid) {
  109. return ElMessage({
  110. message: "获取不到参数",
  111. type: "error",
  112. });
  113. }
  114. try {
  115. let data = await getFormData({ tid });
  116. if (data.code === 200) {
  117. let product = data.product;
  118. CeErpOrderFormData.value = data.CeErpOrderFormData;
  119. let info = {};
  120. let json_info = `[{"title":"logo文件上传/模板截图/设计素材上传等等~","type":"upload"},
  121. {"title":"需要设计的内容","type":"input"},
  122. {"title":"手机号","type":"input"},
  123. {"title":"微信号","type":"input"},
  124. {"title":"请上传微信二维码","type":"upload"}]`;
  125. if (!product) {
  126. product = {
  127. FormJson: json_info,
  128. };
  129. }
  130. if (CeErpOrderFormData.value && CeErpOrderFormData.value.content) {
  131. CeErpOrderFormData.value = {
  132. content: JSON.parse(CeErpOrderFormData.value.content),
  133. id: CeErpOrderFormData.value.ID,
  134. tid: CeErpOrderFormData.value.tid,
  135. };
  136. CeErpOrderFormData.value?.content.map((item) => {
  137. if (
  138. item.type == "upload" &&
  139. item.content &&
  140. typeof item.content == "string"
  141. ) {
  142. item.content?.split(",")?.map((e) => {
  143. loaderData.value.push(baseUrl + e);
  144. });
  145. }
  146. });
  147. }
  148. product.FormJson = json_info;
  149. if (product && product.FormJson != "") {
  150. let formJson = JSON.parse(product.FormJson);
  151. let need = true;
  152. formJson.map((item) => {
  153. if (item.type === "upload") {
  154. item.content = [];
  155. } else {
  156. item.content = "";
  157. }
  158. if (CeErpOrderFormData.value && CeErpOrderFormData.value.content) {
  159. CeErpOrderFormData.value.content.map((e) => {
  160. if (e.title === item.title && e.type === item.type) {
  161. item.content = e.content;
  162. }
  163. });
  164. }
  165. if (item.title == "手机号") {
  166. need = false;
  167. }
  168. if (item.title == "微信号") {
  169. need = false;
  170. }
  171. });
  172. if (need) {
  173. formJson.push(
  174. ...[
  175. { title: "手机号", type: "input" },
  176. { title: "微信号", type: "input" },
  177. ]
  178. );
  179. }
  180. fromData.value = formJson;
  181. }
  182. }
  183. } catch (error) {
  184. console.log("🚀 ~ file: info.vue:15 ~ getData ~ error:", error);
  185. }
  186. }
  187. function handleDownload(data) {
  188. handleBatchDownload(data);
  189. }
  190. getData();
  191. </script>
  192. <style scoped lang="scss">
  193. .container {
  194. max-width: 1400px;
  195. margin: 0 auto;
  196. }
  197. </style>