person-add.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <?php
  2. /**
  3. * @link:http://www.goodmall.com/
  4. * @copyright: Copyright (c) 2020
  5. * Created by PhpStorm
  6. * Author: ganxiaohao
  7. * Date: 2020-05-08
  8. * Time: 17:50
  9. */
  10. use common\helpers\ComponentHelper;
  11. ComponentHelper::loadComponentView('com-select-cat');
  12. ComponentHelper::loadComponentView('com-dialog-select');
  13. ?>
  14. <script src="/resources/js/Sortable.min.js"></script>
  15. <script src="/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
  16. <div id="app" v-cloak>
  17. <el-card class="box-card" shadow="never" style="border:0;min-width: 1200px;"
  18. body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  19. <div slot="header">
  20. <el-breadcrumb separator="/">
  21. <el-breadcrumb-item>
  22. <span style="color: #409EFF;cursor: pointer"
  23. @click="$navigate({r:'pk/personal/index'})"><!--mall/stock/level -->
  24. 个人PK
  25. </span>
  26. </el-breadcrumb-item>
  27. <el-breadcrumb-item>{{titleName}}</el-breadcrumb-item>
  28. </el-breadcrumb>
  29. </div>
  30. <div class="form-body" v-loading="loading">
  31. <div style="display: flex;align-items: center;padding-bottom: 10px;border-bottom: 1px solid #E4E7ED;width: 300px;margin:10px 0 20px 0;">
  32. <div style="width: 5px;height: 20px;background-color: #03C5FF;margin-right: 5px;"></div>
  33. <div>基本信息</div>
  34. </div>
  35. <el-form :model="submitData" :rules="rules" ref="ruleForm" size="small" label-width="150px" style="margin-left: 20px;"><!-- :model="ruleForm" :rules="rules" v-loading="btnLoading" ref="ruleForm"-->
  36. <el-form-item label="PK名称:" style="margin-bottom: 20px" prop="name" label-width="75px">
  37. <el-input placeholder="请输入内容" style="width: 450px;" v-model="submitData.name" :maxlength="10"></el-input>
  38. </el-form-item>
  39. <el-form-item label="PK类型:" style="margin-bottom: 20px" required label-width="auto">
  40. <el-radio v-model="submitData.performance_type" :disabled = "isDataSelect" :label="1">拉新PK</el-radio>
  41. <el-radio v-model="submitData.performance_type" :disabled = "isDataSelect" :label="2">业绩PK</el-radio>
  42. </el-form-item>
  43. <el-form-item v-if="submitData.performance_type == 2" label="结算方式:" style="margin-bottom: 20px" required label-width="auto">
  44. <el-radio v-model="submitData.settlement_type" :disabled = "isDataSelect" :label="1">支付后</el-radio>
  45. <el-radio v-model="submitData.settlement_type" :disabled = "isDataSelect" :label="2">订单完成</el-radio>
  46. </el-form-item>
  47. <el-form-item label="人员数量:" style="margin-bottom: 20px" label-width="85px" prop="people_max_amount">
  48. <el-input placeholder="请输入人员数量" style="width: 250px;margin-right: 20px;" type="number" v-model="submitData.people_max_amount" :disabled="people_max_amount_flag" @input="changeInput2"></el-input>
  49. <el-checkbox v-model="people_max_amount_flag" >不限制</el-checkbox>
  50. </el-form-item>
  51. <el-form-item label="报名费用(元):" style="margin-bottom: 20px" label-width="108px" prop="price">
  52. <el-input placeholder="请输入费用" style="width: 250px;margin-right: 20px;" type="number" v-model="submitData.price" @input="changeInput3"></el-input>
  53. </el-form-item>
  54. <el-form-item label="活动时间段:" style="margin-bottom: 20px" label-width="98px" prop="time">
  55. <el-date-picker
  56. :disabled = "isDataSelect"
  57. v-model="submitData.time"
  58. @change="datetimeChange"
  59. type="datetimerange"
  60. :picker-options="pickerOptions"
  61. range-separator="至"
  62. start-placeholder="开始日期"
  63. end-placeholder="结束日期"
  64. value-format="yyyy-MM-dd HH:mm:ss"
  65. align="center">
  66. </el-date-picker>
  67. </el-form-item>
  68. <el-form-item label="是否开启:" style="margin-bottom: 20px" required label-width="auto">
  69. <el-switch
  70. v-model="submitData.is_enable"
  71. :active-value="1"
  72. :inactive-value="0"
  73. active-text="开"
  74. inactive-text="关"
  75. >
  76. </el-switch>
  77. </el-form-item>
  78. </el-form>
  79. <div style="display: flex;align-items: center;padding-bottom: 10px;border-bottom: 1px solid #E4E7ED;width: 300px;margin:10px 0 20px 0;">
  80. <div style="width: 5px;height: 20px;background-color: #03C5FF;margin-right: 5px;"></div>
  81. <div>奖品设置</div>
  82. </div>
  83. <el-button type="primary" size="small" style="margin-left: 20px;" @click="addPrize">+奖品</el-button>
  84. <el-form v-for="(item,index) in submitData.prize" :key="index" size="small" label-width="80px" style="margin-left: 20px;border-bottom: 1px solid #E4E7ED;position: relative;margin-top: 30px;">
  85. <el-form-item label="奖品等级" style="margin-bottom: 20px" required>
  86. <el-input
  87. placeholder="请输入奖品等级"
  88. style="width: 450px;"
  89. v-model="item.prize_level"
  90. type="textarea"
  91. maxlength="10"
  92. show-word-limit
  93. :rows="2"
  94. >
  95. </el-input>
  96. </el-form-item>
  97. <el-form-item label="奖品名称" style="margin-bottom: 20px" required>
  98. <el-input
  99. placeholder="请输入奖品名称"
  100. style="width: 450px;"
  101. v-model="item.prize_name"
  102. type="textarea"
  103. maxlength="20"
  104. show-word-limit
  105. :rows="2"
  106. ></el-input>
  107. </el-form-item>
  108. <el-form-item label="奖品价值" style="margin-bottom: 20px" required>
  109. <el-input placeholder="请输入奖品价值(元)" style="width: 450px;" v-model="item.prize_price" type="prize_price" @input="((val)=>{changeInput5(val, index)})"></el-input>
  110. </el-form-item>
  111. <el-form-item label="奖品数量" style="margin-bottom: 20px" required>
  112. <el-input placeholder="请输入奖品数量" style="width: 450px;" v-model="item.prize_amount" type="number" @input="((val)=>{changeInput4(val, index)})"></el-input>
  113. </el-form-item>
  114. <el-form-item label="奖励人数" style="margin-bottom: 20px" required>
  115. <el-input placeholder="请输入奖励人数" style="width: 450px;" v-model="item.winner_amount" type="number" @input="((val)=>{changeInput5(val, index)})"></el-input>
  116. </el-form-item>
  117. <el-form-item label="额外加赠" style="margin-bottom: 20px" required>
  118. <el-switch
  119. v-model="item.extra_add"
  120. :active-value="1"
  121. :inactive-value="0"
  122. active-text="是"
  123. inactive-text="否"
  124. >
  125. </el-switch>
  126. </el-form-item>
  127. <div style="position: absolute;top: 0;left: 540px;">
  128. <el-tooltip effect="dark" content="删除该奖品" placement="top">
  129. <img :src="diy_img_prefix + '/static/addons/Pk/del.png'" alt="" @click="delPrize(index)">
  130. </el-tooltip>
  131. </div>
  132. </el-form>
  133. <div style="display: flex;align-items: center;padding-bottom: 10px;border-bottom: 1px solid #E4E7ED;width: 300px;margin:30px 0 20px 0;">
  134. <div style="width: 5px;height: 20px;background-color: #03C5FF;margin-right: 5px;"></div>
  135. <div>分享设置</div>
  136. </div>
  137. <el-form size="small" label-width="150px" style="margin-left: 20px;">
  138. <el-form-item label="自定义分享标题:" style="margin-bottom: 20px" label-width="auto">
  139. <el-input placeholder="请输入自定义分享标题" style="width: 450px;" v-model="submitData.share_title"></el-input>
  140. </el-form-item>
  141. <el-form-item label="自定义分享图:" label-width="auto">
  142. <div style="margin-top: 10px;"><!-- flex="dir:left" -->
  143. <template v-if="submitData.share_pic"><!-- v-if="ruleForm.pic_url.length" -->
  144. <draggable><!-- flex="dif:left" -->
  145. <div style="margin-bottom: 20px;position: relative;cursor: move;background-color: #eee;display: flex;align-items: flex-end;width:100px"><!-- v-for="(item,index) in pic_url" :key="index" -->
  146. <com-image mode="aspectFill" width="100px"
  147. height='100px' :src="submitData.share_pic">
  148. </com-image>
  149. <el-button class="del-btn" size="mini" type="danger"
  150. icon="el-icon-close" circle style="position: absolute;top:-10px;right:-10px"
  151. @click="delPic()">
  152. </el-button>
  153. </div>
  154. </draggable>
  155. </template>
  156. <div v-if="!submitData.share_pic"><!-- v-if="ruleForm.pic_url.length < 9" -->
  157. <com-attachment style="margin-bottom: 10px;" :multiple="false"
  158. :max="1" @selected="picUrl">
  159. <!-- <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 750"
  160. placement="top"> -->
  161. <div flex="main:center cross:center" class="add-image-btn">
  162. + 添加图片
  163. </div>
  164. <!-- </el-tooltip> -->
  165. </com-attachment>
  166. </div>
  167. </div>
  168. </el-form-item>
  169. </el-form>
  170. <el-input
  171. placeholder="创建时间戳"
  172. style="width: 450px;"
  173. v-model="submitData.created_at"
  174. type="hidden"
  175. maxlength="10"
  176. show-word-limit
  177. :rows="2"
  178. >
  179. </el-input>
  180. </div>
  181. <el-button class="button-item" :loading="btnLoading" type="primary" @click="saveFun"
  182. size="small">保存
  183. </el-button>
  184. </el-card>
  185. </div>
  186. <script>
  187. const app = new Vue({
  188. el: '#app',
  189. data() {
  190. return {
  191. diy_img_prefix: '<?= Yii::getAlias('@attachurl') ?>',
  192. isDataSelect:false,
  193. titleName:"添加个人PK",
  194. loading:false,
  195. submitData:{
  196. name:'',
  197. performance_type:1,
  198. /* team_max_amount:1, */
  199. people_max_amount:'',
  200. price:0,
  201. begin_time:'',
  202. settlement_type:1,
  203. end_time:'',
  204. is_enable:1,
  205. prize:[],
  206. share_title:'',
  207. share_pic:'',
  208. time:'',
  209. activity_type:1,
  210. created_at: 0,
  211. updated_at: 0,
  212. },
  213. rules: {
  214. name: [
  215. { required: true, message: '请输入活动名称', trigger: 'blur' }
  216. ],
  217. people_max_amount: [
  218. { required: true, message: '请输入人员数量', trigger: 'blur' }
  219. ],
  220. price: [
  221. { required: true, message: '请输入报名费用,可为0元', trigger: 'blur' }
  222. ],
  223. time: [
  224. { required: true, message: '请选择时间', trigger: 'blur' }
  225. ],
  226. },
  227. prizeObj:{
  228. "prize_level":"",
  229. "prize_name":"",
  230. "prize_amount":'',
  231. "winner_amount":'',
  232. "prize_price": '',
  233. "extra_add": 0
  234. },
  235. team_max_amount_flag:true,
  236. people_max_amount_flag:false,
  237. btnLoading:false,
  238. radio:2,
  239. is_no_restrictions:false,
  240. time:'',
  241. is_team_audit:1,
  242. pic_url: [],
  243. pickerOptions: {
  244. shortcuts: [{
  245. text: '最近一周',
  246. onClick(picker) {
  247. const end = new Date();
  248. const start = new Date();
  249. /* start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  250. picker.$emit('pick', [start, end]); */
  251. end.setTime(start.getTime() + 3600 * 1000 * 24 * 7);
  252. picker.$emit('pick', [start, end]);
  253. }
  254. }, {
  255. text: '最近一个月',
  256. onClick(picker) {
  257. const end = new Date();
  258. const start = new Date();
  259. /* start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  260. picker.$emit('pick', [start, end]); */
  261. end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
  262. picker.$emit('pick', [start, end]);
  263. }
  264. }, {
  265. text: '最近三个月',
  266. onClick(picker) {
  267. const end = new Date();
  268. const start = new Date();
  269. /* start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  270. picker.$emit('pick', [start, end]); */
  271. end.setTime(start.getTime() + 3600 * 1000 * 24 * 90);
  272. picker.$emit('pick', [start, end]);
  273. }
  274. }]
  275. },
  276. };
  277. },
  278. mounted() {
  279. this.submitData.created_at = Date.parse(new Date()) / 1000; // 新建数据的创建时间
  280. this.submitData.updated_at = Date.parse(new Date()) / 1000; // 新建数据的更新时间
  281. /* this.submitData.team_max_amount = -1;
  282. this.submitData.people_max_amount = -1; */
  283. this.people_max_amount_flag = true;
  284. this.submitData.prize.push(JSON.parse(JSON.stringify(this.prizeObj)));
  285. //console.log('进来页面获取的参数id='+getQuery('id'))
  286. if (getQuery('id')) {
  287. this.titleName="编辑个人PK";
  288. this.isDataSelect = true;
  289. //this.getWeightsLevel = getQuery('level');
  290. this.loadData(getQuery('id'));//请求详情的数据
  291. }
  292. },
  293. watch:{
  294. },
  295. methods: {
  296. changeInput2(){
  297. var pattern = /^[1-9][0-9]*$/ // 正整数的正则表达式
  298. // 不符合正整数时
  299. if (!pattern.test(this.submitData.people_max_amount)) {
  300. // input 框绑定的内容为空
  301. this.submitData.people_max_amount = ''
  302. }
  303. },
  304. changeInput3(){
  305. var str = this.submitData.price;
  306. var len1 = str.substr(0, 1)
  307. var len2 = str.substr(1, 1)
  308. //如果第一位是0,第二位不是点,就用数字把点替换掉
  309. if (str.length > 1 && len1 == 0 && len2 != ".") {
  310. str = str.substr(1, 1)
  311. }
  312. //第一位不能是.
  313. if (len1 == ".") {
  314. str = ""
  315. }
  316. //限制只能输入一个小数点
  317. if (str.indexOf(".") != -1) {
  318. var str_ = str.substr(str.indexOf(".") + 1)
  319. if (str_.indexOf(".") != -1) {
  320. str = str.substr(0, str.indexOf(".") + str_.indexOf(".") + 1)
  321. }
  322. }
  323. //正则替换
  324. str = str.replace(/[^\d^\.]+/g, '') // 保留数字和小数点
  325. str = str.replace(/\.\d\d\d$/,'') // 小数点后只能输两位
  326. this.submitData.price = str;
  327. },
  328. changeInput4(val,index){
  329. var pattern = /^[1-9][0-9]*$/ // 正整数的正则表达式
  330. // 不符合正整数时
  331. if (!pattern.test(val)) {
  332. // input 框绑定的内容为空
  333. this.submitData.prize[index].prize_amount = '';
  334. }
  335. this.submitData.prize[index].prize_amount = this.submitData.prize[index].prize_amount.substr(0,6);
  336. },
  337. changeInput5(val,index){
  338. var pattern = /^[1-9][0-9]*$/ // 正整数的正则表达式
  339. // 不符合正整数时
  340. if (!pattern.test(val)) {
  341. // input 框绑定的内容为空
  342. this.submitData.prize[index].winner_amount = '';
  343. }
  344. this.submitData.prize[index].winner_amount = this.submitData.prize[index].winner_amount.substr(0,6);
  345. },
  346. saveFun(){
  347. if(this.people_max_amount_flag){
  348. this.submitData.people_max_amount = -1;
  349. }
  350. this.$refs['ruleForm'].validate((valid) => {
  351. if (valid) {
  352. if(this.submitData.prize.length > 0){
  353. for(var i=0;i<this.submitData.prize.length;i++){
  354. for(let item2 in this.submitData.prize[i]){
  355. if(this.submitData.prize[i][item2] === '' || this.submitData.prize[i][item2] === null){
  356. return this.$message.error('请完善奖品信息');
  357. break;
  358. }
  359. }
  360. }
  361. }
  362. /* if(this.pic_url[0]){
  363. this.submitData.share_pic = this.pic_url[0].pic_url;
  364. } */
  365. let data =JSON.parse(JSON.stringify(this.submitData));
  366. data.prize =JSON.stringify(data.prize);
  367. /* this.submitData.prize = JSON.stringify(this.submitData.prize) */
  368. this.btnLoading = true;
  369. let url;
  370. if(this.submitData.id){//全更新
  371. url = 'pk/personal/patch'
  372. }else{//添加
  373. url = 'pk/personal/patch'
  374. }
  375. request({
  376. params: {
  377. r:url,
  378. },
  379. method: 'post',
  380. data: data
  381. }).then(e => {
  382. this.btnLoading = false;
  383. if (e.data.code == 0) {
  384. this.$message.success(e.data.msg);
  385. navigateTo({
  386. r: 'pk/personal/index',
  387. });
  388. } else {
  389. this.$message.error(e.data.msg);
  390. }
  391. }).catch(e => {
  392. this.$message.error(e);
  393. this.btnLoading = false;
  394. })
  395. } else {
  396. this.$message.error('请填写必要的参数!');
  397. return false;
  398. }
  399. });
  400. },
  401. picUrl(e) {
  402. if (e.length) {
  403. /* let self = this;
  404. e.forEach(function (item, index) {
  405. if (self.pic_url.length >= 9) {
  406. return;
  407. }
  408. self.pic_url.push({
  409. url:'',
  410. pic_url: item.url
  411. });
  412. )
  413. }); */
  414. this.submitData.share_pic = e[0].url;
  415. }
  416. },
  417. delPic(index) {
  418. /* this.pic_url.splice(index, 1) */
  419. this.submitData.share_pic = '';
  420. },
  421. datetimeChange(){
  422. //console.log(this.time[0])
  423. if(this.submitData.time){
  424. this.submitData.begin_time = this.submitData.time[0];
  425. this.submitData.end_time = this.submitData.time[1];
  426. }
  427. },
  428. addPrize(){
  429. this.submitData.prize.push(JSON.parse(JSON.stringify(this.prizeObj)));
  430. },
  431. delPrize(index){
  432. this.submitData.prize.splice(index,1)
  433. },
  434. loadData(id){
  435. this.loading = true;
  436. request({
  437. params: {
  438. r:'pk/personal/personal-add',
  439. id:id
  440. },
  441. method: 'get',
  442. }).then(e => {
  443. this.loading = false;
  444. if (e.data.code == 0) {
  445. this.submitData = e.data.data;
  446. this.submitData.time = [e.data.data.begin_time,e.data.data.end_time]
  447. if(this.submitData.people_max_amount == -1){
  448. this.people_max_amount_flag = true;
  449. this.submitData.people_max_amount = '';
  450. }else{
  451. this.people_max_amount_flag = false;
  452. }
  453. } else {
  454. this.$message.error(e.data.msg);
  455. }
  456. }).catch(e => {
  457. this.loading = false;
  458. });
  459. }
  460. }
  461. });
  462. </script>
  463. <style>
  464. .form-body {
  465. padding: 20px;
  466. background-color: #fff;
  467. margin-bottom: 20px;
  468. padding-right: 20%;
  469. min-width: 900px;
  470. }
  471. .form-body .el-form-item {
  472. padding-right: 25%;
  473. min-width: 850px;
  474. }
  475. .form-button {
  476. margin: 0;
  477. }
  478. .form-button .el-form-item__content {
  479. margin-left: 0 !important;
  480. }
  481. .button-item {
  482. padding: 9px 25px;
  483. }
  484. .check-group {
  485. font-size: 14px !important;
  486. }
  487. .check-group .el-col {
  488. display: flex;
  489. }
  490. .check-group .el-input {
  491. margin: 0 5px;
  492. }
  493. .check-group .el-col .el-checkbox {
  494. display: flex;
  495. align-items: center;
  496. }
  497. .check-group .el-col .el-input {
  498. width: 100px;
  499. }
  500. .check-group .el-col .el-input .el-input__inner {
  501. height: 30px;
  502. width: 100px;
  503. }
  504. .el-checkbox-group .el-col {
  505. margin-bottom: 10px;
  506. }
  507. .add-image-btn {
  508. width: 100px;
  509. height: 100px;
  510. color: #419EFB;
  511. border: 1px solid #e2e2e2;
  512. cursor: pointer;
  513. }
  514. </style>