add.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view class="content">
  3. <view class="title"> 新增项目 </view>
  4. <uni-forms
  5. :modelValue="formData"
  6. label-position="left"
  7. class="form"
  8. ref="form"
  9. :rules="rules"
  10. >
  11. <uni-forms-item required label="项目名称" name="project_name">
  12. <uni-easyinput
  13. type="text"
  14. v-model="formData.project_name"
  15. class="input"
  16. />
  17. </uni-forms-item>
  18. <uni-forms-item label="项目类别" name="type" required>
  19. <picker
  20. @change="selectChangeType"
  21. :range="typeList"
  22. :range-key="'name'"
  23. >
  24. <view class="select">
  25. {{
  26. formData.type && `${formData.type.name}(${formData.type.code})`
  27. }}
  28. </view>
  29. </picker>
  30. </uni-forms-item>
  31. <uni-forms-item label="流程" name="form">
  32. <picker disabled>
  33. <view class="select">
  34. {{
  35. formData.type && (formData.type.id == 7 ? "研发立项" : "销售立项")
  36. }}
  37. </view>
  38. </picker>
  39. </uni-forms-item>
  40. <uni-forms-item
  41. label="行业名称"
  42. name="industry"
  43. v-show="!formData.type || (formData.type && formData.type.id != 7)"
  44. required
  45. >
  46. <picker
  47. @change="selectChangeIndustry"
  48. :range="industryList"
  49. :range-key="'name'"
  50. >
  51. <view class="select">
  52. {{
  53. formData.industry &&
  54. `${formData.industry.name}(${formData.industry.code})`
  55. }}
  56. </view>
  57. </picker>
  58. </uni-forms-item>
  59. <uni-forms-item
  60. label="项目地区"
  61. name="location"
  62. v-show="!formData.type || (formData.type && formData.type.id != 7)"
  63. required
  64. >
  65. <picker
  66. mode="multiSelector"
  67. @columnchange="bindChangeLocationColumn"
  68. @change="selectChangeLocation"
  69. :range="locationList"
  70. :range-key="'name'"
  71. >
  72. <view class="select">
  73. {{
  74. formData.location &&
  75. `${formData.location.name}(${formData.code.location})`
  76. }}
  77. </view>
  78. </picker>
  79. </uni-forms-item>
  80. <uni-forms-item
  81. label="项目简称"
  82. name="name"
  83. v-show="!formData.type || (formData.type && formData.type.id != 7)"
  84. required
  85. >
  86. <uni-easyinput
  87. type="text"
  88. v-model="formData.name"
  89. class="input"
  90. :clearable="false"
  91. @blur="onChangeName"
  92. />
  93. </uni-forms-item>
  94. <uni-forms-item
  95. label="项目期数"
  96. name="version"
  97. v-show="!formData.type || (formData.type && formData.type.id != 7)"
  98. required
  99. >
  100. <picker @change="selectChangeVersion" :range="versionList">
  101. <view class="select">
  102. {{ versionList[this.formData.version - 1] }}
  103. </view>
  104. </picker>
  105. </uni-forms-item>
  106. <uni-forms-item
  107. label="项目编号"
  108. name="code"
  109. v-show="!formData.type || (formData.type && formData.type.id != 7)"
  110. >
  111. <view>
  112. {{
  113. `${formData.code.type}-${formData.code.industry}-${formData.code.location}-${formData.code.name}-${formData.code.version}`
  114. }}
  115. </view>
  116. </uni-forms-item>
  117. </uni-forms>
  118. <view class="group">
  119. <button @click="onHandleSubmit(0)" class="commit">取消</button>
  120. <button @click="onHandleSubmit(1)" type="primary" class="commit">
  121. 确定
  122. </button>
  123. </view>
  124. </view>
  125. </template>
  126. <script>
  127. import { queryProjectType, queryIndustry, queryFlow } from "@/services/project";
  128. import provinces from "./provinces";
  129. import { mapState } from "vuex";
  130. const versionList = ["一期", "二期", "三期", "四期", "五期"];
  131. export default {
  132. data() {
  133. return {
  134. formData: {
  135. project_name: null,
  136. type: null,
  137. flow: null,
  138. industry: null,
  139. location: null,
  140. name: null,
  141. version: null,
  142. code: {
  143. type: "***",
  144. industry: "***",
  145. location: "***",
  146. name: "***",
  147. version: "*",
  148. },
  149. },
  150. rules: {
  151. project_name: {
  152. rules: [
  153. {
  154. required: true,
  155. errorMessage: "请输入项目名称",
  156. },
  157. ],
  158. },
  159. type: {
  160. rules: [
  161. {
  162. required: true,
  163. errorMessage: "请选择项目类别",
  164. },
  165. ],
  166. },
  167. industry: {
  168. rules: [
  169. {
  170. required: true,
  171. errorMessage: "请选择行业名称",
  172. },
  173. ],
  174. },
  175. location: {
  176. rules: [
  177. {
  178. required: true,
  179. errorMessage: "请选择地区",
  180. },
  181. ],
  182. },
  183. name: {
  184. rules: [
  185. {
  186. required: true,
  187. errorMessage: "请输入项目简称",
  188. },
  189. {
  190. maxLength: 3,
  191. errorMessage: "项目简称不能超过3位",
  192. },
  193. {
  194. validateFunction: function (rule, value, data, callback) {
  195. if (value.match(/[^A-Za-z]/g)) {
  196. callback("项目简称只能是英文字符");
  197. } else {
  198. callback();
  199. }
  200. },
  201. },
  202. ],
  203. },
  204. version: {
  205. rules: [
  206. {
  207. required: true,
  208. errorMessage: "请选择期数",
  209. },
  210. ],
  211. },
  212. },
  213. project_id: 0,
  214. typeList: [],
  215. industryList: [],
  216. flowList: [],
  217. versionList,
  218. provinces,
  219. locationList: [provinces, []],
  220. };
  221. },
  222. computed: {
  223. ...mapState(["currentProject"]),
  224. },
  225. onLoad(options) {
  226. this.project_id = options.project_id;
  227. this.init(options);
  228. },
  229. onReady() {
  230. this.$refs.form.setRules(this.rules);
  231. },
  232. methods: {
  233. onHandleSubmit(value) {
  234. if (value) {
  235. this.$refs.form.validate((err, formData) => {
  236. if (!err) {
  237. console.log("success", formData);
  238. uni.navigateTo({
  239. url: "./list",
  240. });
  241. }
  242. });
  243. } else uni.navigateTo({ url: "./list" });
  244. },
  245. async init(options) {
  246. let res;
  247. res = await queryProjectType();
  248. this.typeList = res.data;
  249. res = await queryIndustry();
  250. this.industryList = res.data;
  251. res = await queryFlow();
  252. this.flowList = res.data;
  253. let form = this.formData;
  254. let code = this.formData.code;
  255. let current = this.currentProject;
  256. if (options.project_id) {
  257. form.project_name = current.project_name;
  258. form.type = this.typeList.find(
  259. (item) => item.id == this.currentProject.type_id
  260. );
  261. form.flow = this.flowList.find(
  262. (item) => item.id == this.currentProject.flow_id
  263. );
  264. if (current.type.id != 7) {
  265. form.industry = this.industryList.find(
  266. (item) => item.id == this.currentProject.industry_id
  267. );
  268. form.location = current.location;
  269. form.name = current.name;
  270. form.version = current.version;
  271. code.type = form.type.code;
  272. code.industry = form.industry.code;
  273. code.location = form.location;
  274. code.name = form.name;
  275. code.version = form.version;
  276. }
  277. }
  278. },
  279. binddata(name, value) {
  280. this.$refs.form.setValue(name, value);
  281. },
  282. selectChangeType(e) {
  283. let form = this.formData;
  284. let code = this.formData.code;
  285. form.type = this.typeList[e.target.value];
  286. code.type = form.type.code;
  287. this.binddata("type", e.target.value);
  288. if (form.type.id == 7) {
  289. form.flow = this.flowList.find((item) => item.id == 1);
  290. form.industry = null;
  291. form.location = null;
  292. form.name = null;
  293. form.version = null;
  294. code.industry = "***";
  295. code.location = "***";
  296. code.name = "***";
  297. code.version = "*";
  298. } else form.flow = this.flowList.find((item) => item.id == 4);
  299. },
  300. selectChangeIndustry(e) {
  301. this.formData.industry = this.industryList[e.target.value];
  302. this.formData.code.industry = this.formData.industry.code;
  303. this.binddata("industry", e.target.value);
  304. },
  305. onChangeName(e) {
  306. let name = e.detail.value.toUpperCase();
  307. while (name.length < 3) name += "V";
  308. this.formData.name = name;
  309. this.formData.code.name = name;
  310. },
  311. selectChangeVersion(e) {
  312. this.formData.version = e.target.value + 1;
  313. this.formData.code.version = this.formData.version + "";
  314. this.binddata("version", e.target.value);
  315. },
  316. bindChangeLocationColumn(e) {
  317. e.target.column == 0 &&
  318. (this.locationList[1] = this.provinces[e.target.value].children || []);
  319. },
  320. selectChangeLocation(e) {
  321. let multiIndex = e.target.value;
  322. // let location = this.formData.location;
  323. // let locationCode = this.formData.code.location;
  324. let location = provinces[multiIndex[0]].children
  325. ? provinces[multiIndex[0]].children[multiIndex[1]]
  326. : provinces[multiIndex[0]];
  327. let code =
  328. location.code.length == 4 ? location.code.substr(1) : location.code;
  329. this.formData.location = location;
  330. this.formData.code.location = code;
  331. },
  332. },
  333. };
  334. </script>
  335. <style lang="less" scoped>
  336. .content {
  337. display: flex;
  338. flex-wrap: wrap;
  339. }
  340. .title {
  341. width: 100%;
  342. padding: 0 20px 20px 20px;
  343. background: #f8f8f8;
  344. font: 24px bold;
  345. }
  346. .form {
  347. margin: 20px 10% 0 10%;
  348. width: 100%;
  349. }
  350. .input {
  351. border: 1px solid #666;
  352. }
  353. .select {
  354. width: 100%;
  355. height: 72rpx;
  356. line-height: 70rpx;
  357. border: 1px solid #666;
  358. padding-left: 20rpx;
  359. }
  360. .group {
  361. width: 100%;
  362. display: flex;
  363. position: fixed;
  364. flex-wrap: wrap;
  365. justify-content: flex-start;
  366. bottom: 0;
  367. left: 0;
  368. .commit {
  369. width: 50%;
  370. border-radius: 0;
  371. margin: inherit;
  372. }
  373. }
  374. </style>