projectForm.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div class="infrastructures">
  3. <div class="til">
  4. <p>项目表单设置</p>
  5. <div style="display: flex;">
  6. <p style="cursor:pointer;margin-left: 30px;color: #20A0FF;" @click="addJa('添加表单字段', 'ruleForm')"><i class="el-icon-circle-plus-outline"></i>添加</p>
  7. </div>
  8. </div>
  9. <div class="tabl">
  10. <el-table :data="dataList" highlight-current-row v-loading="listLoading" :height="heightDoms" style="width: 100%;">
  11. <el-table-column type="index" label="序号" width="250px">
  12. <template slot-scope="scope" >
  13. {{scope.$index + 1}}
  14. </template>
  15. </el-table-column>
  16. <el-table-column prop="customName" label="自定义名称" sortable></el-table-column>
  17. <el-table-column prop="customType" label="类型" sortable>
  18. <template slot-scope="scope">
  19. {{scope.row.customType == '2' ? '日期' : (scope.row.customType == '1' ? '图片' : '文本')}}
  20. </template>
  21. </el-table-column>
  22. <el-table-column label="操作" width="280">
  23. <template slot-scope="scope">
  24. <el-button size="mini" type="primary" @click="editor(scope.row, '编辑表单字段')">编辑</el-button>
  25. <el-button size="mini" type="danger" @click="deteles(scope.row)">删除</el-button>
  26. </template>
  27. </el-table-column>
  28. </el-table>
  29. </div>
  30. <!-- 弹窗 -->
  31. <el-dialog :title="titleTex" :visible.sync="dialogVisible" width="400px" :before-close="handleClose">
  32. <div>
  33. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" class="demo-ruleForm">
  34. <el-form-item label="类型">
  35. <el-radio-group v-model="ruleForm.customType">
  36. <el-radio-button label="0">文本</el-radio-button>
  37. <el-radio-button label="1">图片</el-radio-button>
  38. <el-radio-button label="2">日期</el-radio-button>
  39. </el-radio-group>
  40. </el-form-item>
  41. <el-form-item label="名称" prop="customName">
  42. <el-input placeholder="请输入自定义名称" v-model.trim="ruleForm.customName" clearable></el-input>
  43. </el-form-item>
  44. </el-form>
  45. </div>
  46. <span slot="footer" class="dialog-footer">
  47. <el-button @click="dialogVisible = false">取 消</el-button>
  48. <el-button type="primary" @click="determine('ruleForm')" v-loading="listLoading">确 定</el-button>
  49. </span>
  50. </el-dialog>
  51. </div>
  52. </template>
  53. <script>
  54. export default {
  55. props: {},
  56. components: {},
  57. data() {
  58. return {
  59. heightDoms: document.documentElement.clientHeight - 130,
  60. titleTex: '添加表单字段',
  61. dialogVisible: false,
  62. ruleForm: {
  63. id: '',
  64. companyId: '',
  65. customName: '',
  66. customType: '0'
  67. },
  68. rules: {customName: [{required: true, message: '请输入自定义名称', trigger: 'blur'}]},
  69. listLoading: false,
  70. user: JSON.parse(sessionStorage.getItem("user")),
  71. dataList: []
  72. };
  73. },
  74. computed: {},
  75. watch: {},
  76. created() {},
  77. mounted() {
  78. this.getObtain()
  79. },
  80. methods: {
  81. getObtain() {
  82. this.listLoading = true
  83. this.http.post('/project-custom/getProjectCustom', this.ruleForm,
  84. res => {
  85. this.listLoading = false
  86. if(res.code == 'ok') {
  87. this.dataList = res.data
  88. } else {
  89. this.$message({
  90. message: error,
  91. type: "error"
  92. });
  93. }
  94. },
  95. error => {
  96. this.listLoading = false;
  97. this.$message({
  98. message: error,
  99. type: "error"
  100. });
  101. });
  102. },
  103. addJa(tex) {
  104. if(this.dataList.length >= 10) {
  105. this.$message({
  106. message: '最多只能存在十个自定义字段',
  107. type: 'warning'
  108. });
  109. return
  110. }
  111. if(this.$refs['ruleForm']) {
  112. this.$refs['ruleForm'].resetFields();
  113. }
  114. this.titleTex = tex
  115. this.ruleForm = {
  116. id: '',
  117. companyId: '',
  118. customName: '',
  119. customType: '0'
  120. },
  121. this.dialogVisible = true
  122. },
  123. editor(item, tex) {
  124. if(this.$refs['ruleForm']) {
  125. this.$refs['ruleForm'].resetFields();
  126. }
  127. this.titleTex = tex
  128. this.ruleForm = JSON.parse(JSON.stringify(item))
  129. this.dialogVisible = true
  130. },
  131. determine(formName) {
  132. this.$refs[formName].validate((valid) => {
  133. if (valid) {
  134. this.listLoading = true
  135. this.ruleForm.companyId = this.user.companyId
  136. this.http.post( '/project-custom/editProjectCustom', this.ruleForm,
  137. res => {
  138. this.listLoading = false
  139. if(res.code == 'ok') {
  140. this.$message({
  141. message: this.titleTex == '添加表单字段' ? '添加成功' : '编辑成功',
  142. type: 'success'
  143. });
  144. this.dialogVisible = false
  145. this.getObtain()
  146. } else {
  147. this.$message({
  148. message: this.titleTex == '添加表单字段' ? '添加失败: ' + res.msg : '编辑失败: ' + res.msg,
  149. type: 'error'
  150. });
  151. }
  152. },
  153. error => {
  154. this.listLoading = false;
  155. this.$message({
  156. message: error,
  157. type: "error"
  158. });
  159. });
  160. } else {
  161. console.log('error submit!!');
  162. return false;
  163. }
  164. });
  165. },
  166. deteles(item) {
  167. this.http.post( '/project-custom/delete', {
  168. id: item.id
  169. },
  170. res => {
  171. if(res.code == 'ok') {
  172. this.$message({
  173. message: '删除成功',
  174. type: 'success'
  175. });
  176. this.getObtain()
  177. } else {
  178. this.$message({
  179. message: '删除失败:' + res.msg,
  180. type: 'error'
  181. });
  182. }
  183. },
  184. error => {
  185. this.$message({
  186. message: error,
  187. type: "error"
  188. });
  189. });
  190. }
  191. },
  192. };
  193. </script>
  194. <style scoped lang="scss">
  195. .infrastructures {
  196. color: #666;
  197. .til {
  198. display: flex;
  199. justify-content: space-between;
  200. line-height: 0;
  201. background: #f2f2f2;
  202. padding: 10px 25px 10px 25px;
  203. align-items: center;
  204. p {
  205. font-size: 14px;
  206. i {
  207. display: inline-block;
  208. margin-right: 5px;
  209. }
  210. }
  211. }
  212. .tabl {
  213. padding-left: 15px;
  214. box-sizing: border-box;
  215. }
  216. }
  217. </style>