prodTemplate-add-or-update.vue 9.0 KB

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