123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <template>
- <div class="form">
- <van-nav-bar
- title="工序管理"
- left-text="返回"
- left-arrow
- @click-left="onClickLeft"
- >
- </van-nav-bar>
- <testForm
- v-model="formData.data"
- :formOption="formOption"
- :formConfig="formConfig"
- :rules="rules"
- @onSubmit="onSubmit"
- ref="formDom"
- >
- <template #processRouteList>
- <div class="row">
- <div class="col" style="width: 50%">
- <van-checkbox-group
- v-model="formData.data.processRouteList"
- >
- <van-checkbox
- :name="i.id"
- v-for="i in processRouteListData"
- :key="i.id"
- >{{ i.name }}</van-checkbox
- >
- </van-checkbox-group>
- </div>
- <div class="col" style="width: 50%">
- <div v-for="(i, index) in formData.data.processRouteList" draggable="true">
- <van-icon name="arrow-up" @click="sortUp(i)" />
- <van-icon name="arrow-down" @click="sortdown(i)" />
- <span style="margin-right: 10px">{{
- index + 1
- }}</span>
- {{ getName2(i) }}
- </div>
- </div>
- </div>
- </template>
- <template #applicableProductsList>
- <div
- style="color: #999; width: calc(100vw - 32px)"
- @click="show = true"
- >
- 请选择
- </div>
- <div class="selectd" @click="show = true">
- <div>
- <van-tag
- v-for="i in formData.data.applicableProductsList"
- :key="i"
- closeable
- size="medium"
- type="primary"
- @close="deleteTag(i.id)"
- style="margin-right: 10px"
- >
- {{ getName(i) }}
- </van-tag>
- </div>
- </div>
- </template>
- </testForm>
- <van-popup
- v-model:show="show"
- closeable
- position="bottom"
- :style="{ height: '60%' }"
- >
- <div style="height: 50px; width: 100px"></div>
- <van-checkbox-group v-model="formData.data.applicableProductsList">
- <van-cell-group inset v-for="i in productInfoData" :key="i.id">
- <van-cell clickable :title="i.name">
- <template #right-icon>
- <van-checkbox :name="i.id"></van-checkbox>
- </template>
- </van-cell>
- </van-cell-group>
- </van-checkbox-group>
- </van-popup>
- </div>
- </template>
- <script setup>
- import { ref, getCurrentInstance, onMounted, reactive } from 'vue'
- import { showSuccessToast, showToast } from 'vant'
- import { useRoute } from 'vue-router'
- import { getUserInfo } from '@/utils/auth'
- import testForm from '@/components/testForm/index.vue'
- const proxy = getCurrentInstance().proxy
- const route = useRoute()
- const show = ref(false)
- const typeModal = ref(false)
- const unitModal = ref(false)
- const classification = ref([])
- const formData = reactive({
- data: {
- checked: [],
- },
- })
- const formDom = ref(null)
- const formOption = reactive({
- readonly: false, //用于控制整个表单是否只读
- disabled: false,
- labelAlign: 'top',
- scroll: true,
- labelWidth: '62pk',
- // hiddenSubmitBtn: true,
- })
- let selected = ref([])
- const sortUp = (id) => {
- let index = formData.data.processRouteList.findIndex((i) => i === id)
- if (index === 0) {
- return
- }
- let temp = formData.data.processRouteList[index]
- formData.data.processRouteList[index] = formData.data.processRouteList[index - 1]
- formData.data.processRouteList[index - 1] = temp
- }
- const sortdown = (id) => {
- let index = formData.data.processRouteList.findIndex((i) => i === id)
- if (index === formData.data.processRouteList.length - 1) {
- return
- }
- let temp = formData.data.processRouteList[index]
- formData.data.processRouteList[index] = formData.data.processRouteList[index + 1]
- formData.data.processRouteList[index + 1] = temp
- }
- const deleteTag = (id) => {
- let index = formData.data.applicableProductsList.findIndex((i) => i.id === id)
- formData.data.applicableProductsList.splice(index, 1)
- }
- const getName = (id) => {
- let name = ''
- productInfoData.value.forEach((i) => {
- if (i.id === id) {
- name = i.name
- }
- })
- return name
- }
- const getName2 = (id) => {
- let name = ''
- processRouteListData.value.forEach((i) => {
- if (i.id === id) {
- name = i.name
- }
- })
- return name
- }
- const formConfig = reactive([
- {
- type: 'input',
- itemType: 'text',
- label: '车间名称',
- prop: 'name',
- clearable: true,
- },
- {
- type: 'slot',
- label: '工艺线路',
- slotName: 'processRouteList',
- },
- {
- type: 'slot',
- label: '适用产品',
- slotName: 'applicableProductsList',
- },
- ])
- const rules = {
- name: [{ required: true, message: '车间类型不能为空' }],
- fileList: [{ required: true, message: '请上传工序文件' }],
- }
- const unitList = ref([])
- let processRouteListData = ref([])
- const getUserList = () => {
- proxy.get('/system/user/list?pageNum=1&pageSize=10000', {}).then((res) => {
- formConfig[2].data = res.rows
- })
- }
- getUserList()
- const fileList = ref([])
- const onOversize = () => {
- showToast('文件大小不能超过 5MB')
- }
- const onClickLeft = () => history.back()
- const onSubmit = () => {
- console.log(formData)
- formData.data.productList = formData.data.applicableProductsList.map(item=>{
- return {
- productId:item
- }
- })
- proxy
- .post('/technology/' + route.query.type, formData.data)
- .then(() => {
- showSuccessToast(
- route.query.type === 'add' ? '添加成功' : '修改成功'
- )
- setTimeout(() => {
- history.back()
- }, 500)
- })
- }
- const treeToList = (arr) => {
- let res = [] // 用于存储递归结果(扁平数据)
- // 递归函数
- let fn = (source) => {
- source.forEach((el) => {
- res.push(el)
- el.children && el.children.length > 0 ? fn(el.children) : '' // 子级递归
- })
- }
- fn(arr)
- return res
- }
- const getDtl = (id) => {
- proxy
- .post('/productionProcesses/page', { id: route.query.id })
- .then((resDetail) => {
- processRouteListData.value = resDetail.data.rows
- console.log(processRouteListData.value)
- })
- proxy
- .post('/productInfo/page', { pageNum: 1, pageSize: 10000 })
- .then((resDetail) => {
- productInfoData.value = resDetail.data.rows
- })
- }
- let productInfoData = ref([])
- onMounted(() => {
- if (route.query.id) {
- proxy
- .post('/technology/detail', { id: route.query.id })
- .then((resDetail) => {
- formData.data = {
- ...resDetail.data,
- processRouteList: resDetail.data.processRouteList.map(
- (item) => item.id
- ),
- applicableProductsList: resDetail.data.applicableProductsList.map(
- (item) => item.id
- ),
- }
- getDtl()
- })
- }else{
- getDtl()
- }
-
- })
- </script>
- <style scoped lang="scss">
- .row {
- overflow: hidden;
- width: calc(100vw - 32px);
- .col {
- width: 50%;
- float: left;
- box-sizing: border-box;
- padding: 0 10px;
- overflow: hidden;
- .van-icon-arrow-down,
- .van-icon-arrow-up {
- display: inline-block;
- height: 18px;
- margin: 1px 3px;
- line-height: 18px;
- background: #1989fa;
- width: 18px;
- color: #fff;
- border-radius: 9px;
- text-align: center;
- }
- }
- }
- </style>
|