prodTemplate-add-or-update.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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" @keyup.enter.native="dataFormSubmit()" label-width="100px">
  7. <el-form-item label="模板正反面" prop="templateSide">
  8. <el-select v-model="dataForm.templateSide" clearable filterable>
  9. <el-option key="Front" label="正面" value="Front"></el-option>
  10. <el-option key="Back" label="背面" value="Back"></el-option>
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item label="模板用途" prop="templateUsage">
  14. <el-select v-model="usageList" clearable filterable multiple>
  15. <el-option key="smallcard" label="小卡" value="smallcard,YXK,ZJXK,DBYXK,DBZJXK"></el-option>
  16. <el-option key="squarecard" label="大方卡" value="squarecard,FK"></el-option>
  17. <el-option key="XFK" label="小方卡" value="XFK"></el-option>
  18. <el-option key="badge" label="徽章" value="badge,HZ"></el-option>
  19. <el-option key="postcard" label="明信片" value="postcard,MXP"></el-option>
  20. <el-option key="bookmark" label="书签" value="bookmark,SQ"></el-option>
  21. <el-option key="tipscard" label="手幅" value="tipscard,SF"></el-option>
  22. <el-option key="covercard" label="直拍封面" value="covercard,ZP"></el-option>
  23. <el-option key="stub" label="票根" value="stub,PG"></el-option>
  24. <el-option key="FP" label="3寸花式拍立得" value="FP,polaroid"></el-option>
  25. <el-option key="4CFP" label="4寸花式拍立得" value="4CFP"></el-option>
  26. <el-option key="5CFP" label="5寸花式拍立得" value="5CFP"></el-option>
  27. <el-option key="SBSGG" label="竖版四宫格" value="SBSGG"></el-option>
  28. <el-option key="TZSGG" label="田字四宫格" value="TZSGG"></el-option>
  29. <el-option key="EGG" label="横版二宫格" value="EGG"></el-option>
  30. <el-option key="3CFZFP" label="3寸仿真拍立得" value="3CFZFP"></el-option>
  31. <el-option key="4CFZFP" label="4寸仿真拍立得" value="4CFZFP"></el-option>
  32. <el-option key="5CFZFP" label="5寸仿真拍立得" value="5CFZFP"></el-option>
  33. <el-option key="XL3CFZFP" label="撕拉3寸花式仿真拍立得" value="XL3CFZFP"></el-option>
  34. <el-option key="XL4CFZFP" label="撕拉4寸花式仿真拍立得" value="XL4CFZFP"></el-option>
  35. <el-option key="YOUXK" label="游戏卡" value="YOUXK"></el-option>
  36. <el-option key="YYK" label="语音卡" value="YYYXK,YYZJXK"></el-option>
  37. </el-select>
  38. </el-form-item>
  39. <el-form-item label="模板风格" prop="templateStyle">
  40. <el-select v-model="dataForm.templateStyleId" clearable filterable>
  41. <el-option
  42. v-for="node in styleList"
  43. :key="node.styleId"
  44. :label="node.styleName"
  45. :value="node.styleId"
  46. ></el-option>
  47. </el-select>
  48. </el-form-item>
  49. <el-form-item label="模板系列" prop="templateSeries">
  50. <el-select v-model="dataForm.templateSeriesId" clearable filterable>
  51. <el-option
  52. v-for="node in seriesList"
  53. :key="node.seriesId"
  54. :label="node.seriesName"
  55. :value="node.seriesId"
  56. ></el-option>
  57. </el-select>
  58. </el-form-item>
  59. <el-form-item label="模板图片" prop="templatePic">
  60. <img-upload v-model="dataForm.templatePic" :limit="20"></img-upload>
  61. </el-form-item>
  62. <!--<el-form-item label="商家ID" prop="shopId">
  63. <el-input v-model="dataForm.shopId"></el-input>
  64. </el-form-item>-->
  65. <el-form-item label="是否禁用" prop="status">
  66. <el-select v-model="dataForm.status" clearable filterable>
  67. <el-option key="1" label="启用" :value=1 ></el-option>
  68. <el-option key="0" label="禁用" :value=0 ></el-option>
  69. </el-select>
  70. </el-form-item>
  71. <el-form-item label="排序" prop="seq">
  72. <el-input v-model="dataForm.seq" type="number"/>
  73. </el-form-item>
  74. </el-form>
  75. <span slot="footer" class="dialog-footer">
  76. <el-button class="default-btn" @click="visible = false">{{$t("crud.filter.cancelBtn")}}</el-button>
  77. <el-button class="default-btn primary-btn" type="primary" @click="dataFormSubmit()">{{$t("crud.filter.submitBtn")}}</el-button>
  78. </span>
  79. </el-dialog>
  80. </template>
  81. <script>
  82. import ImgUpload from '@/components/imgs-upload'
  83. // import uploadPic from './upload-pic.vue'
  84. export default {
  85. components: {
  86. ImgUpload
  87. },
  88. data () {
  89. return {
  90. visible: false,
  91. dataForm: {
  92. templateId: null,
  93. templateSide: null,
  94. templateStyleId: null,
  95. templateSeriesId: null,
  96. templateStyle: null,
  97. templateSeries: null,
  98. templatePic: null,
  99. shopId: this.$store.state.user.shopId,
  100. status: null,
  101. createTime: null,
  102. templateUsage: null,
  103. seq: 1
  104. },
  105. resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
  106. seriesList: [],
  107. styleList: [],
  108. usageList:[],
  109. dataRule: {
  110. }
  111. }
  112. },
  113. created () {
  114. this.getStyleList()
  115. this.getSeriesList()
  116. },
  117. methods: {
  118. init (templateId) {
  119. this.dataForm.templateId = templateId || 0
  120. this.visible = true
  121. this.$nextTick(() => {
  122. this.$refs['dataForm'].resetFields()
  123. if (this.dataForm.templateId) {
  124. this.$http({
  125. url: this.$http.adornUrl('/prod/prodTemplate/info/' + this.dataForm.templateId),
  126. method: 'get',
  127. params: this.$http.adornParams()
  128. }).then(({data}) => {
  129. this.dataForm = data;
  130. this.usageList = data.templateUsage.split(",");
  131. })
  132. }
  133. })
  134. },
  135. //验证图片尺寸
  136. checkImageSize(imageStr, index) {
  137. let width = 0;
  138. let height = 0;
  139. let templateUsage = this.usageList.join(",");
  140. let isBack = this.dataForm.templateSide === 'Back';
  141. return new Promise((resolve, reject) => {
  142. let image = new Image();
  143. image.onload = function() {
  144. if(templateUsage.indexOf("smallcard") !== -1 || templateUsage.indexOf("polaroid") !== -1 || templateUsage.indexOf("YYYXK") !== -1 || templateUsage.indexOf("YYZJXK") !== -1){
  145. width = 709;
  146. height = 1087;
  147. }else if(templateUsage.indexOf("stub") !== -1 || templateUsage.indexOf("PG") !== -1){
  148. width = 780;
  149. height = 1489;
  150. }else if(templateUsage.indexOf("bookmark") !== -1 || templateUsage.indexOf("SQ") !== -1){
  151. width = 638;
  152. height = 1796;
  153. }else if(templateUsage.indexOf("postcard") !== -1 || templateUsage.indexOf("MXP") !== -1){
  154. width = 1229;
  155. height = 1796;
  156. }else if(templateUsage.indexOf("4CFP") !== -1 || templateUsage.indexOf("4CFZFP") !== -1 || templateUsage.indexOf("XL4CFZFP") !== -1){
  157. width = 921;
  158. height = 1087;
  159. }else if(templateUsage.indexOf("5CFP") !== -1 || templateUsage.indexOf("5CFZFP") !== -1){
  160. width = 1346;
  161. height = 1087;
  162. }else if(templateUsage.indexOf("FP") !== -1 || templateUsage.indexOf("3CFZFP") !== -1 || templateUsage.indexOf("XL3CFZFP") !== -1){
  163. width = 709;
  164. height = 1087;
  165. }else if(templateUsage.indexOf("EGG") !== -1){
  166. width = 1228;
  167. height = 709;
  168. }else if(templateUsage.indexOf("SBSGG") !== -1){
  169. width = 638;
  170. height = 1796;
  171. }else if(templateUsage.indexOf("TZSGG") !== -1){
  172. width = 1229;
  173. height = 1796;
  174. }else if(templateUsage.indexOf("XFK") !== -1){
  175. width = 673;
  176. height = 673;
  177. }else if(templateUsage.indexOf("FK") !== -1){
  178. width = 1229;
  179. height = 1229;
  180. }else if(templateUsage.indexOf("YOUXK") !== -1){
  181. width = 803;
  182. height = 1098;
  183. }
  184. if(isBack){
  185. let imageFormat = imageStr.split('.').pop();
  186. if(imageFormat != 'jpg'){
  187. reject(index);
  188. }
  189. }else if(!isBack && (templateUsage.indexOf("polaroid") !== -1 || templateUsage.indexOf("FP") !== -1 || templateUsage.indexOf("EGG") !== -1)){
  190. let imageFormat = imageStr.split('.').pop();
  191. if(imageFormat != 'png'){
  192. reject(index);
  193. }
  194. }
  195. if ((image.width === width && image.height === height)) {
  196. resolve();
  197. } else {
  198. reject(index);
  199. }
  200. };
  201. image.src = this.resourcesUrl + imageStr;
  202. });
  203. },
  204. // 表单提交
  205. async dataFormSubmit () {
  206. try{
  207. let imgUrlArr = this.dataForm.templatePic.split(",");
  208. await Promise.all(imgUrlArr.map(this.checkImageSize));
  209. this.handleStyleName(this.dataForm.templateStyleId);
  210. this.handleSeriesName(this.dataForm.templateSeriesId);
  211. this.dataForm.templateUsage = this.usageList.join(",");
  212. this.$http({
  213. url: this.$http.adornUrl('/prod/prodTemplate'),
  214. method: this.dataForm.templateId ? 'put' : 'post',
  215. data: this.$http.adornData(this.dataForm)
  216. }).then(({data}) => {
  217. this.$message({
  218. message: this.$i18n.t('publics.operation'),
  219. type: 'success',
  220. duration: 200,
  221. onClose: () => {
  222. this.visible = false;
  223. this.$emit('refreshDataList')
  224. }
  225. })
  226. })
  227. }catch (error) {
  228. this.$message.error(`第 ${error + 1} 张图片不符合尺寸要求。`)
  229. }
  230. },
  231. getStyleList () {
  232. this.$http({
  233. url: this.$http.adornUrl('/prod/prodTemplateStyle/page'),
  234. method: 'get',
  235. params: this.$http.adornParams(
  236. Object.assign({
  237. size: 100,
  238. shopId: this.$store.state.user.shopId
  239. }
  240. )
  241. )
  242. }).then(({data}) => {
  243. this.styleList = data.records
  244. })
  245. },
  246. getSeriesList () {
  247. this.$http({
  248. url: this.$http.adornUrl('/prod/prodTemplateSeries/page'),
  249. method: 'get',
  250. params: this.$http.adornParams(
  251. Object.assign({
  252. size: 100,
  253. shopId: this.$store.state.user.shopId
  254. }
  255. )
  256. )
  257. }).then(({data}) => {
  258. this.seriesList = data.records
  259. })
  260. },
  261. handleStyleName (styleId) {
  262. this.styleList.forEach(style =>{
  263. if (style.styleId == styleId) {
  264. this.dataForm.templateStyle = style.styleName
  265. return;
  266. }
  267. })
  268. },
  269. handleSeriesName (seriesId) {
  270. this.seriesList.forEach(series =>{
  271. if (series.seriesId == seriesId) {
  272. this.dataForm.templateSeries = series.seriesName
  273. }
  274. })
  275. },
  276. }
  277. }
  278. </script>