ckgl/pages/maintenance/m-other.vue
2024-12-28 17:30:09 +08:00

155 lines
4.0 KiB
Vue

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { getAction, putAction } from '../../common/http';
import { showToast } from 'vant';
const list = ref([] as any[])
onMounted(()=>{
init()
})
function init(){
getAction('/extraOption').then((res:any)=>{
if(res.code===200){
list.value=JSON.parse(res.data.payload)
}
})
}
const onClickLeft = () =>{
history.back()
}
const onClickRight=()=>{
list.value.push({options:[{}]})
}
//新增选项
const addxx = (item:any) =>{
item.options.push({})
}
const onSubmit = () =>{
let param={
id:1,
payload:JSON.stringify(list.value)
}
putAction('/extraOption',param).then((res:any)=>{
if(res.code===200){
showToast('提交成功!')
init()
}
})
}
</script>
<template>
<view class="flex">
<van-nav-bar
title="其他要求项维护"
left-text="返回"
left-arrow
right-text="新增"
@click-left="onClickLeft"
@click-right="onClickRight"
/>
<view class="content">
<view class="card" v-for="(item,index) in list" :key="index">
<van-cell-group inset>
<view class="a-b">
<van-icon name="clear" color="red" size="25" @click="list.splice(index,1)"/>
<van-field
v-model="item.name"
name="要求项名称"
label="要求项名称"
colon
class="a-c"
label-width="6em"
:rules="[{ required: true, message: '请填写' }]"
/>
<van-button type="primary" @click="addxx(item)">新增选项</van-button>
</view>
<van-field name="是否必填" label="是否必填" colon label-width="7.5em">
<template #input>
<van-radio-group v-model="item.necessary" direction="horizontal">
<van-radio :name="true">是</van-radio>
<van-radio :name="false">否</van-radio>
</van-radio-group>
</template>
</van-field>
</van-cell-group>
<view class="grid-container">
<view class="grid-item"></view>
<view class="grid-item">内容</view>
<view class="grid-item">是否默认</view>
<view class="grid-item">操作</view>
</view>
<view class="grid-container" v-for="(itemSecond,indexSecond) in item.options" :key="indexSecond">
<view class="grid-item">选项</view>
<view class="grid-item"> <van-field v-model="itemSecond.name" /></view>
<view class="grid-item" style="display: flex;align-items: center;justify-content: center">
<van-checkbox-group v-model="itemSecond.default">
<van-checkbox :name="true"></van-checkbox>
</van-checkbox-group></view>
<view class="grid-item" style="color: red" @click="item.options.splice(indexSecond,1)">删除</view>
</view>
</view>
</view>
<van-button type="primary" style="margin: 10rpx;" @click="onSubmit">提交</van-button>
</view>
</template>
<style scoped lang="scss">
.flex{
display: flex;
flex-direction: column;
height: 100vh;
width: 100vw;
.van-nav-bar{
width: 100%;
}
.content{
flex: 1;
padding: 0 20rpx;
.grid-container {
display: grid;
grid-template-columns: 1fr 2fr 1.5fr 1.5fr;
.grid-item{
border: 1rpx solid #f2f2f2;
text-align: center;
::v-deep .van-cell{
padding: 0 10rpx;
}
}
}
.card{
margin: 16rpx 20rpx;
padding: 10rpx;
border: 1rpx solid #02a7f0;
border-radius: 20rpx;
}
.a-b{
display: flex;
align-items: center;
::v-deep .van-button--normal {
padding: 8rpx;
height: 50rpx;
width: 7em;
}
}
}
::v-deep .van-field{
font-size: 16px;
padding: 0;
}
::v-deep .van-cell-group--inset{
margin: 0;
}
.a-c{
::v-deep .van-field__control{
border-bottom: 1rpx solid #d7d7d7;
}
}
::v-deep .van-field__label{
text-align: end;
}
}
</style>