completeProgress.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px">
  3. <el-form ref="form" label-position="top" :model="form" :rules="rules">
  4. <el-row :gutter="20">
  5. <el-col :span="24">
  6. <el-form-item label="附件" prop="fileUrl">
  7. <el-upload
  8. ref="uploadRef"
  9. action="#"
  10. :before-upload="
  11. (file) => {
  12. return beforeAvatarUpload(file)
  13. }
  14. "
  15. :http-request="uploadRequest"
  16. :limit="1">
  17. <el-button size="mini" type="primary">点击上传</el-button>
  18. </el-upload>
  19. <el-button v-show="form.fileUrl != ''" @click="showFile(form.fileUrl)">查看</el-button>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="24">
  23. <el-form-item label="选择完成日期" prop="date">
  24. <el-date-picker
  25. v-model="form.date"
  26. placeholder="请选择日期"
  27. style="width: 100%"
  28. type="date"
  29. value-format="yyyy-MM-dd HH:mm:ss" />
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="24">
  33. <el-form-item label="备注" prop="remark">
  34. <el-input v-model="form.remark" placeholder="请输入备注" :rows="5" show-word-limit type="textarea" />
  35. </el-form-item>
  36. </el-col>
  37. </el-row>
  38. </el-form>
  39. <template #footer>
  40. <el-button @click="dialogFormVisible = false">取 消</el-button>
  41. <el-button type="primary" @click="complete">确 定</el-button>
  42. </template>
  43. </el-dialog>
  44. </template>
  45. <script>
  46. import deliverWorkApi from '@/api/work/deliverWork'
  47. import to from 'await-to-js'
  48. import axios from 'axios'
  49. import asyncUploadFile from '@/utils/uploadajax'
  50. export default {
  51. name: 'CompleteProgress',
  52. components: {},
  53. props: {
  54. // orderStatusOptions: {
  55. // type: Array,
  56. // default: () => [],
  57. // },
  58. },
  59. data() {
  60. return {
  61. form: {
  62. date: '',
  63. fileUrl: '',
  64. fileName: '',
  65. remark: '',
  66. },
  67. progress: {},
  68. rules: {
  69. fileUrl: [{ required: true, message: '不能为空', trigger: ['blur', 'change'] }],
  70. date: [{ required: true, message: '不能为空', trigger: ['blur', 'change'] }],
  71. },
  72. dialogFormVisible: false,
  73. planId: 0,
  74. title: '',
  75. fileSettings: {
  76. // 文件配置信息
  77. fileSize: 52428800,
  78. fileTypes: '.doc,.docx,.zip,.xls,.xlsx,.rar,.jpg,.jpeg,.gif,.png,.jfif,.txt',
  79. pictureSize: 52428800,
  80. pictureTypes: '.jpg,.jpeg,.gif,.png,.jfif,.txt',
  81. types: '.doc,.docx,.zip,.xls,.xlsx,.rar,.jpg,.jpeg,.gif,.png,.jfif,.mp4,.txt',
  82. videoSize: 104857600,
  83. videoType: '.mp4',
  84. },
  85. }
  86. },
  87. mounted() {},
  88. methods: {
  89. // 打开弹窗
  90. open(row) {
  91. this.title = '完成'
  92. this.progress = row
  93. this.form.date = ''
  94. this.form.fileUrl = ''
  95. this.form.fileName = ''
  96. this.form.remark = ''
  97. if (this.$refs['form']) {
  98. this.$refs['form'].resetFields()
  99. }
  100. if (this.$refs.uploadRef) {
  101. this.$refs.uploadRef.clearFiles() //去掉文件列表
  102. }
  103. this.dialogFormVisible = true
  104. },
  105. // 上传附件
  106. beforeAvatarUpload(file) {
  107. let flag1 = file.size < this.fileSettings.fileSize
  108. if (!flag1) {
  109. this.$message.warning('文件过大,请重新选择!')
  110. return false
  111. }
  112. let flag2 = this.fileSettings.fileTypes.split(',').includes('.' + file.name.split('.').pop())
  113. if (!flag2) {
  114. this.$message.warning('文件类型不符合,请重新选择!')
  115. return false
  116. }
  117. return true
  118. },
  119. // 上传
  120. uploadRequest(option) {
  121. let _this = this
  122. let url = process.env.VUE_APP_UPLOAD_WEED
  123. axios
  124. .post(url)
  125. .then(function (res) {
  126. if (res.data && res.data.fid && res.data.fid !== '') {
  127. option.action = `${process.env.VUE_APP_PROTOCOL}${res.data.publicUrl}/${res.data.fid}`
  128. asyncUploadFile(option).then(() => {
  129. _this.form.fileName = option.file.name
  130. _this.form.fileUrl = `${process.env.VUE_APP_PROTOCOL}${res.data.publicUrl}/${res.data.fid}` // 资料存储url
  131. })
  132. } else {
  133. _this.$message({
  134. type: 'warning',
  135. message: '未上传成功!请刷新界面重新上传!',
  136. })
  137. }
  138. })
  139. .catch(function () {
  140. _this.$message({
  141. type: 'warning',
  142. message: '未上传成功!请重新上传!',
  143. })
  144. })
  145. },
  146. // 查看附件
  147. showFile(url) {
  148. let fileName = this.form.fileName
  149. const xhr = new XMLHttpRequest()
  150. xhr.open('GET', url, true)
  151. xhr.responseType = 'blob' // 通过文件下载url拿到对应的blob对象
  152. xhr.onload = () => {
  153. if (xhr.status === 200) {
  154. let link = document.createElement('a')
  155. let body = document.querySelector('body')
  156. link.href = window.URL.createObjectURL(xhr.response)
  157. link.download = fileName
  158. link.click()
  159. this.$message.success('下载成功')
  160. body.removeChild(link)
  161. window.URL.revokeObjectURL(link.href)
  162. }
  163. }
  164. xhr.send()
  165. },
  166. // 完成
  167. async complete() {
  168. this.$refs['form'].validate(async (valid) => {
  169. if (valid) {
  170. // 10发货任务单/20组装任务单/30部署安装单
  171. if (this.progress.progressType == '20') {
  172. const [err, res] = await to(
  173. deliverWorkApi.completeAssembleGoodsProgress({
  174. id: this.progress.id,
  175. reaEndDate: this.form.date,
  176. fileUrl: this.form.fileUrl,
  177. fileName: this.form.fileName,
  178. remark: this.form.remark,
  179. })
  180. )
  181. if (err) return
  182. if (res.code == 200) {
  183. this.$baseMessage(res.msg, 'success', 'vab-hey-message-success')
  184. this.$emit('fetch-data')
  185. }
  186. } else if (this.progress.progressType == '30') {
  187. const [err, res] = await to(
  188. deliverWorkApi.completeInstall({
  189. id: this.progress.id,
  190. installDate: this.form.date,
  191. installCheckFileUrl: this.form.fileUrl,
  192. fileName: this.form.fileName,
  193. remark: this.form.remark,
  194. })
  195. )
  196. if (err) return
  197. if (res.code == 200) {
  198. this.$baseMessage(res.msg, 'success', 'vab-hey-message-success')
  199. this.$emit('fetch-data')
  200. }
  201. }
  202. this.dialogFormVisible = false
  203. }
  204. })
  205. },
  206. },
  207. }
  208. </script>