AddModal.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <uni-popup ref="popup" background-color="#fff">
  3. <view class="popup-content">
  4. <uni-forms ref="baseForm" :modelValue="formData">
  5. <uni-forms-item label="分类">
  6. <ld-select
  7. :list="typeList"
  8. placeholder="请选择分类"
  9. class="select"
  10. v-model="formData.typeId"
  11. labelKey="name"
  12. valueKey="id"
  13. @change="onChangeType"
  14. />
  15. </uni-forms-item>
  16. <uni-forms-item
  17. v-show="currentType.type === 0 || currentSubType.type === 0"
  18. label="项目"
  19. >
  20. <ld-select
  21. :list="projectList"
  22. placeholder="请选择项目"
  23. class="select"
  24. v-model="formData.projectId"
  25. labelKey="Name"
  26. valueKey="ID"
  27. @change="onChangeProject"
  28. />
  29. </uni-forms-item>
  30. <uni-forms-item label="子类">
  31. <ld-select
  32. :list="currentType.children"
  33. placeholder="请选择子类"
  34. class="select"
  35. v-model="formData.subTypeId"
  36. labelKey="name"
  37. valueKey="id"
  38. @change="onChangeSubType"
  39. />
  40. </uni-forms-item>
  41. </uni-forms>
  42. </view>
  43. <view class="group">
  44. <button @click="close" class="button">取消</button>
  45. <button @click="submit" type="primary">保存</button>
  46. </view>
  47. </uni-popup>
  48. </template>
  49. <script>
  50. export default {
  51. props: ["projectList", "typeList"],
  52. data() {
  53. return {
  54. formData: {},
  55. currentType: {},
  56. currentSubType: {},
  57. };
  58. },
  59. methods: {
  60. open() {
  61. this.$refs.popup.open("center");
  62. },
  63. close() {
  64. this.formData = {};
  65. this.currentType = {};
  66. this.currentSubType = {};
  67. this.$refs.popup.close();
  68. },
  69. submit() {
  70. let type = this.currentType;
  71. let subType = this.currentSubType;
  72. let formData = this.formData;
  73. if (type.type == 0 || subType.type == 0) {
  74. if (!formData.projectId) {
  75. uni.showToast({
  76. title: "请选择项目",
  77. icon: "none",
  78. });
  79. return;
  80. }
  81. } else {
  82. formData.projectId = "0";
  83. }
  84. this.$emit("submit", this.formData);
  85. this.close();
  86. },
  87. onChangeType(value) {
  88. this.formData = {
  89. typeId: value,
  90. projectId: null,
  91. subTypeId: null,
  92. };
  93. this.currentType = this.typeList.find((item) => item.id == value) || {};
  94. this.currentSubType = {};
  95. },
  96. onChangeProject(value) {
  97. this.formData.projectId = value;
  98. },
  99. onChangeSubType(value) {
  100. this.formData.subTypeId = value;
  101. this.currentSubType =
  102. this.currentType.children.find((item) => item.id == value) || {};
  103. },
  104. },
  105. };
  106. </script>
  107. <style lang="less" scoped>
  108. .popup-content {
  109. padding: 40rpx;
  110. }
  111. .group {
  112. display: flex;
  113. button {
  114. width: 50%;
  115. border-radius: 0;
  116. }
  117. }
  118. .select {
  119. width: 100%;
  120. margin-bottom: 25rpx;
  121. background: #fff;
  122. height: 70rpx;
  123. color: #777777;
  124. padding-left: 20rpx;
  125. font-size: 24rpx;
  126. border-radius: 0px;
  127. border-bottom: 1px solid #333;
  128. }
  129. </style>