From 6fe042afc9fc5caa55d325dea1038e3b06a48e18 Mon Sep 17 00:00:00 2001 From: yanzai Date: Fri, 6 Sep 2024 23:02:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86=E9=97=AE?= =?UTF-8?q?=E7=AD=94=E3=80=81=E8=8E=B7=E5=8F=96=E9=97=AE=E7=AD=94=E9=A2=98?= =?UTF-8?q?=E7=9B=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../API/Admin/YeWu/QuestionController.php | 57 +++++- .../Controllers/API/H5/QuestionController.php | 28 +++ Laravel/routes/api.php | 3 + Laravel/routes/web.php | 1 + admin/src/api/api.js | 12 ++ admin/src/views/HospitalMngr/Questions.vue | 186 +++++++++++++++++- 6 files changed, 277 insertions(+), 10 deletions(-) create mode 100644 Laravel/app/Http/Controllers/API/H5/QuestionController.php diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionController.php index 8bdab9a..b43c455 100644 --- a/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionController.php +++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/QuestionController.php @@ -15,9 +15,64 @@ class QuestionController extends Controller if (!isset($searchInfo['q_type'])) return \Yz::echoError1("问卷类型不能为空"); $list = DB::table('questions') ->where(['hospital_id'=>$searchInfo['hospital_id'], - 'q_type'=>$searchInfo['q_type'] + 'q_type'=>$searchInfo['q_type'], + 'is_del'=>0, ])->orderBy('order','asc')->get(); return \Yz::Return(true,"查询成功",['list'=>$list]); + } + public function Save() + { + $QuestionInfo = request('QuestionInfo'); + $params = [ + 'hospital_id'=>isset($QuestionInfo['hospital_id'])?$QuestionInfo['hospital_id']:null, + 'question'=>isset($QuestionInfo['question'])?$QuestionInfo['question']:null, + 'content'=>(isset($QuestionInfo['content']) and !empty($QuestionInfo['content']))?json_encode($QuestionInfo['content'],JSON_UNESCAPED_UNICODE):null, + 'type'=>isset($QuestionInfo['type'])?$QuestionInfo['type']:null, + 'status'=>isset($QuestionInfo['status'])?$QuestionInfo['status']:null, + 'order'=>isset($QuestionInfo['order'])?$QuestionInfo['order']:null, + 'q_type'=>isset($QuestionInfo['q_type'])?$QuestionInfo['q_type']:null, + ]; + $requiredFields = [ + 'hospital_id','question','content','type','status','order','q_type' + ]; + // 判断是否为空 + foreach ($requiredFields as $field) { + if (!isset($params[$field]) || $params[$field] === null) { + return \Yz::echoError1('参数' . $field . '不能为空'); + } + } + if(isset($QuestionInfo['id']) and $QuestionInfo['id']<>0){ + $insert=DB::table('questions')->where(['id'=>$QuestionInfo['id'],'is_del'=>0])->update($params); + }else{ + $insert=DB::table('questions')->insert($params); + } + if($insert){ + return \Yz::Return(true,'操作成功',[]); + }else{ + return \Yz::echoError1('操作失败'); + } + + } + public function GetDetail() + { + $id = request('id'); + $info=DB::table('questions')->where(['id'=>$id,'is_del'=>0])->first(); + if(!!$info){ + $info->content=json_decode($info->content,true); + } + return \Yz::Return(true,'查询完成',$info); + } + public function Del() + { + $id = request('id'); + $del=DB::table('questions')->where(['id'=>$id])->update([ + 'is_del'=>1 + ]); + if($del){ + return \Yz::Return(true,'操作成功',[]); + }else{ + return \Yz::echoError1('操作失败'); + } } } diff --git a/Laravel/app/Http/Controllers/API/H5/QuestionController.php b/Laravel/app/Http/Controllers/API/H5/QuestionController.php new file mode 100644 index 0000000..6050403 --- /dev/null +++ b/Laravel/app/Http/Controllers/API/H5/QuestionController.php @@ -0,0 +1,28 @@ +where(['hospital_id'=>$hospital_id, + 'q_type'=>$q_type, + 'status'=>1, + 'is_del'=>0, + ])->orderBy('order','asc')->get(); + foreach ($list as $key=>$item){ + $item->content=json_decode($item->content,true); + } + return \Yz::Return(true,"查询成功",['list'=>$list]); + } +} diff --git a/Laravel/routes/api.php b/Laravel/routes/api.php index 3266c81..c79fe1f 100644 --- a/Laravel/routes/api.php +++ b/Laravel/routes/api.php @@ -78,6 +78,9 @@ Route::group(['middleware' => ['checktoken', 'log'], 'prefix' => 'v1'], function Route::post('admin/ComboCrowdGetList', 'App\Http\Controllers\API\Admin\YeWu\ComboCrowdController@GetList');//套餐适应人群 Route::post('admin/OrderGetList', 'App\Http\Controllers\API\Admin\YeWu\OrderController@GetList');//订单列表 Route::post('admin/QuestionGetList', 'App\Http\Controllers\API\Admin\YeWu\QuestionController@GetList');//问答列表 + Route::post('admin/QuestionSave', 'App\Http\Controllers\API\Admin\YeWu\QuestionController@Save');//保存题目 + Route::post('admin/QuestionGetDetail', 'App\Http\Controllers\API\Admin\YeWu\QuestionController@GetDetail');//题目详情 + Route::post('admin/QuestionDel', 'App\Http\Controllers\API\Admin\YeWu\QuestionController@Del');//删除题目 diff --git a/Laravel/routes/web.php b/Laravel/routes/web.php index 0791d2f..f7da43f 100644 --- a/Laravel/routes/web.php +++ b/Laravel/routes/web.php @@ -43,6 +43,7 @@ Route::group(['prefix' => 'H5'], function () { Route::post('/GetPersonList', 'App\Http\Controllers\API\H5\UserController@GetPersonList');//获取名下全部体检人 Route::post('/SetDefaultPerson', 'App\Http\Controllers\API\H5\UserController@SetDefaultPerson');//设置默认体检人 Route::post('/HospitalIntroduction', 'App\Http\Controllers\API\H5\HospitalExtraController@Introduction');//医院简介 + Route::post('/QuestionGetList', 'App\Http\Controllers\API\H5\QuestionController@GetList');//问题列表 }); diff --git a/admin/src/api/api.js b/admin/src/api/api.js index ef0e629..a9a1743 100644 --- a/admin/src/api/api.js +++ b/admin/src/api/api.js @@ -220,4 +220,16 @@ export const OrderGetList = (data={}) => { //获取问答列表 export const QuestionGetList = (data={}) => { return axios({url:import.meta.env.VITE_APP_API+'v1/admin/QuestionGetList',data:data}) +} +//保存题目 +export const QuestionSave = (data={}) => { + return axios({url:import.meta.env.VITE_APP_API+'v1/admin/QuestionSave',data:data}) +} +//获取题目详情 +export const QuestionGetDetail = (data={}) => { + return axios({url:import.meta.env.VITE_APP_API+'v1/admin/QuestionGetDetail',data:data}) +} +//删除题目 +export const QuestionDel = (data={}) => { + return axios({url:import.meta.env.VITE_APP_API+'v1/admin/QuestionDel',data:data}) } \ No newline at end of file diff --git a/admin/src/views/HospitalMngr/Questions.vue b/admin/src/views/HospitalMngr/Questions.vue index fd44d2f..541b477 100644 --- a/admin/src/views/HospitalMngr/Questions.vue +++ b/admin/src/views/HospitalMngr/Questions.vue @@ -10,13 +10,14 @@ :value="item.id" /> 切换 + 新建问题 问卷类型 + @change="QuestionBigTypeChange()"> 满意度调查 健康问卷 @@ -38,19 +39,74 @@ 关闭 - + + + +
+ + + + + + + 填空 + 单选 + 多选 + + + + + 添加 + + +
+
+ + + + +
+ +
+ +
+ + + + + + +
+
+ +
@@ -60,14 +116,16 @@ onMounted } from 'vue' import { - ElMessage + ElMessage,ElMessageBox } from 'element-plus' import { HospitalGetEnableList, - QuestionGetList + QuestionGetList,QuestionSave,QuestionGetDetail,QuestionDel } from '@/api/api.js' import { - Edit + Edit, + Top, + Bottom,Delete } from '@element-plus/icons-vue' let loading = ref(false) let tableData = ref([]) @@ -87,8 +145,34 @@ const ChangeHospital = () => { GetList() } - const QuestionTypeChange = () => { + const QuestionBigTypeChange = () => { GetList() + + } + //弹框里切换题目类型 + const QuestionTypeChange = () => { + QuestionInfo.value.Tempcontent = '' + QuestionInfo.value.item = [] + } + //弹框里点击添加题目选项 + const QuestionOptionAdd = () => { + if (QuestionInfo.value.Tempcontent.length > 0) { + QuestionInfo.value.item.push(QuestionInfo.value.Tempcontent) + QuestionInfo.value.Tempcontent = '' + } + } + const OptionUp=(index)=>{ + let temp = QuestionInfo.value.item[index-1]; + QuestionInfo.value.item[index-1]=QuestionInfo.value.item[index] + QuestionInfo.value.item[index]=temp + } + const OptionDown=(index)=>{ + let temp = QuestionInfo.value.item[index+1]; + QuestionInfo.value.item[index+1]=QuestionInfo.value.item[index] + QuestionInfo.value.item[index]=temp + } + const OptionDel=(index)=>{ + QuestionInfo.value.item.splice(index, 1); } let hospital_list = ref([]); const GetEnableHospitalList_func = () => { @@ -104,6 +188,90 @@ } }) } + let QuestionInfo = ref({}); + const EditClick = (row='') => { + dialogVisible.value = true + QuestionInfo.value.order = 1 + QuestionInfo.value.status = 1 + QuestionInfo.value.Tempcontent = '' + QuestionInfo.value.item = [] + QuestionInfo.value.id=0 + if(row!=''){ + GetDetail(row.id); + } + + + } + //获取详情 + const GetDetail=(id)=>{ + loading.value = true + QuestionGetDetail({ + id: id + }).then(res => { + loading.value = false + if (res.status) { + QuestionInfo.value=res.data + if(QuestionInfo.value.type===1){ + QuestionInfo.value.Tempcontent=res.data.content + }else{ + QuestionInfo.value.item=res.data.content + } + + } else { + ElMessage.error(res.msg) + } + }) + } + const Del=(row)=>{ + ElMessageBox.confirm( + '确定删除吗?', + '提示', + { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + } + ) + .then(() => { + loading.value = true + QuestionDel({ + id: row.id + }).then(res => { + loading.value = false + if (res.status) { + ElMessage({ + type: 'success', + message: '删除完成', + }) + GetList() + } else { + ElMessage.error(res.msg) + } + }) + }) + } + const AddQuestion=()=>{ + QuestionInfo.value.q_type=searchInfo.value.q_type + QuestionInfo.value.hospital_id=searchInfo.value.hospital_id + QuestionInfo.value.content=QuestionInfo.value.item + if(QuestionInfo.value.type===1){ + QuestionInfo.value.content=QuestionInfo.value.Tempcontent + } + console.log(QuestionInfo.value); + loading.value = true + QuestionSave({ + QuestionInfo: QuestionInfo.value + }).then(res => { + loading.value = false + if (res.status) { + dialogVisible.value = false + GetList() + } else { + ElMessage.error(res.msg) + } + }) + + } const GetList = () => { loading.value = true QuestionGetList({ @@ -118,7 +286,7 @@ }) } onMounted(() => { - searchInfo.value.q_type =2 + searchInfo.value.q_type = 2 GetEnableHospitalList_func() })