index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <div style="padding-bottom: 60px">
  3. <van-nav-bar title="完工入库" left-text="" left-arrow>
  4. <template #right> 添加 </template>
  5. </van-nav-bar>
  6. <van-search v-model="req.keyword" placeholder="请输入搜索关键词" />
  7. <testForm
  8. v-model="formData.data"
  9. :formOption="formOption"
  10. :formConfig="formConfig"
  11. :rules="rules"
  12. @onSubmit="onSubmit"
  13. ref="formDom"
  14. ></testForm>
  15. </div>
  16. </template>
  17. <script setup>
  18. import { ref, getCurrentInstance, onMounted, reactive } from "vue";
  19. import commonList from "@/components/common-list.vue";
  20. import { useRoute } from "vue-router";
  21. import testForm from "@/components/testForm/index.vue";
  22. const loading = ref(false);
  23. const router = useRoute();
  24. const req = ref({
  25. pageNum: 1,
  26. keyword: null,
  27. });
  28. const finished = ref(false);
  29. const classification = ref([]);
  30. const proxy = getCurrentInstance().proxy;
  31. const formDom = ref(null);
  32. const formOption = reactive({
  33. readonly: false, //用于控制整个表单是否只读
  34. disabled: false,
  35. labelAlign: "top",
  36. scroll: true,
  37. labelWidth: "62pk",
  38. // hiddenSubmitBtn: true,
  39. btnConfig: {
  40. isNeed: true,
  41. label: "明细",
  42. prop: "list",
  43. plain: true,
  44. // itemType: "default",
  45. listConfig: [
  46. {
  47. type: "input",
  48. itemType: "text",
  49. label: "姓名",
  50. prop: "name",
  51. clearable: true,
  52. readonly: true,
  53. },
  54. {
  55. type: "picker",
  56. label: "选择器",
  57. prop: "select",
  58. itemType: "onePicker",
  59. showPicker: false,
  60. readonly: false,
  61. // 指定label、value
  62. fieldNames: {
  63. text: "att",
  64. value: "id",
  65. },
  66. pickerOption: {
  67. columns: [
  68. {
  69. att: "ceshi",
  70. id: "1",
  71. },
  72. {
  73. att: "ceshi1",
  74. id: "2",
  75. },
  76. ],
  77. },
  78. },
  79. {
  80. type: "picker",
  81. label: "时间选择器",
  82. prop: "date",
  83. itemType: "datePicker",
  84. showPicker: false,
  85. split: "-", //时间分隔符
  86. columnsType: ["year", "month"], //只选年月
  87. },
  88. ],
  89. clickFn: () => {
  90. formData.data.list.push({
  91. name: "cz",
  92. });
  93. },
  94. },
  95. });
  96. const formConfig = reactive([
  97. {
  98. type: "input",
  99. itemType: "text",
  100. label: "姓名",
  101. prop: "name",
  102. clearable: true,
  103. },
  104. {
  105. type: "input",
  106. itemType: "textarea",
  107. label: "富文本",
  108. prop: "reamlke",
  109. },
  110. {
  111. type: "input",
  112. itemType: "password",
  113. label: "密码",
  114. prop: "password",
  115. },
  116. // {
  117. // type: "switch",
  118. // label: "开关",
  119. // prop: "switch1",
  120. // },
  121. // {
  122. // type: "checkbox",
  123. // label: "复选框组",
  124. // prop: "checkbox",
  125. // data: [
  126. // {
  127. // text: "1",
  128. // value: "1",
  129. // },
  130. // {
  131. // text: "2",
  132. // value: "2",
  133. // },
  134. // ],
  135. // },
  136. // {
  137. // type: "radio",
  138. // label: "单选框",
  139. // prop: "radio",
  140. // data: [
  141. // {
  142. // label: "dan1",
  143. // id: "10",
  144. // },
  145. // {
  146. // title: "dan2",
  147. // value: "20",
  148. // },
  149. // ],
  150. // },
  151. {
  152. type: "picker",
  153. label: "选择器",
  154. prop: "select",
  155. itemType: "onePicker",
  156. showPicker: false,
  157. fieldNames: {
  158. text: "label",
  159. value: "id",
  160. },
  161. pickerOption: {
  162. columns: [
  163. {
  164. label: "值1",
  165. id: "1",
  166. },
  167. {
  168. label: "值2",
  169. id: "2",
  170. },
  171. ],
  172. },
  173. },
  174. {
  175. type: "picker",
  176. label: "时间选择器",
  177. prop: "date",
  178. itemType: "datePicker",
  179. showPicker: false,
  180. split: "-",
  181. columnsType: ["year", "month"], //只选年月
  182. },
  183. {
  184. type: "cascader",
  185. label: "通用级联",
  186. prop: "common",
  187. itemType: "common",
  188. showPicker: false,
  189. // options: classification.value,
  190. options: [],
  191. fieldNames: {
  192. text: "label",
  193. value: "id",
  194. children: "children",
  195. },
  196. // onChangeFn: (option) => {
  197. // // console.log("aa");
  198. // },
  199. // finishFn: (current, option) => {
  200. // current.showPicker = false;
  201. // },
  202. },
  203. {
  204. type: "cascader",
  205. label: "城市",
  206. prop: "city",
  207. itemType: "city",
  208. showPicker: false,
  209. },
  210. {
  211. type: "upload",
  212. label: "上传qqq",
  213. prop: "fileList",
  214. },
  215. // {
  216. // type: "slot",
  217. // slotName: "测试",
  218. // label: "1646",
  219. // },
  220. ]);
  221. const rules = {
  222. name: [{ required: true, message: "请填写姓名" }],
  223. password: [{ required: true, message: "请填写密码" }],
  224. reamlke: [{ required: true, message: "请填写备注" }],
  225. checkbox: [{ required: true, message: "请选择" }],
  226. radio: [{ required: true, message: "请选择" }],
  227. select: [{ required: true, message: "请选择" }],
  228. date: [{ required: true, message: "请选择时间" }],
  229. common: [{ required: true, message: "请选择级联" }],
  230. // city: [{ required: true, message: "请选择城市" }],
  231. };
  232. const formData = reactive({
  233. data: {
  234. name: "scz",
  235. password: "123456789",
  236. reamlke: "beizhu回显",
  237. select: "1",
  238. date: "2022-01-09",
  239. common: "1651135364980989953",
  240. city: "22",
  241. cityName: "合肥",
  242. // fileList: [
  243. // {
  244. // url: "https://os.winfaster.cn/byteSailing/test/2023/04/25/2e13ecba1978472d9e97fcec6335c975.png",
  245. // fileName: "board-2.png",
  246. // },
  247. // ],
  248. list: [
  249. {
  250. name: "qqq",
  251. select: "1",
  252. date: "2022-01",
  253. },
  254. {
  255. name: "www",
  256. select: "2",
  257. date: "2023-01",
  258. },
  259. ],
  260. },
  261. });
  262. const onSubmit = () => {
  263. // 城市级联选择器和上传附件数据需手动赋值
  264. if (formData.data.fileList && formData.data.fileList.length > 0) {
  265. formData.data.fileList = formData.data.fileList.map((item) => ({
  266. id: item.id,
  267. fileName: item.fileName,
  268. }));
  269. } else {
  270. formData.data.fileList = [];
  271. }
  272. if (formData.data.cityObj) {
  273. formData.data.countryId =
  274. formData.data.cityObj.selectedOptions[0].value;
  275. formData.data.provinceId =
  276. formData.data.cityObj.tabIndex === 2
  277. ? formData.data.cityObj.selectedOptions[1].value
  278. : null;
  279. formData.data.cityId =
  280. formData.data.cityObj.tabIndex === 1
  281. ? formData.data.cityObj.selectedOptions[1].value
  282. : formData.data.cityObj.selectedOptions[2].value;
  283. }
  284. console.log(formData.data, "wssa");
  285. };
  286. // getList();
  287. onMounted(() => {
  288. proxy
  289. .post("/productClassify/tree", { parentId: "", name: "", definition: "1" })
  290. .then((res) => {
  291. classification.value = res.data;
  292. const index = formConfig.findIndex(
  293. (x) => x.type == "cascader" && x.itemType == "common"
  294. );
  295. formConfig[index].options = classification.value;
  296. formDom.value.formDataInit(true);
  297. });
  298. });
  299. </script>
  300. <style lang="scss" scoped>
  301. .list {
  302. min-height: 70vh;
  303. }
  304. </style>