add.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. type_id: Number(formData.subTypeId),
  126. comment: "",
  127. data: [
  128. {
  129. project_id: Number(formData.projectId),
  130. workload: 0,
  131. day: this.day,
  132. },
  133. ],
  134. },
  135. ];
  136. // 新增
  137. await addWorkHours(params);
  138. this.close();
  139. },
  140. close() {
  141. uni.navigateBack();
  142. },
  143. async onChangeType(value) {
  144. let item = this.typeList.find((t) => t.id == value);
  145. this.formData = {
  146. typeId: value,
  147. projectId: null,
  148. subTypeId: null,
  149. };
  150. this.currentType = item;
  151. this.currentSubType = {};
  152. this.projectName = "";
  153. if (!item.type) {
  154. this.getProject(value);
  155. } else {
  156. await this.getSubType({ parent_id: item.id });
  157. if (value == 33) {
  158. this.onChangeSubType(this.subTypeList[0].id);
  159. }
  160. }
  161. },
  162. async onChangeProject(index) {
  163. let project = this.projectList[index];
  164. this.formData.projectId = project.ID;
  165. this.projectName = project.fullName;
  166. await this.getSubType({
  167. parent_id: this.currentType.id,
  168. project_id: project.ID,
  169. });
  170. if (this.currentType.id == 35) {
  171. this.onChangeSubType(this.subTypeList[0].id);
  172. }
  173. if (this.currentType.id == 2) {
  174. if (index == 0) {
  175. this.onChangeSubType(this.subTypeList[0].id);
  176. } else {
  177. this.onChangeSubType(this.subTypeList[1].id);
  178. }
  179. }
  180. },
  181. onChangeSubType(value) {
  182. this.formData.subTypeId = value;
  183. this.currentSubType =
  184. this.subTypeList.find((item) => item.id == value) || {};
  185. },
  186. },
  187. };
  188. </script>
  189. <style lang="less" scoped>
  190. .content {
  191. height: 80vh;
  192. width: 90%;
  193. margin: 0 auto;
  194. background: #fff;
  195. }
  196. .date {
  197. line-height: 70rpx;
  198. }
  199. .popup-content {
  200. padding: 40rpx;
  201. }
  202. .group {
  203. width: 100%;
  204. display: flex;
  205. position: fixed;
  206. bottom: 0;
  207. left: 0;
  208. button {
  209. width: 50%;
  210. border-radius: 0;
  211. }
  212. }
  213. .select {
  214. width: 100%;
  215. margin-bottom: 25rpx;
  216. background: #fff;
  217. height: 70rpx;
  218. color: #777777;
  219. padding-left: 20rpx;
  220. font-size: 24rpx;
  221. border-radius: 0px;
  222. border-bottom: 1px solid #333;
  223. }
  224. </style>