index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 = 673;
  146. height = 673;
  147. }else if(prodName.indexOf("方卡") !== -1){
  148. width = 1217;
  149. height = 1217;
  150. }else if(prodName.indexOf("手幅") !== -1){
  151. width = 1252;
  152. height = 3614;
  153. }else if(prodName.indexOf("毛绒徽章") !== -1){
  154. width = 827;
  155. height = 827;
  156. }else if(prodName.indexOf("手幅") !== -1){
  157. width = 1252;
  158. height = 3614;
  159. }
  160. let _URL = window.URL || window.webkitURL;
  161. let img = new Image();
  162. img.onload = function() {
  163. let valid = img.width == width && img.height == height;
  164. valid ? resolve() : reject();
  165. };
  166. img.src = _URL.createObjectURL(file);
  167. }).then(
  168. () => {
  169. return file;
  170. },
  171. () => {
  172. this.$message.error("上传的图片宽高必须是" + width + "*" + height);
  173. return Promise.reject();
  174. }
  175. );
  176. return isJpg && isSize;
  177. },
  178. deleteCardItem(item, index){
  179. this.$confirm('确定要删除吗?', '提示', {
  180. confirmButtonText: '确定',
  181. cancelButtonText: '取消',
  182. type: 'warning'
  183. }).then(() => {
  184. this.$http({
  185. url: this.$http.adornUrl('/prod/orderCardItem/' + item.cardItemId),
  186. method: 'delete',
  187. }).then(({ data }) =>{
  188. if(data){
  189. this.$delete(this.cardItemList, index);
  190. this.$message.success("删除成功");
  191. }else{
  192. this.$message.error("删除失败");
  193. }
  194. })
  195. });
  196. },
  197. addOrUpdateCardItem(item){
  198. this.$confirm('确定要更新吗?', '提示', {
  199. confirmButtonText: '确定',
  200. cancelButtonText: '取消',
  201. type: 'warning'
  202. }).then(() => {
  203. this.$http({
  204. url: this.$http.adornUrl('/prod/orderCardItem/saveOrUpdate'),
  205. method: 'post',
  206. data: this.$http.adornData(item)
  207. }).then(({ data }) =>{
  208. if(data){
  209. this.$set(item, 'cardItemId', data.cardItemId);
  210. this.$message.success("保存成功");
  211. }else{
  212. this.$message.error("保存失败");
  213. }
  214. })
  215. });
  216. },
  217. onFrontUploadSuccess (item, response, file) {
  218. this.$set(item,'frontPic',response.filePath);
  219. this.$forceUpdate()
  220. },
  221. onBackUploadSuccess (item, response, file) {
  222. this.$set(item,'backPic',response.filePath);
  223. this.$forceUpdate()
  224. },
  225. addCardItem(){
  226. if(this.cardItemList.length > 0){
  227. let item = this.cardItemList[0];
  228. let newItem = {orderNumber: item.orderNumber, orderItemId: this.orderItem.orderItemId, prodName: item.prodName, skuName: item.skuName, flag: 0, prodCount: 1 }
  229. this.cardItemList.push(newItem);
  230. }else{
  231. let newItem = {orderNumber: this.orderItem.orderNumber, orderItemId: this.orderItem.orderItemId, prodName: this.orderItem.prodName, skuName: this.orderItem.skuName, flag: 0, prodCount: 1}
  232. this.cardItemList.push(newItem);
  233. }
  234. },
  235. handleFlag(item, index){
  236. let fl = item.flag == 1? 0 : 1
  237. this.$http({
  238. url: this.$http.adornUrl('/prod/orderCardItem/flag'),
  239. method: 'post',
  240. data: this.$http.adornParams(
  241. Object.assign({
  242. cardItemId: item.cardItemId,
  243. flag: fl
  244. },
  245. )
  246. )
  247. }).then(({data}) => {
  248. if(data){
  249. this.$message({
  250. message: "标记完成",
  251. type: 'success',
  252. });
  253. this.cardItemList[index].flag = fl;
  254. }else{
  255. this.$message({
  256. message: "标记失败",
  257. type: 'error',
  258. })
  259. }
  260. })
  261. },
  262. previewPic(cardItem, picUrl, prodName, side){
  263. this.previewPicUrl = this.resourcesUrl + picUrl
  264. this.previewPicDialogVisible = true;
  265. this.side = side;
  266. 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. }else if(prodName.indexOf('书签') != -1){
  281. this.prodType = '书签';
  282. }else if(prodName.indexOf('徽章') != -1){
  283. this.prodType = '徽章';
  284. }else if(prodName.indexOf('手幅') != -1){
  285. this.prodType = '手幅';
  286. }else if(prodName.indexOf('毛绒徽章') != -1){
  287. this.prodType = '毛绒徽章';
  288. }
  289. this.$nextTick(() =>{
  290. this.$refs.canvasPreviewRef.init(cardItem, this.resourcesUrl + picUrl, this.prodType, side)
  291. })
  292. },
  293. getDataList () {
  294. this.$http({
  295. url: this.$http.adornUrl('/prod/orderCardItem/page'),
  296. method: 'get',
  297. params: this.$http.adornParams(
  298. Object.assign({
  299. size: 300,
  300. orderNumber: this.orderItem.orderNumber,
  301. orderItemId: this.orderItem.orderItemId,
  302. },
  303. )
  304. )
  305. }).then(({data}) => {
  306. this.cardItemList = data.records;
  307. })
  308. },
  309. }
  310. }
  311. </script>
  312. <style lang="scss" scoped>
  313. .previewClass{
  314. position:absolute;
  315. border-style:solid;
  316. border-color:red;
  317. opacity:0.3;
  318. z-index:3;
  319. }
  320. #cardBottom{
  321. position:absolute;
  322. z-index:1;
  323. }
  324. .avatar-uploader .el-upload {
  325. border: 1px dashed #d9d9d9;
  326. border-radius: 6px;
  327. cursor: pointer;
  328. position: relative;
  329. overflow: hidden;
  330. }
  331. .avatar-uploader .el-upload:hover {
  332. border-color: #409EFF;
  333. }
  334. .avatar-uploader-icon {
  335. font-size: 28px;
  336. color: #8c939d;
  337. width: 100px;
  338. height: 100px;
  339. line-height: 100px;
  340. text-align: center;
  341. }
  342. .avatar {
  343. width: 100px;
  344. height: 100px;
  345. display: block;
  346. }
  347. /* .prods-select-body {
  348. height: 600px;
  349. overflow: auto;
  350. border-top: 1px solid #eeeeee;
  351. border-right: 1px solid #eeeeee;
  352. border-bottom: 1px solid #eeeeee;
  353. } */
  354. .brand-select-pop {
  355. & ::v-deep .el-dialog__body {
  356. padding-top: 20px;
  357. padding-bottom: 20px;
  358. }
  359. .main-container {
  360. margin: 0;
  361. .pagination {
  362. text-align: right;
  363. }
  364. }
  365. }
  366. </style>