add.vue 5.4 KB

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