Explorar o código

Merge branch 'develop' of https://gitlab.liveplus.online/feuc/frontent into develop

sh %!s(int64=4) %!d(string=hai) anos
pai
achega
c5500921b2
Modificáronse 5 ficheiros con 52 adicións e 4 borrados
  1. 14 2
      src/api/op.js
  2. 5 0
      src/api/rest.js
  3. 8 0
      src/api/unit.js
  4. 14 0
      src/views/unit/index-bak.vue
  5. 11 2
      src/views/unit/index.vue

+ 14 - 2
src/api/op.js

@@ -1,4 +1,4 @@
-import { fGet, fSave, fPut, fDelete } from '@/api/rest'
+import { fGet, fSave, fPut, fDelete, fSort } from '@/api/rest'
 
 function hasArea(obj, key) {
   const k = key || 'area'
@@ -115,10 +115,14 @@ function fnDelete(options) {
   const listObj = this.self.list[opt.list] || {}
   this.self.$confirm(`您是否确认要删除${title}`, '删除确认').then(() => {
     const url = opt.url || listObj.url || this.self.URI
+    console.log(opt.url)
     fDelete(url, opt.row).then(res => {
       this.list(opt.reload)
+      alert('删除成功')
     })
-  }).catch(() => {})
+  }).catch(() => {
+    alert('删除失败')
+  })
 }
 
 function fnSave(options) {
@@ -199,6 +203,13 @@ function fnMultiSelect(options) {
   listObj.selectedRows = opt.rows || []
 }
 
+function fnSort(options) {
+  const opt = Options(options, { form: 'form', title: '排序' })
+  fSort(opt.url, opt.data).then(res => {
+    this.list(opt.reload)
+  }).catch(() => {})
+}
+
 // 批量操作
 function fnBatchOp(options) {
   const opt = Options(options, { params: {}})
@@ -323,6 +334,7 @@ export function M(self) {
   this.upload = fnUpload
   this.beforeUpload = fnBeforeUpload
   this.closeUploader = fnCloseUploader
+  this.sort = fnSort
 }
 
 // --- 以下为工具类

+ 5 - 0
src/api/rest.js

@@ -76,3 +76,8 @@ export function fUpdate(uri, data) {
   }
   return fPatch(uri, data)
 }
+
+export function fSort(uri, data) {
+  data = data || {}
+  return fPost(uri, { type: data.type })
+}

+ 8 - 0
src/api/unit.js

@@ -52,3 +52,11 @@ export function convertUnits(unitPairs) {
     params: { unitPairs }
   })
 }
+
+// delete
+export function remove(id) {
+  return request({
+    url: `/api/units/${id}`,
+    method: 'delete'
+  })
+}

+ 14 - 0
src/views/unit/index-bak.vue

@@ -228,7 +228,18 @@ export default {
         this.dialogFormVisible = false
       })
     },
+    handleDelete(row) {
+      remove(row.id).then(res => {
+        this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
+        this.list.splice(index, 1)
+        this.fetchData()
+      }).catch(res => {
+        console.log(1)
+        this.$message.error(res.data.message)
+      })
+    },
     handleCommand(data) {
+      console.log(1)
       switch (data.command) {
         case 'update':
           this.handleCreateOrUpdate('UPDATE', data.row)
@@ -245,6 +256,9 @@ export default {
         case 'moveBottom':
           this.updateSort(data.row, 3)
           break
+        case 'delete':
+          this.handleDelete(data.row)
+          break
       }
     }
   }

+ 11 - 2
src/views/unit/index.vue

@@ -94,7 +94,7 @@
           <!-- &nbsp;&nbsp;
           <i class="el-icon-delete" style="cursor:pointer;color:#999999;margin-right:5px;"></i>
           &nbsp;&nbsp;
-          <i class="el-icon-top" style="cursor:pointer;color:#999999;margin-right:5px;"></i>
+          <i class="el-icon-top" style="cursor:pointer;color:#999999;margin-right:5px;" @click="moveUp(row)"></i>
           &nbsp;&nbsp;
           <i class="el-icon-bottom" style="cursor:pointer;color:#999999;"></i> -->
         </template>
@@ -205,11 +205,20 @@ export default {
       })
     },
     create() {
-      this.M.create({ form: 'form', title: '新增', data: {} })
+      this.M.create({ form: 'form', title: '新增', data: {}})
     },
     edit(row) {
       this.M.edit({ form: 'form', title: 'name', row: row })
     },
+    deleteUnit(row) {
+      this.M.delete({ url: '/api/units/' + row.id })
+    },
+    moveUp(row) {
+      this.M.sort({ url: '/api/units/' + row.id + '/sort', data: {type: 0} })
+    },
+    moveDown(row) {
+      this.M.sort({ url: '/api/units/' + row.id + '/sort', data: {type: 1}})
+    },
     baseUnitChange() {
       if (!!this.dlg.form.data.baseUnitId) {
         const baseUnit = this.baseUnitOptions.find(v => v.value == this.dlg.form.data.baseUnitId)