add.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="content">
  3. <view class="title"> 新增项目 </view>
  4. <uni-forms :modelValue="formData" label-position="left" class="form">
  5. <uni-forms-item label="项目名称">
  6. <uni-easyinput
  7. type="text"
  8. v-model="formData.project_name"
  9. class="input"
  10. />
  11. </uni-forms-item>
  12. <uni-forms-item label="项目类别">
  13. <picker
  14. @change="selectChangeType"
  15. :range="typeList"
  16. :range-key="'name'"
  17. >
  18. <view class="select">
  19. {{
  20. formData.type && `${formData.type.name}(${formData.type.code})`
  21. }}
  22. </view>
  23. </picker>
  24. </uni-forms-item>
  25. <uni-forms-item label="流程">
  26. <picker disabled>
  27. <view class="select">
  28. {{
  29. formData.type && (formData.type.id == 7 ? "研发立项" : "销售立项")
  30. }}
  31. </view>
  32. </picker>
  33. </uni-forms-item>
  34. <uni-forms-item
  35. label="行业名称"
  36. v-show="!formData.type || (formData.type && formData.type.id != 7)"
  37. >
  38. <picker
  39. @change="selectChangeIndustry"
  40. :range="industryList"
  41. :range-key="'name'"
  42. >
  43. <view class="select">
  44. {{
  45. formData.industry &&
  46. `${formData.industry.name}(${formData.industry.code})`
  47. }}
  48. </view>
  49. </picker>
  50. </uni-forms-item>
  51. <uni-forms-item
  52. label="项目地区"
  53. v-show="!formData.type || (formData.type && formData.type.id != 7)"
  54. >
  55. <picker> <view class="select"></view></picker>
  56. </uni-forms-item>
  57. <uni-forms-item
  58. label="项目简称"
  59. v-show="!formData.type || (formData.type && formData.type.id != 7)"
  60. >
  61. <uni-easyinput
  62. type="text"
  63. v-model="formData.name"
  64. class="input"
  65. :clearable="false"
  66. @blur="onChangeName"
  67. />
  68. </uni-forms-item>
  69. <uni-forms-item
  70. label="项目期数"
  71. v-show="!formData.type || (formData.type && formData.type.id != 7)"
  72. >
  73. <picker @change="selectChangeVersion" :range="versionList">
  74. <view class="select">
  75. {{ versionList[this.formData.version - 1] }}
  76. </view>
  77. </picker>
  78. </uni-forms-item>
  79. <uni-forms-item
  80. label="项目编号"
  81. v-show="!formData.type || (formData.type && formData.type.id != 7)"
  82. >
  83. <view>
  84. {{
  85. `${formData.code.type}-${formData.code.industry}-${formData.code.location}-${formData.code.name}-${formData.code.version}`
  86. }}
  87. </view>
  88. </uni-forms-item>
  89. </uni-forms>
  90. <view class="group">
  91. <button @click="onHandleSubmit(0)" class="commit">取消</button>
  92. <button @click="onHandleSubmit(1)" type="primary" class="commit">
  93. 确定
  94. </button>
  95. </view>
  96. </view>
  97. </template>
  98. <script>
  99. import { queryProjectType, queryIndustry } from "@/services/project";
  100. import { mapState } from "vuex";
  101. const versionList = ["一期", "二期", "三期", "四期", "五期"];
  102. export default {
  103. data() {
  104. return {
  105. formData: {
  106. project_name: null,
  107. type: null,
  108. flow: null,
  109. industry: null,
  110. location: null,
  111. name: null,
  112. version: null,
  113. code: {
  114. type: "***",
  115. industry: "***",
  116. location: "***",
  117. name: "***",
  118. version: "*",
  119. },
  120. },
  121. project_id: 0,
  122. typeList: [],
  123. industryList: [],
  124. versionList,
  125. };
  126. },
  127. computed: {
  128. ...mapState(["currentProject"]),
  129. },
  130. onLoad(options) {
  131. this.project_id = options.project_id;
  132. this.init(options);
  133. },
  134. methods: {
  135. onHandleSubmit(value) {
  136. if (value) console.log(this.formData);
  137. uni.navigateTo({
  138. url: "./list",
  139. });
  140. },
  141. async init(options) {
  142. let form = this.formData;
  143. let code = this.formData.code;
  144. let current = this.currentProject;
  145. if (options.project_id) {
  146. form.project_name = current.project_name;
  147. form.type = this.typeList.find(
  148. (item) => item.id == this.currentProject.type_id
  149. );
  150. form.flow = this.typeList.find(
  151. (item) => item.id == this.currentProject.flow_id
  152. );
  153. if (current.type.id != 7) {
  154. form.industry = this.industryList.find(
  155. (item) => item.id == this.currentProject.industry_id
  156. );
  157. form.location = current.location;
  158. form.name = current.name;
  159. form.version = current.version;
  160. code.type = form.type.code;
  161. code.industry = form.industry.code;
  162. code.location = form.location;
  163. code.name = form.name;
  164. code.version = form.version;
  165. }
  166. }
  167. let res;
  168. res = await queryProjectType();
  169. this.typeList = res.data;
  170. res = await queryIndustry();
  171. this.industryList = res.data;
  172. },
  173. selectChangeType(e) {
  174. let form = this.formData;
  175. let code = this.formData.code;
  176. form.type = this.typeList[e.target.value];
  177. code.type = form.type.code;
  178. if (form.type.id == 7) {
  179. form.flow = this.typeList.find((item) => item.id == 1);
  180. form.industry = null;
  181. form.location = null;
  182. form.name = null;
  183. form.version = null;
  184. code.industry = "***";
  185. code.location = "***";
  186. code.name = "***";
  187. code.version = "*";
  188. } else form.flow = this.typeList.find((item) => item.id == 4);
  189. },
  190. selectChangeIndustry(e) {
  191. this.formData.industry = this.industryList[e.target.value];
  192. this.formData.code.industry = this.formData.industry.code;
  193. },
  194. onChangeName(e) {
  195. let name = e.detail.value.toUpperCase();
  196. while (name.length < 3) name += "V";
  197. this.formData.name = name;
  198. this.formData.code.name = name;
  199. },
  200. selectChangeVersion(e) {
  201. this.formData.version = e.target.value + 1;
  202. this.formData.code.version = this.formData.version + "";
  203. },
  204. },
  205. };
  206. </script>
  207. <style lang="less" scoped>
  208. .content {
  209. display: flex;
  210. flex-wrap: wrap;
  211. }
  212. .title {
  213. width: 100%;
  214. padding: 0 20px 20px 20px;
  215. background: #f8f8f8;
  216. font: 24px bold;
  217. }
  218. .form {
  219. margin: 20px 10% 0 10%;
  220. width: 100%;
  221. }
  222. .input {
  223. border: 1px solid #666;
  224. }
  225. .select {
  226. width: 100%;
  227. height: 72rpx;
  228. line-height: 70rpx;
  229. border: 1px solid #666;
  230. padding-left: 20rpx;
  231. }
  232. .group {
  233. width: 100%;
  234. display: flex;
  235. position: fixed;
  236. flex-wrap: wrap;
  237. justify-content: flex-start;
  238. bottom: 0;
  239. left: 0;
  240. .commit {
  241. width: 50%;
  242. border-radius: 0;
  243. margin: inherit;
  244. }
  245. }
  246. </style>