add.vue 6.3 KB

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