add.vue 5.2 KB

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