transport.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <!-- 运输企业管理 -->
  3. <div>
  4. <actionBar menuTitle="运输企业管理" :operateList="operateList" :formList="formList" :ruleForm="searchRuleForm"
  5. @openModel="openModel" @searchProtocol="searchProtocol"></actionBar>
  6. <treeTable :suspension="true" :treeData="treeData" :treeDataList="treeDataList" @buttonData="buttonData">
  7. </treeTable>
  8. <el-dialog :title="shopTitle" :visible.sync="shopDialogVisible" width="60%" :close-on-click-modal="false"
  9. @close="closeDialog">
  10. <forms ref="childRules" :formNewList="formRuleList" :ruleForm="ruleForm" :operationType="operationType"
  11. labelWidth="130px"></forms>
  12. <span slot="footer" class="dialog-footer" v-if="operationType != 'logs'">
  13. <el-button plain @click="shopDialogVisible = false">取 消</el-button>
  14. <el-button type="primary" :loading="confirmLoading" @click="handleAdd">确 定</el-button>
  15. </span>
  16. </el-dialog>
  17. </div>
  18. </template>
  19. <script>
  20. import {
  21. getTruckList,
  22. getEnterprise,
  23. addEnterprise,
  24. putEnterprise,
  25. enterEnterprise,
  26. delEnterprise
  27. } from '@/api/transport'
  28. import actionBar from '@/components/actionBar'
  29. import treeTable from '@/components/treeTable'
  30. import forms from '@/components/forms'
  31. import {
  32. rules,
  33. formRules
  34. } from "./transportation.js";
  35. export default {
  36. components: {
  37. actionBar,
  38. treeTable,
  39. forms
  40. },
  41. data() {
  42. return {
  43. formList: [{
  44. type: 'input',
  45. label: '运输企业名称',
  46. field: 'name',
  47. placeholder: '请输入运输企业名称查找',
  48. }],
  49. searchRuleForm: {
  50. name: '',
  51. },
  52. operateList: [{
  53. type: 'add',
  54. title: '添加一级运输企业',
  55. icon: 'el-icon-plus',
  56. }],
  57. treeData: rules(),
  58. treeDataList: [],
  59. shopDialogVisible: false,
  60. shopTitle: '添加',
  61. formRuleList: [],
  62. ruleForm: {},
  63. parentId: 0,
  64. operationType: '',
  65. enterpriseId: null,
  66. confirmLoading: false,
  67. searchValue: {},
  68. }
  69. },
  70. mounted() {
  71. const dataList = formRules();
  72. this.formRuleList = dataList;
  73. this.getList()
  74. },
  75. methods: {
  76. // 搜索
  77. searchProtocol(value) {
  78. this.searchValue = value
  79. this.treeDataList = []
  80. this.getList()
  81. },
  82. getList() {
  83. getTruckList(this.searchValue).then(res => {
  84. if (res.code == 200) {
  85. this.treeDataList = res.data
  86. }
  87. })
  88. },
  89. openModel(type) {
  90. this.operationType = type
  91. if (type == 'add') {
  92. this.shopTitle = '添加'
  93. }
  94. this.shopDialogVisible = true
  95. },
  96. // 弹窗表单添加
  97. handleAdd() {
  98. if (this.operationType == 'add') {
  99. let flag = this.$refs['childRules'].validateForm();
  100. if (flag) {
  101. this.confirmLoading = true
  102. var params = {
  103. ...this.ruleForm
  104. }
  105. params.city = this.ruleForm.cityRegion[0]
  106. params.area = this.ruleForm.cityRegion[1]
  107. delete params.cityRegion;
  108. addEnterprise({
  109. parentId: this.parentId,
  110. provTruckEnterprise: params
  111. }).then(res => {
  112. if (res.code == 200) {
  113. this.$message({
  114. message: '操作成功',
  115. type: 'success'
  116. });
  117. this.getList()
  118. }
  119. this.confirmLoading = false
  120. this.shopDialogVisible = false
  121. }).catch(() => {
  122. this.confirmLoading = false
  123. })
  124. } else {
  125. this.$message.error('表单信息不完整,请继续填写完整');
  126. }
  127. } else if (this.operationType == 'edit') {
  128. this.editItem()
  129. }
  130. },
  131. editItem() {
  132. let flag = this.$refs['childRules'].validateForm();
  133. if (flag) {
  134. this.confirmLoading = true
  135. var params = {
  136. ...this.ruleForm
  137. }
  138. params.city = this.ruleForm.cityRegion[0]
  139. params.area = this.ruleForm.cityRegion[1]
  140. delete params.cityRegion;
  141. putEnterprise({
  142. id: this.enterpriseId,
  143. provTruckEnterprise: params
  144. }).then(res => {
  145. if (res.code == 200) {
  146. this.$message({
  147. message: '操作成功',
  148. type: 'success'
  149. });
  150. this.getList()
  151. }
  152. this.shopDialogVisible = false
  153. this.confirmLoading = false
  154. }).catch(() => {
  155. this.confirmLoading = false
  156. })
  157. } else {
  158. this.$message.error('表单信息不完整,请继续填写完整');
  159. }
  160. },
  161. // 进入
  162. enterInto(id) {
  163. enterEnterprise({
  164. id: id,
  165. }).then(res => {
  166. if (res.code == 200) {
  167. this.$message({
  168. message: res.msg,
  169. type: 'success'
  170. });
  171. // this.getList()
  172. }
  173. })
  174. },
  175. // 删除
  176. deleteItem(id) {
  177. this.$confirm('此操作将永久删除该企业, 是否继续?', '提示', {
  178. confirmButtonText: '确定',
  179. cancelButtonText: '取消',
  180. type: 'warning'
  181. }).then(() => {
  182. delEnterprise({
  183. id: id,
  184. }).then(res => {
  185. if (res.code == 200) {
  186. this.$message({
  187. message: '操作成功',
  188. type: 'success'
  189. });
  190. this.getList()
  191. }
  192. })
  193. }).catch(() => {});
  194. },
  195. // 表格操作按钮
  196. buttonData(row, type) {
  197. this.enterpriseId = row.id
  198. this.operationType = type
  199. if (type == 'add') {
  200. this.shopTitle = '添加'
  201. } else if (type == 'edit') {
  202. this.shopTitle = '修改'
  203. } else if (type == 'logs') {
  204. this.formRuleList.forEach((item, index) => {
  205. item.disabled = true
  206. })
  207. this.shopTitle = '详情'
  208. }
  209. if (type == 'del') {
  210. if (row.children && row.children.length > 0) {
  211. this.$message({
  212. message: '请先删除子级企业',
  213. type: 'warning'
  214. });
  215. } else {
  216. this.deleteItem(row.id)
  217. }
  218. } else if (type == 'edit' || type == 'logs') {
  219. if (row.provTruckEnterprise) {
  220. this.ruleForm = JSON.parse(JSON.stringify(row.provTruckEnterprise))
  221. var arr = []
  222. arr.push(row.provTruckEnterprise.city)
  223. arr.push(row.provTruckEnterprise.area)
  224. this.ruleForm.cityRegion = arr
  225. }
  226. this.shopDialogVisible = true
  227. } else if (type == 'add') {
  228. this.parentId = row.id
  229. this.shopDialogVisible = true
  230. } else if (type == 'entry') {
  231. // 进入
  232. this.$store.commit('SET_NAME', row.name)
  233. localStorage.setItem('companyName', row.name);
  234. this.enterInto(row.id)
  235. }
  236. },
  237. closeDialog() {
  238. this.ruleForm = {}
  239. this.formRuleList.forEach((item, index) => {
  240. item.disabled = false
  241. })
  242. this.$refs.childRules.resetCheck();
  243. }
  244. }
  245. }
  246. </script>
  247. <style lang="scss" scoped>
  248. </style>