123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <template>
- <view class="content">
- <view class="title"> 新增项目 </view>
- <uni-forms :modelValue="formData" label-position="left" class="form">
- <uni-forms-item label="项目名称">
- <uni-easyinput
- type="text"
- v-model="formData.project_name"
- class="input"
- />
- </uni-forms-item>
- <uni-forms-item label="项目类别">
- <picker
- @change="selectChangeType"
- :range="typeList"
- :range-key="'name'"
- >
- <view class="select">
- {{
- formData.type && `${formData.type.name}(${formData.type.code})`
- }}
- </view>
- </picker>
- </uni-forms-item>
- <uni-forms-item label="流程">
- <picker disabled>
- <view class="select">
- {{
- formData.type && (formData.type.id == 7 ? "研发立项" : "销售立项")
- }}
- </view>
- </picker>
- </uni-forms-item>
- <uni-forms-item
- label="行业名称"
- v-show="!formData.type || (formData.type && formData.type.id != 7)"
- >
- <picker
- @change="selectChangeIndustry"
- :range="industryList"
- :range-key="'name'"
- >
- <view class="select">
- {{
- formData.industry &&
- `${formData.industry.name}(${formData.industry.code})`
- }}
- </view>
- </picker>
- </uni-forms-item>
- <uni-forms-item
- label="项目地区"
- v-show="!formData.type || (formData.type && formData.type.id != 7)"
- >
- <picker> <view class="select"></view></picker>
- </uni-forms-item>
- <uni-forms-item
- label="项目简称"
- v-show="!formData.type || (formData.type && formData.type.id != 7)"
- >
- <uni-easyinput
- type="text"
- v-model="formData.name"
- class="input"
- :clearable="false"
- @blur="onChangeName"
- />
- </uni-forms-item>
- <uni-forms-item
- label="项目期数"
- v-show="!formData.type || (formData.type && formData.type.id != 7)"
- >
- <picker @change="selectChangeVersion" :range="versionList">
- <view class="select">
- {{ versionList[this.formData.version - 1] }}
- </view>
- </picker>
- </uni-forms-item>
- <uni-forms-item
- label="项目编号"
- v-show="!formData.type || (formData.type && formData.type.id != 7)"
- >
- <view>
- {{
- `${formData.code.type}-${formData.code.industry}-${formData.code.location}-${formData.code.name}-${formData.code.version}`
- }}
- </view>
- </uni-forms-item>
- </uni-forms>
- <view class="group">
- <button @click="onHandleSubmit(0)" class="commit">取消</button>
- <button @click="onHandleSubmit(1)" type="primary" class="commit">
- 确定
- </button>
- </view>
- </view>
- </template>
- <script>
- import { queryProjectType, queryIndustry } from "@/services/project";
- import { mapState } from "vuex";
- const versionList = ["一期", "二期", "三期", "四期", "五期"];
- export default {
- data() {
- return {
- formData: {
- project_name: null,
- type: null,
- flow: null,
- industry: null,
- location: null,
- name: null,
- version: null,
- code: {
- type: "***",
- industry: "***",
- location: "***",
- name: "***",
- version: "*",
- },
- },
- project_id: 0,
- typeList: [],
- industryList: [],
- versionList,
- };
- },
- computed: {
- ...mapState(["currentProject"]),
- },
- onLoad(options) {
- this.project_id = options.project_id;
- this.init(options);
- },
- methods: {
- onHandleSubmit(value) {
- if (value) console.log(this.formData);
- uni.navigateTo({
- url: "./list",
- });
- },
- async init(options) {
- let form = this.formData;
- let code = this.formData.code;
- let current = this.currentProject;
- if (options.project_id) {
- form.project_name = current.project_name;
- form.type = this.typeList.find(
- (item) => item.id == this.currentProject.type_id
- );
- form.flow = this.typeList.find(
- (item) => item.id == this.currentProject.flow_id
- );
- if (current.type.id != 7) {
- form.industry = this.industryList.find(
- (item) => item.id == this.currentProject.industry_id
- );
- form.location = current.location;
- form.name = current.name;
- form.version = current.version;
- code.type = form.type.code;
- code.industry = form.industry.code;
- code.location = form.location;
- code.name = form.name;
- code.version = form.version;
- }
- }
- let res;
- res = await queryProjectType();
- this.typeList = res.data;
- res = await queryIndustry();
- this.industryList = res.data;
- },
- selectChangeType(e) {
- let form = this.formData;
- let code = this.formData.code;
- form.type = this.typeList[e.target.value];
- code.type = form.type.code;
- if (form.type.id == 7) {
- form.flow = this.typeList.find((item) => item.id == 1);
- form.industry = null;
- form.location = null;
- form.name = null;
- form.version = null;
- code.industry = "***";
- code.location = "***";
- code.name = "***";
- code.version = "*";
- } else form.flow = this.typeList.find((item) => item.id == 4);
- },
- selectChangeIndustry(e) {
- this.formData.industry = this.industryList[e.target.value];
- this.formData.code.industry = this.formData.industry.code;
- },
- onChangeName(e) {
- let name = e.detail.value.toUpperCase();
- while (name.length < 3) name += "V";
- this.formData.name = name;
- this.formData.code.name = name;
- },
- selectChangeVersion(e) {
- this.formData.version = e.target.value + 1;
- this.formData.code.version = this.formData.version + "";
- },
- },
- };
- </script>
- <style lang="less" scoped>
- .content {
- display: flex;
- flex-wrap: wrap;
- }
- .title {
- width: 100%;
- padding: 0 20px 20px 20px;
- background: #f8f8f8;
- font: 24px bold;
- }
- .form {
- margin: 20px 10% 0 10%;
- width: 100%;
- }
- .input {
- border: 1px solid #666;
- }
- .select {
- width: 100%;
- height: 72rpx;
- line-height: 70rpx;
- border: 1px solid #666;
- padding-left: 20rpx;
- }
- .group {
- width: 100%;
- display: flex;
- position: fixed;
- flex-wrap: wrap;
- justify-content: flex-start;
- bottom: 0;
- left: 0;
- .commit {
- width: 50%;
- border-radius: 0;
- margin: inherit;
- }
- }
- </style>
|