add.vue 5.9 KB

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