index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <schema-table
  9. ref="table"
  10. :schema="schema"
  11. />
  12. <merchant-dialog
  13. ref="addDialog"
  14. @done="onAdded"
  15. />
  16. <confirm-dialog
  17. ref="uploadDialog"
  18. title="新增导入文件"
  19. @confirm="onUpload"
  20. >
  21. <el-upload
  22. ref="upload"
  23. class="o-upload l-flex__auto"
  24. action="none"
  25. :auto-upload="false"
  26. :show-file-list="false"
  27. :on-change="onChange"
  28. drag
  29. >
  30. <div class="l-flex--row">
  31. <i class="o-upload__icon el-icon-upload" />
  32. <template v-if="upload.file">
  33. <div class="u-color--blue">
  34. {{ upload.file.name }}
  35. </div>
  36. </template>
  37. <template v-else>
  38. <span class="c-sibling-item">
  39. 拖拽文件到此或
  40. </span>
  41. <span class="c-sibling-item near u-color--blue">
  42. 点击选择文件
  43. </span>
  44. </template>
  45. </div>
  46. </el-upload>
  47. </confirm-dialog>
  48. <el-dialog
  49. :visible.sync="showProgress"
  50. custom-class="c-dialog--transparent"
  51. :close-on-click-modal="false"
  52. :close-on-press-escape="false"
  53. >
  54. <el-progress
  55. class="u-align-self--stretch"
  56. :percentage="progress"
  57. :stroke-width="24"
  58. text-inside
  59. status="success"
  60. />
  61. </el-dialog>
  62. </wrapper>
  63. </template>
  64. <script>
  65. import {
  66. getMerchantsByQuery,
  67. deleteMerchant,
  68. uploadMerchant
  69. } from '@/api/merchant.js'
  70. import MerchantDialog from './components/MerchantDialog.vue'
  71. export default {
  72. components: {
  73. MerchantDialog
  74. },
  75. data () {
  76. return {
  77. upload: {},
  78. showProgress: false,
  79. progress: 0
  80. }
  81. },
  82. computed: {
  83. schema () {
  84. return {
  85. props: {
  86. size: 'small'
  87. },
  88. list: getMerchantsByQuery,
  89. buttons: [
  90. { type: 'add', on: this.addStreamingMedia },
  91. { type: 'add', label: '上传', on: this.uploadStreamingMedia }
  92. ],
  93. filters: [
  94. { key: 'name', type: 'search', placeholder: '门店名称' },
  95. { key: 'personName', type: 'search', placeholder: '门店负责人' },
  96. { type: 'refresh' }
  97. ],
  98. cols: [
  99. { prop: 'name', label: '门店名称' },
  100. { prop: 'personName', label: '门店负责人', width: 100, align: 'center' },
  101. { prop: 'personPhone', label: '负责人手机号', width: 100, align: 'center' },
  102. { prop: 'cityName', label: '城市名称' },
  103. { prop: 'countyName', label: '区县名称' },
  104. { prop: 'address', label: '详细地址' },
  105. { prop: 'region', label: '省区' },
  106. { prop: 'serviceName', label: '服务商' },
  107. { prop: 'servicePerson', label: '服务商联系人', width: 100, align: 'center' },
  108. { prop: 'servicePhone', label: '服务商电话', width: 100, align: 'center' },
  109. { label: '门店认证状态', type: 'tag', render: ({ authStatus }) => authStatus
  110. ? {
  111. type: 'danger',
  112. label: '未认证'
  113. }
  114. : {
  115. type: 'success',
  116. label: '已认证'
  117. }, size: 'sm', width: 92 },
  118. { label: '中通有投门店', type: 'tag', render: ({ status }) => status
  119. ? {
  120. type: 'danger',
  121. label: '否'
  122. }
  123. : {
  124. type: 'success',
  125. label: '是'
  126. }, size: 'sm', width: 92 },
  127. { type: 'invoke', render: [
  128. { label: '编辑', on: this.onView },
  129. { label: '删除', on: this.onDel }
  130. ], width: 100 }
  131. ]
  132. }
  133. }
  134. },
  135. methods: {
  136. onView (asset) {
  137. this.$refs.addDialog.show(asset)
  138. },
  139. onDel (asset) {
  140. deleteMerchant(asset).then(() => {
  141. this.$refs.table.decrease(1)
  142. })
  143. },
  144. addStreamingMedia () {
  145. this.$refs.addDialog.show()
  146. },
  147. uploadStreamingMedia () {
  148. this.upload = {
  149. file: null
  150. }
  151. this.$refs.uploadDialog.show()
  152. },
  153. onUpload (done) {
  154. if (!this.upload.file) {
  155. this.$message({
  156. type: 'warning',
  157. message: '请选择升级APK'
  158. })
  159. return
  160. }
  161. const formData = new FormData()
  162. const { file } = this.upload
  163. console.log(file)
  164. formData.append('upload-file', file)
  165. this.progress = 0
  166. this.showProgress = true
  167. uploadMerchant(formData, ({ loaded, total }) => {
  168. this.progress = Math.min(99, loaded * 100 / total | 0)
  169. }).finally(() => {
  170. this.progress = 100
  171. this.showProgress = false
  172. }).then(() => {
  173. done()
  174. this.$refs.table.resetCondition()
  175. })
  176. },
  177. onChange ({ raw }) {
  178. this.$refs.upload.clearFiles()
  179. this.upload.file = raw
  180. },
  181. onAdded (streamingMedia) {
  182. this.$refs.table.resetCondition(streamingMedia)
  183. }
  184. }
  185. }
  186. </script>