cqReports.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <div class="cqReportsPage">
  3. <div class="check-btns">
  4. <el-button type="primary" size="mini" @click="addReport">新增12</el-button>
  5. </div>
  6. <el-row :gutter="30" id="viewerDom" v-viewer>
  7. <el-col
  8. :xs="12"
  9. :sm="8"
  10. :md="6"
  11. :lg="4"
  12. :xl="4"
  13. v-for="item in reportList"
  14. :key="item.id"
  15. >
  16. <div class="photoItem">
  17. <div class="photoInfo">
  18. <i @click="delectImg(item.id)" class="iconfont icon-shanchu"></i>
  19. </div>
  20. <div class="photoImg">
  21. <img :src="$host+item.qualityphoto" />
  22. </div>
  23. <div class="photoMsg">{{ item.qualitydesc }}</div>
  24. </div>
  25. </el-col>
  26. </el-row>
  27. <!-- 新增食品许可证发证检验 -->
  28. <el-dialog
  29. title="新增"
  30. :visible.sync="addPrportVisible"
  31. @close="AddDialogClosed"
  32. width="33%"
  33. >
  34. <div>
  35. <el-form
  36. ref="addUserFormRef"
  37. :model="addSyForm"
  38. label-width="100px"
  39. :rules="addUserFormRules"
  40. >
  41. <el-form-item label="检验标题 : " prop="reportTitle">
  42. <el-input v-model="addSyForm.reportTitle"></el-input>
  43. </el-form-item>
  44. <el-form-item label="上传图片 : " prop="img" ref="uploadimg">
  45. <el-upload
  46. class="avatar-uploader"
  47. action
  48. :auto-upload="false"
  49. :show-file-list="false"
  50. :on-change="changeUpload"
  51. >
  52. <img
  53. v-if="addSyForm.img"
  54. :src="$host + addSyForm.img"
  55. class="avatar"
  56. />
  57. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  58. </el-upload>
  59. </el-form-item>
  60. <el-form-item>
  61. <el-button @click="cancel">取 消</el-button>
  62. <el-button type="primary" @click="addUserSubm">确认</el-button>
  63. </el-form-item>
  64. </el-form>
  65. </div>
  66. </el-dialog>
  67. <!-- vueCropper 剪裁图片实现-->
  68. <el-dialog title="图片剪裁" :visible.sync="cropperVisible" append-to-body>
  69. <div class="cropper-content">
  70. <div style="width: 100%; height: 500px">
  71. <vueCropper
  72. ref="cropper"
  73. :img="option.img"
  74. autoCrop
  75. centerBox
  76. fixed
  77. :fixedNumber="option.fixedNumber"
  78. :outputSize="option.size"
  79. :outputType="option.outputType"
  80. ></vueCropper>
  81. </div>
  82. </div>
  83. <div slot="footer" class="dialog-footer">
  84. <el-button @click="cropperVisible = false">取 消</el-button>
  85. <el-button type="primary" @click="finish">确认</el-button>
  86. </div>
  87. </el-dialog>
  88. </div>
  89. </template>
  90. <script>
  91. export default {
  92. props: {
  93. backcode: {
  94. type: String,
  95. required: true
  96. }
  97. },
  98. data() {
  99. return {
  100. addPrportVisible: false,
  101. cropperVisible: false,
  102. totalNum: 0,
  103. reportList: [],
  104. // 裁剪组件的基础配置option
  105. option: {
  106. img: '', // 裁剪图片的地址
  107. info: true, // 裁剪框的大小信息
  108. outputSize: 0.8, // 裁剪生成图片的质量
  109. outputType: 'jpeg', // 裁剪生成图片的格式
  110. // canScale: false, // 图片是否允许滚轮缩放
  111. // autoCrop: true, // 是否默认生成截图框
  112. // autoCropWidth: 300, // 默认生成截图框宽度
  113. // autoCropHeight: 200, // 默认生成截图框高度
  114. // fixedBox: true, // 固定截图框大小 不允许改变
  115. fixed: true, // 是否开启截图框宽高固定比例
  116. fixedNumber: [70, 99], // 截图框的宽高比例
  117. full: true, // 是否输出原图比例的截图
  118. canMoveBox: false, // 截图框能否拖动
  119. original: false, // 上传图片按照原始比例渲染
  120. centerBox: false, // 截图框是否被限制在图片里面
  121. infoTrue: true // true 为展示真实输出图片宽高 false 展示看到的截图框宽高
  122. },
  123. addSyForm: {
  124. img: '',
  125. reportTitle: ''
  126. },
  127. addUserFormRules: {
  128. img: [{ required: true, message: '请上传产品图片', trigger: 'change' }],
  129. reportTitle: [
  130. { required: true, message: '请输入产地', trigger: 'blur' }
  131. ]
  132. }
  133. }
  134. },
  135. mounted() {
  136. this.getInfo()
  137. },
  138. methods: {
  139. getInfo() {
  140. this.$axios({
  141. method: 'POST',
  142. url: '/api/quality_info',
  143. data: this.qs.stringify({
  144. backcode: this.backcode
  145. })
  146. }).then((res) => {
  147. if (res.status == 200) {
  148. this.reportList = res.data._list
  149. }
  150. })
  151. },
  152. delectImg(id) {
  153. this.$confirm('确认删除么?', '提示', {
  154. confirmButtonText: '确定',
  155. cancelButtonText: '取消',
  156. type: 'warning'
  157. })
  158. .then(() => {
  159. this.$axios({
  160. method: 'POST',
  161. url: '/api/del_quality',
  162. data: this.qs.stringify({
  163. id
  164. })
  165. }).then((res) => {
  166. if (res.data == 1) {
  167. this.$message({
  168. type: 'success',
  169. message: '删除成功!'
  170. })
  171. this.getInfo()
  172. }
  173. })
  174. })
  175. .catch(() => {
  176. this.$message({
  177. type: 'info',
  178. message: '已取消删除'
  179. })
  180. })
  181. },
  182. // 点击裁剪,这一步是可以拿到处理后的地址
  183. finish() {
  184. // 获取截图的base64 数据
  185. this.$refs.cropper.getCropBlob((data) => {
  186. var form = new FormData()
  187. let file = this.blobToFile(data, 'filename.jpg')
  188. form.append('img_file', file)
  189. this.cropperVisible = false
  190. this.$axios({
  191. method: 'POST',
  192. url: '/api/base_photo',
  193. data: form
  194. }).then((res) => {
  195. this.addSyForm.img = res.data.src
  196. })
  197. })
  198. },
  199. //bloc格式
  200. blobToFile(Blob, fileName) {
  201. Blob.lastModifiedDate = new Date()
  202. Blob.name = fileName
  203. return Blob
  204. },
  205. changeUpload(file, fileList) {
  206. const isLt5M = file.size / 1024 / 1024 < 5
  207. if (!isLt5M) {
  208. this.$message.error('上传文件大小不能超过 5MB!')
  209. return false
  210. }
  211. // 上传成功后将图片地址赋值给裁剪框显示图片
  212. this.$nextTick(() => {
  213. console.log(file);
  214. this.option.img = URL.createObjectURL(file.raw)
  215. this.flag = 1
  216. this.cropperVisible = true
  217. })
  218. },
  219. //在线状态选择
  220. addReport() {
  221. this.addPrportVisible = true
  222. },
  223. //改变page
  224. changePage(val) {
  225. this.page = val
  226. },
  227. cancel() {
  228. this.$router.go(-1)
  229. },
  230. addUserSubm() {
  231. this.$refs.addUserFormRef.validate((valid) => {
  232. if (valid) {
  233. this.$axios({
  234. method: 'POST',
  235. url: '/api/quality_info',
  236. data: this.qs.stringify({
  237. backcode: this.backcode,
  238. qualitydesc: this.addSyForm.reportTitle,
  239. qualityphoto: this.addSyForm.img
  240. })
  241. }).then((res) => {
  242. if (res.status == 200) {
  243. this.addPrportVisible = false
  244. this.$message.success('提交成功!')
  245. this.getInfo()
  246. }
  247. })
  248. }
  249. })
  250. },
  251. AddDialogClosed(){
  252. this.addSyForm={}
  253. }
  254. }
  255. }
  256. </script>
  257. <style lang="less" scoped>
  258. .cqReportsPage {
  259. position: relative;
  260. .check-btns {
  261. position: absolute;
  262. right: 10px;
  263. top: -40px;
  264. }
  265. }
  266. .photoItem {
  267. position: relative;
  268. border-radius: 10px;
  269. overflow: hidden;
  270. .photoInfo {
  271. position: absolute;
  272. top: 10px;
  273. left: 10px;
  274. right: 10px;
  275. display: flex;
  276. justify-content: space-between;
  277. span {
  278. color: #fff;
  279. }
  280. i {
  281. cursor: pointer;
  282. color: red;
  283. }
  284. }
  285. .photoImg {
  286. height: 250px;
  287. cursor: pointer;
  288. img {
  289. width: 100%;
  290. height: 100%;
  291. }
  292. }
  293. .photoMsg {
  294. background-color: #fff;
  295. text-align: center;
  296. line-height: 50px;
  297. font-size: 16px;
  298. text-align: center;
  299. }
  300. }
  301. .dialogImagePreview {
  302. /deep/.el-dialog__header {
  303. background: #fff;
  304. border-bottom: none;
  305. }
  306. }
  307. .handAddBtn {
  308. position: absolute;
  309. right: 6%;
  310. top: 21%;
  311. i {
  312. font-size: 28px;
  313. cursor: pointer;
  314. }
  315. }
  316. .handAddForm {
  317. .el-form {
  318. width: 83%;
  319. }
  320. .el-select {
  321. width: 100%;
  322. }
  323. .handAddFormBtn {
  324. text-align: right;
  325. }
  326. }
  327. .discernResult {
  328. display: flex;
  329. justify-content: space-between;
  330. line-height: 30px;
  331. padding: 3px 37px;
  332. .name {
  333. font-size: 14px;
  334. i {
  335. font-size: 20px;
  336. font-weight: bold;
  337. }
  338. i,
  339. span {
  340. color: #14a478;
  341. }
  342. }
  343. .number {
  344. span {
  345. color: #14a478;
  346. }
  347. }
  348. }
  349. </style>