edit.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. <template>
  2. <div v-loading="isLoading" class="page-form-container">
  3. <el-form ref="submitFormRef" :model="submitForm" :rules="formDataRules" label-width="120px" class="addForm">
  4. <el-form-item label="供应商类型:" prop="shopType">
  5. <el-select
  6. v-model="submitForm.shopType"
  7. placeholder="请选择供应商类型"
  8. style="width: 100%"
  9. :disabled="editType === 'edit'"
  10. @change="handleTypeChange"
  11. >
  12. <el-option label="品牌方" :value="1" />
  13. <el-option label="代理商" :value="2" />
  14. </el-select>
  15. </el-form-item>
  16. <!-- 供应商名称 -->
  17. <el-form-item v-if="submitForm.shopType === 2" label="供应商名称:" prop="shopName">
  18. <el-input
  19. v-model="submitForm.shopName"
  20. placeholder="请输入供应商名称"
  21. maxlength="50"
  22. show-word-limit
  23. :disabled="editType === 'edit'"
  24. />
  25. </el-form-item>
  26. <template v-if="submitForm.shopType === 1">
  27. <el-form-item clearable label="供应商名称:" prop="brandId">
  28. <el-select
  29. v-if="editType === 'add'"
  30. v-model="submitForm.brandId"
  31. placeholder="请选择品牌"
  32. style="width: 100%"
  33. filterable
  34. @change="handleBrandChange"
  35. >
  36. <el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id" />
  37. </el-select>
  38. <el-input
  39. v-else
  40. v-model="submitForm.shopName"
  41. placeholder="请输入供应商名称"
  42. maxlength="50"
  43. show-word-limit
  44. :disabled="editType === 'edit'"
  45. />
  46. </el-form-item>
  47. <!-- 制造商 -->
  48. <el-form-item label="制造商:">
  49. <el-input v-model="submitForm.manufacturer" placeholder="请输入制造商名称" maxlength="50" show-word-limit />
  50. </el-form-item>
  51. </template>
  52. <!-- 供应商名称END -->
  53. <el-form-item label="手机号:" prop="mobile">
  54. <el-input
  55. v-model="submitForm.mobile"
  56. placeholder="请输入手机号"
  57. maxlength="11"
  58. show-word-limit
  59. @input="handleMobileInput"
  60. />
  61. </el-form-item>
  62. <el-form-item label="联系人:" prop="linkMan">
  63. <el-input v-model="submitForm.linkMan" placeholder="请输入联系人" />
  64. </el-form-item>
  65. <!-- 代理商logo -->
  66. <transition name="fade">
  67. <el-form-item v-if="submitForm.shopType === 2" label="代理商logo:" prop="logo">
  68. <el-input v-show="false" v-model="submitForm.logo" />
  69. <upload-image
  70. :limit="1"
  71. tip="建议尺寸:200px * 200px"
  72. :image-list="logoList"
  73. @success="uploadLogoImageSuccess"
  74. @remove="handleLogoImageRemove"
  75. />
  76. </el-form-item>
  77. </transition>
  78. <transition name="fade">
  79. <el-form-item v-if="submitForm.shopType === 2" label="代理品牌:" prop="shopInfo" class="brand-list">
  80. <template v-if="supplierBrands !== []">
  81. <el-tag
  82. v-for="(brand, index) in supplierBrands"
  83. :key="index"
  84. closable
  85. type="success"
  86. @close="handleRemoveBrand(brand)"
  87. @click="handleEditBrand(brand)"
  88. >{{ brand.brandName }}</el-tag>
  89. </template>
  90. <el-tag type="primary" @click="handleAddBrand">添加品牌<span class="el-icon-plus" /></el-tag>
  91. <el-input v-show="false" v-model="submitForm.shopInfo" />
  92. </el-form-item>
  93. </transition>
  94. <template v-if="submitForm.shopType === 1">
  95. <el-form-item label="产地:" prop="countryId">
  96. <el-select v-model="submitForm.countryId" placeholder="产地" style="width: 100%" filterable>
  97. <el-option
  98. v-for="item in countryList"
  99. :key="item.countryId"
  100. :label="item.countryName"
  101. :value="item.countryId"
  102. />
  103. </el-select>
  104. </el-form-item>
  105. <el-form-item label="品牌logo:" class="no-input" prop="brandAuthLogo">
  106. <upload-image
  107. tip="建议尺寸:200px * 200px"
  108. :image-list="brandAuthLogoList"
  109. @success="uploadBrandAuthSuccess"
  110. @remove="handleRemoveBrandAuthLogo"
  111. />
  112. <el-input v-show="false" v-model="submitForm.brandAuthLogo" />
  113. </el-form-item>
  114. <el-form-item label="官网认证链接:">
  115. <el-input v-model="submitForm.securityLink" placeholder="请输入官网认证链接" />
  116. </el-form-item>
  117. </template>
  118. <!-- 公众号信息 -->
  119. <el-form-item label="微信公众号:">
  120. <el-select v-model="submitForm.wxAccountType" placeholder="请选择微信公众号类型" style="width: 100%">
  121. <el-option label="请选择" :value="0" />
  122. <el-option label="服务号" :value="2" />
  123. <el-option label="订阅号" :value="1" />
  124. </el-select>
  125. </el-form-item>
  126. <transition-group name="fade">
  127. <template v-if="submitForm.wxAccountType !== 0">
  128. <el-form-item key="appID" label="appID:">
  129. <el-input v-model="submitForm.appId" placeholder="微信公众号appID" />
  130. </el-form-item>
  131. <el-form-item v-if="submitForm.wxAccountType === 2" key="appSecret" label="appSecret:">
  132. <el-input v-model="submitForm.appSecret" placeholder="微信公众号appsecret" />
  133. </el-form-item>
  134. <el-form-item key="qrCodeImage" label="公众号二维码:" prop="qrCodeImage">
  135. <upload-image
  136. tip="建议尺寸:200px * 200px"
  137. :image-list="qrCodeImageList"
  138. @success="uploadQrCodeImageSuccess"
  139. @remove="handleRemoveQrCodeImage"
  140. />
  141. <el-input v-show="false" v-model="submitForm.qrCodeImage" />
  142. </el-form-item>
  143. </template>
  144. </transition-group>
  145. <!-- 公众号信息END -->
  146. <el-form-item label="供应商状态:">
  147. <el-select v-model="submitForm.shopStatus" placeholder="请选择供应商状态" style="width: 100%">
  148. <el-option label="启用" :value="1" />
  149. <el-option label="禁用" :value="0" />
  150. </el-select>
  151. </el-form-item>
  152. </el-form>
  153. <div class="control-box">
  154. <el-button type="primary" @click="submit">保存</el-button>
  155. <el-button type="warning" @click="navigateBack()">返回</el-button>
  156. </div>
  157. <!-- 供应商添加品牌的对话框 -->
  158. <el-dialog :title="editBrandText" :visible.sync="dialogAddBrand" width="width" @close="handleDialogAddBrandClosed">
  159. <el-form ref="subFormRef" :model="subForm" label-width="120px" :rules="formDataRules">
  160. <el-form-item label="选择品牌:" prop="brandId">
  161. <el-select
  162. v-model="subForm.brandId"
  163. placeholder="请选择品牌"
  164. style="width: 100%"
  165. filterable
  166. @change="handleBrandChange"
  167. >
  168. <el-option v-for="item in otherBrandList" :key="item.id" :label="item.name" :value="item.id" />
  169. </el-select>
  170. </el-form-item>
  171. <el-form-item label="产地:" prop="countryId">
  172. <el-select v-model="subForm.countryId" placeholder="产地" style="width: 100%" filterable>
  173. <el-option
  174. v-for="item in countryList"
  175. :key="item.countryId"
  176. :label="item.countryName"
  177. :value="item.countryId"
  178. />
  179. </el-select>
  180. </el-form-item>
  181. <el-form-item label="制造商:">
  182. <el-input v-model="subForm.manufacturer" placeholder="请输入制造商名称" maxlength="50" show-word-limit />
  183. </el-form-item>
  184. <el-form-item label="品牌logo:" class="no-input" prop="brandAuthLogo">
  185. <upload-image
  186. tip="建议尺寸:200px * 200px"
  187. :image-list="brandAuthLogoList"
  188. @success="uploadBrandAuthSuccess"
  189. @remove="handleRemoveBrandAuthLogo"
  190. />
  191. <el-input v-show="false" v-model="subForm.brandAuthLogo" />
  192. </el-form-item>
  193. <el-form-item label="代理声明:" prop="statementType">
  194. <el-radio-group v-model="subForm.statementType" @change="handleStatementChange">
  195. <el-radio :label="1">弹窗</el-radio>
  196. <el-radio :label="2">链接</el-radio>
  197. <el-radio :label="3">图片</el-radio>
  198. <el-radio :label="4">文件</el-radio>
  199. </el-radio-group>
  200. </el-form-item>
  201. <el-form-item v-if="subForm.statementType === 1" ref="statement" label="弹窗:" prop="statementContent">
  202. <el-input v-model="subForm.statementContent" type="textarea" />
  203. </el-form-item>
  204. <el-form-item v-else-if="subForm.statementType === 2" ref="statement" label="链接:" prop="statementLink">
  205. <el-input v-model="subForm.statementLink" />
  206. </el-form-item>
  207. <el-form-item
  208. v-else-if="subForm.statementType === 3"
  209. ref="statement"
  210. label="图片:"
  211. class="no-input"
  212. prop="statementImage"
  213. >
  214. <upload-image
  215. tip="建议尺寸:200px * 200px"
  216. :image-list="statementImageList"
  217. @success="uploadStatementImageSuccess"
  218. @remove="handleRemoveStatementImage"
  219. />
  220. <el-input v-show="false" v-model="subForm.statementImage" />
  221. </el-form-item>
  222. <el-form-item v-else ref="statement" label="文件:" prop="statementFileId">
  223. <upload-file
  224. ref="fileUpload"
  225. :auto-upload="false"
  226. :data="uploadParams"
  227. :file-list="statementFileList"
  228. :before-upload="beforeUploadStatementFile"
  229. @success="uploadStatementFileSuccess"
  230. @remove="removeStatementFile"
  231. @change="changeStatementFile"
  232. />
  233. <el-input v-show="false" v-model="subForm.statementFileId" />
  234. </el-form-item>
  235. <el-form-item label="官网认证链接:" prop="securityLink">
  236. <el-input v-model="subForm.securityLink" placeholder="请输入官网认证链接" />
  237. </el-form-item>
  238. </el-form>
  239. <div slot="footer">
  240. <el-button @click="addBrandSubmitCancel">取 消</el-button>
  241. <el-button type="primary" :loading="submitLoading" @click="handleSaveBrand">确 定</el-button>
  242. </div>
  243. </el-dialog>
  244. </div>
  245. </template>
  246. <script>
  247. import UploadFile from '@/components/UploadFile'
  248. import UploadImage from '@/components/UploadImage'
  249. import { mapGetters } from 'vuex'
  250. import { isMobile } from '@/utils/validate'
  251. import { fetchBrandList } from '@/api/brand'
  252. import { deepClone } from '@/utils'
  253. import { addSupplier, getSupplierById } from '@/api/supplier'
  254. import { Promise } from 'jszip/lib/external'
  255. let uuid = 0
  256. export default {
  257. components: { UploadImage, UploadFile },
  258. data() {
  259. const validMobile = (rule, value, callback) => {
  260. if (!isMobile(value)) {
  261. return callback(new Error('手机号格式不正确'))
  262. }
  263. return callback()
  264. }
  265. const validShopInfo = (rule, value, callback) => {
  266. console.log(value)
  267. if (value <= 0) {
  268. return callback(new Error('代理品牌不能为空'))
  269. }
  270. return callback()
  271. }
  272. return {
  273. id: '', // 供应商id
  274. editType: '',
  275. isLoading: false,
  276. submitLoading: false,
  277. dialogAddBrand: false,
  278. brandTagClickType: '', // 品牌表单点击类型
  279. selectedShopType: 1, // 当前选中的供应商类型
  280. currentBrand: {}, // 当前选中的品牌
  281. selectedBrandIds: [], // 代理商已添加的品牌id
  282. editBrandInfo: {},
  283. // 表单1
  284. submitForm: {
  285. shopType: 1, // 供应商类型
  286. shopName: '', // 供应商名称
  287. brandId: '', // 品牌id
  288. mobile: '', // 手机号
  289. linkMan: '', // 联系人
  290. countryId: 1, // 产地id
  291. brandAuthLogo: '', // 品牌logo
  292. securityLink: '', // 官网认证链接
  293. shopStatus: 1, // 供应商状态,
  294. shopInfo: '',
  295. wxAccountType: 0,
  296. appId: '',
  297. appSecret: '',
  298. qrCodeImage: '', // 微信公众号二维码
  299. logo: '', // 代理商logo
  300. manufacturer: '' // 制造商
  301. },
  302. // 表单2
  303. subForm: {
  304. brandId: '', // 品牌id
  305. countryId: 1, // 产地id
  306. brandAuthLogo: '', // 品牌logo
  307. securityLink: '', // 官网认证链接
  308. statementType: 1, // 代理声明类型
  309. statementContent: '', // 声明内容
  310. statementFileId: null, // 声明文件id
  311. statementImage: '', // 声明图片
  312. statementLink: '', // 声明链接
  313. manufacturer: '' // 制造商
  314. },
  315. supplierBrands: [],
  316. brandList: [],
  317. // 表单数据校验
  318. formDataRules: {
  319. shopType: { required: true, message: '供应商类型不能为空', tigger: 'change', type: 'number' },
  320. shopName: { required: true, message: '供应名称不能为空', tigger: 'change' },
  321. mobile: [
  322. { required: true, message: '手机号不能为空', tigger: 'change' },
  323. { validator: validMobile, tigger: 'change' }
  324. ],
  325. linkMan: { required: true, message: '联系人不能为空', tigger: 'blur' },
  326. countryId: { required: true, message: '产地不能为空', tigger: 'change', type: 'number' },
  327. brandAuthLogo: { required: true, message: '品牌logo不能为空', tigger: 'change' },
  328. shopInfo: [
  329. { required: true, message: '代理品牌不能为空', tigger: 'change', type: 'number' },
  330. { validator: validShopInfo, tigger: 'change' }
  331. ],
  332. brandId: { required: true, message: '品牌不能为空', tigger: 'change', type: 'number' },
  333. statementContent: { required: true, message: '声明内容不能为空', tigger: 'change' }, // 声明内容
  334. statementFileId: { required: true, message: '声明文件不能为空', tigger: 'change', type: 'number' }, // 声明文件id
  335. statementImage: { required: true, message: '声明图片不能为空', tigger: 'change' }, // 声明图片
  336. statementLink: { required: true, message: '声明链接不能为空', tigger: 'change' }, // 声明链接,
  337. logo: { required: true, message: '代理商logo不能为空', tigger: 'change' }
  338. },
  339. // 上传图片列表
  340. logoList: [],
  341. brandAuthLogoList: [],
  342. qrCodeImageList: [],
  343. // brandAuthLogoList:[],
  344. statementImageList: [],
  345. // 上传的文件列表
  346. statementFileList: [], // 文件
  347. statementFileName: '' // 声明文件名称 临时
  348. }
  349. },
  350. computed: {
  351. ...mapGetters(['countryList', 'authUserId']),
  352. // 去除重复的品牌后的列表
  353. otherBrandList() {
  354. if (this.brandTagClickType === 'add') {
  355. return this.brandList.filter((item) => this.selectedBrandIds.indexOf(item.id) === -1)
  356. }
  357. if (this.brandTagClickType === 'edit') {
  358. const exclude = this.selectedBrandIds.filter((id) => id !== this.editBrandInfo.brandId)
  359. return this.brandList.filter((item) => exclude.indexOf(item.id) === -1)
  360. }
  361. return this.brandList
  362. },
  363. // 文件上传参数
  364. uploadParams() {
  365. return {
  366. brandId: this.currentBrand.id,
  367. authUserId: this.id
  368. }
  369. },
  370. // 文案提示
  371. editTypeText() {
  372. return this.editType === 'edit' ? '修改' : '添加'
  373. },
  374. editBrandText() {
  375. return this.brandTagClickType === 'edit' ? '修改品牌' : '添加品牌'
  376. }
  377. },
  378. watch: {
  379. // 根据供应商类型变化获取品牌列表
  380. selectedShopType(nVal) {
  381. this.getBrandList(nVal)
  382. }
  383. },
  384. created() {
  385. this.editType = this.$route.query.type || 'add'
  386. this.id = parseInt(this.$route.query.id) || ''
  387. this.getBrandList(this.selectedShopType)
  388. this.fetchSupplierInfo()
  389. },
  390. methods: {
  391. /** 数据回显 */
  392. // 获取供应商信息
  393. fetchSupplierInfo() {
  394. if (!this.id) return
  395. getSupplierById({ authUserId: this.id }).then((res) => {
  396. this.initSupplierInfo(res.data)
  397. })
  398. },
  399. // 初始化供应商信息
  400. initSupplierInfo(info) {
  401. for (const key in this.submitForm) {
  402. if (Object.hasOwnProperty.call(info, key)) {
  403. this.submitForm[key] = info[key]
  404. }
  405. }
  406. this.selectedShopType = info.shopType
  407. if (this.selectedShopType === 1) {
  408. // 品牌方
  409. const shopInfo = info.shopInfo[0]
  410. this.submitForm.brandId = shopInfo.brandId
  411. this.submitForm.countryId = shopInfo.countryId
  412. this.submitForm.brandAuthLogo = shopInfo.brandAuthLogo
  413. this.submitForm.securityLink = shopInfo.securityLink
  414. this.submitForm.manufacturer = shopInfo.manufacturer
  415. this.submitForm.brandName = shopInfo.brandName
  416. if (shopInfo.brandAuthLogo) {
  417. this.brandAuthLogoList = [{ name: shopInfo.brandName, url: shopInfo.brandAuthLogo }]
  418. }
  419. } else {
  420. // 代理商
  421. this.supplierBrands = info.shopInfo.map((item) => {
  422. item.uuid = ++uuid
  423. this.selectedBrandIds.push(item.brandId)
  424. return item
  425. })
  426. // 代理商logo
  427. if (this.submitForm.logo) {
  428. this.logoList = [{ name: this.submitForm.brandName, url: this.submitForm.logo }]
  429. }
  430. this.submitForm.shopInfo = this.supplierBrands.length
  431. }
  432. // 微信公众号二维码
  433. if (this.submitForm.qrCodeImage) {
  434. this.qrCodeImageList = [{ name: '', url: this.submitForm.qrCodeImage }]
  435. }
  436. },
  437. /** 数据回显END */
  438. // 提交保存
  439. async submit() {
  440. try {
  441. await this.$refs.submitFormRef.validate()
  442. } catch (err) {
  443. return
  444. }
  445. this.isLoading = true
  446. let params = {}
  447. if (this.selectedShopType === 1) {
  448. params = this.getBrandParams()
  449. } else {
  450. params = this.getShopParams()
  451. }
  452. // 设置创建人
  453. params.createBy = this.authUserId
  454. params.authUserId = this.id
  455. console.log(params)
  456. addSupplier(params)
  457. .then((res) => {
  458. this.$message.success(`${this.editTypeText}供应商成功`)
  459. this.$store.dispatch('tagsView/delView', this.$route)
  460. this.$router.replace('/supplier/list')
  461. })
  462. .finally(() => {
  463. this.isLoading = false
  464. })
  465. },
  466. /** 封装请求参数 */
  467. // 代理商参数
  468. getShopParams() {
  469. const params = {
  470. shopType: 2, // 供应商类型
  471. shopName: '', // 供应商名称
  472. logo: '', // 代理商logo
  473. mobile: '', // 手机号
  474. linkMan: '', // 联系人
  475. securityLink: '', // 官网认证链接
  476. shopStatus: 1, // 供应商状态,
  477. wxAccountType: 2,
  478. appId: '',
  479. appSecret: '',
  480. qrCodeImage: '', // 微信公众号二维码
  481. manufacturer: '' // 制造商
  482. }
  483. for (const key in params) {
  484. if (Object.hasOwnProperty.call(this.submitForm, key)) {
  485. params[key] = this.submitForm[key]
  486. }
  487. }
  488. params.shopInfo = deepClone(this.supplierBrands).map((item) => {
  489. delete item.statementFileName
  490. delete item.uuid
  491. return item
  492. })
  493. return params
  494. },
  495. // 品牌方参数
  496. getBrandParams() {
  497. const params = {
  498. shopType: 1, // 供应商类型
  499. mobile: '', // 手机号
  500. linkMan: '', // 联系人
  501. wxAccountType: 2,
  502. appId: '',
  503. appSecret: '',
  504. qrCodeImage: '', // 微信公众号二维码
  505. shopStatus: 1 // 供应商状态,
  506. }
  507. for (const key in params) {
  508. if (Object.hasOwnProperty.call(this.submitForm, key)) {
  509. params[key] = this.submitForm[key]
  510. }
  511. }
  512. params.shopName = this.currentBrand.name
  513. params.shopInfo = [
  514. {
  515. brandId: this.submitForm.brandId,
  516. countryId: this.submitForm.countryId,
  517. brandAuthLogo: this.submitForm.brandAuthLogo,
  518. securityLink: this.submitForm.securityLink,
  519. manufacturer: this.submitForm.manufacturer, // 制造商
  520. statementType: 1,
  521. statementContent: '',
  522. statementFileId: null,
  523. statementImage: '',
  524. statementLink: ''
  525. }
  526. ]
  527. return params
  528. },
  529. // 大理上添加
  530. /** 封装请求参数 end */
  531. // 品牌改变事件
  532. handleBrandChange(id) {
  533. console.log(id)
  534. this.currentBrand = this.brandList.find((item) => item.id === id)
  535. this.brandAuthLogoList = [{ name: this.currentBrand.name, url: this.currentBrand.authLogo }]
  536. this.submitForm.brandAuthLogo = this.currentBrand.authLogo
  537. this.subForm.brandAuthLogo = this.currentBrand.authLogo
  538. },
  539. /** 品牌标签操作 */
  540. // 添加品牌对话框
  541. handleAddBrand() {
  542. this.brandTagClickType = 'add'
  543. // 文件上传参数
  544. this.dialogAddBrand = true
  545. },
  546. // 修改品牌
  547. handleEditBrand(row) {
  548. this.brandTagClickType = 'edit'
  549. // 等待dialog表单渲染完成后再设置值
  550. this.$nextTick(() => {
  551. this.editBrandInfo = row
  552. // 设置选中品牌信息
  553. this.currentBrand.id = row.brandId
  554. this.currentBrand.name = row.brandName
  555. this.currentBrand.authLogo = row.brandAuthLogo
  556. this.statementFileName = row.statementFileName
  557. if (row.brandAuthLogo) {
  558. this.brandAuthLogoList = [{ name: row.brandName, url: row.brandAuthLogo }]
  559. }
  560. if (row.statementImage) {
  561. this.statementImageList = [{ name: row.brandName, url: row.statementImage }]
  562. }
  563. if (row.statementFileId) {
  564. this.statementFileList = [{ name: row.statementFileName }]
  565. }
  566. for (const key in this.subForm) {
  567. if (Object.hasOwnProperty.call(this.editBrandInfo, key)) {
  568. this.subForm[key] = this.editBrandInfo[key]
  569. }
  570. }
  571. console.log(this.subForm)
  572. })
  573. this.dialogAddBrand = true
  574. },
  575. // 移除品牌
  576. handleRemoveBrand(row) {
  577. // 从已选品牌id列表中移除
  578. this.selectedBrandIds.splice(this.selectedBrandIds.indexOf(row.brandId), 1)
  579. // 从已添加品牌列表中移除
  580. const findIndex = this.supplierBrands.findIndex((item) => item.uuid === row.uuid)
  581. this.supplierBrands.splice(findIndex, 1)
  582. this.submitForm.shopInfo = this.supplierBrands.length
  583. },
  584. // 保存品牌
  585. async handleSaveBrand() {
  586. if (this.subForm.statementType === 4) {
  587. console.log('有文件上传')
  588. if (!this.subForm.statementFileId || this.subForm.statementFileId === -1) {
  589. this.submitLoading = true
  590. this.$refs.fileUpload.$refs.fileUpload.submit()
  591. return
  592. }
  593. }
  594. try {
  595. await this.$refs.subFormRef.validate()
  596. this.handleSaveBrandAction()
  597. } catch (error) {
  598. console.log(error)
  599. }
  600. },
  601. // 取消保存品牌
  602. addBrandSubmitCancel() {
  603. // 取消上传文件
  604. if (this.$refs.fileUpload) {
  605. this.$refs.fileUpload.$refs.fileUpload.abort()
  606. this.$message.info('文件上传已取消')
  607. }
  608. this.dialogAddBrand = false
  609. },
  610. // 保存品牌操作
  611. handleSaveBrandAction() {
  612. // 深度克隆数据
  613. const brandInfo = deepClone(this.subForm)
  614. // 保存已添加品牌id
  615. this.selectedBrandIds.push(this.currentBrand.id)
  616. // 设置品牌名称(显示使用)
  617. brandInfo.brandName = this.currentBrand.name
  618. brandInfo.brandAuthLogo = this.currentBrand.authLogo
  619. brandInfo.statementFileName = this.statementFileName
  620. if (this.brandTagClickType === 'add') {
  621. // 设置唯一id
  622. brandInfo.uuid = ++uuid
  623. // 保存数据到代理商品牌列表
  624. this.supplierBrands.push(brandInfo)
  625. }
  626. if (this.brandTagClickType === 'edit') {
  627. // 使用新数据替换旧数据
  628. const findIndex = this.supplierBrands.findIndex((item) => item.uuid === this.editBrandInfo.uuid)
  629. this.supplierBrands.splice(findIndex, 1, brandInfo)
  630. }
  631. this.dialogAddBrand = false
  632. },
  633. // 添加品牌对话框关闭
  634. handleDialogAddBrandClosed() {
  635. this.subForm.securityLink = ''
  636. this.subForm.manufacturer = ''
  637. this.subForm.statementType = 1
  638. this.statementFileName = ''
  639. this.statementImageList = []
  640. this.statementFileList = []
  641. this.brandAuthLogoList = []
  642. this.currentBrand = {}
  643. this.submitForm.shopInfo = this.supplierBrands.length
  644. // 按钮loading结束
  645. this.submitLoading = false
  646. // 初始化表单
  647. this.$refs.subFormRef.resetFields()
  648. console.log(this.subForm)
  649. },
  650. // 声明类型切换
  651. handleStatementChange() {
  652. this.$refs.statement.clearValidate()
  653. },
  654. // 供应商类型改变事件
  655. handleTypeChange(type) {
  656. this.selectedShopType = type
  657. this.brandAuthLogoList = []
  658. this.statementImageList = []
  659. this.currentBrand = {}
  660. },
  661. // 获取品牌列表
  662. getBrandList(type) {
  663. fetchBrandList({ type }).then((res) => {
  664. if (res.code !== 0) {
  665. return
  666. }
  667. this.brandList = res.data
  668. })
  669. },
  670. /** 品牌标签操作END */
  671. // 输入框输入时
  672. handleMobileInput() {
  673. this.submitForm.mobile = this.submitForm.mobile.replace(/[^\w\.\/]/gi, '')
  674. },
  675. /** 图片上传 */
  676. // 代理商logo
  677. uploadLogoImageSuccess({ response, file, fileList }) {
  678. this.logoList = fileList
  679. this.submitForm.logo = response.data
  680. },
  681. handleLogoImageRemove({ file, fileList }) {
  682. this.logoList = fileList
  683. this.submitForm.logo = ''
  684. },
  685. // 品牌logo
  686. uploadBrandAuthSuccess({ response, file, fileList }) {
  687. this.brandAuthLogoList = fileList
  688. this.submitForm.brandAuthLogo = response.data
  689. this.subForm.brandAuthLogo = response.data
  690. },
  691. handleRemoveBrandAuthLogo({ file, fileList }) {
  692. this.brandAuthLogoList = fileList
  693. this.submitForm.brandAuthLogo = ''
  694. this.subForm.brandAuthLogo = ''
  695. },
  696. // 公众号二维码
  697. uploadQrCodeImageSuccess({ response, file, fileList }) {
  698. this.qrCodeImageList = fileList
  699. this.submitForm.qrCodeImage = response.data
  700. },
  701. handleRemoveQrCodeImage({ file, fileList }) {
  702. this.qrCodeImageList = fileList
  703. this.submitForm.qrCodeImage = ''
  704. },
  705. // 声明图片
  706. uploadStatementImageSuccess({ response, file, fileList }) {
  707. this.statementImageList = fileList
  708. this.subForm.statementImage = response.data
  709. },
  710. handleRemoveStatementImage({ file, fileList }) {
  711. this.statementImageList = fileList
  712. this.subForm.statementImage = ''
  713. },
  714. /** 文件上传 */
  715. uploadStatementFileSuccess({ response, file, fileList }) {
  716. this.statementFileList = fileList
  717. this.subForm.statementFileId = response.data.fileId
  718. this.statementFileName = response.data.fileName
  719. // 验证表单数据并保存
  720. this.$refs.subFormRef.validate((valide) => {
  721. if (!valide) return
  722. this.handleSaveBrandAction()
  723. })
  724. },
  725. removeStatementFile({ file, fileList }) {
  726. this.statementFileList = []
  727. this.subForm.statementFileId = null
  728. },
  729. changeStatementFile({ file, fileList }) {
  730. this.statementFileList = fileList
  731. this.subForm.statementFileId = -1
  732. },
  733. beforeUploadStatementFile(file) {
  734. const maxSize = 30
  735. if (file.size <= maxSize * 1024 * 1024) return true
  736. return this.$confirm(`您上传的文件大于${maxSize}MB,是否继续上传?文件上传过程中请您耐心等待!`, '文件上传提示', {
  737. confirmButtonText: '继续',
  738. cancelButtonText: '取消',
  739. type: 'warning'
  740. })
  741. .then(() => {
  742. return Promise.resolve()
  743. })
  744. .catch(() => {
  745. this.$message.info('已取消上传')
  746. this.submitLoading = false
  747. return Promise.reject()
  748. })
  749. }
  750. }
  751. }
  752. </script>
  753. <style lang="scss" scoped>
  754. .addForm {
  755. .brand-list {
  756. .el-tag {
  757. margin-right: 5px;
  758. cursor: pointer;
  759. }
  760. }
  761. }
  762. </style>