index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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==='edit'" type="primary" size="mini" style="margin-right: 5px" @click="addOrUpdateCardItem(item)">保存</el-button>
  53. <el-button v-if="mode==='edit' && item.cardItemId" type="danger" size="mini" style="margin-right: 5px" @click="deleteCardItem(item, index)">删除</el-button>
  54. </span>
  55. </el-row>
  56. <el-row style="width: 210px; height: 30px; text-align: center ;color: red; font-weight: bold">
  57. <span>No.{{index + 1}}</span>
  58. <span v-if="showFlagBtn" style="color: white">
  59. __________
  60. </span>
  61. <span>X</span>
  62. <span v-if="mode=='view'">{{item.prodCount}}</span>
  63. <el-input type="number" size="mini" style="width: 60px;height: 20px" v-if="mode=='edit'" v-model="item.prodCount"></el-input>
  64. </el-row>
  65. </div>
  66. <div v-if="mode=='edit'" style="display: inline-block;">
  67. <el-button
  68. circle
  69. icon="el-icon-plus"
  70. @click="addCardItem">
  71. </el-button>
  72. </div>
  73. </div>
  74. <CanvasPreview v-if= "previewPicDialogVisible" ref="canvasPreviewRef"></CanvasPreview>
  75. </div>
  76. </template>
  77. <script>
  78. import CanvasPreview from "../canvas-preview/index";
  79. export default {
  80. components: {CanvasPreview},
  81. data () {
  82. return {
  83. lang: localStorage.getItem('lang') || 'zh_CN',
  84. cardItemList:[],
  85. previewPicUrl: null,
  86. prodType: null,
  87. previewPicDialogVisible: false,
  88. side:null,
  89. resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
  90. mode: 'view',
  91. previewWidth: 0,
  92. previewHeight: 0,
  93. bloodWidth: 0
  94. }
  95. },
  96. props: {
  97. orderItem: {
  98. default: null,
  99. type: Object
  100. },
  101. showFlagBtn:{
  102. default: true,
  103. type: Boolean
  104. }
  105. },
  106. created() {
  107. this.$nextTick(() => {
  108. this.getDataList();
  109. })
  110. },
  111. methods: {
  112. previewLoad(event){
  113. this.previewWidth = event.srcElement.clientWidth;
  114. this.previewHeight = event.srcElement.clientHeight;
  115. },
  116. handleBeforeUpload(file, fileList, item){
  117. let fileType = file.type;
  118. let isJpg = fileType === 'image/jpg' || fileType === 'image/jpeg';
  119. if(!isJpg){
  120. this.$message.error("只允许上传JPG格式的图片");
  121. return false;
  122. }
  123. let isSize = true;
  124. //如果当前是编辑的小卡,就需要判断是否符合尺寸
  125. let width = 709;
  126. let height = 1087;
  127. let prodName = item.prodName;
  128. isSize = new Promise(function(resolve, reject) {
  129. if(prodName.indexOf("小卡") !== -1 || prodName.indexOf("仿拍立得") !== -1){
  130. width = 709;
  131. height = 1087;
  132. }else if(prodName.indexOf("票根") !== -1){
  133. width = 780;
  134. height = 1489;
  135. }else if(prodName.indexOf("直拍封面") !== -1){
  136. width = 697;
  137. height = 1217;
  138. }else if(prodName.indexOf("明信片") !== -1){
  139. width = 1252;
  140. height = 1819;
  141. }else if(prodName.indexOf("书签") !== -1){
  142. width = 638;
  143. height = 1819;
  144. }else if(prodName.indexOf("方卡") !== -1){
  145. width = 1217;
  146. height = 1217;
  147. }else if(prodName.indexOf("手幅") !== -1){
  148. width = 1252;
  149. height = 3614;
  150. }else if(prodName.indexOf("毛绒徽章") !== -1){
  151. width = 827;
  152. height = 827;
  153. }
  154. let _URL = window.URL || window.webkitURL;
  155. let img = new Image();
  156. img.onload = function() {
  157. let valid = img.width == width && img.height == height;
  158. valid ? resolve() : reject();
  159. };
  160. img.src = _URL.createObjectURL(file);
  161. }).then(
  162. () => {
  163. return file;
  164. },
  165. () => {
  166. this.$message.error("上传的图片宽高必须是" + width + "*" + height);
  167. return Promise.reject();
  168. }
  169. );
  170. return isJpg && isSize;
  171. },
  172. deleteCardItem(item, index){
  173. this.$confirm('确定要删除吗?', '提示', {
  174. confirmButtonText: '确定',
  175. cancelButtonText: '取消',
  176. type: 'warning'
  177. }).then(() => {
  178. this.$http({
  179. url: this.$http.adornUrl('/prod/orderCardItem/' + item.cardItemId),
  180. method: 'delete',
  181. }).then(({ data }) =>{
  182. if(data){
  183. this.$delete(this.cardItemList, index);
  184. this.$message.success("删除成功");
  185. }else{
  186. this.$message.error("删除失败");
  187. }
  188. })
  189. });
  190. },
  191. addOrUpdateCardItem(item){
  192. this.$confirm('确定要更新吗?', '提示', {
  193. confirmButtonText: '确定',
  194. cancelButtonText: '取消',
  195. type: 'warning'
  196. }).then(() => {
  197. this.$http({
  198. url: this.$http.adornUrl('/prod/orderCardItem/saveOrUpdate'),
  199. method: 'post',
  200. data: this.$http.adornData(item)
  201. }).then(({ data }) =>{
  202. if(data){
  203. this.$set(item, 'cardItemId', data.cardItemId);
  204. this.$message.success("保存成功");
  205. }else{
  206. this.$message.error("保存失败");
  207. }
  208. })
  209. });
  210. },
  211. onFrontUploadSuccess (item, response, file) {
  212. this.$set(item,'frontPic',response.filePath);
  213. this.$forceUpdate()
  214. },
  215. onBackUploadSuccess (item, response, file) {
  216. this.$set(item,'backPic',response.filePath);
  217. this.$forceUpdate()
  218. },
  219. addCardItem(){
  220. if(this.cardItemList.length > 0){
  221. let item = this.cardItemList[0];
  222. let newItem = {orderNumber: item.orderNumber, orderItemId: this.orderItem.orderItemId, prodName: item.prodName, skuName: item.skuName, flag: 0, prodCount: 1 }
  223. this.cardItemList.push(newItem);
  224. }else{
  225. let newItem = {orderNumber: this.orderItem.orderNumber, orderItemId: this.orderItem.orderItemId, prodName: this.orderItem.prodName, skuName: this.orderItem.skuName, flag: 0, prodCount: 1}
  226. this.cardItemList.push(newItem);
  227. }
  228. },
  229. handleFlag(item, index){
  230. let fl = item.flag == 1? 0 : 1
  231. this.$http({
  232. url: this.$http.adornUrl('/prod/orderCardItem/flag'),
  233. method: 'post',
  234. data: this.$http.adornParams(
  235. Object.assign({
  236. cardItemId: item.cardItemId,
  237. flag: fl
  238. },
  239. )
  240. )
  241. }).then(({data}) => {
  242. if(data){
  243. this.$message({
  244. message: "标记完成",
  245. type: 'success',
  246. });
  247. this.cardItemList[index].flag = fl;
  248. }else{
  249. this.$message({
  250. message: "标记失败",
  251. type: 'error',
  252. })
  253. }
  254. })
  255. },
  256. previewPic(cardItem, picUrl, prodName, side){
  257. this.previewPicUrl = this.resourcesUrl + picUrl
  258. this.previewPicDialogVisible = true;
  259. this.side = side;
  260. if(prodName.indexOf('小卡') != -1){
  261. this.prodType = '小卡';
  262. } else if(prodName.indexOf('仿拍立得') != -1){
  263. this.prodType = '仿拍立得';
  264. }else if(prodName.indexOf('直拍封面') != -1){
  265. this.prodType = '直拍封面';
  266. }else if(prodName.indexOf('票根') != -1){
  267. this.prodType = '票根';
  268. }else if(prodName.indexOf('明信片') != -1){
  269. this.prodType = '明信片';
  270. }else if(prodName.indexOf('方卡') != -1){
  271. this.prodType = '方卡';
  272. }else if(prodName.indexOf('书签') != -1){
  273. this.prodType = '书签';
  274. }else if(prodName.indexOf('徽章') != -1){
  275. this.prodType = '徽章';
  276. }else if(prodName.indexOf('手幅') != -1){
  277. this.prodType = '手幅';
  278. }else if(prodName.indexOf('毛绒徽章') != -1){
  279. this.prodType = '毛绒徽章';
  280. }
  281. this.$nextTick(() =>{
  282. this.$refs.canvasPreviewRef.init(cardItem, this.resourcesUrl + picUrl, this.prodType, side)
  283. })
  284. },
  285. getDataList () {
  286. this.$http({
  287. url: this.$http.adornUrl('/prod/orderCardItem/page'),
  288. method: 'get',
  289. params: this.$http.adornParams(
  290. Object.assign({
  291. size: 300,
  292. orderNumber: this.orderItem.orderNumber,
  293. orderItemId: this.orderItem.orderItemId,
  294. },
  295. )
  296. )
  297. }).then(({data}) => {
  298. this.cardItemList = data.records;
  299. })
  300. },
  301. }
  302. }
  303. </script>
  304. <style lang="scss" scoped>
  305. .previewClass{
  306. position:absolute;
  307. border-style:solid;
  308. border-color:red;
  309. opacity:0.3;
  310. z-index:3;
  311. }
  312. #cardBottom{
  313. position:absolute;
  314. z-index:1;
  315. }
  316. .avatar-uploader .el-upload {
  317. border: 1px dashed #d9d9d9;
  318. border-radius: 6px;
  319. cursor: pointer;
  320. position: relative;
  321. overflow: hidden;
  322. }
  323. .avatar-uploader .el-upload:hover {
  324. border-color: #409EFF;
  325. }
  326. .avatar-uploader-icon {
  327. font-size: 28px;
  328. color: #8c939d;
  329. width: 100px;
  330. height: 100px;
  331. line-height: 100px;
  332. text-align: center;
  333. }
  334. .avatar {
  335. width: 100px;
  336. height: 100px;
  337. display: block;
  338. }
  339. /* .prods-select-body {
  340. height: 600px;
  341. overflow: auto;
  342. border-top: 1px solid #eeeeee;
  343. border-right: 1px solid #eeeeee;
  344. border-bottom: 1px solid #eeeeee;
  345. } */
  346. .brand-select-pop {
  347. & ::v-deep .el-dialog__body {
  348. padding-top: 20px;
  349. padding-bottom: 20px;
  350. }
  351. .main-container {
  352. margin: 0;
  353. .pagination {
  354. text-align: right;
  355. }
  356. }
  357. }
  358. </style>