printPicLib-add-or-update.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <el-dialog
  3. :title="!dataForm.templateId ? this.$i18n.t('crud.addTitle') : this.$i18n.t('temp.modify')"
  4. :close-on-click-modal="false"
  5. :visible.sync="visible">
  6. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="100px">
  7. <el-form-item label="关联产品" prop="prodId">
  8. <el-select v-model="dataForm.prodId" clearable filterable @change="prodChange">
  9. <el-option v-for="(item, index) in prodList"
  10. :key="index"
  11. :label="item.prodName"
  12. :value="item.prodId">
  13. </el-option>
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item label="分类" prop="category">
  17. <el-input v-model="dataForm.category" style="width: 185px" />
  18. </el-form-item>
  19. <el-row>
  20. <el-col>
  21. <el-form-item label="正面" prop="frontUrl">
  22. <img-upload v-model="dataForm.frontUrl" :limit="40"></img-upload>
  23. </el-form-item>
  24. </el-col>
  25. </el-row>
  26. <el-row>
  27. <el-col :span="6">
  28. <el-form-item label="背面" prop="backUrl">
  29. <img-upload v-model="dataForm.backUrl" :limit="1"></img-upload>
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="6">
  33. <el-form-item label="复制卡背数量">
  34. <el-input type="number" v-model="dataForm.backCopyNum"></el-input>
  35. </el-form-item>
  36. </el-col>
  37. </el-row>
  38. <el-form-item label="是否禁用" prop="isDelete">
  39. <el-select v-model="dataForm.isDelete" clearable filterable>
  40. <el-option key="1" label="启用" :value=0 ></el-option>
  41. <el-option key="0" label="禁用" :value=1 ></el-option>
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item label="排序" prop="seq">
  45. <el-input v-model="dataForm.seq" style="width: 185px" type="number"/>
  46. </el-form-item>
  47. </el-form>
  48. <span slot="footer" class="dialog-footer">
  49. <el-button class="default-btn" @click="visible = false">{{$t("crud.filter.cancelBtn")}}</el-button>
  50. <el-button class="default-btn primary-btn" type="primary" @click="dataFormSubmit()">{{$t("crud.filter.submitBtn")}}</el-button>
  51. </span>
  52. </el-dialog>
  53. </template>
  54. <script>
  55. import ImgUpload from '@/components/imgs-upload'
  56. export default {
  57. components: {
  58. ImgUpload
  59. },
  60. data () {
  61. return {
  62. visible: false,
  63. dataForm: {
  64. id: null,
  65. frontUrl: null,
  66. backUrl: null,
  67. prodId: null,
  68. prodName: null,
  69. seq: null,
  70. isDelete: 0,
  71. category:null,
  72. backCopyNum: 1,
  73. shopId: this.$store.state.user.shopId,
  74. },
  75. resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
  76. prodList: [],
  77. dataRule: {
  78. },
  79. }
  80. },
  81. created(){
  82. this.getProdList();
  83. },
  84. methods: {
  85. init (id) {
  86. this.dataForm.id = id || 0
  87. this.visible = true
  88. this.$nextTick(() => {
  89. this.$refs['dataForm'].resetFields()
  90. if (this.dataForm.id) {
  91. this.$http({
  92. url: this.$http.adornUrl('/print/printPicLib/info/' + this.dataForm.id),
  93. method: 'get',
  94. params: this.$http.adornParams()
  95. }).then(({data}) => {
  96. this.dataForm = data
  97. })
  98. }
  99. })
  100. },
  101. prodChange(prodId){
  102. this.prodList.map(item =>{
  103. if(item.prodId === prodId){
  104. this.dataForm.prodName = item.prodName;
  105. }
  106. });
  107. },
  108. getProdTypeSize(){
  109. let width = 0;
  110. let height = 0;
  111. let prodName = this.dataForm.prodName;
  112. if(prodName.indexOf('小卡') !== -1 || prodName.indexOf("3寸花式拍立得") !== -1){
  113. width = 709;
  114. height = 1087;
  115. }else if(prodName.indexOf("4寸花式拍立得") !== -1){
  116. width = 921;
  117. height = 1087;
  118. }else if(prodName.indexOf("5寸花式拍立得") !== -1){
  119. width = 1346;
  120. height = 1087;
  121. }else if(prodName.indexOf("票根") !== -1){
  122. width = 780;
  123. height = 1489;
  124. }else if(prodName.indexOf("圆形徽章") !== -1){
  125. width = 850;
  126. height = 850;
  127. }else if(prodName.indexOf("书签") !== -1){
  128. width = 638;
  129. height = 1796;
  130. }else if(prodName.indexOf("竖版四宫格") !== -1){
  131. width = 638;
  132. height = 1796;
  133. }else if(prodName.indexOf("小方卡") !== -1){
  134. width = 709;
  135. height = 709;
  136. }else if(prodName.indexOf("方卡") !== -1){
  137. width = 1229;
  138. height = 1229;
  139. }else if(prodName.indexOf("明信片") !== -1){
  140. width = 1229;
  141. height = 1796;
  142. }else if(prodName.indexOf("二宫格") !== -1){
  143. width = 1252;
  144. height = 732;
  145. }else if(prodName.indexOf("直拍") !== -1){
  146. width = 732;
  147. height = 1252;
  148. }
  149. return {width, height};
  150. },
  151. //验证图片尺寸
  152. checkImageSize(imageStr, index) {
  153. let width = this.getProdTypeSize().width;
  154. let height = this.getProdTypeSize().height;
  155. return new Promise((resolve, reject) => {
  156. let image = new Image();
  157. image.onload = function() {
  158. let imageFormat = imageStr.split('.').pop();
  159. if(imageFormat !== 'jpg'){
  160. reject(index);
  161. }
  162. if ((image.width === width && image.height === height)) {
  163. resolve();
  164. } else {
  165. reject(index);
  166. }
  167. };
  168. image.src = this.resourcesUrl + imageStr;
  169. });
  170. },
  171. getProdList(){
  172. this.$http({
  173. url: this.$http.adornUrl('/prod/prod/simpleList'),
  174. method: 'GET',
  175. params: this.$http.adornParams({ customized:0, customType:2, shopId: this.dataForm.shopId})
  176. }).then(({data}) => {
  177. this.prodList = data
  178. })
  179. },
  180. // 表单提交
  181. async dataFormSubmit () {
  182. try{
  183. let frontImgs = this.dataForm.frontUrl.split(",");
  184. // if(this.dataForm.backUrl){
  185. // imgs[1] = this.dataForm.backUrl ? this.dataForm.backUrl:null;
  186. // }
  187. await Promise.all(frontImgs.map(this.checkImageSize));
  188. this.$http({
  189. url: this.$http.adornUrl('/print/printPicLib'),
  190. method: this.dataForm.id ? 'put' : 'post',
  191. data: this.$http.adornData(this.dataForm)
  192. }).then(({data}) => {
  193. this.$message({
  194. message: this.$i18n.t('publics.operation'),
  195. type: 'success',
  196. duration: 200,
  197. onClose: () => {
  198. this.visible = false
  199. this.$emit('refreshDataList')
  200. }
  201. })
  202. })
  203. }catch (error) {
  204. this.$message.error(`第 ${error + 1} 张图片不符合尺寸要求。`)
  205. }
  206. }
  207. }
  208. }
  209. </script>