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
  17. v-show="
  18. currentType.id === 2 ||
  19. currentType.id === 3 ||
  20. currentType.id === 35
  21. "
  22. label="项目"
  23. >
  24. <comboxSearch
  25. emptyTips="无匹配项"
  26. placeholder="请选择项目"
  27. keyName="fullName"
  28. :isJSON="true"
  29. :candidates="projectList"
  30. @getValue="onChangeProject"
  31. />
  32. <!-- <ld-select
  33. :list="projectList"
  34. placeholder="请选择项目"
  35. class="select"
  36. v-model="formData.projectId"
  37. labelKey="fullName"
  38. valueKey="ID"
  39. @change="onChangeProject"
  40. /> -->
  41. </uni-forms-item>
  42. <uni-forms-item label="子类">
  43. <ld-select
  44. :list="currentType.children"
  45. placeholder="请选择子类"
  46. class="select"
  47. v-model="formData.subTypeId"
  48. labelKey="name"
  49. valueKey="id"
  50. :disabled="currentType.id == 2 || currentType.id == 35"
  51. @change="onChangeSubType"
  52. />
  53. </uni-forms-item>
  54. <uni-forms-item label="日期">
  55. <view class="date">{{ this.day }}</view>
  56. </uni-forms-item>
  57. </uni-forms>
  58. </view>
  59. <view class="group">
  60. <button @click="close" class="button">取消</button>
  61. <button @click="submit" type="primary">保存</button>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import comboxSearch from "@/components/cuihai-combox/cuihai-combox";
  67. import { addWorkHours, queryProject } from "@/services/workload";
  68. import { mapState } from "vuex";
  69. export default {
  70. components: { comboxSearch },
  71. computed: {
  72. ...mapState(["typeList"]),
  73. projectList() {
  74. let list = [];
  75. let type = this.currentType;
  76. switch (type.id) {
  77. case 2:
  78. list.push({
  79. fullName: "售前支持(10100)",
  80. ID: "0",
  81. });
  82. return list.concat(this.allProjectList["0"]);
  83. case 3:
  84. return this.allProjectList["1"];
  85. case 35:
  86. return this.allProjectList["7"];
  87. }
  88. },
  89. },
  90. data() {
  91. return {
  92. formData: {},
  93. currentType: {},
  94. currentSubType: {},
  95. allProjectList: [],
  96. day: "",
  97. };
  98. },
  99. onLoad(options) {
  100. this.day = options.day;
  101. this.getProject();
  102. },
  103. methods: {
  104. async getProject() {
  105. let data = {};
  106. data["0"] = await queryProject({ stage: 0 });
  107. data["1"] = await queryProject({ stage: 1 });
  108. data["7"] = await queryProject({ stage: 7 });
  109. this.allProjectList = data;
  110. },
  111. async submit() {
  112. let type = this.currentType;
  113. let subType = this.currentSubType;
  114. let formData = this.formData;
  115. if (type.type == 0 || subType.type == 0) {
  116. if (!formData.projectId) {
  117. uni.showToast({
  118. title: "请选择项目",
  119. icon: "none",
  120. });
  121. return;
  122. }
  123. } else {
  124. formData.projectId = "0";
  125. }
  126. let params = [
  127. {
  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. onChangeType(value) {
  147. let item = this.typeList.find((t) => t.id == value);
  148. if (value == 33 || value == 35) {
  149. this.formData = {
  150. typeId: value,
  151. project: null,
  152. subType: item.children[0].id,
  153. };
  154. this.currentType = item;
  155. this.onChangeSubType(item.children[0].id);
  156. } else {
  157. this.formData = {
  158. typeId: value,
  159. projectId: null,
  160. subTypeId: null,
  161. };
  162. this.currentType = item;
  163. this.currentSubType = {};
  164. }
  165. },
  166. onChangeProject(index) {
  167. let project = this.projectList[index];
  168. this.formData.projectId = project.ID;
  169. if (this.currentType.id == 2) {
  170. let subList = this.currentType.children;
  171. if (project.ID == "0") {
  172. this.onChangeSubType(subList[0].id);
  173. } else {
  174. this.onChangeSubType(subList[1].id);
  175. }
  176. }
  177. },
  178. onChangeSubType(value) {
  179. this.formData.subTypeId = value;
  180. this.currentSubType =
  181. this.currentType.children.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>