other.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <template-page ref="pageRef" :get-list="getList" :table-attributes="tableAttributes" :table-events="tableEvents" :operationColumnWidth="80"
  3. :options-evens-group="optionsEvensGroup" :moreParameters="moreParameters" :column-parsing="columnParsing"
  4. :operation="operation" :exportList="exportList" :replaceOrNotMap="true">
  5. </template-page>
  6. </template>
  7. <script>
  8. import TemplatePage from '@/components/template/template-page-1.vue'
  9. import import_mixin from '@/components/template/import_mixin.js'
  10. import ImageUpload from '@/components/file-upload'
  11. import { required, mobileRequired, mobile, httpUrl, email } from '@/components/template/rules_verify.js'
  12. import { del } from "@/api/workOrder/settlementStandardInstall";
  13. import { listPageV2,pageExport, add, edit } from "@/api/workOrder/settlementStandardOther";
  14. import { thousands } from '@/utils/common'
  15. export default {
  16. components: { TemplatePage, ImageUpload },
  17. mixins: [import_mixin],
  18. data() {
  19. return {
  20. // 事件组合
  21. optionsEvensGroup: [
  22. [
  23. [
  24. {
  25. name: '新建',
  26. click: this.addData
  27. }
  28. ],
  29. ],
  30. ],
  31. // 表格属性
  32. tableAttributes: {
  33. // 启用勾选列
  34. selectColumn: false
  35. },
  36. // 表格事件
  37. tableEvents: {
  38. 'selection-change': this.selectionChange
  39. },
  40. // 勾选选中行
  41. recordSelected: [],
  42. /** 表单变量 */
  43. formDialogType: 0,
  44. formDialogTitles: ["新增","编辑", "详情"],
  45. formDialog: false,
  46. formData: {
  47. companyName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
  48. },
  49. editIndex: null,
  50. mainList: [],
  51. smallList: [],
  52. typeList: []
  53. }
  54. },
  55. computed: {
  56. // 更多参数
  57. moreParameters() {
  58. return []
  59. },
  60. formItems() {
  61. return []
  62. }
  63. },
  64. methods: {
  65. // 列表请求函数
  66. getList: listPageV2,
  67. getList(p) {
  68. try {
  69. var pam = JSON.parse(JSON.stringify(p))
  70. this.editIndex = null
  71. return listPageV2(pam)
  72. } catch (error) {
  73. console.log(error)
  74. }
  75. },
  76. // 列表导出函数
  77. exportList: pageExport,
  78. // 表格列解析渲染数据更改
  79. columnParsing(item, defaultData) {
  80. if (item.jname === 'typeName') {
  81. defaultData.render = (h, { row, index, column }) => {
  82.   return this.editIndex == index? (
  83. <div class="redbordererr">
  84. <el-form-item prop={`tableData.${index}.typeName`} rules={[{required: true, message: '其他费用类型不能为空', trigger: 'blur'}]}>
  85. <el-input type="text" value={row.typeName} placeholder="请输入"
  86. onInput={(val)=>{
  87. row.typeName=val
  88. row.type=val
  89. }}>
  90. </el-input>
  91. </el-form-item>
  92. </div>
  93.     ):(<div style="padding: 6px;">{row.typeName}</div>)
  94.   }
  95. }
  96. if (item.jname === 'label') {
  97. defaultData.render = (h, { row, index, column }) => {
  98.   return this.editIndex == index? (
  99. <div class="redbordererr">
  100. <el-form-item prop={`tableData.${index}.label`} rules={[{required: true, message: '功率不能为空', trigger: 'blur'}]}>
  101. <el-input type="text" value={row.label} placeholder="请输入"
  102. onInput={(val)=>{
  103. row.label=val
  104. }}>
  105. </el-input>
  106. </el-form-item>
  107. </div>
  108.     ):(<div style="padding: 6px;">{row.label}</div>)
  109.   }
  110. }
  111. if (item.jname === 'normAmount') {
  112. defaultData.render = (h, { row, index, column }) => {
  113.   return this.editIndex == index? (
  114. <div class="redbordererr">
  115. <el-form-item prop={`tableData.${index}.normAmount`} rules={[{required: true, message: '单价不能为空', trigger: 'blur'}]}>
  116. <el-input type="text" value={row.normAmount} placeholder="请输入"
  117. onInput={(val)=>{
  118. row.normAmount=val
  119. }}>
  120. </el-input>
  121. </el-form-item>
  122. </div>
  123.     ):(<div style="padding: 6px;">{thousands(row.normAmount)}</div>)
  124.   }
  125. }
  126. if (item.jname === 'remark') {
  127. defaultData.render = (h, { row, index, column }) => {
  128.   return this.editIndex == index? (
  129. <div class="redbordererr">
  130. <el-form-item prop={`tableData.${index}.remark`}>
  131. <el-input type="text" value={row.remark} placeholder="请输入"
  132. onInput={(val)=>{
  133. row.remark=val
  134. }}>
  135. </el-input>
  136. </el-form-item>
  137. </div>
  138.     ):(<div style="padding: 6px;">{row.remark}</div>)
  139.   }
  140. defaultData.columnAttributes.width = 200
  141. }
  142. return defaultData
  143. },
  144. // 监听勾选变化
  145. selectionChange(data) {
  146. this.recordSelected = data
  147. },
  148. // 表格操作列
  149. operation(h, { row, index, column }) {
  150. return (
  151. <div class='operation-btns'>
  152. {row.id?<el-button type="text" onClick={() => {
  153. this.$refs.pageRef.tableForm().validate((valid) => {
  154. if (valid) {
  155. if(this.editIndex != index){
  156. this.editIndex = index
  157. }else{
  158. this.edit(row)
  159. }
  160. } else {
  161. console.log('error submit!!');
  162. return false;
  163. }
  164. });
  165. }}>{this.editIndex == index?'确定':'编辑'}</el-button>:null}
  166. {!row.id?<el-button type="text" onClick={() => {
  167. this.$refs.pageRef.tableForm().validate((valid) => {
  168. if (valid) {
  169. this.add(row)
  170. } else {
  171. console.log('error submit!!');
  172. return false;
  173. }
  174. });
  175. }}>保存</el-button>:null}
  176. <el-button type="text" style="color: #FF0000" onClick={() => {
  177. row.id?this.$confirm('请确认是否删除该数据, 是否继续?', '提示', {
  178. confirmButtonText: '确定',
  179. cancelButtonText: '取消',
  180. type: 'warning'
  181. }).then(() => {
  182. del({
  183. id: row.id
  184. }).then(res => {
  185. if (res.code == 200) {
  186. this.$message({ type: 'success', message: '删除成功!' })
  187. this.$refs.pageRef.refreshList()
  188. } else {
  189. this.$message.error(res.msg);
  190. }
  191. })
  192. }): this.$refs.pageRef.deleteRowData(0);this.editIndex = null
  193. }}>删除</el-button>
  194. </div>
  195. )
  196. },
  197. addData() {
  198. this.$refs.pageRef.tableForm().validate((valid) => {
  199. if (valid) {
  200. this.editIndex = 0
  201. this.$refs.pageRef.insertionData(0,{
  202. companyWechatName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
  203. settleNormType: 'OTHER',
  204. typeName: '',
  205. type: '',
  206. label: '',
  207. normAmount: '',
  208. remark: ''
  209. })
  210. } else {
  211. console.log('error submit!!');
  212. return false;
  213. }
  214. });
  215. },
  216. openForm() {
  217. this.formDialog = true;
  218. },
  219. add(row){
  220. add(row).then(res => {
  221. if(res.code ==200){
  222. this.editIndex = null
  223. this.$message({ type: 'success', message: `保存成功!` })
  224. this.$refs.pageRef.refreshList()
  225. }
  226. })
  227. },
  228. edit(row){
  229. edit({
  230. id: row.id,
  231. settleNormType: 'OTHER',
  232. typeName: row.typeName,
  233. type: row.type,
  234. label: row.label,
  235. normAmount: row.normAmount,
  236. remark: row.remark
  237. }).then(res => {
  238. if(res.code ==200){
  239. this.editIndex = null
  240. this.$message({ type: 'success', message: `编辑成功!` })
  241. this.$refs.pageRef.refreshList()
  242. }
  243. })
  244. }
  245. }
  246. }
  247. </script>
  248. <style lang="scss" scoped>
  249. .tab{
  250. padding: 20px 20px 0 20px;
  251. }
  252. .redbordererr {
  253. ::v-deep .el-form-item {
  254. margin: 0 !important;
  255. overflow: hidden;
  256. }
  257. }
  258. </style>