fullyCollectionInfoDialog.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="800px" @close="handleClose" append-to-body>
  3. <el-form validate-on-rule-change :rules="rules" ref="form" :model="form" label-width="140px">
  4. <!-- 动态渲染问题区域 -->
  5. <div v-if="form.answers && form.answers.length > 0">
  6. <div style="margin-bottom: 20px;margin-top: 20px;" v-for="(answer, index) in form.answers" :key="index">
  7. <div style="margin-bottom: 20px;margin-top: 20px;">
  8. <span style="font-size: 15px;font-weight: bold; margin-left: 31px">{{ answer.title }}</span>
  9. </div>
  10. <div style="margin-left: 31px;">
  11. <!-- 修改:移除 @change 事件,添加 disabled 属性 -->
  12. <el-checkbox-group
  13. v-model="answer.value"
  14. size="mini"
  15. disabled>
  16. <div v-for="(option, optionIndex) in answer.options" :key="`${index}-${optionIndex}`" style="display: flex; align-items: center; margin-bottom: 10px;">
  17. <!-- 修改:添加 disabled 属性 -->
  18. <el-checkbox :label="option.value" style="margin-right: 10px; flex-shrink: 0;" disabled>
  19. {{ option.name }}
  20. </el-checkbox>
  21. <!-- 备注输入区域(只读模式) -->
  22. <div v-if="option.open && isOptionSelected(answer, option)" style="display: inline-block;">
  23. <!-- 修改:添加 readonly 属性,并移除 @blur 事件 -->
  24. <el-input
  25. v-model="option.remarkText"
  26. placeholder="请输入备注信息"
  27. size="mini"
  28. maxlength="20"
  29. show-word-limit
  30. style="width: 200px; margin-left: 5px;"
  31. readonly
  32. :class="{ 'remark-required': !option.remarkText || option.remarkText.trim() === '' }"/>
  33. <!-- 修改:只显示必填标识,但不显示错误提示文字 -->
  34. <div v-if="!option.remarkText || option.remarkText.trim() === ''" class="remark-error-tip">此项为必填</div>
  35. </div>
  36. </div>
  37. </el-checkbox-group>
  38. </div>
  39. </div>
  40. </div>
  41. </el-form>
  42. <div slot="footer" class="dialog-footer">
  43. <el-button @click="dialogVisible = false">关 闭</el-button>
  44. <!-- 修改:移除确定按钮,因为不允许编辑 -->
  45. </div>
  46. </el-dialog>
  47. </template>
  48. <script>
  49. import { getInfo, submitSalesInfo } from "@/api/qw/collectionPendingSales";
  50. export default {
  51. name: "FullyCollectionInfoDialog",
  52. props: {
  53. visible: {
  54. type: Boolean,
  55. default: false
  56. },
  57. id: {
  58. type: Number,
  59. required: true
  60. },
  61. userId: {
  62. type: Number,
  63. required: true
  64. },
  65. questionId: {
  66. type: Number,
  67. required: true
  68. }
  69. },
  70. data() {
  71. return {
  72. dialogVisible: false,
  73. form: {
  74. id: null,
  75. questionId: null,
  76. packageId: null,
  77. payType: null,
  78. amount: null,
  79. isPackage: null,
  80. answers: [],
  81. userName: '',
  82. userPhoneFour: '',
  83. sex: null,
  84. age: null,
  85. allergy: '',
  86. remark: ''
  87. },
  88. privatePackageOptions: [],
  89. loading: false,
  90. rules: {}
  91. };
  92. },
  93. computed: {
  94. dialogTitle() {
  95. return "查看采集信息";
  96. }
  97. },
  98. watch: {
  99. visible: {
  100. handler(val) {
  101. this.dialogVisible = val;
  102. if (val) {
  103. this.initDialog();
  104. }
  105. },
  106. immediate: true
  107. }
  108. },
  109. created() {
  110. },
  111. methods: {
  112. // 验证需要备注的选项是否填写了备注 - 不需要了,因为只读模式
  113. validateRequiredRemarks() {
  114. // 只读模式下不需要验证
  115. return true;
  116. },
  117. // 监听复选框组的变化 - 不需要了
  118. onCheckboxGroupChange(answer) {
  119. // 只读模式下不需要处理变化
  120. },
  121. // 检查选项是否被选中
  122. isOptionSelected(answer, option) {
  123. return answer.value && answer.value.includes(option.value);
  124. },
  125. // 备注输入框失去焦点时的处理 - 不需要了
  126. onRemarkBlur(option) {
  127. // 只读模式下不需要处理
  128. },
  129. initDialog() {
  130. this.resetFormData();
  131. if (this.userId) {
  132. this.loadUserData();
  133. }
  134. this.$nextTick(() => {
  135. if (this.$refs.form) {
  136. this.$refs.form.clearValidate();
  137. }
  138. });
  139. },
  140. loadUserData() {
  141. this.loading = true;
  142. getInfo({userId: this.userId, questionId: this.questionId}).then(response => {
  143. const data = response.data;
  144. this.form = {
  145. id: data.id,
  146. questionId: data.questionId,
  147. packageId: data.packageId,
  148. payType: data.payType,
  149. amount: data.amount,
  150. isPackage: data.isPackage,
  151. answers: this.processAnswers(data.answers),
  152. userName: data.userName,
  153. userPhoneFour: data.userPhoneFour,
  154. sex: data.sex,
  155. age: data.age,
  156. allergy: data.allergy,
  157. remark: data.remark
  158. };
  159. }).catch(error => {
  160. this.$message.error('加载用户信息失败');
  161. console.error('加载用户信息失败:', error);
  162. }).finally(() => {
  163. this.loading = false;
  164. });
  165. },
  166. // 处理答案数据,确保选项有备注相关的字段
  167. processAnswers(answers) {
  168. if (!answers || !Array.isArray(answers)) {
  169. return [];
  170. }
  171. return answers.map(answer => {
  172. // 建立 value -> text 的映射,用于快速回填备注
  173. const remarksMap = {};
  174. if (answer.remarksList && Array.isArray(answer.remarksList)) {
  175. answer.remarksList.forEach(item => {
  176. remarksMap[item.value] = item.text;
  177. });
  178. }
  179. const processedOptions = (answer.options || []).map(option => ({
  180. ...option,
  181. remarkText: remarksMap[option.value] || '' // 有备注则填充,否则为空
  182. }));
  183. return {
  184. ...answer,
  185. value: answer.value || [], // 确保 value 存在
  186. options: processedOptions
  187. };
  188. });
  189. },
  190. resetFormData() {
  191. this.form = {
  192. id: null,
  193. questionId: null,
  194. packageId: null,
  195. payType: null,
  196. amount: null,
  197. isPackage: null,
  198. answers: [],
  199. userName: '',
  200. userPhoneFour: '',
  201. sex: null,
  202. age: null,
  203. allergy: '',
  204. remark: ''
  205. };
  206. },
  207. // 提交表单 - 不需要了,因为只读模式
  208. submitForm() {
  209. // 只读模式下不需要提交功能
  210. },
  211. handleClose() {
  212. this.dialogVisible = false;
  213. this.$emit('update:visible', false);
  214. this.resetFormData();
  215. }
  216. }
  217. };
  218. </script>
  219. <style scoped>
  220. /* 修改样式,使只读状态更明显 */
  221. .remark-required >>> .el-input__inner {
  222. border-color: #e4e7ed !important; /* 默认边框颜色 */
  223. background-color: #f5f7fa; /* 浅灰色背景 */
  224. }
  225. .remark-error-tip {
  226. color: #909399; /* 灰色字体,表示只读状态 */
  227. font-size: 12px;
  228. line-height: 1.5;
  229. margin-left: 5px;
  230. }
  231. /* 为只读复选框添加样式 */
  232. .el-checkbox__input.is-disabled + .el-checkbox__label {
  233. color: #c0c4cc !important; /* 灰色文字 */
  234. }
  235. </style>