edit.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div>
  3. <el-form
  4. ref="form"
  5. :model="formData"
  6. :rules="rules"
  7. label-width="165px"
  8. class="goods-form">
  9. <el-form-item
  10. label="标题"
  11. prop="title">
  12. <el-input
  13. v-model="formData.title"
  14. style="width: 500px"
  15. placeholder="" />
  16. </el-form-item>
  17. <el-form-item>
  18. <template #label>
  19. <span style="color: #f56c6c">*</span>&nbsp;logo
  20. </template>
  21. <input
  22. style="display: none"
  23. type="text"
  24. name="logo"
  25. :value="formData.logo" />
  26. <image-upload
  27. :max="1"
  28. :list.sync="imagesList"></image-upload>
  29. </el-form-item>
  30. <el-form-item label="主题色">
  31. <el-color-picker v-model="formData.theme_color"></el-color-picker>
  32. </el-form-item>
  33. <el-form-item label="字体色">
  34. <el-color-picker v-model="formData.font_color"></el-color-picker>
  35. </el-form-item>
  36. <el-form-item label="隐藏价格">
  37. <el-radio-group v-model="formData.hide_prices">
  38. <el-radio :label="0">显示</el-radio>
  39. <el-radio :label="1">隐藏</el-radio>
  40. </el-radio-group>
  41. </el-form-item>
  42. <el-form-item>
  43. <template #label>
  44. <span style="color: #f56c6c">*</span>&nbsp;网址
  45. </template>
  46. <el-radio-group v-model="domainType">
  47. <el-radio :label="1">catalogue域名</el-radio>
  48. <el-radio :label="2">第三方域名</el-radio>
  49. </el-radio-group>
  50. <el-form-item
  51. prop="pre"
  52. v-if="domainType === 1">
  53. <el-input
  54. @change="(e) => (formData.url = e + '.promocatalogue.com.au')"
  55. v-model="formData.pre">
  56. <template #append>.promocatalogue.com.au</template>
  57. </el-input>
  58. </el-form-item>
  59. <el-form-item
  60. prop="other"
  61. v-if="domainType === 2">
  62. <el-input
  63. @change="(e) => (formData.url = e)"
  64. v-model="formData.other"></el-input>
  65. </el-form-item>
  66. <el-input
  67. v-show="false"
  68. v-model="formData.url"
  69. style="width: 500px"
  70. placeholder="" />
  71. </el-form-item>
  72. <el-form-item
  73. label="二级域名"
  74. prop="alias_url"
  75. v-if="domainType === 2">
  76. <el-input v-model="formData.alias_url"></el-input>
  77. </el-form-item>
  78. <el-form-item
  79. label="Enquiry接收邮箱"
  80. prop="email">
  81. <el-input
  82. v-model="formData.email"
  83. style="width: 500px"
  84. placeholder="">
  85. </el-input>
  86. </el-form-item>
  87. <el-form-item
  88. label="Margin"
  89. prop="margin">
  90. <el-input
  91. v-model="formData.margin"
  92. style="width: 500px"
  93. type="number"
  94. placeholder="">
  95. <template slot="append">%</template>
  96. </el-input>
  97. </el-form-item>
  98. <el-form-item
  99. label="Setup Margin"
  100. prop="setup_margin">
  101. <el-input
  102. v-model="formData.setup_margin"
  103. style="width: 500px"
  104. type="number"
  105. placeholder="">
  106. <template slot="append">%</template>
  107. </el-input>
  108. </el-form-item>
  109. <el-form-item
  110. label="页脚信息"
  111. prop="footer">
  112. <el-input
  113. name="footer"
  114. v-model="formData.footer"
  115. style="width: 100%">
  116. </el-input>
  117. </el-form-item>
  118. <el-form-item
  119. label="Contact Us"
  120. prop="">
  121. <tinymce
  122. v-model="formData.contactus"
  123. :height="500"
  124. :width="980"
  125. style="display: inline-block" />
  126. </el-form-item>
  127. <el-form-item
  128. label="About Us"
  129. prop="">
  130. <tinymce
  131. v-model="formData.aboutus"
  132. :height="500"
  133. :width="980"
  134. style="display: inline-block" />
  135. </el-form-item>
  136. <el-form-item
  137. label="Terms & Conditions:"
  138. prop="">
  139. <tinymce
  140. v-model="formData.terms"
  141. :height="500"
  142. :width="980"
  143. style="display: inline-block" />
  144. </el-form-item>
  145. <el-form-item>
  146. <div class="flex">
  147. <el-button
  148. type="primary"
  149. :loading="loading"
  150. @click="checkForm">
  151. {{ $t('btn_save') }}
  152. </el-button>
  153. <el-button
  154. :loading="loading"
  155. @click="close">
  156. {{ $t('btn_close') }}
  157. </el-button>
  158. </div>
  159. </el-form-item>
  160. </el-form>
  161. </div>
  162. </template>
  163. <script>
  164. import Tinymce from '@/components/Tinymce'
  165. import imageUpload from '@/components/ImageUpload'
  166. import { common } from '@/api'
  167. import cloneDeep from 'lodash.clonedeep'
  168. export default {
  169. name: 'CompEditShop',
  170. components: { Tinymce, 'image-upload': imageUpload },
  171. props: {
  172. id: {
  173. type: Number,
  174. default: 0,
  175. },
  176. status: {
  177. type: Number,
  178. default: 2,
  179. },
  180. form: {
  181. type: Object,
  182. default: () => {},
  183. },
  184. },
  185. data() {
  186. return {
  187. domainType: 1,
  188. loading: false,
  189. formData: {},
  190. rules: {
  191. title: [
  192. {
  193. required: true,
  194. message: this.$t('text_please_input'),
  195. trigger: 'blur',
  196. },
  197. ],
  198. logo: [
  199. {
  200. required: true,
  201. message: this.$t('text_please_input'),
  202. trigger: 'change',
  203. },
  204. ],
  205. pre: [
  206. {
  207. required: true,
  208. message: this.$t('text_please_input'),
  209. trigger: 'blur',
  210. },
  211. ],
  212. other: [
  213. {
  214. required: true,
  215. message: this.$t('text_please_input'),
  216. trigger: 'blur',
  217. },
  218. ],
  219. email: [
  220. {
  221. required: true,
  222. message: this.$t('text_please_input'),
  223. trigger: 'blur',
  224. },
  225. ],
  226. margin: [
  227. {
  228. required: true,
  229. message: this.$t('text_please_input'),
  230. trigger: 'blur',
  231. },
  232. ],
  233. setup_margin: [
  234. {
  235. required: true,
  236. message: this.$t('text_please_input'),
  237. trigger: 'blur',
  238. },
  239. ],
  240. },
  241. imagesList: [],
  242. }
  243. },
  244. watch: {
  245. form: {
  246. handler() {
  247. // console.log('form watch run')
  248. // if (this.status === 3) {
  249. this.transData()
  250. // }
  251. },
  252. deep: true,
  253. },
  254. // imagesList() {
  255. // this.formData.logo = this.imagesList.length ? this.imagesList[0].url : ''
  256. // this.$refs.form.validateField('logo')
  257. // },
  258. },
  259. methods: {
  260. transData() {
  261. this.loading = true
  262. const temp = JSON.parse(JSON.stringify(this.form))
  263. if (temp.logo && temp.logo.length) {
  264. // this.$set(this, 'imagesList', [
  265. // {
  266. // url: temp.logo,
  267. // },
  268. // ])
  269. this.imagesList = [
  270. {
  271. uid: '',
  272. url: 'https:' + temp.logo,
  273. },
  274. ]
  275. }
  276. if (temp.url) {
  277. const regexp = /\.promocatalogue\.com\.au/
  278. if (regexp.test(temp.url)) {
  279. this.domainType = 1
  280. if (!temp.pre) {
  281. temp.pre = temp.url.replace(regexp, '')
  282. }
  283. } else {
  284. this.domainType = 2
  285. if (!temp.other) {
  286. temp.other = temp.url.trim()
  287. }
  288. }
  289. } else {
  290. this.domainType = 1
  291. }
  292. if (!temp.theme_color) {
  293. temp.theme_color = '#fff'
  294. }
  295. if (!temp.font_color) {
  296. temp.font_color = '#222'
  297. }
  298. if (typeof temp.hide_prices !== 'number') {
  299. temp.hide_prices = 0
  300. }
  301. if (!temp.footer) {
  302. temp.footer = ''
  303. }
  304. if (!temp.alias_url) {
  305. temp.alias_url = ''
  306. }
  307. this.formData = temp
  308. this.loading = false
  309. },
  310. close() {
  311. this.formData = {}
  312. this.imagesList = []
  313. this.$refs.form.clearValidate()
  314. this.$emit('close', 1)
  315. },
  316. checkForm() {
  317. this.formData.url =
  318. this.domainType === 1
  319. ? this.formData.pre + '.promocatalogue.com.au'
  320. : this.formData.other.trim()
  321. this.$refs.form.validate((valid) => {
  322. if (!valid) {
  323. return
  324. }
  325. if (!this.imagesList.length) {
  326. this.$message.error('请上传logo')
  327. return
  328. }
  329. const f = cloneDeep(this.formData)
  330. this.loading = true
  331. f.logo = this.imagesList[0].url.replace(this.$mediaRegExp, '/')
  332. if (f.id) {
  333. common
  334. .editSite(f)
  335. .then((res) => {
  336. if (res.code === 1) {
  337. this.$emit('update')
  338. this.$message.success('保存成功')
  339. }
  340. })
  341. .finally(() => {
  342. this.loading = false
  343. })
  344. } else {
  345. common
  346. .addSite(f)
  347. .then((res) => {
  348. if (res.code === 1) {
  349. this.$emit('update')
  350. this.$message.success('保存成功')
  351. }
  352. })
  353. .finally(() => {
  354. this.loading = false
  355. })
  356. }
  357. })
  358. },
  359. },
  360. }
  361. </script>