add.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view class="content">
  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.id === 2 || currentType.id === 3"
  18. label="项目"
  19. >
  20. <comboxSearch
  21. emptyTips="无匹配项"
  22. placeholder="请选择项目"
  23. keyName="fullName"
  24. :isJSON="true"
  25. :candidates="projectList"
  26. @getValue="onChangeProject"
  27. />
  28. <!-- <ld-select
  29. :list="projectList"
  30. placeholder="请选择项目"
  31. class="select"
  32. v-model="formData.projectId"
  33. labelKey="fullName"
  34. valueKey="ID"
  35. @change="onChangeProject"
  36. /> -->
  37. </uni-forms-item>
  38. <uni-forms-item label="子类">
  39. <ld-select
  40. :list="currentType.children"
  41. placeholder="请选择子类"
  42. class="select"
  43. v-model="formData.subTypeId"
  44. labelKey="name"
  45. valueKey="id"
  46. :disabled="currentType.id == 2"
  47. @change="onChangeSubType"
  48. />
  49. </uni-forms-item>
  50. <uni-forms-item label="日期">
  51. <view class="date">{{ this.day }}</view>
  52. </uni-forms-item>
  53. </uni-forms>
  54. </view>
  55. <view class="group">
  56. <button @click="close" class="button">取消</button>
  57. <button @click="submit" type="primary">保存</button>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import comboxSearch from "@/components/cuihai-combox/cuihai-combox";
  63. import { addWorkHours, queryProject } from "@/services/workload";
  64. import { mapState } from "vuex";
  65. export default {
  66. components: { comboxSearch },
  67. computed: {
  68. ...mapState(["typeList"]),
  69. projectList() {
  70. let list = [];
  71. let type = this.currentType;
  72. if (type.id == 2) {
  73. list.push({
  74. fullName: "售前支持(10100)",
  75. ID: "0",
  76. });
  77. return list.concat(this.allProjectList["0"]);
  78. }
  79. return this.allProjectList["1"];
  80. },
  81. },
  82. data() {
  83. return {
  84. formData: {},
  85. currentType: {},
  86. currentSubType: {},
  87. allProjectList: [],
  88. day: "",
  89. };
  90. },
  91. onLoad(options) {
  92. this.day = options.day;
  93. this.getProject();
  94. },
  95. methods: {
  96. async getProject() {
  97. let data = {};
  98. data["0"] = await queryProject({ stage: 0 });
  99. data["1"] = await queryProject({ stage: 1 });
  100. this.allProjectList = data;
  101. },
  102. async submit() {
  103. let type = this.currentType;
  104. let subType = this.currentSubType;
  105. let formData = this.formData;
  106. if (type.type == 0 || subType.type == 0) {
  107. if (!formData.projectId) {
  108. uni.showToast({
  109. title: "请选择项目",
  110. icon: "none",
  111. });
  112. return;
  113. }
  114. } else {
  115. formData.projectId = "0";
  116. }
  117. let params = [
  118. {
  119. type_id: Number(formData.subTypeId),
  120. comment: "",
  121. data: [
  122. {
  123. project_id: Number(formData.projectId),
  124. workload: 0,
  125. day: this.day,
  126. },
  127. ],
  128. },
  129. ];
  130. // 新增
  131. await addWorkHours(params);
  132. this.close();
  133. },
  134. close() {
  135. uni.navigateBack();
  136. },
  137. onChangeType(value) {
  138. this.formData = {
  139. typeId: value,
  140. projectId: null,
  141. subTypeId: null,
  142. };
  143. this.currentType = this.typeList.find((item) => item.id == value) || {};
  144. this.currentSubType = {};
  145. },
  146. onChangeProject(index) {
  147. let project = this.projectList[index];
  148. this.formData.projectId = project.ID;
  149. if (this.currentType.id == 2) {
  150. let subList = this.currentType.children;
  151. if (project.ID == "0") {
  152. this.onChangeSubType(subList[0].id);
  153. } else {
  154. this.onChangeSubType(subList[1].id);
  155. }
  156. }
  157. },
  158. onChangeSubType(value) {
  159. this.formData.subTypeId = value;
  160. this.currentSubType =
  161. this.currentType.children.find((item) => item.id == value) || {};
  162. },
  163. },
  164. };
  165. </script>
  166. <style lang="less" scoped>
  167. .content {
  168. height: 80vh;
  169. width: 90%;
  170. margin: 0 auto;
  171. background: #fff;
  172. }
  173. .date {
  174. line-height: 70rpx;
  175. }
  176. .popup-content {
  177. padding: 40rpx;
  178. }
  179. .group {
  180. width: 100%;
  181. display: flex;
  182. position: fixed;
  183. bottom: 0;
  184. left: 0;
  185. button {
  186. width: 50%;
  187. border-radius: 0;
  188. }
  189. }
  190. .select {
  191. width: 100%;
  192. margin-bottom: 25rpx;
  193. background: #fff;
  194. height: 70rpx;
  195. color: #777777;
  196. padding-left: 20rpx;
  197. font-size: 24rpx;
  198. border-radius: 0px;
  199. border-bottom: 1px solid #333;
  200. }
  201. </style>