goods.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('com-dialog-select');
  4. ?>
  5. <div id="app" v-cloak>
  6. <el-card class="box-card" shadow="never" style="border:0;min-width: 1000px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  7. <div slot="header">
  8. <div>
  9. <span>商品设置</span>
  10. </div>
  11. </div>
  12. <div class="form_box">
  13. <el-form :model="formData" :rules="rules" size="small" ref="ruleForm" label-width="160px" v-loading="loading">
  14. <el-card shadow="never">
  15. <div>
  16. <el-row>
  17. <el-col :span="16">
  18. <el-form-item label="选择商品:" required label-width="160px">
  19. <com-dialog-select :multiple="true" :extra-search="{from:'lucky_group'}" @selected="goodsSelect" title="商品选择">
  20. <el-button type="primary">选择商品</el-button>
  21. </com-dialog-select>
  22. <el-table max-height="400" :data="goods_list" size="small" stripe border style="width: 100%;margin-top: 20px;">
  23. <el-table-column type="index" label="序号" align="center" width="60">
  24. </el-table-column>
  25. <el-table-column prop="goods_id" label="商品id" align="center" min-width="80">
  26. </el-table-column>
  27. <el-table-column label="商品信息" min-width="150">
  28. <template slot-scope="scope">
  29. <div style="display: flex;align-items: center;">
  30. <el-image fit="cover" :src="scope.row.cover_pic" style="width: 40px;height: 40px;display: block;margin-right: 5px;flex-shrink: 0;"></el-image>
  31. <div>
  32. <div>{{scope.row.goods_name}}</div>
  33. </div>
  34. </div>
  35. </template>
  36. </el-table-column>
  37. <el-table-column prop="price" label="售价(元)" align="center" min-width="80">
  38. </el-table-column>
  39. <el-table-column label="商品状态" align="center" min-width="80">
  40. <template slot-scope="scope">
  41. <el-tag type="success" effect="dark" v-if="scope.row.status == 1">销售中</el-tag>
  42. <el-tag type="danger" effect="dark" v-else>下架</el-tag>
  43. </template>
  44. </el-table-column>
  45. <el-table-column prop="goods_stock" label="库存" align="center" min-width="80">
  46. </el-table-column>
  47. <el-table-column prop="num" label="操作" align="center" min-width="80">
  48. <template slot-scope="scope">
  49. <el-button type="danger" @click="delFun(scope.$index)">删除</el-button>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. </el-form-item>
  54. <el-form-item label="抽取交易额:" required label-width="160px">
  55. <el-input placeholder="请输入百分比" style="width: 200px;" v-model="formData.price" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
  56. <template slot="append">%</template>
  57. </el-input>
  58. </el-form-item>
  59. </el-col>
  60. </el-row>
  61. </div>
  62. </el-card>
  63. </el-form>
  64. <el-button :loading="btnLoading" class="button-item" type="primary" style="margin-top: 24px;" @click="save" size="small">
  65. 保存
  66. </el-button>
  67. </div>
  68. </el-card>
  69. </div>
  70. <script>
  71. const app = new Vue({
  72. el: '#app',
  73. data() {
  74. return {
  75. formData: {
  76. goods_ids: '',
  77. price:0
  78. },
  79. loading: false,
  80. btnLoading: false,
  81. goods_list: [],
  82. rules: {},
  83. cateLists: [{
  84. id: 1,
  85. sort: 1,
  86. title: '分类1'
  87. }],
  88. }
  89. },
  90. created() {
  91. this.id = getQuery('id');
  92. },
  93. mounted: function() {
  94. this.loadData(this.id);
  95. },
  96. methods: {
  97. // 选中商品处理
  98. goodsSelect(param) {
  99. for (let j in param) {
  100. let item = param[j];
  101. let flag = true;
  102. for (let i in this.goods_list) {
  103. if (this.goods_list[i].goods_id == item.id) {
  104. flag = false;
  105. break;
  106. }
  107. }
  108. if (flag) {
  109. this.goods_list.push({
  110. goods_id: item.id,
  111. price: item.price,
  112. status: item.status,
  113. goods_stock: item.stock,
  114. goods_name: item.goods_name,
  115. cover_pic: item.cover_pic,
  116. });
  117. }
  118. }
  119. },
  120. // 删除商品
  121. delFun(index) {
  122. this.goods_list.splice(index, 1)
  123. },
  124. save() {
  125. let arr = []
  126. let arrs = []
  127. let forNum = this.goods_list.length;
  128. for (let i = 0; i < forNum; i++) {
  129. let item = this.goods_list[i];
  130. arr.push(item.goods_id)
  131. }
  132. this.formData.goods_ids = arr.join(',');
  133. this.formData.percent = Math.abs(this.formData.percent);
  134. // console.log(this.formData);return null;
  135. this.$refs['ruleForm'].validate((valid) => {
  136. if (valid) {
  137. if (!this.formData.goods_ids) return this.$message.error("请选择商品");
  138. if (this.btnLoading) return;
  139. this.btnLoading = true;
  140. request({
  141. params: {
  142. r: 'boss-three/default/goods',
  143. id: this.id
  144. },
  145. method: 'post',
  146. data: this.formData
  147. }).then(e => {
  148. this.btnLoading = false;
  149. if (e.data.code == 0) {
  150. this.$navigate({
  151. r: 'boss-three/default/goods',
  152. id: this.id
  153. })
  154. this.$message.success(e.data.msg);
  155. } else {
  156. this.btnLoading = false;
  157. this.$message.error(e.data.msg);
  158. }
  159. }).catch(e => {
  160. console.log(e);
  161. this.$message.error('网络错误');
  162. this.btnLoading = false;
  163. })
  164. } else {
  165. this.$message.error('请填写必要的参数!');
  166. return false;
  167. }
  168. });
  169. },
  170. loadData(id) {
  171. if (this.loading === true) return;
  172. this.loading = true;
  173. request({
  174. params: {
  175. r: 'boss-three/default/goods',
  176. id: id
  177. },
  178. method: 'get'
  179. }).then(e => {
  180. // console.log('======== loadData result: ', e);
  181. this.loading = false;
  182. if (e.data.code == 0) {
  183. this.goods_list = e.data.data.goods_list;
  184. this.formData.price = e.data.data.data.price;
  185. }
  186. }).catch(e => {
  187. this.loading = false;
  188. })
  189. },
  190. },
  191. });
  192. </script>
  193. <style>
  194. .form_box {
  195. /* background-color: #f3f3f3;
  196. padding: 0 0 20px; */
  197. background-color: #fff;
  198. padding: 20px;
  199. }
  200. .button-item {
  201. margin-top: 12px;
  202. padding: 9px 25px;
  203. }
  204. .el-input-group__append {
  205. background-color: #fff;
  206. color: #353535;
  207. }
  208. .el-card__body {
  209. padding: 0;
  210. }
  211. .el-card {
  212. border: none;
  213. }
  214. .el-table thead {
  215. font-size: 14px;
  216. color: #333;
  217. }
  218. /* .el-table__footer-wrapper, .el-table__header-wrapper{
  219. border-bottom: 1.4px solid #D6D6D6;
  220. } */
  221. .dialogClass .el-dialog__body {
  222. padding-bottom: 0;
  223. }
  224. .el-date-editor .el-range-separator {
  225. /* 设置选择日期框的中间的 ‘至’ 的宽度 */
  226. width: 8%;
  227. }
  228. .el-textarea__inner {
  229. display: block;
  230. resize: vertical;
  231. padding: 5px 15px !important;
  232. }
  233. .el-input-number .el-input__inner {
  234. text-align: left;
  235. }
  236. /* .edui-default .edui-editor{
  237. height: 250px;
  238. } */
  239. </style>