edit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <div class="app-container">
  3. <div v-if="editType === 'add'" class="filter-container">
  4. <div class="filter-control">
  5. <span style="color: red;">在本页面,对每三个月给超级会员自动发放的优惠券进行配置,配置完成后下一阶段才生效(最少配置1个,最多5个)。</span>
  6. <el-button type="primary" icon="el-icon-plus" size="mini" :disabled="disabled" @click="handleAddList">新增优惠券</el-button>
  7. </div>
  8. </div>
  9. <div v-else class="filter-container">
  10. <div class="filter-control">
  11. <span>优惠月份:</span>
  12. <el-input
  13. v-model="formParams.month"
  14. placeholder="开始月份"
  15. clearable
  16. suffix-icon="el-icon-date"
  17. :disabled="true"
  18. style="width:100px;"
  19. />
  20. -
  21. <el-input
  22. v-model="formParams.endMonth"
  23. placeholder="结束月份"
  24. clearable
  25. suffix-icon="el-icon-date"
  26. :disabled="true"
  27. style="width:100px;"
  28. />
  29. <el-button type="primary" icon="el-icon-plus" size="mini" :disabled="disabled" style="margin-left: 30px;" @click="handleAddList">新增优惠券</el-button>
  30. </div>
  31. </div>
  32. <el-form ref="couponFrom" :model="form" label-width="100px">
  33. <div v-for="(formItem,index) in form.formList" :key="formItem.key" class="form-cell" :data-key="formItem.key">
  34. <el-form-item :label="`优惠券${index+1}:`" style="margin-bottom: 10px;" :rules="rules.couponType">
  35. <el-radio-group v-model="formItem.couponType">
  36. <el-radio :label="0">活动券</el-radio>
  37. <el-radio :label="1">品类券</el-radio>
  38. <el-radio :label="3">店铺券</el-radio>
  39. </el-radio-group>
  40. </el-form-item>
  41. <template v-if="formItem.couponType === 3">
  42. <el-form-item label="供应商" :prop="`formList.${index}.shopData`" :rules="rules.shopData">
  43. <template v-if="formItem.shopData && formItem.shopData.length === 0">
  44. <el-button type="primary" autofocussize="mini" size="mini" icon="el-icon-plus" @click="handleShopDialogVisible(index)">选择供应商</el-button>
  45. <el-checkbox-group v-show="false" v-model="formItem.shopData" />
  46. </template>
  47. <template v-else>
  48. <el-table :data="formItem.shopData" border width="1000">
  49. <el-table-column prop="name" label="供应商名称" align="center" width="300" />
  50. <el-table-column prop="sname" label="供应商简称" align="center" width="200" />
  51. <el-table-column prop="linkMan" label="联系人" align="center" width="100" />
  52. <el-table-column prop="contractMobile" label="手机号" align="center" width="150">
  53. <template slot-scope="{ row }">
  54. {{ row.contractMobile ? row.contractMobile : '---' }}
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="操作" align="center">
  58. <el-button type="text" @click="deleteShop(formItem,index)">删除</el-button>
  59. </el-table-column>
  60. </el-table>
  61. </template>
  62. </el-form-item>
  63. </template>
  64. <el-form-item label="优惠券金额:" :prop="`formList.${index}.couponAmount`" :rules="rules.couponAmount">
  65. <el-input v-model="formItem.couponAmount" style="width: 150px" size="mini" />
  66. </el-form-item>
  67. <el-form-item label="优惠条件:" :prop="`formList.${index}.touchPrice`" :rules="rules.touchPrice">
  68. <el-input v-model="formItem.touchPrice" style="width: 220px" size="mini">
  69. <template slot="prepend" style="padding: 0 10px;">订单商品总额满:</template>
  70. </el-input>
  71. </el-form-item>
  72. <el-form-item label="优惠商品:" :hidden="formItem.couponType === 0 ? false : true" style="margin-bottom: 10px;" :rules="rules.productType">
  73. <el-radio-group v-model="formItem.productType">
  74. <el-radio :label="'1'">全商城商品</el-radio>
  75. <el-radio :label="'2'">指定商品</el-radio>
  76. </el-radio-group>
  77. </el-form-item>
  78. <template v-if="formItem.productType === '2'&& formItem.couponType === 0">
  79. <el-form-item label="商品信息" :prop="`formList.${index}.associateList`" :rules="rules.associateList">
  80. <el-button type="primary" icon="el-icon-sort" size="mini" :disabled="disabled3(formItem.associateList)" @click="handleOnInputBlur(formItem,index)">一键排序</el-button>
  81. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleGoodDialogVisible(index)">添加商品</el-button>
  82. <el-checkbox-group v-show="false" v-model="formItem.associateList" />
  83. <el-table v-show="formItem.associateList && formItem.associateList.length>0" :data="formItem.associateList" border>
  84. <el-table-column property="mainImage" label="商品图片" align="center" width="80">
  85. <template slot-scope="{ row }">
  86. <el-popover
  87. placement="top-start"
  88. title=""
  89. width="180"
  90. trigger="hover"
  91. >
  92. <img :src="row.mainImage" alt="" style="width:150px;height:150px;">
  93. <img slot="reference" :src="row.mainImage" alt="" style="width:30px;height:30px;">
  94. </el-popover>
  95. </template>
  96. </el-table-column>
  97. <el-table-column property="name" label="商品名称" align="center" />
  98. <el-table-column property="shopName" label="供应商" align="center" />
  99. <el-table-column label="网站状态" align="center" width="80">
  100. <template slot-scope="scope">
  101. <el-switch
  102. v-model="scope.row.pcStatus"
  103. active-color="#1890ff"
  104. inactive-color="#DCDFE6"
  105. active-value="1"
  106. inactive-value="0"
  107. />
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="小程序状态" align="center" width="100">
  111. <template slot-scope="scope">
  112. <el-switch
  113. v-model="scope.row.appletsStatus"
  114. active-color="#1890ff"
  115. inactive-color="#DCDFE6"
  116. active-value="1"
  117. inactive-value="0"
  118. />
  119. </template>
  120. </el-table-column>
  121. <el-table-column label="排序" align="center" width="100">
  122. <template slot-scope="{row}">
  123. <el-input v-model="row.sort" maxlength="4" minlength="1" />
  124. </template>
  125. </el-table-column>
  126. <el-table-column label="操作" align="center">
  127. <template slot-scope="scope">
  128. <el-button type="text" @click="handleDeletePros(formItem,scope.$index)">删除</el-button>
  129. </template>
  130. </el-table-column>
  131. </el-table>
  132. </el-form-item>
  133. </template>
  134. <el-form-item label="优惠品类:" :hidden="formItem.couponType ===1 ? false : true" :rules="rules.categoryType">
  135. <el-radio-group v-model="formItem.categoryType">
  136. <el-radio :label="'1'">产品</el-radio>
  137. <el-radio :label="'2'">仪器</el-radio>
  138. </el-radio-group>
  139. </el-form-item>
  140. <el-button class="delete_label" :disabled="disabled1" icon="el-icon-delete" size="mini" type="danger" @click="handleDelete(formItem,index)">删除</el-button>
  141. </div>
  142. </el-form>
  143. <div class="el-dialog__footer">
  144. <el-button type="primary" @click="onSubmit('couponFrom')">保存</el-button>
  145. </div>
  146. <!-- 供应商弹框 -->
  147. <shop-dialog v-if="dialogShopVisible" ref="shopDialog" @cancel="handleShopCancel" @confirm="handleShopConfirm" />
  148. <!-- 商品弹框 -->
  149. <good-dialog v-if="dialogGoodVisible" ref="goodDialog" @cancel="handleGoodCancel" @confirm="handleGoodConfirm" />
  150. </div>
  151. </template>
  152. <script>
  153. import { svipCoupon, saveVipCoupon, delCoupon } from '@/api/member/member'
  154. import goodDialog from './components/good-dialog'
  155. import shopDialog from './components/shop-dialog'
  156. const defaultForm = () => {
  157. return {
  158. shopId: 0,
  159. shopData: [],
  160. couponType: 0,
  161. couponAmount: '',
  162. touchPrice: '',
  163. productType: '1',
  164. categoryType: '1',
  165. associateList: []// 指定商品信息
  166. }
  167. }
  168. export default {
  169. name: 'MemberEdit',
  170. components: { goodDialog, shopDialog },
  171. data() {
  172. return {
  173. defaultShop: {
  174. shopId: 0,
  175. shopData: []
  176. },
  177. form: {
  178. formList: []
  179. },
  180. formParams: {
  181. id: '',
  182. month: '',
  183. endMonth: '',
  184. status: '',
  185. configure: 1, // 专属优惠券配置 1是、0否
  186. coupons: []
  187. },
  188. doctorId: '',
  189. editType: 'add',
  190. time: '',
  191. dialogTableVisible: false,
  192. shopTotal: 0,
  193. rows: [],
  194. // 供应商列表
  195. shopTableData: [],
  196. // 商品列表
  197. dialogProductVisible: false,
  198. productTableData: [],
  199. productTotal: 0,
  200. addIndex: 0,
  201. dialogShopVisible: false,
  202. dialogGoodVisible: false,
  203. rules: {
  204. couponType: [{ required: true, message: '请选择优惠券类型', trigger: 'blur' }],
  205. shopId: [{ required: true, message: '请选择供应商', trigger: 'blur' }],
  206. productType: [{ required: true, message: '请选择优惠商品', trigger: 'blur' }],
  207. shopData: [{ required: true, type: 'array', message: '请添加一个供应商', trigger: ['change'] }],
  208. associateList: [{ required: true, type: 'array', message: '请至少添加一个商品', trigger: ['change'] }],
  209. categoryType: [{ required: true, message: '请选择优惠品类', trigger: 'blur' }],
  210. couponAmount: [{ required: true, message: '优惠券金额不能为空', trigger: 'blur' }],
  211. touchPrice: [{ required: true, message: '优惠条件不能为空', trigger: 'blur' }]
  212. },
  213. delFlag: false
  214. }
  215. },
  216. computed: {
  217. disabled() {
  218. return this.form.formList.length === 5
  219. },
  220. disabled1() {
  221. return this.form.formList.length === 1
  222. }
  223. },
  224. created() {
  225. this.editType = this.$route.query.type || 'edit'
  226. console.log('editType', this.editType)
  227. this.initForm(this.editType)
  228. },
  229. methods: {
  230. initForm(type) {
  231. if (type === 'add') {
  232. console.log('add')
  233. this.svipCoupon(type, 1, 0)
  234. } else {
  235. console.log('edit')
  236. this.svipCoupon(type, 0, this.$route.query.id)
  237. }
  238. },
  239. async svipCoupon(type, configure, id) {
  240. const res = await svipCoupon({ id: id, configure: configure })
  241. const data = res.data.svipcouponForm
  242. this.formParams = { ...this.formParams, ...data }
  243. if (data.coupons.length > 0) {
  244. this.delFlag = true
  245. this.form.formList = data.coupons.map((el) => {
  246. el = { ...el, ...this.defaultShop }
  247. if (el.shop) {
  248. el.shopData.push(el.shop)
  249. }
  250. return el
  251. })
  252. console.log('formList', this.form.formList)
  253. } else {
  254. for (let i = 0; i <= 2; i++) {
  255. this.form.formList.push(defaultForm())
  256. }
  257. }
  258. },
  259. handleShopDialogVisible(index) {
  260. // 显示选择供应商弹窗
  261. this.addIndex = index
  262. this.dialogShopVisible = true
  263. },
  264. handleGoodDialogVisible(index) {
  265. // 显示选择商品弹窗
  266. this.addIndex = index
  267. this.dialogGoodVisible = true
  268. },
  269. deleteShop(formItem, index) {
  270. // 清除供应商
  271. formItem.shopId = ''
  272. formItem.shopData = []
  273. this.$nextTick(() => {
  274. console.log('index', formItem)
  275. this.form.formList[index].shopId
  276. this.form.formList[index].shopData
  277. })
  278. },
  279. handleShopConfirm(data) {
  280. // 确认选择供应商
  281. this.form.formList[this.addIndex].shopId = data.shopId
  282. this.form.formList[this.addIndex].shopData.push(data)
  283. console.log('formList', this.form.formList[this.addIndex])
  284. this.handleShopCancel()
  285. },
  286. handleGoodConfirm(data) {
  287. // 确认选择商品
  288. console.log('data', data)
  289. console.log('addIndex', this.addIndex)
  290. const from = this.form.formList[this.addIndex]
  291. from.associateList.push(data)
  292. console.log('from', this.form.formList)
  293. this.handleGoodCancel()
  294. },
  295. handleDeletePros(formItem, index) {
  296. // 删除商品
  297. this.$confirm('确定删除吗?', '提示', {
  298. confirmButtonText: '确定',
  299. cancelButtonText: '取消',
  300. type: 'warning'
  301. }).then(() => {
  302. formItem.associateList.splice(index, 1)
  303. })
  304. },
  305. onSubmit(formName) {
  306. this.$refs[formName].validate(valid => {
  307. if (valid) {
  308. this.handleFormParams()
  309. this.$confirm('是否提交数据', '提示', {
  310. confirmButtonText: '确定',
  311. cancelButtonText: '取消',
  312. type: 'warning'
  313. }).then(() => {
  314. console.log('formParams', this.formParams)
  315. if (this.editType === 'add') {
  316. this.formParams.configure = 1
  317. } else {
  318. this.formParams.configure = 0
  319. }
  320. this.saveVipCoupon(this.formParams)
  321. })
  322. } else {
  323. return false
  324. }
  325. })
  326. },
  327. handleFormParams() {
  328. // 处理参数
  329. this.formParams.coupons = this.form.formList.map((el) => {
  330. if (el.associateList && el.associateList.length > 0) {
  331. el.associateList = el.associateList.map((pro) => {
  332. return {
  333. sort: pro.sort,
  334. pcStatus: pro.pcStatus,
  335. appletsStatus: pro.appletsStatus,
  336. name: pro.name,
  337. shopName: pro.shopName,
  338. mainImage: pro.mainImage,
  339. productId: pro.productId
  340. }
  341. })
  342. }
  343. return el
  344. })
  345. },
  346. async saveVipCoupon(params) {
  347. // 保存超级会员优惠券
  348. await saveVipCoupon(params)
  349. this.$message.success('保存成功')
  350. setTimeout(() => {
  351. this.$router.push({ path: '/member/coupon/list' })
  352. }, 1000)
  353. },
  354. handleShopCancel() {
  355. // 取消选择供应商
  356. this.dialogShopVisible = false
  357. this.$refs.shopDialog.visible = false
  358. },
  359. handleGoodCancel() {
  360. // 取消编辑商品
  361. this.dialogGoodVisible = false
  362. this.$refs.goodDialog.visible = false
  363. },
  364. handleAddList() {
  365. // 新增优惠券
  366. this.form.formList.push(defaultForm())
  367. },
  368. handleDelete(item, index) {
  369. // 删除单挑优惠券
  370. if (this.delFlag) {
  371. this.delCoupon(item.id, index)
  372. } else {
  373. this.form.formList.splice(index, 1)
  374. }
  375. },
  376. async delCoupon(id, index) {
  377. // 保存超级会员优惠券
  378. await delCoupon(id)
  379. this.form.formList.splice(index, 1)
  380. },
  381. handleOnInputBlur(formItem) {
  382. // 商品排序
  383. formItem.associateList.sort(this.sortByEnent('sort'))
  384. },
  385. sortByEnent(i) {
  386. // 排序
  387. return function(a, b) {
  388. return a[i] - b[i] // a[i] - b[i]为正序,倒叙为 b[i] - a[i]
  389. }
  390. },
  391. handlePcStatusChange(row) {
  392. // PC状态开启关闭
  393. console.log('row', row)
  394. if (row.pcStatus === '0') {
  395. row.pcStatus = '1'
  396. } else {
  397. row.pcStatus = '0'
  398. }
  399. },
  400. handleAppStatusChange(row) {
  401. // 小程序状态开启关闭
  402. if (row.appletsStatus === '0') {
  403. row.appletsStatus = '1'
  404. } else {
  405. row.appletsStatus = '0'
  406. }
  407. },
  408. disabled3(array) {
  409. if (array && array.length >= 2) {
  410. return false
  411. } else {
  412. return true
  413. }
  414. }
  415. }
  416. }
  417. </script>
  418. <style>
  419. .form-cell{
  420. border: 1px solid #e1e1e1;
  421. border-radius: 8px;
  422. box-sizing: border-box;
  423. box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.07);
  424. padding: 20px;
  425. position: relative;
  426. margin-bottom: 20px;
  427. }
  428. .delete_label{
  429. position: absolute;
  430. right: 2%;
  431. top: 20px;
  432. }
  433. </style>