index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <div style="display: inline-block; overflow: auto">
  3. <div>
  4. <div v-if="showFlagBtn">
  5. <el-radio v-model="mode" label="view">预览模式</el-radio>
  6. <el-radio v-model="mode" label="edit">编辑模式</el-radio>
  7. </div>
  8. <div style="border: 2px solid pink; display: inline-block;margin-right: 5px;" v-for="(item, index) in cardItemList" :key="item.cardItemId">
  9. <el-row :gutter="12" style="padding-top: 5px">
  10. <el-col :span="12">
  11. <el-card :body-style="{ padding: '0px' }">
  12. <div style="padding: 3px; text-align: center">
  13. <span>正面</span>
  14. </div>
  15. <el-image style="width: 100px; height: 100px;" v-if="mode=='view'" :src="resourcesUrl + item.frontPic" @click="previewPic(item, item.frontPic, item.prodName, 'front')"/>
  16. <el-upload v-else
  17. class="avatar-uploader"
  18. accept="image/jpg"
  19. :before-upload="(file, fileList)=>handleBeforeUpload(file, fileList,item)"
  20. :action="$http.adornUrl('/admin/file/simpleUpload')"
  21. :headers="{Authorization: $cookie.get('Authorization_vs'),locale:lang}"
  22. :on-success="(res,file)=>{onFrontUploadSuccess(item,res,file)}"
  23. :show-file-list="false">
  24. <img v-if="item.frontPic" :src="resourcesUrl + item.frontPic" class="avatar">
  25. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  26. </el-upload>
  27. </el-card>
  28. </el-col>
  29. <el-col :span="12">
  30. <el-card :body-style="{ padding: '0px' }">
  31. <div style="padding: 3px; text-align: center">
  32. <span>背面</span>
  33. </div>
  34. <el-image v-if="mode=='view'" :src="resourcesUrl + item.backPic" style="width: 100px; height: 100px;" @click="previewPic(item, item.backPic, item.prodName, 'back')"/>
  35. <el-upload v-else
  36. class="avatar-uploader"
  37. :before-upload="(file, fileList)=>handleBeforeUpload(file, fileList,item)"
  38. :action="$http.adornUrl('/admin/file/simpleUpload')"
  39. :headers="{Authorization: $cookie.get('Authorization_vs'),locale:lang}"
  40. :on-success="(res,file)=>{onBackUploadSuccess(item,res,file)}"
  41. :show-file-list="false">
  42. <img v-if="item.backPic" :src="resourcesUrl + item.backPic" class="avatar">
  43. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  44. </el-upload>
  45. </el-card>
  46. </el-col>
  47. </el-row>
  48. <el-row style="width: 210px; height: 30px; text-align: center ;color: red; font-weight: bold">
  49. <span v-if="showFlagBtn">
  50. <el-button v-if="item.flag==0 && mode=='view'" type="success" size="mini" style="margin-right: 20px" @click="handleFlag(item, index)">待标记</el-button>
  51. <el-button v-if="item.flag==1 && mode=='view'" type="warning" size="mini" style="margin-right: 5px" @click="handleFlag(item, index)">已标记</el-button>
  52. <el-button v-if="mode=='view'" type="text" size="mini" @click="openOrgPicForm(item, index)">原图</el-button>
  53. <el-button v-if="item.prodName.indexOf('语音') !== -1 && mode=='view'" type="text" size="mini" @click="openYYForm(item, index)">查看语音</el-button>
  54. <el-button v-if="mode==='edit'" type="primary" size="mini" style="margin-right: 5px" @click="addOrUpdateCardItem(item)">保存</el-button>
  55. <el-button v-if="mode==='edit' && item.cardItemId" type="danger" size="mini" style="margin-right: 5px" @click="deleteCardItem(item, index)">删除</el-button>
  56. </span>
  57. </el-row>
  58. <el-row style="width: 210px; height: 30px; text-align: center ;color: red; font-weight: bold">
  59. <span>No.{{index + 1}}</span>
  60. <span v-if="showFlagBtn" style="color: white">
  61. __________
  62. </span>
  63. <span>X</span>
  64. <span v-if="mode=='view'">{{item.prodCount}}</span>
  65. <el-input type="number" size="mini" style="width: 60px;height: 20px" v-if="mode=='edit'" v-model="item.prodCount"></el-input>
  66. </el-row>
  67. </div>
  68. <div v-if="mode=='edit'" style="display: inline-block;">
  69. <el-button
  70. circle
  71. icon="el-icon-plus"
  72. @click="addCardItem">
  73. </el-button>
  74. </div>
  75. </div>
  76. <CanvasPreview v-if= "previewPicDialogVisible" ref="canvasPreviewRef"></CanvasPreview>
  77. <YuyinPreview ref="yuYinPreviewRef"></YuyinPreview>
  78. <OrgPicPreview ref="orgPicPreviewRef"></OrgPicPreview>
  79. </div>
  80. </template>
  81. <script>
  82. import CanvasPreview from "../canvas-preview/index";
  83. import YuyinPreview from "../yuyin-preview/index";
  84. import OrgPicPreview from "../org-pic-preview/index";
  85. export default {
  86. components: {CanvasPreview, YuyinPreview,OrgPicPreview},
  87. data () {
  88. return {
  89. lang: localStorage.getItem('lang') || 'zh_CN',
  90. cardItemList:[],
  91. previewPicUrl: null,
  92. prodType: null,
  93. previewPicDialogVisible: false,
  94. previewYuyinDialogVisible: false,
  95. side:null,
  96. resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
  97. mode: 'view',
  98. previewWidth: 0,
  99. previewHeight: 0,
  100. bloodWidth: 0
  101. }
  102. },
  103. props: {
  104. orderItem: {
  105. default: null,
  106. type: Object
  107. },
  108. showFlagBtn:{
  109. default: true,
  110. type: Boolean
  111. }
  112. },
  113. created() {
  114. this.$nextTick(() => {
  115. this.getDataList();
  116. })
  117. },
  118. methods: {
  119. openYYForm(item, index){
  120. this.$nextTick(() =>{
  121. this.$refs.yuYinPreviewRef.init(item)
  122. })
  123. },
  124. openOrgPicForm(item, index){
  125. this.$nextTick(() =>{
  126. this.$refs.orgPicPreviewRef.init(item)
  127. })
  128. },
  129. previewLoad(event){
  130. this.previewWidth = event.srcElement.clientWidth;
  131. this.previewHeight = event.srcElement.clientHeight;
  132. },
  133. handleBeforeUpload(file, fileList, item){
  134. let fileType = file.type;
  135. let isJpg = fileType === 'image/jpg' || fileType === 'image/jpeg';
  136. if(!isJpg){
  137. this.$message.error("只允许上传JPG格式的图片");
  138. return false;
  139. }
  140. let isSize = true;
  141. //如果当前是编辑的小卡,就需要判断是否符合尺寸
  142. let width = 709;
  143. let height = 1087;
  144. let prodName = item.prodName;
  145. isSize = new Promise(function(resolve, reject) {
  146. if(prodName.indexOf("小卡") !== -1 || prodName.indexOf("影像级花式拍立得") !== -1){
  147. width = 709;
  148. height = 1087;
  149. }else if(prodName.indexOf("票根") !== -1){
  150. width = 780;
  151. height = 1489;
  152. }else if(prodName.indexOf("直拍封面") !== -1){
  153. width = 732;
  154. height = 1252;
  155. }else if(prodName.indexOf("二宫格") !== -1){
  156. width = 1252;
  157. height = 732;
  158. }else if(prodName.indexOf("明信片") !== -1){
  159. width = 1229;
  160. height = 1796;
  161. }else if(prodName.indexOf("三宫格") !== -1){
  162. width = 673;
  163. height = 1547;
  164. }else if(prodName.indexOf("书签") !== -1){
  165. width = 638;
  166. height = 1796;
  167. }else if(prodName.indexOf("小方卡") !== -1){
  168. width = 673;
  169. height = 673;
  170. }else if(prodName.indexOf("方卡") !== -1){
  171. width = 1229;
  172. height = 1229;
  173. }else if(prodName.indexOf("手幅") !== -1){
  174. width = 1252;
  175. height = 3614;
  176. }else if(prodName.indexOf("毛绒徽章") !== -1){
  177. width = 827;
  178. height = 827;
  179. }else if(prodName.indexOf("圆形徽章") !== -1){
  180. width = 850;
  181. height = 850;
  182. }else if(prodName.indexOf("手幅") !== -1){
  183. width = 1252;
  184. height = 3614;
  185. }else if(prodName.indexOf("4寸典藏级花式拍立得") !== -1){
  186. width = 921;
  187. height = 1087;
  188. }else if(prodName.indexOf("5寸典藏级花式拍立得") !== -1){
  189. width = 1346;
  190. height = 1087;
  191. }else if(prodName.indexOf("长方形贴纸") !== -1){
  192. width = 780;
  193. height = 1134;
  194. }else if(prodName.indexOf("方形贴纸") !== -1){
  195. width = 662;
  196. height = 662;
  197. }else if(prodName.indexOf("撕拉") !== -1){
  198. width = 768;
  199. height = 768;
  200. }
  201. let _URL = window.URL || window.webkitURL;
  202. let img = new Image();
  203. img.onload = function() {
  204. let valid = img.width == width && img.height == height;
  205. valid ? resolve() : reject();
  206. };
  207. img.src = _URL.createObjectURL(file);
  208. }).then(
  209. () => {
  210. return file;
  211. },
  212. () => {
  213. this.$message.error("上传的图片宽高必须是" + width + "*" + height);
  214. return Promise.reject();
  215. }
  216. );
  217. return isJpg && isSize;
  218. },
  219. deleteCardItem(item, index){
  220. this.$confirm('确定要删除吗?', '提示', {
  221. confirmButtonText: '确定',
  222. cancelButtonText: '取消',
  223. type: 'warning'
  224. }).then(() => {
  225. this.$http({
  226. url: this.$http.adornUrl('/prod/orderCardItem/' + item.cardItemId),
  227. method: 'delete',
  228. }).then(({ data }) =>{
  229. if(data){
  230. this.$delete(this.cardItemList, index);
  231. this.$message.success("删除成功");
  232. }else{
  233. this.$message.error("删除失败");
  234. }
  235. })
  236. });
  237. },
  238. addOrUpdateCardItem(item){
  239. this.$confirm('确定要更新吗?', '提示', {
  240. confirmButtonText: '确定',
  241. cancelButtonText: '取消',
  242. type: 'warning'
  243. }).then(() => {
  244. this.$http({
  245. url: this.$http.adornUrl('/prod/orderCardItem/saveOrUpdate'),
  246. method: 'post',
  247. data: this.$http.adornData(item)
  248. }).then(({ data }) =>{
  249. if(data){
  250. this.$set(item, 'cardItemId', data.cardItemId);
  251. this.$message.success("保存成功");
  252. }else{
  253. this.$message.error("保存失败");
  254. }
  255. })
  256. });
  257. },
  258. onFrontUploadSuccess (item, response, file) {
  259. this.$set(item,'frontPic',response.filePath);
  260. this.$forceUpdate()
  261. },
  262. onBackUploadSuccess (item, response, file) {
  263. this.$set(item,'backPic',response.filePath);
  264. this.$forceUpdate()
  265. },
  266. addCardItem(){
  267. if(this.cardItemList.length > 0){
  268. let item = this.cardItemList[0];
  269. let newItem = {orderNumber: item.orderNumber, orderItemId: this.orderItem.orderItemId, prodName: item.prodName, skuName: item.skuName, flag: 0, prodCount: 1 }
  270. this.cardItemList.push(newItem);
  271. }else{
  272. let newItem = {orderNumber: this.orderItem.orderNumber, orderItemId: this.orderItem.orderItemId, prodName: this.orderItem.prodName, skuName: this.orderItem.skuName, flag: 0, prodCount: 1}
  273. this.cardItemList.push(newItem);
  274. }
  275. },
  276. handleFlag(item, index){
  277. let fl = item.flag == 1? 0 : 1
  278. this.$http({
  279. url: this.$http.adornUrl('/prod/orderCardItem/flag'),
  280. method: 'post',
  281. data: this.$http.adornParams(
  282. Object.assign({
  283. cardItemId: item.cardItemId,
  284. flag: fl
  285. },
  286. )
  287. )
  288. }).then(({data}) => {
  289. if(data){
  290. this.$message({
  291. message: "标记完成",
  292. type: 'success',
  293. });
  294. this.cardItemList[index].flag = fl;
  295. }else{
  296. this.$message({
  297. message: "标记失败",
  298. type: 'error',
  299. })
  300. }
  301. })
  302. },
  303. previewPic(cardItem, picUrl, prodName, side){
  304. this.previewPicUrl = this.resourcesUrl + picUrl
  305. this.previewPicDialogVisible = true;
  306. this.side = side;
  307. if(prodName.indexOf('小卡') != -1){
  308. this.prodType = '小卡';
  309. } else if(prodName.indexOf('3寸花式拍立得') != -1){
  310. this.prodType = '3寸花式拍立得';
  311. }else if(prodName.indexOf('4寸典藏级花式拍立得') != -1){
  312. this.prodType = '4寸典藏级花式拍立得';
  313. }else if(prodName.indexOf('5寸典藏级花式拍立得') != -1){
  314. this.prodType = '5寸典藏级花式拍立得';
  315. }else if(prodName.indexOf('直拍封面') != -1){
  316. this.prodType = '直拍封面';
  317. }else if(prodName.indexOf('票根') != -1){
  318. this.prodType = '票根';
  319. }else if(prodName.indexOf('明信片') != -1){
  320. this.prodType = '明信片';
  321. }else if(prodName.indexOf('小方卡') != -1){
  322. this.prodType = '小方卡';
  323. }else if(prodName.indexOf('方卡') != -1){
  324. this.prodType = '方卡';
  325. }else if(prodName.indexOf('四宫格书签') != -1){
  326. this.prodType = '四宫格书签';
  327. }else if(prodName.indexOf('徽章') != -1){
  328. this.prodType = '徽章';
  329. }else if(prodName.indexOf('手幅') != -1){
  330. this.prodType = '手幅';
  331. }else if(prodName.indexOf('毛绒徽章') != -1){
  332. this.prodType = '毛绒徽章';
  333. }else if(prodName.indexOf('三宫格') != -1){
  334. this.prodType = '三宫格';
  335. }else if(prodName.indexOf('长方形贴纸') != -1){
  336. this.prodType = '长方形贴纸';
  337. }else if(prodName.indexOf('方形贴纸') != -1){
  338. this.prodType = '方形贴纸';
  339. }else if(prodName.indexOf('二宫格') != -1){
  340. this.prodType = '二宫格';
  341. }else if(prodName.indexOf('撕拉') != -1){
  342. this.prodType = '撕拉';
  343. }
  344. this.$nextTick(() =>{
  345. this.$refs.canvasPreviewRef.init(cardItem, this.resourcesUrl + picUrl, this.prodType, side)
  346. })
  347. },
  348. getDataList () {
  349. this.$http({
  350. url: this.$http.adornUrl('/prod/orderCardItem/page'),
  351. method: 'get',
  352. params: this.$http.adornParams(
  353. Object.assign({
  354. size: 300,
  355. orderNumber: this.orderItem.orderNumber,
  356. orderItemId: this.orderItem.orderItemId,
  357. },
  358. )
  359. )
  360. }).then(({data}) => {
  361. this.cardItemList = data.records;
  362. })
  363. },
  364. }
  365. }
  366. </script>
  367. <style lang="scss" scoped>
  368. .previewClass{
  369. position:absolute;
  370. border-style:solid;
  371. border-color:red;
  372. opacity:0.3;
  373. z-index:3;
  374. }
  375. #cardBottom{
  376. position:absolute;
  377. z-index:1;
  378. }
  379. .avatar-uploader .el-upload {
  380. border: 1px dashed #d9d9d9;
  381. border-radius: 6px;
  382. cursor: pointer;
  383. position: relative;
  384. overflow: hidden;
  385. }
  386. .avatar-uploader .el-upload:hover {
  387. border-color: #409EFF;
  388. }
  389. .avatar-uploader-icon {
  390. font-size: 28px;
  391. color: #8c939d;
  392. width: 100px;
  393. height: 100px;
  394. line-height: 100px;
  395. text-align: center;
  396. }
  397. .avatar {
  398. width: 100px;
  399. height: 100px;
  400. display: block;
  401. }
  402. /* .prods-select-body {
  403. height: 600px;
  404. overflow: auto;
  405. border-top: 1px solid #eeeeee;
  406. border-right: 1px solid #eeeeee;
  407. border-bottom: 1px solid #eeeeee;
  408. } */
  409. .brand-select-pop {
  410. & ::v-deep .el-dialog__body {
  411. padding-top: 20px;
  412. padding-bottom: 20px;
  413. }
  414. .main-container {
  415. margin: 0;
  416. .pagination {
  417. text-align: right;
  418. }
  419. }
  420. }
  421. </style>