add.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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="subTypeList"
  39. placeholder="请选择子类"
  40. class="select"
  41. v-model="formData.subTypeId"
  42. labelKey="fullName"
  43. valueKey="id"
  44. :disabled="currentType.id == 2"
  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, queryWorkType } 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. subTypeList: [],
  88. day: "",
  89. };
  90. },
  91. onLoad(options) {
  92. this.day = options.day;
  93. },
  94. methods: {
  95. async getProject(value) {
  96. let data = [];
  97. data = await queryProject({ stage: value });
  98. this.project = data;
  99. },
  100. async getSubType(params) {
  101. let res = {};
  102. res = await queryWorkType(params);
  103. this.subTypeList = res.data.map((item) => ({
  104. ...item,
  105. fullName: `${item.name}(${item.code})`,
  106. }));
  107. },
  108. async submit() {
  109. let type = this.currentType;
  110. let subType = this.currentSubType;
  111. let formData = this.formData;
  112. if (type.type == 0 || subType.type == 0) {
  113. if (!formData.projectId) {
  114. uni.showToast({
  115. title: "请选择项目",
  116. icon: "none",
  117. });
  118. return;
  119. }
  120. } else {
  121. formData.projectId = "0";
  122. }
  123. let params = [
  124. {
  125. parent_type_id: Number(formData.typeId),
  126. type_id: Number(formData.subTypeId),
  127. comment: "",
  128. data: [
  129. {
  130. project_id: Number(formData.projectId),
  131. workload: 0,
  132. day: this.day,
  133. },
  134. ],
  135. },
  136. ];
  137. // 新增
  138. await addWorkHours(params);
  139. this.close();
  140. },
  141. close() {
  142. uni.navigateBack();
  143. },
  144. async onChangeType(value) {
  145. let item = this.typeList.find((t) => t.id == value);
  146. this.formData = {
  147. typeId: value,
  148. projectId: null,
  149. subTypeId: null,
  150. };
  151. this.currentType = item;
  152. this.currentSubType = {};
  153. this.subTypeList = [];
  154. this.projectName = "";
  155. if (!item.type) {
  156. this.getProject(value);
  157. } else {
  158. await this.getSubType({ parent_id: item.id });
  159. if (value == 33) {
  160. this.onChangeSubType(this.subTypeList[0].id);
  161. }
  162. }
  163. },
  164. async onChangeProject(index) {
  165. this.subTypeList = [];
  166. this.formData.subTypeId = null;
  167. if (index != -1) {
  168. let project = this.projectList[index];
  169. this.formData.projectId = project.ID;
  170. this.projectName = project.fullName;
  171. await this.getSubType({
  172. parent_id: this.currentType.id,
  173. project_id: project.ID,
  174. });
  175. if (this.currentType.id == 35) {
  176. this.onChangeSubType(this.subTypeList[0].id);
  177. }
  178. if (this.currentType.id == 2) {
  179. if (index == 0) {
  180. this.onChangeSubType(this.subTypeList[0].id);
  181. } else {
  182. this.onChangeSubType(this.subTypeList[1].id);
  183. }
  184. }
  185. }
  186. },
  187. onChangeSubType(value) {
  188. this.formData.subTypeId = value;
  189. this.currentSubType =
  190. this.subTypeList.find((item) => item.id == value) || {};
  191. },
  192. },
  193. };
  194. </script>
  195. <style lang="less" scoped>
  196. .content {
  197. height: 80vh;
  198. width: 90%;
  199. margin: 0 auto;
  200. background: #fff;
  201. }
  202. .date {
  203. line-height: 70rpx;
  204. }
  205. .popup-content {
  206. padding: 40rpx;
  207. }
  208. .group {
  209. width: 100%;
  210. display: flex;
  211. position: fixed;
  212. bottom: 0;
  213. left: 0;
  214. button {
  215. width: 50%;
  216. border-radius: 0;
  217. }
  218. }
  219. .select {
  220. width: 100%;
  221. margin-bottom: 25rpx;
  222. background: #fff;
  223. height: 70rpx;
  224. color: #777777;
  225. padding-left: 20rpx;
  226. font-size: 24rpx;
  227. border-radius: 0px;
  228. border-bottom: 1px solid #333;
  229. }
  230. </style>